apache编译安装与做nagios前端展示-创新互联-古蔺大橙子建站
RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
apache编译安装与做nagios前端展示-创新互联

一.apache编译安装篇

创新互联不只是一家网站建设的网络公司;我们对营销、技术、服务都有自己独特见解,公司采取“创意+综合+营销”一体化的方式为您提供更专业的服务!我们经历的每一步也许不一定是最完美的,但每一步都有值得深思的意义。我们珍视每一份信任,关注我们的成都网站设计、做网站质量和服务品质,在得到用户满意的同时,也能得到同行业的专业认可,能够为行业创新发展助力。未来将继续专注于技术创新,服务升级,满足企业一站式全网营销推广需求,让再小的品牌网站建设也能产生价值!

1.安装apache需安装以下的几个包,apr 、apr-util、pcre等。

2.下载安装apr

把文件放到/usr/local/src目录下,

tar -zxvf  apr-1.5.2.tar.gz

cd  apr-1.5.2

./configure --prefix=/usr/local/apr

make

make install

3.下载安装apr-util

tar -zxvf apr-util-1.5.4.tar.gz

cd apr-util-1.5.4

./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr#这里配置的时候要指定apr的安装路径。

make

make install

4.安装pcre

tar -zxvf pcre

cd pcre

./configure --prefix=/usr/local/pcre

make && make install

5.安装apache 这里安装的版本是2.4.18,比较新的版本

tar -zxvf httpd-2.4.18.tar.gz

cd httpd-2.4.18

./configure --prefix=/usr/local/apache2 --sysconfdir=/etc/httpd --enable-so --enable-ssl --enable-cgi --enable-cgid --enable-rewrite --enable-deflate --with-z --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre --with-openssl=/usr/local/ssl --enable-modules=most --enable-mpms-shared=all --with-mpm=event

#各编译参数说明

--prefix=/usr/local/apache2 # 家目录

--sysconfdir=/etc/httpd #配置文件目录

--enable-so #加载动态共享对象,可实现模块动态生效

--enable-ssl #支持SSL/TLS,可实现https访问

--enable-ssl #支持CGI脚本(默认对非线程的MPM模式开启)

--enable-rewrite #启用Rewirte功能

--enable-deflate #支持压缩

--with-zlib#指定zlib库,不指定自动寻找

--with-apr=/usr/local/apr #指定apr路径

--with-apr-util=/usr/local/apr-util #指定apr-util路径

--with-pcre=/usr/local/pcre #指定pcre路径

--with-openssl=/usr/local/ssl #指定openssl的路径

--enable-modules=most#指定动态启用的模块

--enable-mpms-shared=all #支持动态加载的MPM模块,可选"all"

--with-mpm=event#设置默认启用的MPM模式

make

make install

6.安装完成后安装目录下会有以下的几个目录

bin  build  cgi-bin  conf  error  htdocs  icons  include  logs  man  manual  modules

[root@sever9 ~]# tree -d /usr/local/apache2#安装目录树
/usr/local/apache2
├── bin#主程序目录
├── build
├── cgi-bin#cgi文件存放目录
├── error#发生错误时返回给客户端的信息
│  └── include
├── htdocs
├── icons#httpd图标文件
│  └── small
├── include#头文件
├── logs#日志文件
├── man#帮助手册
│  ├── man1
│  └── man8
├── manual
│  ├── developer
│  ├── faq
│  ├── howto
│  ├── p_w_picpaths
│  ├── misc
│  ├── mod
│  ├── platform
│  ├── programs
│  ├── rewrite
│  ├── ssl
│  ├── style
│  │  ├── css
│  │  ├── lang
│  │  ├── latex
│  │  ├── scripts
│  │  └── xsl
│  │      └── util
│  └── vhosts
└── modules#模块文件

7.配置目录下的文件

