0

【原创】Centos5.2下Cacti安装配置

已有 108 阅读此文人 - - Linux,系统管理 -

Cacti安装配置【原创】
作者:哈密瓜
Bbs:http://bbs.linuxtone.org
Blog:http://hi.baidu.com/gyl4802959

前景:
系统环境:centos5.2

1.编译安装基本环境
1.1 使用 yum 程序安装所需开发包(以下为标准的 RPM 包名称)
#rpm --import http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
#yum -y install ntp vim-enhanced gcc gcc-c++ gcc-g77 flex bison autoconf automake bzip2-devel ncurses-devel zlib-devel libjpeg-devel libpng-devel libtiff-devel freetype-devel libXpm-devel gettext-devel pam-devel kernel

1.2编译安装软件包
源码编译安装所需包(Source)
1.2.1 GD2
# cd /usr/local/src
# tar xvf gd-2.0.35.tar.gz
# cd gd-2.0.35
# ./configure --prefix=/usr/local/gd2
# make
# make install

1.2. 2 libXML2
# cd /usr/local/src
# tar xvf libxml2-2.6.29.tar.bz2
# cd libxml2-2.6.29
# ./configure --prefix=/usr/local/libxml2
# make
# make install

1.2.3 LibMcrypt
# cd /usr/local/src
# tar xvf libmcrypt-2.5.8.tar.bz2
# cd libmcrypt-2.5.8
# ./configure --prefix=/usr/local/libmcrypt
# make
# make install

1.2.4 OpenSSL和OpenSSH
# cd /usr/local/src
# tar xvf openssl-0.9.8g.tar.gz
# cd openssl-0.9.8g
# ./config --prefix=/usr/local/openssl
# make
# make test
# make install

# cd ..
# tar xvf openssh-5.0p1.tar.gz
# cd openssh-5.0p1
# ./configure \
"--prefix=/usr" \
"--with-pam" \
"--with-zlib" \
"--sysconfdir=/etc/ssh" \
"--with-ssl-dir=/usr/local/openssl" \
"--with-md5-passwords"
# make
# make install
配置:
禁用 SSH V1 协议
# vi /etc/ssh/ssh_config
找到
#Protocol 2,1
改为:
Protocol 2
禁用服务器端GSSAPI
找到以下两行,并将它们注释:
GSSAPIAuthentication yes
GSSAPICleanupCredentials yes
禁用 DNS 名称解析
找到:
#UseDNS yeas
改为:
UseDNS no
禁用客户端 GSSAPI
# vi /etc/ssh/ssh_config 找到:
GSSAPIAuthentication yes
将这行注释掉。
最后,确认修改正确后重新启动 SSH 服务
# service sshd restart
# ssh -v
确认 OpenSSH 以及 OpenSSL 版本正确。

2.编译安装A.M.P环境
2.1下载软件编译安装
2.1.1下载软件
# cd /usr/local/src
httpd-2.2.8.tar.gz
mysql-5.0.51b.tar.gz
php-5.2.6.tar.bz2
2.1.2 安装MySQL
查看分析你的CPU型号:
http://gentoo-wiki.com/Safe_Cflags 查找您的GCC编译参数.
确定系统CPU类型:
# cat /proc/cpuinfo | grep "model name"
执行后会看到系统中CPU的具体型号,记下CPU型号。
# tar xvf mysql-5.0.51b.tar.gz
# cd mysql-5.0.51b
# vi mysql.sh
CHOST="i686-pc-linux-gnu"
CFLAGS="-march=prescott -O2 -pipe -fomit-frame-pointer"
CXXFLAGS="${CFLAGS}"
./configure \
"--prefix=/usr/local/mysql" \
"--localstatedir=/data/mysql/data" \
"--with-comment=Source" \
"--with-server-suffix=-LinuxTone" \
"--with-mysqld-user=mysql" \
"--without-debug" \
"--with-big-tables" \
"--with-charset=gbk" \
"--with-collation=gbk_chinese_ci" \
"--with-extra-charsets=all" \
"--with-pthread" \
"--enable-static" \
"--enable-thread-safe-client" \
"--with-client-ldflags=-all-static" \
"--with-mysqld-ldflags=-all-static" \
"--enable-assembler" \
"--without-isam" \
"--without-innodb" \
"--without-ndb-debug"
make && make install
mkdir -p /data/mysql/data
useradd mysql -d /data/mysql -s /sbin/nologin
/usr/local/mysql/bin/mysql_install_db --user=mysql
cd /usr/local/mysql
chown -R root:mysql .
chown -R mysql /data/mysql/data
cp share/mysql/my-huge.cnf /etc/my.cnf
cp share/mysql/mysql.server /etc/rc.d/init.d/mysqld
chmod 755 /etc/rc.d/init.d/mysqld
chkconfig --add mysqld
/etc/rc.d/init.d/mysqld start

