帅帅男孩 发表于 2018-11-22 12:48:22

apache2.4.9 + php5.5.12 + nagios4.0.5 安装指南

1、下载apache所需软件包
安装apache2.4.9必须先安装apr、apr-util、pcre包
apr-1.5.1.tar.gzapr-util-1.5.3.tar.gzcd.shhttpd-2.4.9.tar.gzpcre-8.33.zip
2、安装
# 解压缩
tar fvxz apr-1.5.1.tar.gz
tar fvxz apr-util-1.5.3.tar.gz
tar httpd-2.4.9.tar.gz
tar fvxz httpd-2.4.9.tar.gz
tar fvxz pcre-8.33.zip
unzip pcre-8.33.zip
# 编译安装apr
cd /data/apr-1.5.1
./configure --prefix=/usr/local/apr
make && make install
# 编译安装apr-util
cd ../apr-util-1.5.3
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
make && make install
# 编译安装pcre
cd ../pcre-8.33
./configure --prefix=/usr/local/pcre
make && make install
# 编译安装apache
# 安装之前请确保系统之前预装的httpd已被卸载
cd ../httpd-2.4.9
# 参数依次是: httpd安装路径httpd配置文件存放路径启用模块化方式启用ssl安全连接# 启用cgi脚本功能启用url重写启用服务器压缩启用正则表达式支持    apr安装路径
# apr util安装路径   启用常用模块以确保apache正常工作    将多进程模型非静态化
# 启用事件异步模型
./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd
--enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib
--with-pcre=/usr/local/pcre --with-apr=/usr/local/apr
--with-apr-util=/usr/local/apr-util/ --enable-modules=most
--enable-mpms-shared=all --with-mpm=event
make && make install3、错误提示
安装openssl依赖关系 即可解决下面问题
checking whether to enable mod_ssl... configure:
error: mod_ssl has been requested but can not be built due to prerequisite failures

4、启动&测试
# /usr/local/apache/bin/apachectl start

如果成功,可以停止 Apache 服务器并继续安装 PHP:

/usr/local/apache2/bin/apachectl stop
OR
/usr/local/apache/bin/apachectl -k stop(推荐)

5、安装php5.5.12
tar fvxz php-5.5.12.tar.gz
./configure --prefix=/usr/local/php5 --with-apxs2=/usr/local/apache/bin/apxs
make && make install
6、配置php.ini
cp php.ini-development /usr/local/lib/php.ini
7、编辑 httpd.conf 文件以调用 PHP 模块。LoadModule 达式右边的路径必须指向系统中的 PHP 模块。以上的 make install 命令可能已经完成了这些,但务必要检查
LoadModule php5_module modules/libphp5.so

8、apache解析php,添加如下内容:
# 让Apache将扩展名.php 解析成 PHP。为了避免潜在的危险,例如上传或者创建类似 exploit.php.jpg 的文件并被当做 PHP 执行,我们不再使用 Apache 的 AddType 指令来设置。

    SetHandler application/x-httpd-php

# 将.php,.php2,.php3,.php4,.php5,.php6,以及.phtml文件都当做PHP来运行

    SetHandler application/x-httpd-php

# .phps 文件由 PHP 源码过滤器处理,使得其在显示时可以高亮源码

    SetHandler application/x-httpd-php-source

