CentOS 6.5安裝nagios

linux下nagios安裝

系統環境:CentOS 6.5
安裝包httpd-2.2.12.tar.bz2 ,   pcre-8.30.tar.bz2  ,   php-5.4.6.tar.bz2  ,   nagios-3.2.3.tar.gz  ,   nagios-plugins-1.4.14.tar.gz
PS: 使用的apache安裝包中的pcre安裝報錯,所以另外下載了一個pcre包

首先yum  remove  httpd , 刪除系統自帶的httpd ,  關閉selinux , 關閉iptables , 啓動項中刪除iptables (此用於測試環境 , 生產環境不建議

安裝 apache
解壓httpd和pcre   tar xf httpd-2.2.12.tar.bz2 -C /usr/src      tar xf pcre-8.30.tar.bz2 -C /usr/src
安裝httpd依賴包apr和apr-util , 這兩個軟件在httpd的srclib文件夾中 , 編譯安裝即可
cd /usr/src/httpd-2.2.12/srclib/apr
./configure --prefix=/usr/local/apr && make && make install && echo "apr installed"
cd /usr/src/httpd-2.2.12/srclib/apr-util
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr && make && make install && echo "apr-util installed"
pcre同樣
cd /usr/src/pcre-8.30
./configure --prefix=/usr/local/pcre && make && make install && echo "pcre installed"
編譯安裝apache
cd /usr/src/httpd-2.2.12
./configure --prefix=/usr/local/apache2 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-so --enable-rewrite && make && make install && echo "apache installed"
PS: 如果編譯是加入pcre會報錯
安裝PHP
解壓PHP包   tar xf php-5.4.6.tar.bz2 -C /usr/src
編譯安裝
cd /usr/src/php-5.4.6
./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs && make && make install && echo "php is ok"
cp /usr/src/php-5.4.6/php.ini-development /usr/local/php/php.ini

配置httpd.conf
DirectoryIndex index.html  改爲   DirectoryIndex index.php index.html
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz   之後加入   AddType application/x-httpd-php .php

/usr/local/apache2/bin/apachectl  start   啓動apache服務 , 瀏覽器中輸入localhost可訪問apache測試頁
查看php是否可以使用
把apache下htdocs下的index.html該爲index.php
內容是
<?php
phpinfo();
?>
重啓apache服務,訪問localhost

安裝nagios
安裝前準備
創建nagcmd用戶組
groupadd  nagcmd
創建nagios用戶
useradd  -G nagcmd -s /sbin/nologin  nagios
解壓編譯安裝
tar xf nagios-3.2.3.tar.gz  -C /usr/src/
./configure --prefix=/usr/local/nagios && make all  &&  make install
make install-init 在/etc/rc.d/init.d目錄下創建nagios腳本
make install-commandmode配置目錄權限
make install-config安裝nagios示例配置文件 , 路徑在/usr/local/nagios/etc
make install-webconf /etc/httpd/conf.d目錄下創建nagios.conf ,  這個文件會告訴apache 哪個路徑下是nagios的文件
也可以在apache配置文件末尾添加一下代碼

ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin"

<Directory "/usr/local/nagios/sbin">
#  SSLRequireSSL
   Options ExecCGI
   AllowOverride None
   Order allow,deny
   Allow from all
#  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
</Directory>

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

<Directory "/usr/local/nagios/share">
#  SSLRequireSSL
   Options None
   AllowOverride None
   Order allow,deny
   Allow from all
#  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
</Directory>


安裝nagios插件
tar xf nagios-plugins-1.4.14.tar.gz -C /usr/src
cd /usr/src/nagios-plugins-1.4.14
./configure --prefix=/usr/local/nagios  && make && make install

chown -R nagios:nagios /usr/local/nagios

apache源碼包安裝默認用戶是daemon,加入nagcmd組中
usermod -G nagcmd daemon

啓動項添加
chkconfig --add nagios
chkconfig --level 35 nagios on

創建apache目錄驗證文件
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
PS: htpasswd.users是nagios安裝是make install-webconf那一步生成文件中定義好的;nagiosadmin是nagios默認用戶
重啓apache服務
本地主機訪問localhost/nagios ,會出現輸入用戶名密碼的驗證窗口,登錄之後就可以看到nagios主頁了


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章