cd /usr/local/mysql/bin
for i in *; do ln -s /usr/local/mysql/bin/$i /usr/bin/$i; done
#sh mysql.sh 即可开始编译.
2.1.3 编译安装Apache
# cd /usr/local/src
# tar xvf httpd-2.2.8.tar.gz
# cd httpd-2.2.8
./configure \
"--prefix=/usr/local/apache2" \
"--with-included-apr" \
"--enable-so" \
"--enable-deflate=shared" \
"--enable-expires=shared" \
"--enable-rewrite=shared" \
"--enable-static-support" \
"--disable-userdir"
make
make install
echo '/usr/local/apache2/bin/apachectl start ' >> /etc/rc.local
2.1.4 编译安装PHP
# cd /usr/local/src
# tar xjvf php-5.2.6.tar.bz2
# cd php-5.2.6
#vi init.sh
./configure \
"--prefix=/usr/local/php" \
"--with-apxs2=/usr/local/apache2/bin/apxs" \
"--with-config-file-path=/usr/local/php/etc" \
"--with-mysql=/usr/local/mysql" \
"--with-libxml-dir=/usr/local/libxml2/bin" \
"--with-gd=/usr/local/gd2" \
"--with-jpeg-dir" \
"--with-png-dir" \
"--with-bz2" \
"--with-xmlrpc" \
"--with-freetype-dir" \
"--with-zlib-dir " \
"--with-openssl=/usr/local/openssl" \
"--with-mcrypt=/usr/local/libmcrypt" \
"--enable-sysvsem" \
"--enable-inline-optimization" \
"--enable-soap" \
"--enable-gd-native-ttf" \
"--enable-ftp" \
"--enable-mbstring" \
"--enable-exif" \
"--disable-debug" \
"--disable-ipv6" \
"--enable-sockets" \
"--disable-cgi" \
"--with-snmp"
make
make install
cp php.ini-dist /usr/local/php/etc/php.ini

另一个编译参数:(建议用上面那个)
./configure \
"--prefix=/usr/local/php" \
"--enable-fastcgi" \
"--enable-discard-path" \
"--enable-force-cgi-redirect" \
"--with-config-file-path=/usr/local/php/etc" \
"--enable-zend-multibyte" \
"--with-mysql=/usr/local/mysql" \
"--with-mysqli=/usr/local/mysql/bin/mysql_config" \
"--with-libxml-dir=/usr/local/libxml2/bin" \
"--with-xmlrpc" \
"--with-gd=/usr/local/gd2" \
"--with-jpeg-dir" \
"--with-png-dir" \
"--with-bz2" \
"--with-freetype-dir" \
"--with-zlib-dir " \
"--with-openssl=/usr/local/openssl" \
"--with-mcrypt=/usr/local/libmcrypt" \
"--enable-sysvsem" \
"--enable-inline-optimization" \
"--enable-soap" \
"--enable-gd-native-ttf" \
"--enable-ftp" \
"--enable-mbstring" \
"--enable-exif" \
"--disable-debug" \
"--disable-ipv6" \
"--enable-sockets" \
"--with-snmp"
make
make install
mkdir /usr/local/php/etc
cp php.ini-dist /usr/local/php/etc/php.ini
注:在这边安装时候可能提示
configure: error: snmp.h not found. Check your SNMP installation.
这时候就提前安装snmp 就是2.3那一步
2.2 整合Apache与PHP及系统初化配置.2.2.1 整合Apache与PHP# vi /usr/local/apache2/conf/httpd.conf找到:
AddType application/x-gzip .gz .tgz
在该行下面添加
AddType application/x-httpd-php .php
找到:

DirectoryIndex index.html

将该行改为

DirectoryIndex index.html index.htm index.php

找到:
#Include conf/extra/httpd-mpm.conf
#Include conf/extra/httpd-info.conf
#Include conf/extra/httpd-vhosts.conf (虚拟主机配置文件存放目录.)
#Include conf/extra/httpd-default.conf
去掉前面的“#”号,取消注释。注意:以上 4 个扩展配置文件中的设置请按照相关原则进行合理配置!修改完成后保存退出。# /usr/local/apache2/bin/apachectl restart
2.2.2 查看确认L.A.M.P环境信息
在网站根目录放置 info.php 脚本,检查phpinfo中的各项信息是否正确。

2.2.3配置虚拟主机
#vi /usr/local/apache2/conf/extra/httpd-vhosts.conf
NameVirtualHost *:80

    ServerAdmin cnseek@gmail.com
    DocumentRoot "/data/www/wwwroot/cacti"
ServerName cacti.test.com
ServerAlias cacti.test.cn
#    ErrorLog "logs/dummy-host.example.com-error_log"
 #   CustomLog "|/usr/sbin/cronolog /data/logs/access_www.linuxtone.org.%Y%m%d" combined

2.3安装snmp采集工具
SNMP全名是简单网络管理协议,几乎所有的网络设备(交换机、路由器等)和操作系统默认安装了认都安装了snmp服务。
Cacti系统所在的服务器并不一定要安装SNMP服务,但是Cacti系统采集数据要用到Net-SNMP包里面的几个工具,所以最好也在Cacti服务器上安装SNMP服务。我们可以直接在系统中运行snmpwalk和snmpget看是否有该命令,如果有则无需安装了。
如果操作系统没有安装SNMP,可以到本文最后的资源里的Net-SNMP官方网站上下载源码或二进制包进行安装。
#yum -y install net-snmp*
#rpm -qa|grep snmp
net-snmp-libs-5.3.1-24.el5_2.2
net-snmp-perl-5.3.1-24.el5_2.2
net-snmp-utils-5.3.1-24.el5_2.2
net-snmp-5.3.1-24.el5_2.2
net-snmp-devel-5.3.1-24.el5_2.2

