设为首页 收藏本站
查看: 836|回复: 0

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

[复制链接]

尚未签到

发表于 2019-1-13 08:01:37 | 显示全部楼层 |阅读模式
  一.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
│   ├── images
│   ├── 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))
  显示效果如下图

  加为系统服务并设置自动启动
  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,和刚设置的密码
  

  页面会显示如下图所示
  






运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-662558-1-1.html 上篇帖子: nagios+plugin+pnp4nagios+rrdtool实现图形化监控 下篇帖子: centos 搭建 nagios 监控系统.
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表