# mod_rewrite也有助于将那些不需要运行的.php文件的源码高亮显示,而并不需要将他们更名.phps文件
RewriteEngine On
RewriteRule (.*\.php)s$ $1   9、安装nagios及插件

    1.创建nagios用户和用户在
      # useradd -s /sbin/nologin nagios
      # mkdir /usr/local/nagios
      # chown -R nagios.nagios /usr/local/nagios
    2. 编译安装nagios
      # tar fvxz nagios-4.0.5.tar.gz
      # cd nagios-4.0.5
      # ./configure -prefix=/usr/local/nagios
      指定nagios的安装目录,这里指定安装在/usr/local/nagios目录下
      # make all && make install
      通过make install命令来安装nagios主程序的CGI和HTML文件
      # make install-init
      通过make install-init命令可以在/etc/rc.d/init.d目录下创建nagios启动脚本
      # make install-commandmode
      通过make install-commandmode命令来配置目录权限
      # make install-config
      通过make install-config命令来安装nagios示例配置文件,这里安装路径是/usr/local/nagios/etc
    3.设置开机自启动
      # chkconfig --add nagios
      # chkconfig --level 35 nagios on
      # chkconfig --list nagios
    nagios    0:off    1:off    2:off    3:on    4:on    5:on    6:off
    4.安装nagios插件
      # tar fvxz nagios-plugins-2.0.tar.gz
      # cd nagios-plugins-2.0
      # ./configure --prefix=/usr/local/nagios
      # make && make install
      插件的安装最好喝nagios安装路径一致,这样插件会在nagios主程序目录(即/usr/local/nagios下的libexec目录)生成很多可执行文件
    5.安装nagios汉化插件
      # tar jvxf nagios-cn-3.2.3.tar.bz2
      # cd nagios-cn-3.2.3
      # ./configure
      # make all && make install  10、配置apache
# vim /etc/httpd/httpd.conf
          user daemon   #修改为nagios
          group daemon    #修改为nagios
      
            DirectoryIndex index.html index.php #增加index.php
      
      LoadModule php5_module      modules/libphp5.so# 去掉前面注释
      
      在最后增加如下内容:
      ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin"

      AuthType      Basic
      Options         ExecCGI
      AllowOverride   None
      Order allow,deny
      Allow   from    all
      AuthName      "Nagios Access"
      AuthUserFile    /usr/local/nagios/etc/htpasswd
      Require valid-user

Alias   /nagios "/usr/local/nagios/share"

      AuthType      Basic
      Options None
      AllowOverride   None
      Order   allow,deny
      Allow   from    all
      AuthName      "Nagios Access"
      AuthUserFile    /usr/local/nagios/etc/htpasswd
      Require valid-user

AddType application/x-httpd-php .php  11、创建apache目录验证文件
# /usr/local/apache2/bin/htpasswd \
> -c /usr/local/nagios/etc/htpasswd nagios
New password: (输入密码)
Re-type new password: (在输入一次密码)
Adding password for user nagios  12、关闭selinx 和 iptables服务
两种方法:
第一种最直接,关闭 SELinux,对于 SELinux 不是很熟悉的用户,请选择此。
# cat /etc/sysconfig/selinux
SELINUX=disabled
第二种给打上正确的安全脉络。
chcon -R -t httpd_sys_content_t /usr/local/nagios/sbin/
chcon -R -t httpd_sys_content_t /usr/local/nagios/share/
# /etc/init.d/iptables stop  

  13、启动apache和nagios服务
# /usr/local/apache/bin/apachectl start
# /etc/init.d/nagios start  14、验证nagios页面
15、错误提示
  用IE浏览器提示乱码错误 或 提示需要下载.cgi 弹窗


  

  此时要修改apache配置文件
# vi /etc/httpd/httpd.conf
    找到 并去除前面的注释即可
    LoadModule cgi_module modules/mod_cgi.so  

  16、重新启动apache服务即可

# /usr/local/apache/bin/apachectl -k stop
# /usr/local/apache/bin/apachectl start  

  17、nagios配置文件介绍
