文章很粗糙,主要記錄本身安裝過程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