花了近一天的時間整合了cacti和nagios,cacti用來檢測運行狀態(tài)nagios主要用來預(yù)警。期間參考了很多網(wǎng)友的文章,在此感謝下!在這里記錄一下配置過程,以備后忘。。說整合其實只是表面的,cacti和nagios還是以他們原來的方式進行工作,ndo負責將nagios收集的數(shù)據(jù)存在數(shù)據(jù)庫中,cacti的npc插件會從數(shù)據(jù)庫中取數(shù)據(jù)在cacti的npc標簽中來展現(xiàn)。
環(huán)境是cenos5.1+最小化安裝+development tools
開始配置。。
vi /etc/yum.repos.d/Dag.repo###定義第三方源
[dag]
name=Dag RPM Repository for Red Hat Enterprise Linux
baseurl=http://apt.sw.be/redhat/el$releasever/en/$basearch/dag
http://rh-mirror.linux.iastate.edu/pub/dag/redhat/el$releasever/en/$basearch/dag
http://wftp.tu-chemnitz.de/pub/linux/dag/redhat/el$releasever/en/$basearch/dag
http://archive.cs.uu.nl/mirror/dag.wieers/redhat/el$releasever/en/$basearch/dag
http://apt.sw.be/redhat/el$releasever/en/$basearch/dag
http://mirror.cpsc.ucalgary.ca/mirror/dag/redhat/el$releasever/en/$basearch/dag
http://rpmfind.net/linux/dag/redhat/el$releasever/en/$basearch/dag
http://ftp.riken.jp/Linux/dag/redhat/el$releasever/en/$basearch/dag
http://mirrors.ircam.fr/pub/dag/redhat/el$releasever/en/$basearch/dag
gpgcheck=0
enabled=1
protect=0
gpgcheck=1
gpgkey=http://dag.wieers.com/packages/RPM-GPG-KEY.dag.txt
##################################################
vi utterramblings.repo ###定義php獨立源
name=Jason's Utter Ramblings Repo
baseurl=http://www.jasonlitka.com/media/EL$releasever/$basearch/
enabled=1
gpgcheck=1
gpgkey=http://www.jasonlitka.com/media/RPM-GPG-KEY-jlitka
#########################################################################
一次性安裝所需軟件
yum -y install httpd mysql-server rrdtool mysql-devel php-devel net-snmp php php-mysql php-gd php-pdo php-snmp cacti nagios nagios-plugins
或者也可以直接安裝centos官方推薦軟件庫:
下載rpm包
wget http://apt.sw.be/redhat/el5/en/i386/RPMS.dag/rpmforge-release-0.3.6-1.el5.rf.i386.rpm
安裝DAG的PGP Key
rpm --import http://dag.wieers.com/rpm/packages/RPM-GPG-KEY.dag.txt
驗證下載包的完整性
rpm -K rpmforge-release-0.3.6-1.el5.rf.*.rpm
安裝包
rpm -ivh rpmforge-release-0.3.6-1.el5.rf.*.rpm
參考網(wǎng)址:
http://doc.linuxpk.com/58083.html
安裝php-json
wget http://www.aurore.net/projects/php-json/php-json-ext-1.2.0.tar.bz2
tar xvjf php-json-ext-1.2.0.tar.bz2
cd php-json-ext-1.2.0
###初始化PHP環(huán)境
phpize
./configure
make&&make install#####
(如果提示沒有這個命令則首先要
yum -y install php-devel
如果還不行,說明你的編譯工具有問題,安裝一下就可以了
yum -y install autoconf
yum -y install automake
yum -y install libtool
)
查看有沒有安裝成功
find / -name '*json.so'
./usr/lib/php/modules/json.so
說明已經(jīng)有了
vi /etc/php.ini
添加 include ('/etc/php.d/json.ini')
vi /etc/php.d/json.ini
內(nèi)容如下:
extension=json.so
重啟httpd
apachectl graceful
到此所需要的軟件都安裝完畢
開始配置cacti
修改cacti訪問權(quán)限
vi /etc/httpd/conf.d/cacti.conf
如下:
<Directory /var/www/cacti/>
DirectoryIndex index.php
Options -Indexes
AllowOverride all
order deny,allow
#deny from all
#allow from 127.0.0.1
allow from all
AddType application/x-httpd-php .php
php_flag magic_quotes_gpc on
php_flag track_vars on
</Directory>
建立cacti數(shù)據(jù)庫和授權(quán)
mysqladmin create cacti
mysql>grant all privileges on cacti.* to cacti@localhost identified by 'cacti';
mysql>flush privileges;
mysql>exit;
導入數(shù)據(jù):
cd /var/www/cacti
mysql -ucacti -p cacti<cacti.sql
更改配置:
vi /var/www/cacti/include/config.php
$database_username = "cacti";
$database_password = "cacti";
vi /var/www/cacti/include/globle.php
$database_username = "cacti";
$database_password = "cacti";
制定任務(wù)計劃:
crontab -e -u cacti
*/5 * * * * php -f /var/www/cacti/poller.php >/dev/null 2>&1
重新啟動apache
service httpd restart
訪問http://yourserver/cacti/ 進行安裝,用戶名密碼都是admin
下載cacti插件管理器
wget http://mirror.cactiusers.org/downloads/plugins/cacti-plugin-0.8.7d-PA-v2.4.zip
unzip cacti-plugin-0.8.7d-PA-v2.4.zip
cd files-0.8.7d
cp -rf * /var/www/cacti/
導入數(shù)據(jù):
cd ..
mysql -ucacti -pcacti cacti<pa.sql####也可以使用root
更改訪問路徑:
vi /var/www/cacti/include/globle.php
$config['url_path'] = '/cacti/';
配置nagios
我這里面沒有更進一步配置nagios,npc安裝完后nagios會自動啟動本機的一些監(jiān)控項目,如果想要監(jiān)控其他的主機,則需要單獨配置nagios,npc會予以展示
更改apache訪問權(quán)限使nagios可以正常使用
htpasswd -c /etc/nagios/htpasswd.users nagiosadmin
安裝ndoutils
wget http://sourceforge.net/project/downloading.php?group_id=26589&filename=ndoutils-1.4b7.tar.gz
tar zxvf ndoutils-1.4b7.tar.gz
cd ndoutils-1.4b7
./configure --with-mysql-inc=/usr/include/mysql --with-mysql-lib=/usr/lib/mysql --enable-mysql --disable-pgsql --with-ndo2db-user=nagios --with-ndo2db-group=nagios
make clean
make
復(fù)制文件
cd src
cp ndomod-3x.o ndo2db-3x log2ndo file2sock /usr/bin/
cd ../config
cp ndo2db.cfg ndomod.cfg /etc/nagios/
配置文件
vi /etc/nagios/ndo2db.cfg
socket_name=/var/nagios/ndo.sock
db_name=cacti
db_prefix=npc_
db_user=cacti
db_pass=cacti
debug_level=1
debug_file=/var/nagios/ndo2db.debug
vi /etc/nagios/ndomod.cfg
output=/var/nagios/ndo.sock
buffer_file=/var/nagios/ndomod.tmp
vi /etc/nagios/nagios.cfg ##確認以下五項的值正確
check_external_commands=1
command_check_interval = -1
event_broker_options = -1
broker_module = /usr/bin/ndomod-3x.o config_file=/etc/nagios/ndomod.cfg
process_performance_data=1
安裝npc
wget http://www.assembla.com/spaces/npc/documents/aUjAwmdW8r3BuPab7jnrAJ/download?filename=npc-2.0.0b.166.tar.gz
tar zxvf npc-2.0.0b.166.tar.gz
cd npc
拷貝內(nèi)容到cacti plugins文件夾
cp npc /var/www/cacti/plugins/
添加插件識別
vi /var/www/cacti/include/globle.php
$plugins[] = 'npc';
到此 所有需要安裝的東西完畢
使用npc
進入你的cacti主頁面
在'User Management'中選擇'admin',在下邊'Realm Permissions'中鉤選'Plugin Management'。這時右側(cè)會出現(xiàn)'Plugin Management'連接,進去后在'uninstalled'中安裝npc,然后在'intalled'中enable npc,然后在回去admin的'Realm Permissions'中會出現(xiàn)'use npc',把它選中。
接著在右側(cè)欄目中選擇settings,點選npc的標簽
鉤選Remote Commands
Nagios Command File Path: /var/nagios/rw/nagios.cmd
Nagios URL: http://yourserver/nagios/
save一下
3.出現(xiàn)類似Error: Missing Dependency: mysql = 5.0.45-7.el5 is needed by package mysql-server的情況
請刪除系統(tǒng)中已經(jīng)安裝的包,例如已經(jīng)安裝不同版本的mysql則出現(xiàn)上述問題
4.使用root登陸時候提示:Access denied for user 'root'@'localhost' (using password: NO/YES)
默認使用yum安裝mysql后,root密碼為空,出現(xiàn)這個問題從下面兩個點入手,以下部分內(nèi)容參考網(wǎng)絡(luò),感謝網(wǎng)友;
如果此方法行不通,那么參考我如下的方法(偶弄了半天,畢竟是菜鳥。。)
service mysqld stop
mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
mysql -uroot mysql
select user();查看返回的內(nèi)容,如果如下所示:
+--------+
| user() |
+--------+
| root@ |
+--------+
則需更改root登陸主機,參考如下命令:
mysql> UPDATE mysql.user SET Host='%' WHERE Host=' ' ;
mysql>GRANT ALL PRIVILEGES ON *.* TO root@"%";
mysql> FLUSH PRIVILEGES ; mysql>exit
service mysqld restart
登陸成功。至于這個問題是如何引起的,還不明確,懷疑和主機名有關(guān)系,知道的高手們請指點下,小弟mysql超級菜鳥