[root@sever9 httpd]# tree /etc/httpd
/etc/httpd
├── extra#扩展的配置文件
│  ├── httpd-autoindex.conf
│  ├── httpd-dav.conf
│  ├── httpd-default.conf
│  ├── httpd-info.conf
│  ├── httpd-languages.conf
│  ├── httpd-manual.conf
│  ├── httpd-mpm.conf
│  ├── httpd-multilang-errordoc.conf
│  ├── httpd-ssl.conf
│  ├── httpd-userdir.conf
│  ├── httpd-vhosts.conf
│  └── proxy-html.conf
├── httpd.conf#主配置文件
├── magic
├── mime.types
└── original
   ├── extra
   │  ├── httpd-autoindex.conf
   │  ├── httpd-dav.conf
   │  ├── httpd-default.conf
   │  ├── httpd-info.conf
   │  ├── httpd-languages.conf
   │  ├── httpd-manual.conf
   │  ├── httpd-mpm.conf
   │  ├── httpd-multilang-errordoc.conf
   │  ├── httpd-ssl.conf
   │  ├── httpd-userdir.conf
   │  ├── httpd-vhosts.conf
   │  └── proxy-html.conf
   └── httpd.conf

8.修改配置文件

vim /etc/httpd/httpd.conf

找到下面的该行,把监听端口改成本地的80

#ServerName www.example.com:80

ServerName  localhost:80

修改httpd的主配置文件,设置Pid文件的路径

PidFile "/var/run/httpd.pid"
修改系统的PATH环境变量,让/usr/local/apache2/bin目录下的命令都可以执行:

vim /etc/profile.d/httpd.sh

export PATH=/usr/local/apache2/bin:$PATH

source /etc/profile.d/httpd.sh

检查下语法

[root@sever9 ~]# httpd -t
Syntax OK
导出头文件

ln -sv /usr/local/apache2/include /usr/local/include/httpd

`/usr/local/include/httpd' -> `/usr/local/apache2/include'

导出man手册,可以用man httpd查看http的命令

vim /etc/man.config

MANPATH /usr/local/apache2/man

9.编辑服务脚本

vim /etc/init.d/httpd

#!/bin/bash
#
# httpd  Startup script for the Apache HTTP Server
#
# chkconfig: - 85 15
# description: Apache is a World Wide Web server. It is used to serve \
#  HTML files and CGI.
# processname: httpd
# config: /etc/httpd/httpd.conf
# config: /etc/sysconfig/httpd
# pidfile: /var/run/httpd.pid
# Source function library.
. /etc/rc.d/init.d/functions
if [ -f /etc/sysconfig/httpd ]; then
   . /etc/sysconfig/httpd
fi
# Start httpd in the C locale by default.
HTTPD_LANG=${HTTPD_LANG-"C"}
# This will prevent initlog from swallowing up a pass-phrase prompt if
# mod_ssl needs a pass-phrase from the user.
INITLOG_ARGS=""
# Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server
# with the thread-based "worker" MPM; BE WARNED that some modules may not
# work correctly with a thread-based MPM; notably PHP will refuse to start.
# Path to the apachectl script, server binary, and short-form for messages.
apachectl=/usr/local/apache2/bin/apachectl#apache 控制脚本路径httpd=${HTTPD-/usr/local/apache2/bin/httpd}#apache 主程序的路径

prog=httpd
pidfile=${PIDFILE-/var/run/httpd.pid}#注意该http.pid文件的路径lockfile=${LOCKFILE-/var/lock/subsys/httpd}
RETVAL=0
start() {
 echo -n $"Starting $prog: "
 LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS
 RETVAL=$?
 echo
 [ $RETVAL = 0 ] && touch ${lockfile}
 return $RETVAL
}
stop() {
  echo -n $"Stopping $prog: "
  killproc -p ${pidfile} -d 10 $httpd
  RETVAL=$?
  echo
  [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
}
reload() {
 echo -n $"Reloading $prog: "
 if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; then
   RETVAL=$?
   echo $"not reloading due to configuration syntax error"
   failure $"not reloading $httpd due to configuration syntax error"
 else
   killproc -p ${pidfile} $httpd -HUP
   RETVAL=$?
 fi
 echo
}
# See how we were called.
case "$1" in
start)
 start;;
