这个是linux下安装配置Nagios和Cacti的第一个步骤,即配置一个web的环境,这里采用的是lamp的架构!
这里采用的linux平台是RHEL 5.4的版本
首先是mysql的编译安装(GCC和MAKE都要安装上,其他的套件按需安装)
免费下载地址在 http://linux.linuxidc.com/
用户名与密码都是www.linuxidc.com
[root@localhost httpd]# useradd mysql
[root@localhost ~]# ll mysql-5.1.59.tar.gz
-rw-r–r– 1 root root 24325443 Oct 14 22:38 mysql-5.1.59.tar.gz
[root@localhost ~]# tar zxvf mysql-5.1.59.tar.gz
[root@localhost mysql-5.1.59]# ./configure –prefix=/usr/local/mysql –enable-local-infile –with-charset=gbk –with-extra-charsets=all –with-low-memory –with-mysqld-user=mysql –enable-thread-safe-client
[root@localhost mysql-5.1.59]# make && make install
[root@localhost mysql-5.1.59]# cd /usr/local/mysql/
[root@localhost mysql]# chown -R mysql.mysql .
[root@localhost mysql]# ./bin/mysql_install_db –user=mysql
[root@localhost mysql]# chown -R root .
[root@localhost mysql]# chown -R mysql /var/
[root@localhost mysql]# ./bin/mysqld_safe –user=mysql &
[root@localhost mysql]# netstat -tulnp|grep 3306
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 20438/mysqld
[root@localhost mysql]# cd ~(这部分是制作mysql的开机启动项)
[root@localhost ~]# echo “/usr/local/mysql/lib/mysql” >> /etc/ld.so.conf
[root@localhost ~]# ldconfig -v
[root@localhost ~]# ln -s /usr/local/mysql/bin/mysql /usr/local/bin/mysql
[root@localhost ~]# cp mysql-5.1.59/support-files/mysql.server /etc/init.d/mysqld
[root@localhost ~]# chmod 775 /etc/init.d/mysqld
[root@localhost ~]# cp mysql-5.1.59/support-files/my-medium.cnf /etc/my-cnf
[root@localhost ~]# chkconfig –add mysqld
[root@localhost ~]# chkconfig mysqld on
[root@localhost ~]# chkconfig –list|grep mysqld
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:of
接着是apache的编译安装
[root@localhost ~]# ll httpd-2.2.6.tar.gz
-rw-r–r– 1 root root 6028951 Sep 6 2007 httpd-2.2.6.tar.gz
[root@localhost ~]# tar zxvf httpd-2.2.6.tar.gz
[root@localhost ~]# cd httpd-2.2.6
[root@localhost httpd-2.2.6]# ./configure –prefix=/usr/local/httpd –enable-so –enable-rewrite –enable-ssl –with-ssl=/usr/local/openssl
–with-zlib –enable-mods-shared=all –enable-track-vars –with-mysql=/usr/local/mysql
[root@localhost httpd-2.2.6]# make && make install
[root@localhost httpd-2.2.6]# echo “/usr/local/httpd/bin/apachectl start” >> /etc/rc.local
[root@localhost httpd-2.2.6]# /usr/local/httpd/bin/apachectl start
[root@localhost httpd-2.2.6]# netstat -tulnp|grep 80
tcp 0 0 :::80 :::* LISTEN 19055/httpd
接着添加php的支持
[root@localhost ~]# cd /usr/local/httpd/conf/
[root@localhost conf]# cp httpd.conf httpd.conf.bak
[root@localhost conf]# vi httpd.conf (红色字体为修改部分)
DocumentRoot “/var/www”
<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
Allow from all
</Directory>
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
最后是php的编译安装
[root@localhost ~]# ll php-5.2.5.tar.gz
-rw-r–r– 1 root root 9972372 Jan 3 2008 php-5.2.5.tar.gz
[root@localhost ~]# tar zxvf php-5.2.5.tar.gz
[root@localhost php-5.2.5]# ./configure –prefix=/usr/local/php \
> –with-config-file-path=/etc \
> –with-apxs2=/usr/local/httpd/bin/apxs \
> –enable-fastcgi –enable-safe-mode \
> –with-zlib –with-bz2 \
> –with-freetype-dir \
> –enable-mbstring \
> –with-mysql=/usr/local/mysql \
> –with-mysqli=/usr/local/mysql/bin/mysql_config \
> –with-gd –with-libxml-dir \
> –with-png-dir –with-jepg-dir –enable-sockets
[root@localhost php-5.2.5]# make && make install
如果本机已经rpm方式安装php,那么进行下边红色字体的动作
[root@localhost php-5.2.5]# yum -y remove php*
[root@localhost php-5.2.5]# cp php.ini-dist /etc/php.ini
最后测试的部分
[root@localhost ~]# cd /var/www/
[root@localhost www]# vi info.php
<?
phpinfo();
?>
[root@localhost www]# cp /usr/local/httpd/htdocs/index.html .
重启的服务就可以出来php那个经典的页面,表示成功!
总结,这个实验是为了搭建Nagios和Cacti需要的web环境,接下来的实验就进入Nagios和Cacti的部分!
这个实验是Nagios和Cacti安装与配置的第二个步骤之Cacti安装与配置,采用的实验环境是之前搭建的lamp的环境,这步需要安装很多的辅助套件,Cacti就是通过net-snmp进行数据的采集,通过Mysql进行模板、主机信息、以及rra信息的存储,通过RRdtool进行数据的存储和绘图,Cacti是直接与管理员交互的平台。
需要安装的套件为 rrdtool、 net-snmp、cacti-spine、cacti
首先套件安装和设置的具体步骤
[root@localhost ~]# ll rrdtool-1.4.5.tar.gz
-rw-r–r– 1 root root 1348713 Oct 15 2011 rrdtool-1.4.5.tar.gz
[root@localhost ~]# tar zxvf rrdtool-1.4.5.tar.gz
[root@localhost rrdtool-1.4.5]# ./configure –prefix=/usr/local/rrdtool
[root@localhost rrdtool-1.4.5]# make && make install
[root@localhost ~]# ll net-snmp-5.6.1.1.tar.gz
-rw-r–r– 1 root root 5937279 Oct 15 2011 net-snmp-5.6.1.1.tar.gz
[root@localhost ~]# tar zxvf net-snmp-5.6.1.1.tar.gz
[root@localhost net-snmp-5.6.1.1]# ./configure //写以下两项,其他的采用系统默认的即可
System Contact Information ():cactiuser
System Location (Unknown):office_7f
[root@localhost net-snmp-5.6.1.1]# make && make install
[root@localhost ~]# ll cacti-spine-0.8.7h.tar.gz //cacti的一个加速器
-rw-r–r– 1 root root 623334 Oct 15 2011 cacti-spine-0.8.7h.tar.gz
[root@localhost ~]# tar zxvf cacti-spine-0.8.7h.tar.gz
[root@localhost cacti-spine-0.8.7h]# ./configure –prefix=/usr/local/spine
[root@localhost cacti-spine-0.8.7h]# make && make install
[root@localhost cacti-spine-0.8.7h]# cd /usr/local/spine/etc/
[root@localhost etc]# cp spine.conf.dist spine.conf
[root@localhost etc]# vi spine.conf
DB_Host localhost
DB_Database cacti
DB_User cactiuser
DB_Pass 721wyzj //修改密码
DB_Port 3306
DB_PreG 0
[root@localhost ~]# ll cacti-0.8.7h.tar.gz
-rw-r–r– 1 root root 2249323 Oct 15 2011 cacti-0.8.7h.tar.gz
[root@localhost ~]# tar zxvf cacti-0.8.7h.tar.gz
[root@localhost ~]# mv cacti-0.8.7h /var/www/cacti
接下来进行数据库和用户的设置
[root@localhost ~]# useradd cactiuser
[root@localhost ~]# vi /etc/crontab //添加下边的计划任务
*/5 * * * * cactiuser /usr/local/php/bin/php /var/www/cacti/poller.php >/dev/null 2>&1
[root@localhost ~]# mysql //添加必须的cacti这个数据库
mysql> create database cacti;
mysql> grant all privileges on cacti.* to identified by “721wyzj”;
mysql> flush privileges;
mysql> \q
Bye
[root@localhost cacti]# mysql -p cacti <cacti.sql mysql //导入数据库的表
[root@localhost cacti]# mysql -p cacti //出现以下的数据表示导入成功
mysql> show tables;
+—————————+
| Tables_in_cacti |
+—————————+
| cdef |
…………………………….
………………………………..
………………………………..|
| user_log |
| version |
+—————————+
48 rows in set (0.01 sec)
[root@localhost cacti]# cd ..
[root@localhost www]# chown -R root.root cacti/
[root@localhost cacti]# chown -R cactiuser log/ rra/ //这个是cacti数据交互的地方,cactiuer必须保有写入的权限
[root@localhost cacti]# cd include/
[root@localhost include]# cp config.php config.php.bak
[root@localhost include]# vi config.php
$database_type = “mysql”;
$database_default = “cacti”;
$database_hostname = “localhost”;
$database_username = “cactiuser”;
$database_password = “721wyzj”; //修改的部分
$database_port = “3306”;
$database_ssl = false;
最后是windows下操作的部分,在IE地址栏里输入以下内容,安装cacti
http://192.168.1.192/cacti/install/index.php
安装成功之后,通过账号,密码admin:admin登入进行相关的设置即可
总结,这是Nagios和Cacti安装与配置的第二个步骤,主要进行Cacti安装与配置,然而对设备的管理仍需辅以相关的插件来进行,接下来进一步的探索!
这个是Nagios和Cacti安装与配置的第三个步骤,就是给cacti打补丁和安装weathermap插件,建立在之前的实验平台上,此文章主要介绍安装。
第一部分:
装cati-plugin的解决方案
需要的套件 cacti-plugin-0.8.7h-PA-v3.0.tar.gz
[root@localhost ~]# tar zxvf cacti-plugin-0.8.7h-PA-v3.0.tar.gz
[root@localhost ~]# cd cacti-plugin-arch/
[root@localhost cacti-plugin-arch]# cp -rf files/* /var/www/cacti/
[root@localhost cacti-plugin-arch]# cd /var/www/cacti/
[root@localhost cacti]# mysql -u root cacti < ~/cacti-plugin-arch/pa.sql
[root@localhost cacti]# cd include/
[root@localhost include]# vi global.php //修改以下的字段即可
$database_username = “cactiuser”;
$database_password = “721wyzj”;
if (! isset($url_path)) {
$url_path = “/cacti/”;
}
之后登陆http://192.168.1.192/cacti/index.php User Management–>admin–>Plugin Management (添加上这个即可)
实验总结
之前一直采用类似以下的方式补丁步骤
patch -p1 -N < cacti-plugin-0.8.7g-PA-v2.8.diff
之后再修改vi /var/www/cacti/include/global.php
$database_username = “cactiuser”;
$database_password = “721wyzj”;
$config[‘url_path’] = ‘/cacti/’;
但是很无奈登陆时一直出现Call to undefined function api_plugin_hook() 的错误提示,谷歌了好多解决方案,都不奏效,后来发现解开压缩包所在的目录下有files的目录,再结合网络的搜索得知,还有另外一种方案–覆盖,于是就尝试的去做也就是以上成功的案例,终于问题解决,深吸一口气啊!
第二部分:weathermap插件的安装
[root@localhost ~]# ll php-weathermap-0.97a.zip
-rw-r–r– 1 root root 2927302 Oct 16 2011 php-weathermap-0.97a.zip
[root@localhost ~]# unzip php-weathermap-0.97a.zip
[root@localhost ~]# mv weathermap/ /var/www/cacti/plugins
[root@localhost ~]# cd /var/www/cacti/plugins/weathermap/
[root@localhost weathermap]# chown -R cactiuser output/
[root@localhost weathermap]# chown -R apache configs/
[root@localhost weathermap]# chmod -R u+w configs/
[root@localhost weathermap]# cp editor-config.php-dist editor-config.php
[root@localhost weathermap]# vi editor-config.php
$cacti_base = “/var/www/cacti”;
$cacti_url = “http://192.168.1.192/cacti/”;
$mapdir= $cacti_base.’/plugins/weathermap/configs’;
[root@localhost weathermap]# vi editor.php //从false修改成ture
$ENABLED=ture;
这样就设置成功了,接着就是web的操作,为了安装这个软件耗费很久的时间,最后解决的办法是修改global.php里的url_path为/cacti/,之前不需要修改的这个,没想到在插件里用到了,这是出其不意啊!