2.4安装rrdtool
我这里使用的是rpm包安装
#wget ftp://rpmfind.net/linux/fedora/updates/9/i386.newkey/rrdtool-1.3.4-2.fc9.i386.rpm
#rpm -ivh rrdtool-1.3.4-2.fc9.i386.rpm
warning: rrdtool-1.3.4-2.fc9.i386.rpm: Header V3 DSA signature: NOKEY, key ID 6df2196f
error: Failed dependencies:
dejavu-lgc-fonts is needed by rrdtool-1.3.4-2.fc9.i386
#yum -y install dejavu-lgc-fonts
#rpm -ivh rrdtool-1.3.4-2.fc9.i386.rpm
warning: rrdtool-1.3.4-2.fc9.i386.rpm: Header V3 DSA signature: NOKEY, key ID 6df2196f
Preparing... ########################################### [100%]
1:rrdtool ########################################### [100%]

3.安装配置cacti
下载cacti的源码包
#wget http://www.cacti.net/downloads/cacti-0.8.7b.tar.gz
#tar zvxf cacti-0.8.7b.tar.gz
#mv cacti-0.8.7b /data/www/wwwroot/cacti
#cd /data/www/wwwroot/cacti

配置帐号及mysql:
groupadd cacti
useradd -g cacti cactiuser
mysql -uroot -p
mysql> create database cactidb;
mysql> grant all on cactidb.* to root;
mysql> grant all on cactidb.* to root@localhost;
mysql> grant all on cactidb.* to cactiuser;
mysql> grant all on cactidb.* to cactiuser@localhost identified by '123456';
mysql> flush privileges;
mysql> exit

Catci配置:
# mysql cactidb -uroot -p < cacti.sql # chown -R cactiuser rra/ log/ # chmod -R 777 rra/ log/ # vi include/config.php $database_type = "mysql"; $database_default = "cactidb"; $database_hostname = "localhost"; $database_username = "cactiuser"; $database_password = "123456"; $database_port = "3306"; 配置让系统每五分钟去取一次snmp数据: #crontab -u cactiuser -e //注意要用cactiuser就是你刚刚建立的那个帐号去运行crontab */5 * * * * /usr/local/php/bin/php /data/www/wwwroot/cacti/poller.php > /dev/null 2>&1

4.snmp配置
4.1客户端:
#yum -y install net-snmp*
#vi /etc/snmp/snmpd.conf
# SNMP configfile for Linux servers

com2sec local 127.0.0.1 public
com2sec local 192.168.22.0/24 public
#这边也可以把public换成其他的譬如hmgcacti这样下面服务器上测试也要换成hmgcacti

group MyROGroup v1 local
group MyROGroup v2c local
group MyROGroup usm local

view all included .1 80
access MyROGroup "" any noauth exact all none none
syslocation (/etc/snmpd/snmpd.conf)
syscontact Me
#service snmpd restart
4.2 服务器:
运行命令:
#snmpwalk -v 2c -c public 192.168.22.17 if #这边的public要跟上面客户端设置一样
IF-MIB::ifIndex.1 = INTEGER: 1
IF-MIB::ifIndex.2 = INTEGER: 2
IF-MIB::ifIndex.3 = INTEGER: 3
IF-MIB::ifIndex.4 = INTEGER: 4
IF-MIB::ifIndex.5 = INTEGER: 5
IF-MIB::ifDescr.1 = STRING: lo
IF-MIB::ifDescr.2 = STRING: eth0
IF-MIB::ifDescr.3 = STRING: eth1
IF-MIB::ifDescr.4 = STRING: eth2
IF-MIB::ifDescr.5 = STRING: eth3
IF-MIB::ifType.1 = INTEGER: softwareLoopback(24)
..............................................................................................
IF-MIB::ifOutQLen.3 = Gauge32: 0
IF-MIB::ifOutQLen.4 = Gauge32: 0
IF-MIB::ifOutQLen.5 = Gauge32: 0
IF-MIB::ifSpecific.1 = OID: SNMPv2-SMI::zeroDotZero
IF-MIB::ifSpecific.2 = OID: SNMPv2-SMI::zeroDotZero
IF-MIB::ifSpecific.3 = OID: SNMPv2-SMI::zeroDotZero
IF-MIB::ifSpecific.4 = OID: SNMPv2-SMI::zeroDotZero
IF-MIB::ifSpecific.5 = OID: SNMPv2-SMI::zeroDotZero
配置完成
打开浏览器输入
http://ip/
输入用户名密码,默认的是admin,admin
然后提示修改密码
好了配置结束
尽情的去享受cacti吧!

期待你一针见血的评论,Come on!

不用想啦,马上 "登录"  发表自已的想法.