stop)
 stop;;
status)
 status -p ${pidfile} $httpd
 RETVAL=$?;;
restart)
 stop
 start;;
condrestart)
 if [ -f ${pidfile} ] ; then
   stop
   start
 fi;;
reload)
 reload;;
graceful|help|configtest|fullstatus)
 $apachectl $@
 RETVAL=$?;;
*)
 echo $"Usage: $prog {start|stop|restart|condrestart|reload|status|fullstatus|graceful|help|configtest}"
 exit 1
esac
exit $RETVAL

10.为脚本加执行权限,并启动测试

chmod +x /etc/init.d/httpd

[root@sever9 ~]# chmod +x /etc/rc.d/init.d/httpd
[root@sever9 ~]# service httpd start
Starting httpd:                                           [ OK ]
查看监听的端口

[root@sever9 ~]# ss -tnlp

LISTEN     0     128                                                                     :::80                                                                     :::*     users:(("httpd",16817,4),("httpd",16819,4),("httpd",16820,4),("httpd",16821,4))

显示效果如下图

apache 编译安装与做nagios前端展示

加为系统服务并设置自动启动

chkconfig --add httpd

chkconfig httpd on

二.做nagios前端展示篇

1.编译安装php

这里我们安装的版本是5.6.11,

tar -jxvf php-5.6.11.tar.bz2

cd php-5.6.11

./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs

make && make install

2.配置apache支持nagios

修改/etc/httpd/httpd.conf的文件

把 User deamon
Group deamon

改为

User nagios

Group nagios

然后找到

DirectoryIndex index.html

修改为

DirectoryIndex index.html index.php

AddType application/x-httpd-php .php

再找到模块项,把下面的几个模块选项注释去掉。

LoadModule cgid_module modules/mod_cgid.so

LoadModule actions_module modules/mod_actions.so

为了安全起见,一般情况下要让nagios 的web监控页面必须经过授权才能访问,这需要增加验证配置,即在httpd.conf文件最后添加如下信息:

定义别名:

ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin"#nagiosCGI脚本位置

#  SSLRequireSSL

  Options ExecCGI

  AllowOverride None

   Require all granted

#  Allow from 127.0.0.1

  AuthName "Nagios Access"

  AuthType Basic

  AuthUserFile /usr/local/nagios/etc/htpasswd.users#nagios用户认证文件

  Require valid-user

Alias /nagios "/usr/local/nagios/share"#访问网页文件路径别名

#  SSLRequireSSL

  Options None

  AllowOverride None

  Require all granted

#  Order deny,allow

#  Deny from all

#  Allow from 127.0.0.1

  AuthName "Nagios Access"

  AuthType Basic

  AuthUserFile /usr/local/nagios/etc/htpasswd.users

  Require valid-user

3.创建apache目录验证文件

在上面的配置中,指定了目录验证文件htpasswd,下面要创建这个文件:

/usr/local/apache2/bin/htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

New password:

Re-type new password:

Adding password for user nagiosadmin

4.关闭并重启apache

service httpd restart

启动apache,报403拒绝访问,这里是2.4*的版本

要在httpd.conf里改配置文件

  AllowOverride none

  Require all denied

改为

  AllowOverride none

  Require all granted

并重启apache

nagios展示效果:

打开

http://172.30.65.169/nagios/的页面,输入nagios认证用户名nagiosadmin,和刚设置的密码

页面会显示如下图所示

apache 编译安装与做nagios前端展示

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


当前文章:apache编译安装与做nagios前端展示-创新互联
网页地址:http://scgulin.cn/article/djhogp.html