您好,登錄后才能下訂單哦!
所需軟件:httpd-2.4.1.tar.gz mysql-5.0.96.tar.gz php-5.3.25.tar.gz
nagios-3.2.0.tar.gz nagios-plugins-1.4.16.tar.gz nrpe-2.12.tar.gz
rrdtool-1.4.8.tar.gz cacti-0.8.8a.tar.gz cacti-spine-0.8.8a.tar.gz
ntop-v0.2-1.tgz monitor-v1.3-1.tgz ndoutils-1.5.2.tar.gz
npc-2.0.4.tar.gz json-1.2.1.tgz PDO_MYSQL-1.0.2.tgz
一.設(shè)置lamp環(huán)境
編譯安裝httpd
Shell>tar zxvf httpd-2.4.1.tar.gz
Shell>cd httpd-2.4.1
Shell>./configure --prefix=/usr/local/apache --enable-so
Shell>make && make install
編譯安裝msyql
Shell>tar zxvf mysql-5.3.25.tar.gz
Shell>cd mysql-5.3.25
Shell>./configure --prefix=/usr/local/mysql --enable-thread-safe-client
Shell>make && make install
Shell>groupadd mysql
Shell>useradd mysql -g mysql
Shell>chown -r mysql.mysql /var/lib/mysql
Shell>/usr/local/mysql/bin/mysql_install_db ##初始化數(shù)據(jù)庫(kù)##
Shell>cp support-files/my-medium.cnf /etc/my.cnf
Shell>/usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --user=root &
##啟動(dòng)mysql##
Shell>/usr/local/msyql/bin/mysqldadmin -uroot -p 123456 #修改mysql登陸密碼##
Shell>ps -ef |grep mysqld ##查看mysq進(jìn)程##
編譯安裝
Shell>tar zxvf php-5.3.25.tar.gz
Shell>cd php-5.3.25
Shell>./confiugre --prefix=/usr/local/php --with--mysql=/usr/local/mysql
--with-apxs2=/usr/local/apache/bin/apxs --enable-sockets
--with-config-file-path=/usr/local/php/etc ##修改php.ini的存放位置##
Shell>make && make install
Shell>cp php.ini-production /etc/php.ini
安裝pdo_mysql擴(kuò)展模塊
Shell>tar zxvf PDO_MYSQL-1.0.2.tgz
Shell>cd PDO_MYSQL-1.0.2
Shell>/usr/local/php/bin/phpize
Shell>make && make install
Shell>vim /usr/local/php/etc/php.ini
extension_dir = "/usr/local/php/lib/php/extensions/no-debug-zts-20090626/"
extension = pdo_mysql.so
重啟apahce 查看是否已加載 php -m |grep pdo-mysql
二、Apache php整合
打開(kāi)Apache配置文件httpd.conf
添加PHPIniDir "/etc/php.ini"
跳轉(zhuǎn)到373后添加
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
跳轉(zhuǎn)到246行添加 index.php
保存退出重啟apache
Shell>/usr/local/apache/bin/apachectl start
測(cè)試apache,php是否整合
Shell>vim /usr/local/apache/htdocs/text.php
<?php
Phpinfo;
?>
打開(kāi)瀏覽器輸入http://ip/test.php,輸出php信息說(shuō)明配置成功
測(cè)試php mysql整合
Shell>vim /usr/local/apache/htdocs/test.php
<?php
$link=mysql_connect("localhost","root","123456");
if(!$link) echo "FAILD!";
else echo "OK!";
?>
保存退出打開(kāi)瀏覽器http://ip/test.php 輸出ok說(shuō)明配置成功
三、安裝nagios
Shell>useradd -s /sbin/nologin nagios
Shell>mkdir -p /usr/local/nagios
Shell>chown -R nagios.nagios /usr/local/nagios
Shell>usermod -G nagios -a apache ##將apache用戶加入到nagios組中
Shell>tar zxvf nagios-3.2.0.tar.gz
Shell>cd nagios-3.2.0
Shell>./configure --prefix=/usr/local/nagios
Shell>make all
Shell>make install
Shell>make install-init
Shell>make install-commandmode
Shell>make install-config
安裝nagios插件
Shell>tar zxvf nagios-plugins-1.4.16.tar.gz
Shell>cd nagios-plugins-1.4.16
Shell>./configure --prefix=/usr/local/nagios
Shell>make && make install
打開(kāi)apache配置文件httpd.conf 在末尾添加以后代碼:
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>
創(chuàng)建nagios登陸用戶
Shell>/usr/local/apache/bin/htpasswd -c /usr/local/nagios/etc/htpasswd admin ##輸入登陸密碼
修改nagios目錄下cgi.cfg
Shell>vim /usr/local/nagios/etc/cgi.cfg
authorized_for_system_information=admin #多個(gè)用戶用逗號(hào)分隔
authorized_for_configuration_information=admin
authorized_for_system_commands=admin
authorized_for_all_services=admin
authorized_for_all_hosts=admin
authorized_for_all_service_commands=admin
authorized_for_all_host_commands=admin
修改nagios目錄下nagios.cfg
command_check_interval=10s ##檢查時(shí)間間隔
check_external_commands=1 ##允許web界面下重啟、關(guān)閉nagios進(jìn)程等
檢查下nagios配置文件是否正確
Shell>/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
修改apache 運(yùn)行的用戶
Shell>vim /usr/local/apache/conf/httpd.conf
User apache
Group apache
啟動(dòng)nagios
Shell>/usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
啟動(dòng)apache
Shell>/usr/local/apache/bin/httpd -k start
打開(kāi)瀏覽器輸入http://ip/nagios就可以看到nagios的主界面
四、安裝nrpe
被監(jiān)控機(jī)上安裝
Shell>groupadd nagios
Shell>useradd -g nagios -d /usr/local/nagios -s /sbin/nologin nagios
Shell>tar zxvf nagios-plugins-1.4.16.tar.gz
Shell>cd nagios-plugins-1.4.16
Shell>./configure --prefix=/usr/local/nagios
Shell>make && make install
Shell>tar zxvf nrpe-2.12.tar.gz
Shell>cd nrpe-2.12
Shell>./configure
Shell>make all
Shell>make instlal-plugin
Shell>make install-daemon
Shell> make install-daemon-config
Shell>chown -R nagios.nagios /usr/local/nagios
配置nrpe
Shell>vim /usr/local/nagios/etc/nrpe.cfg
allowed_hosts=127.0.0.1,監(jiān)控機(jī)ip
Shell>echo “nrpe:監(jiān)控機(jī)ip” >>/etc/host.allow
啟動(dòng)nrpe
Shell>/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
Shell>echo “/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d “ >>/etc/rc.local
## 設(shè)置開(kāi)機(jī)啟動(dòng)nrpe
檢查nrpe是否正常
Shell>netstat -atnlp |grep 5666
Shell>/usr/local/nagios/libexec/check_nrpe -H localhost
NRPE v2.12 ##說(shuō)明nrpe啟動(dòng)成功
監(jiān)控機(jī)上安裝
Shell>tar zxvf nrpe-2.12.tar.gz
Shell>cd nrpe-2.12
Shell>./configure --prefix=/usr/local/nagios
Shell>make
Shell>make install-plugin
測(cè)試是否可以連接被監(jiān)控機(jī)
Shell>/usr/local/nagios/libexec/check_nrpe -H 被監(jiān)控機(jī)ip
NRPE v2.12 ##說(shuō)明可以和被監(jiān)控機(jī)通信
五.安裝cacti
安裝rrdtool
Shell>tar zxvf rrdtool-1.4.8.tar.gz
Shell>cd rrdtool-1.4.8
Shell>./configure
Shell>make &&make install
安裝net-snmp
Shell>yum install net-snmp* -y
配置mysql
Shell>/usr/local/mysql/bin/mysql -uroot -p
Mysql>create database cactidb;
Mysql>grant all privileges on cactidb.* to “cactier”@”locahost” identified by “123456”
Mysql>grant all privileges on cactidb.* to “cactier”@”localhost” identified by “123456”
配置snmp.conf (紅色字體為修改部分)
Shell>vim /etc/snmp/snmp.conf
# sec.name source community
com2sec notConfigUser default public
# name incl/excl subtree mask(optional)
view systemview included .1.3.6.1.2.1.1
view systemview included .1.3.6.1.2.1.25.1.1
# group context sec.model sec.level prefix read write notif
access notConfigGroup "" any noauth exact all none none
## incl/excl subtree mask
view all included .1 80
Shell>service snmpd start
安裝cacti
Shell>tar zxvf cacti-0.8.8a.tar.gz
Shell>mv cacti-0.8.8a cacti
Shell>mv cacti /usr/local/apache/htdocs
Shell>cd /usr/local/apache/htdocs/cacti
Shell>/usr/local/mysql/bin/mysql -uroot -p cactidb <cacti.sql
Shell>chown -R cactier /usr/local/apache/htdocs/cacti/rra /usr/local/apache/htdocs/cacti/log
編輯cacti/include/config.php文件
Shell>vim /usr/local/apache/htdocs/cacti/config.php
$database_type = "mysql";
$database_default = "cactidb";
$database_hostname = "localhost";
$database_username = "cactier";
$database_password = "123456";
$database_port = "3306";
保存退出
Shell>useradd cactier
Shell>passwd cactier
Shell>crontab -u cactier -e
*/1 * * * * * /usr/bin/php /var/www/html/cacti/poller.php >/dev/null 2>&1
登陸cacti
打開(kāi)瀏覽器輸入http://ip/cacti ---->設(shè)置
注意第一次登陸cacti默認(rèn)用戶名和密碼為admin,登陸后要修改密碼
安裝spine
Shell>tar zxvf cacti-spine-0.8.8a.tar.gz
Shell>cd cacti-spine-0.8.8a
Shell>./configure --prefix=/usr/local/spine
Shell>make &&make install
Shell>mv /usr/local/spine/etc/spine.conf.dist /usr/local/spine/etc/spine.conf
Shell>vim /usr/local/spine/etc/spine.conf
DB_Host localhost
DB_Database cactidb
DB_User cactier
DB_Pass 123456
DB_Port 3306
DB_PreG 0
Shell>ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock
設(shè)置spine路徑,Console——Settings——Paths--->>/usr/local/spine/bin/spine
更改cacti輪詢器為spine,Console——Settings——Poller--->>poller type:spine -->>Poller Interval:every minute Cron Interval:every minute
Shell>/usr/local/spine/bin/spine
整合ntop monitor到cacti中
Shell>tar zxvf ntop-4.0.tar.gz
Shell>cd ntop-4.0
Shell>./autogen.sh
Shell>./configure --prefix=/usr/local/ntop
Shell>make && make install
Shell>chown -R ntop.ntop /usr/local/ntop/share/ntop
Shell>chown -R ntop.ntop /usr/local/ntop/var/ntop
配置啟動(dòng)ntop
Shell>ntop -A 輸入密碼
Shell>n/usr/local/ntop/bin/top -i eth0 -d -L -u ntop
Shell>echo '/usr/local/ntop/bin/ntop -i eth0 -d -L -u ntop &> /dev/null' >> /etc/rc.local
安裝ntop插件
Shell>tar zxvf ntop-v0.2-1.tgz -C /usr/local/apache/htdocs/cacti/plugins/
Shell>vim /usr/local/apache/htdocs/cacti/include/config.php
添加$plugins[] = "ntop";
設(shè)置cacti: console---utilities---user managemet---admin---plugin management view ntop
兩個(gè)選項(xiàng)選上,保存 console---configureation---plugin management---啟用ntop
安裝monitor
Shell>tar zxvf monitor-v1.3-1.tgz -C /usr/local/apache/htdocs/cacti/plugins/
Shell>vim /usr/local/apache/htdocs/cacti/include/config.php
添加$plugins[] = "monitor";
設(shè)置cacti:略 (步驟和安裝ntop一樣)
Nagios、cacti整合
安裝ndoutils
Shell>tar zxvf ndoutils-1.5.2.tar.gz
Shell>cd ndoutils-1.5.2
Shell>./configure --prefix=/usr/local/nagios --enable-mysql --disable-pgsql
--with-mysql-inc=/usr/local/mysql/include
--with-mysql-lib=/usr/local/mysql/lib/mysql
Shell>make && make install
Shell>cp -v src/{ndomod-3x.o,ndo2db-3x,file2sock,log2ndo} /usr/local/nagios/bin/
Shell>./installdb -ucactier -p123456 -hlocalhost -d cactidb
Shell>cp -v config/{ndo2db.cfg-sample,ndomod.cfg-sample} /usr/local/nagios/etc/
Shell>mv /usr/local/nagios/etc/ndo2db.cfg-sample /usr/local/nagios/etc/ndo2db.cfg
Shell>mv /usr/local/nagios/etc/ndomod.cfg-sample /usr/local/nagios/etc/ndomod.cfg
Shell>chown -R nagios.nagios /usr/local/nagios/etc/ndo*
Shell>chown -R nagios.nagios /usr/local/nagios/bin/*
Shell>vim /usr/local/nagios/etc/nagios.cfg添加
broker_module=/usr/local/nagios/bin/ndomod-3x.o
config_file=/usr/local/nagios/etc/ndomod.cfg
event_broker_options=-1
Shell>vim /usr/local/nagios/etc/ndo2db.cfg
socket_type=tcp
db_servertype=mysql
db_host=localhost
db_port=3306
db_name=cactidb
db_prefix=nagios_
db_user=cactier
db_pass=123456
Shell>vim /usr/local/nagios/etc/ndomod.cfg
output_type=tcpsocket
output=127.0.0.1
Shell>cp ./daemon-init /etc/init.d/ndo2db
Shell> vi /etc/init.d/ndo2db
# 檢查里面的路徑確保不會(huì)出現(xiàn)“//”,并將Ndo2dbBin修改成下面的值:
Ndo2dbBin=/var/www/html/nagios/bin/ndo2db-3x
Shell>chmod +x /etc/init.d/ndo2db
Shell>service ndo2db start
查看是否有錯(cuò)誤
Shell>tail -f /var/logl/messages 或者 tail -f /usr/local/nagios/var/nagios.log
安裝npc
Shell> tar zxvf npc-2.0.4.tar.gz -C /usr/local/apache/htdocs/cacti/plugins
Shell>vim /usr/local/apache/htdocs/cacti/include/config.php
添加$plugins[] = 'npc';
安裝npc支持json
Shell>tar zxvf json-1.2.1.tgz
Shell>cd json-1.2.1
Shell>/usr/local/php/bin/phpize
Shell>./configure
Shell>make && make install
安裝完后會(huì)有類似這樣的提示:
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20050922/
查看是否有導(dǎo)入信息
Shell>/usr/local/php/bin/php -i |grep php.ini
##Configuration File Loaded Configuration File php.ini路徑
Shell>vim /etc/php.ini
添加extension = json.so
查看json 是否加載
Shell>/usr/local/php/bin/php -m |grep json
修改ndo2db.cfg文件
Shell>vim /usr/local/nagios/etc/ndo2db.cfg
db_prefix=nagios_ 修改為db_prefix=npc_
修改cacti npc插件
Console-->settings-->npc -->Remote Commands選項(xiàng)打勾--->輸入nagios command file pathc -->輸入nagios URL -->host icons service icons選項(xiàng)打勾
-->logging level 選擇DEBUG 保存
修改數(shù)據(jù)庫(kù)表結(jié)構(gòu):
Shell>/usr/local/mysql/bin/mysql -uroot -p
Msyql>use cactidb;
Msyql>
ALTER TABLE `npc_hostchecks` ADD COLUMN `long_output` varchar(8192) NOT NULL default '' AFTER `output`;
ALTER TABLE `npc_hoststatus` ADD COLUMN `long_output` varchar(8192) NOT NULL default '' AFTER `output`;
ALTER TABLE `npc_servicechecks` ADD COLUMN `long_output` varchar(8192) NOT NULL default '' AFTER `output`;
ALTER TABLE `npc_servicestatus` ADD COLUMN `long_output` varchar(8192) NOT NULL default '' AFTER `output`;
ALTER TABLE `npc_statehistory` ADD COLUMN `long_output` varchar(8192) NOT NULL default '' AFTER `output`;
ALTER TABLE `npc_eventhandlers` ADD COLUMN `long_output` varchar(8192) NOT NULL default '' AFTER `output`;
ALTER TABLE `npc_systemcommands` ADD COLUMN `long_output` varchar(8192) NOT NULL default '' AFTER `output`;
ALTER TABLE `npc_notifications` ADD COLUMN `long_output` varchar(8192) NOT NULL default '' AFTER `output`;
Mysql>exit
重啟ndo2db nagios 服務(wù)
Shell>service ndo2db restart
Shell>/usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。