文章很粗糙,主要记录本身安装过程php
apache+php+nagios
1.安装apache+php
1.1 apache安装
tar jxvf apr-1.4.6.tar.bz2
[root@open-source src]# cd apr-1.4.6
[root@open-source apr-1.4.6]# ./configure --prefix=/usr/local/apr
[root@open-source apr-1.4.6]# make && make install
[root@open-source src]# tar zxvf apr-util-1.3.9.tar.gz
[root@open-source src]# cd apr-util-1.3.9
[root@open-source apr-util-1.3.9]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[root@open-source apr-util-1.3.9]# make && make install
[root@open-source src]# tar zxvf httpd-2.4.7.tar.gz ^C
[root@open-source src]# cd httpd-2.4.7
[root@open-source httpd-2.4.7]# ./configure --prefix=/usr/local/app/apache2 --enable-dav --enable-so \
--enable-maintainer-mode --enable-rewrite --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util \
--with-pcre=/usr/local/pcre
[root@open-source httpd-2.4.7]# make && make install
1.2 php安装
[root@open-source php-5.5.5]# ./configure --prefix=/usr/local/php5 \
--with-apxs2=/usr/local/app/apache2/bin/apxs --with-config-file-path=/usr/local/php/etc \
--with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-iconv-dir \
--with-freetype-dir=/usr/local/libs --with-jpeg-dir=/usr/local/libs --with-png-dir=/usr/local/libs \
--with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop \
--enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-fpm --enable-mbstring \
--with-mcrypt=/usr/local/libs --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl \
--enable-sockets --with-xmlrpc --enable-zip --enable-soap --enable-opcache --with-pdo-mysql \
--enable-maintainer-zts --enable-fpm
make && make install
2.nagios安装配置
2.1 nagios安装
[root@open-source src]# useradd -s /sbin/nologin nagios
[root@open-source src]# mkdir /usr/local/nagios
[root@open-source src]# chown nagios.nagios /usr/local/nagios -R
[root@open-source src]# tar zxvf nagios-3.4.3.tar.gz
[root@open-source src]# cd nagios
[root@open-source nagios]# ./configure --prefix=/usr/local/nagios
[root@open-source nagios]# make all
[root@open-source nagios]# make install
[root@open-source nagios]# make install-commandmode
[root@open-source nagios]# make install-config
[root@open-source nagios]# make install-init
2.2 nagios 添加自启动
[root@open-source nagios]# chkconfig --add nagios
[root@open-source nagios]# chkconfig --level 35 nagios on
[root@open-source nagios]# chkconfig --list nagios
安装nagios插件
[root@open2 src]# cd nagios-plugins-1.4.16
[root@open2 nagios-plugins-1.4.16]# ./configure prefix=/usr/local/nagios
[root@open2 nagios-plugins-1.4.16]# make && make install
2.3 配置apache支持php
找到apache 的配置文件/usr/local/apache2/conf/httpd.conf
找到:
User daemon
Group daemon
修改成
User nagios
Group nagios
而后找到
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
修改成
<IfModule dir_module>
DirectoryIndex index.html index.php
</IfModule>
接着增长以下内容:
AddType application/x-httpd-php .php
2.4 配置apache对nagios设置
为了安全起见,通常状况下要让nagios 的web 监控页面必须通过受权才能访问,这须要增长验证配置,即在httpd.conf 文件最后添加以下信息:
复制代码
#setting for nagios
ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin"
<Directory "/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
</Directory>
Alias /nagios "/usr/local/nagios/share"
<Directory "/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
</Directory>
2.5 添加nagios登陆帐号密码
/usr/local/app/apache2/bin/htpasswd -c /usr/local/nagios/etc/htpasswd nagiosuser
2.6 测试配置文件是否正确启动nagios
测试
# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
启动
/usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
三、修改nagios配置文件
3.1 Nagios的主配置文件是nagios.cfg,咱们就从这个文件开始修改。用vi编辑nagios.cfg,
注释行 #cfg_file=/usr/local/nagios/etc/localhost.cfg[2],而后把下面几行的注释去掉:
cfg_file=/usr/local/nagios/etc/contactgroups.cfg //联系组配置文件路径
cfg_file=/usr/local/nagios/etc/contacts.cfg //联系人配置文件路径
cfg_file=/usr/local/nagios/etc/hostgroups.cfg //主机组配置文件路径
cfg_file=/usr/local/nagios/etc/hosts.cfg //主机配置文件路径
cfg_file=/usr/local/nagios/etc/services.cfg //服务配置文件路径
cfg_file=/usr/local/nagios/etc/timeperiods.cfg //监视时段配置文件路径
改check_external_commands=0为check_external_commands=1 这行的做用是容许执行在web界面下重启nagios、
中止主机/服务检查等操做。把command_check_interval的值从默认的1改为command_check_interval=10s
(根据本身的状况定这个命令检查时间间隔,不要太长也不要过短)。主配置文件要改的基本上就是这些,经过上面的修改,
发现/usr/local/nagios/etc并无文件hosts.cfg等一干文件,怎么办?稍后手动建立它们。
3.2 第二个要修改的配置文件是cgi.cfg,它的做用是控制相关cgi脚本。
先确保use_authentication=1。曾看过很多的文章,都是建议把use_authentication的值设置成”0”来取消验证,
这是一个十分糟糕的想法。接下来修改default_user_name=nagiosuser ,再后面的修改在下表列出:
authorized_for_system_information=nagiosadmin,nagiosuser
authorized_for_configuration_information=nagiosadmin,nagiosuser
authorized_for_system_commands=nagiosuser //多个用户之间用逗号隔开
authorized_for_all_services=nagiosadmin,nagiosuser
authorized_for_all_hosts=nagiosadmin,nagiosuser
authorized_for_all_service_commands=nagiosadmin,nagiosuser
authorized_for_all_host_commands=nagiosadmin,nagiosuser
那么上述用户名打那里来的呢?是执行命令 /usr/local/apache/bin/htpasswd –c /usr/local/nagios/etc/htpasswd nagiosuser
所生成的,这个要注意,不能随便加没有存在的验证用户,为了安全起见,不要添加过多的验证用户。
四、客户端
4.1 创建帐户并安装nagios插件
[root@open2 src]# useradd nagios
[root@open2 src]# passwd nagios
Changing password for user nagios.
New password:
BAD PASSWORD: it is too short
BAD PASSWORD: is too simple
Retype new password:
passwd: all authentication tokens updated successfully.
[root@open2 src]# cd nagios-plugins-1.4.16
[root@open2 nagios-plugins-1.4.16]# ./configure prefix=/usr/local/nagios
[root@open2 nagios-plugins-1.4.16]# make && make install
[root@open2 nagios-plugins-1.4.16]# cd /usr/local/nagios/
[root@open2 nagios]# ls
include libexec share
[root@open2 nagios]# chown nagios.nagios -R /usr/local/nagios/
[root@open2 nagios]# cd /usr/src/
[root@open2 src]# wget http://prdownloads.sourceforge.net/sourceforge/nagios/nrpe-2.13.tar.gz
[root@open2 src]# tar zxvf nrpe-2.13.tar.gz
[root@open2 nrpe-2.13]# cd nrpe-2.13
[root@open2 nrpe-2.13]# ./configure
[root@open2 nrpe-2.13]# make all
4.2 接下来安装NPRE插件,daemon和示例配置文件。
c.1 安装check_nrpe 这个插件
# make install-plugin
监控机须要安装check_nrpe 这个插件,被监控机并不须要,咱们在这里安装它只是为了测试目的。
c.2 安装deamon
# make install-daemon
c.3 安装配置文件
# make install-daemon-config
[root@open2 nrpe-2.13]# vim /etc/xinetd.d/nrpe
only_from = 127.0.0.1 192.168.101.77
[root@open2 nrpe-2.13]# printf "nrpe\t5666/tcp\t#nrpe\n" >>/etc/services ^C
[root@open2 nrpe-2.13]# tail -1 /etc/services
nrpe 5666/tcp #nrpe
[root@open2 nrpe-2.13]# yum -y install xinetd^C
[root@open2 nrpe-2.13]# service xinetd restart^C
[root@open2 nrpe-2.13]# /usr/local/nagios/libexec/check_nrpe -H localhost
[root@open2 etc]# cat nrpe.cfg |grep -v "#"|grep -v "^$"
log_facility=daemon
pid_file=/var/run/nrpe.pid
server_port=5666
nrpe_user=nagios
nrpe_group=nagios
allowed_hosts=127.0.0.1
dont_blame_nrpe=0
debug=0
command_timeout=60
connection_timeout=300
command[check_users]=/usr/local/nagios/libexec/check_users -w 5 -c 10
command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20
command[check_sda1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/sda1
command[check_zombie_procs]=/usr/local/nagios/libexec/check_procs -w 5 -c 10 -s Z
command[check_total_procs]=/usr/local/nagios/libexec/check_procs -w 150 -c 200
html