cgi.cfg  控制CGI访问的配置文件
nagios.cfgnagios主配置文件resource.cfg变量定义文件,又称为资源文件;此文件中定义变量,以便由其他配置文件引用,如$USER1$objectsobjects目录下有很大配置文件模板,用于定义nagios对象objects/commands.cfg命令定义配置文件,其中定义的命令可以被其他配置文件所引用
objects/contacts.cfg定义联系人和联系人组的配置文件objects/localhost.cfg定义监控本地主机的配置文件objects/printer.cfg定义监控打印机的一个配置文件模板,默认没有启动objects/switch.cfg监控路由器的一个配置文件模板,默认没有启动objects/templates.cfg8定义主机和服务的一个模板配置文件,可以在其他配置文件中引用objects/timeperiods.cfg定义nagios监控时间段的配置文件objects/windows.cfg
监控windows主机的配置文件模板,默认没有启动  18、配置文件
1.主机定义文件
定义你要监控的对象,这里定义的 host_name 被应用到其它的所有配置文件中,这个是我们配
置 Nagios 必须修改的配置文件。
# vi /usr/local/nagios/etc/objects/hosts.cfg
define host{
host_name   Nagios-Server #设置主机的名字,该名字会出现在hostgroups.cfg 和 services.cfg 中。
alias         Nagios Server    #别名
address       192.168.140.128    #主机的 IP 地址
check_command                check-host-alive    #检查的命令
check_interval               5                   #检测的时间间隔
retry_interval               1                   #检测失败后重试的时间间隔
max_check_attempts         5                   #最大重试次数
check_period               24x7                #检测的时段
process_perf_data            0
retain_nonstatus_information      0
contact_groups                  sagroup      #联系组
notification_interval             30             #通知的时间间隔
notification_period               24x7         #通知的时间段
notification_options            d,u,r          #通知的选项
                                    #w—报警(warning),u—未知(unkown)
                                    #c—严重(critical),r—从异常情况恢复正常
}
define host{
host_name      Nagios-Client
alias            Nagios Client
address                        192.168.140.129
check_command                  check-host-alive
check_interval               5
retry_interval               1
max_check_attempts             5
check_period                   24x7
process_perf_data            0
retain_nonstatus_information   0
contact_groups               sagroup
notification_interval          30
notification_period            24x7
notification_options         d,u,r
}
2.主机组定义文件
将刚才定义的两个主机加入到主机组中,针对生产环境就像把所有的 MySQL 服务器加到一个
MySQL 主机组里,方便管理和查看。
# vi /usr/local/nagios/etc/objects/hostgroups.cfg
define hostgroup {
hostgroup_name          Nagios-Example            #主机组名字
alias                   Nagios Example            #主机组别名
members               Nagios-Server,Nagios-Client #主机组成员,用逗号隔开
}
3.服务定义文件
服务定义文件定义你需要监控的对象的服务,比如本例子为检测主机是否存活,在后面会讲到如
何监控其它服务,比如服务器负载、内存、磁盘等。
# vi /usr/local/nagios/etc/objects/services.cfg
define service {
host_name                Nagios-Server               #主机名
service_description      check-host-alive            #服务描述
check_period             24x7                        #检测的时间段
max_check_attempts      4
normal_check_interval   3
retry_check_interval      2
contact_groups            sagroup
notification_interval   10
notification_period       24x7
notification_options      w,u,c,r
check_command             check-host-alive
}
define service {
host_name                  Nagios-Client
service_description          check-host-alive
check_period               24x7
max_check_attempts            4
normal_check_interval         3
retry_check_interval          2
contact_groups                sagroup
notification_interval         10
notification_period         24x7
notification_options          w,u,c,r
check_command               check-host-alive
}
# vi /usr/local/nagios/etc/objects/servicegroup.cfg
define servicegroup{
servicegroup_name             Host-Alive
alias                         Host Alive
members   Nagios-Server,check-host-alive,Nagios-Client,check-host-alive
}
5 联系人定义文件
# vi /usr/local/nagios/etc/objects/contacts.cfg
define contact{
contact_name                  nagiosadmin
use                           generic-contact
alias                           System Administrator
email                           nagios@localhost
}
6 联系人组定义文件
# vi /usr/local/nagios/etc/objects/contactgroups.cfg
define contactgroup{
contactgroup_name                sagroup
alias                            Nagios Administrators
members                        nagiosadmin
}
7 检测配置是否正确
# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg  




页: [1]
查看完整版本: apache2.4.9 + php5.5.12 + nagios4.0.5 安装指南