标签:cacti
cacti迁移在新机器上部署
使用的是CentOS 6.6,kernel版本:2.6.32-642.13.1.el6.x86_64
yum install rrdtool-devel rrdtool-perl rrdtool
版本:
root@pts/0 # rpm -qa|grep rrdtool
rrdtool-perl-1.3.8-7.el6.x86_64
rrdtool-1.3.8-7.el6.x86_64
rrdtool-devel-1.3.8-7.el6.x86_64
yum -y install net-snmp net-snmp-libs net-snmp-utils net-snmp-devel
配置
root@pts/0 # vim /etc/snmp/snmpd.conf
access notConfigGroup "" any noauth exact all none none
com2sec notConfigUser default public
dontLogTCPWrappersConnects yes
group notConfigGroup v1 notConfigUser
group notConfigGroup v2c notConfigUser
pass_persist .1.3.6.1.3.1 /usr/bin/perl /usr/local/bin/iostat-persist.pl
syscontact Root <root@localhost> (configure /etc/snmp/snmp.local.conf)
syslocation Unknown (edit /etc/snmp/snmpd.conf)
view all included .1 80
view systemview included .1.3.6.1.2.1.1
view systemview included .1.3.6.1.2.1.25.1.1
# Allow Systems Management Data Engine SNMP to connect to snmpd using SMUX
smuxpeer .1.3.6.1.4.1.674.10892.1
测试
root@pts/0 # snmpwalk -v 1 -c public 127.0.0.1 .1.3.6.1.2.1.1.1.0
SNMPv2-MIB::sysDescr.0 = STRING: Linux pb-yunwei-1-212.youyuan-idc.com 2.6.32-642.13.1.el6.x86_64 #1 SMP Wed Jan 11 20:56:24 UTC 2017 x86_64
mysql-community.repo
root@pts/0 # cat mysql-community.repo
[mysql-connectors-community]
name=MySQL Connectors Community
baseurl=http://repo.mysql.com/yum/mysql-connectors-community/el/6/$basearch/
enabled=1
gpgcheck=0
gpgkey=file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[mysql-tools-community]
name=MySQL Tools Community
baseurl=http://repo.mysql.com/yum/mysql-tools-community/el/6/$basearch/
enabled=1
gpgcheck=0
gpgkey=file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
# Enable to use MySQL 5.5
[mysql55-community]
name=MySQL 5.5 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.5-community/el/6/$basearch/
enabled=0
gpgcheck=0
gpgkey=file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
# Enable to use MySQL 5.6
[mysql56-community]
name=MySQL 5.6 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/6/$basearch/
enabled=1
gpgcheck=0
gpgkey=file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
# Note: MySQL 5.7 is currently in development. For use at your own risk.
# Please read with sub pages: https://dev.mysql.com/doc/relnotes/mysql/5.7/en/
[mysql57-community-dmr]
name=MySQL 5.7 Community Server Development Milestone Release
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/6/$basearch/
enabled=0
gpgcheck=0
gpgkey=file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
mysql-community-source.repo
root@pts/0 # cat mysql-community-source.repo
[mysql-connectors-community-source]
name=MySQL Connectors Community - Source
baseurl=http://repo.mysql.com/yum/mysql-connectors-community/el/6/SRPMS
enabled=0
gpgcheck=0
gpgkey=file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[mysql-tools-community-source]
name=MySQL Tools Community - Source
baseurl=http://repo.mysql.com/yum/mysql-tools-community/el/6/SRPMS
enabled=0
gpgcheck=0
gpgkey=file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[mysql55-community-source]
name=MySQL 5.5 Community Server - Source
baseurl=http://repo.mysql.com/yum/mysql-5.5-community/el/6/SRPMS
enabled=0
gpgcheck=0
gpgkey=file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[mysql56-community-source]
name=MySQL 5.6 Community Server - Source
baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/6/SRPMS
enabled=0
gpgcheck=0
gpgkey=file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[mysql57-community-dmr-source]
name=MySQL 5.7 Community Server Development Milestone Release - Source
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/6/SRPMS
enabled=0
gpgcheck=0
gpgkey=file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
webtatic.repo
root@pts/0 # cat webtatic.repo
[webtatic]
name=Webtatic Repository EL6 - $basearch
#baseurl=https://repo.webtatic.com/yum/el6/$basearch/
mirrorlist=https://mirror.webtatic.com/yum/el6/$basearch/mirrorlist
failovermethod=priority
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-webtatic-andy
[webtatic-debuginfo]
name=Webtatic Repository EL6 - $basearch - Debug
#baseurl=https://repo.webtatic.com/yum/el6/$basearch/debug/
mirrorlist=https://mirror.webtatic.com/yum/el6/$basearch/debug/mirrorlist
failovermethod=priority
enabled=0
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-webtatic-andy
[webtatic-source]
name=Webtatic Repository EL6 - $basearch - Source
#baseurl=https://repo.webtatic.com/yum/el6/SRPMS/
mirrorlist=https://mirror.webtatic.com/yum/el6/SRPMS/mirrorlist
failovermethod=priority
enabled=0
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-webtatic-andy
webtatic-testing.repo
root@pts/0 # cat webtatic-testing.repo
[webtatic-testing]
name=Webtatic Repository EL6 - $basearch - Testing
#baseurl=https://repo.webtatic.com/yum/el6-testing/$basearch/
mirrorlist=https://mirror.webtatic.com/yum/el6-testing/$basearch/mirrorlist
failovermethod=priority
enabled=0
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-webtatic-andy
[webtatic-testing-debuginfo]
name=Webtatic Repository EL6 - $basearch - Testing Debug
#baseurl=https://repo.webtatic.com/yum/el6-testing/$basearch/debug/
mirrorlist=https://mirror.webtatic.com/yum/el6-testing/$basearch/debug/mirrorlist
failovermethod=priority
enabled=0
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-webtatic-andy
[webtatic-testing-source]
name=Webtatic Repository EL6 - $basearch - Testing Source
#baseurl=https://repo.webtatic.com/yum/el6-testing/SRPMS/
mirrorlist=https://mirror.webtatic.com/yum/el6-testing/SRPMS/mirrorlist
failovermethod=priority
enabled=0
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-webtatic-andy
webtatic-archive.repo
root@pts/0 # cat webtatic-archive.repo
[webtatic-archive]
name=Webtatic Repository EL6 - $basearch - Archive
#baseurl=https://repo.webtatic.com/yum/el6-archive/$basearch/
mirrorlist=https://mirror.webtatic.com/yum/el6-archive/$basearch/mirrorlist
failovermethod=priority
enabled=0
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-webtatic-andy
[webtatic-archive-debuginfo]
name=Webtatic Repository EL6 - $basearch - Archive Debug
#baseurl=https://repo.webtatic.com/yum/el6-archive/$basearch/debug/
mirrorlist=https://mirror.webtatic.com/yum/el6-archive/$basearch/debug/mirrorlist
failovermethod=priority
enabled=0
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-webtatic-andy
[webtatic-archive-source]
name=Webtatic Repository EL6 - $basearch - Archive Source
#baseurl=https://repo.webtatic.com/yum/el6-archive/SRPMS/
mirrorlist=https://mirror.webtatic.com/yum/el6-archive/SRPMS/mirrorlist
failovermethod=priority
enabled=0
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-webtatic-andy
yum -y install httpd php56w php56w-mysql php56w-snmp php56w-xml php56w-gd mysql-community-client mysql-community-server mysql-devel
root@pts/0 # rpm -qa|grep php
php56w-pdo-5.6.30-1.w6.x86_64
php56w-xml-5.6.30-1.w6.x86_64
php56w-cli-5.6.30-1.w6.x86_64
php56w-mysql-5.6.30-1.w6.x86_64
php56w-5.6.30-1.w6.x86_64
php56w-common-5.6.30-1.w6.x86_64
php56w-snmp-5.6.30-1.w6.x86_64
php56w-gd-5.6.30-1.w6.x86_64
root@pts/0 # rpm -qa|grep mysql
mysql-community-libs-5.6.35-2.el6.x86_64
mysql-community-server-5.6.35-2.el6.x86_64
php56w-mysql-5.6.30-1.w6.x86_64
mysql-community-common-5.6.35-2.el6.x86_64
libmysqlclient16-5.1.69-1.w6.x86_64
mysql-community-client-5.6.35-2.el6.x86_64
root@pts/0 # rpm -qa|grep http
httpd-tools-2.2.15-56.el6.centos.3.x86_64
httpd-2.2.15-56.el6.centos.3.x86_64
如果报错,将原来的安装包删除掉
wget http://www.cacti.net/downloads/spine/cacti-spine-0.8.8h.tar.gz
wget http://www.cacti.net/downloads/cacti-0.8.8h.tar.gz
tar -zxvf cacti-0.8.8h.tar.gz
mv cacti-0.8.8h /var/www/html
mysqladmin --user=root -p create cacti
mysql -uroot -p cacti < cacti.sql
mysql -u root -p mysql
mysql> GRANT ALL ON cacti.* TO cactiuser@localhost IDENTIFIED BY ‘123‘;
mysql> flush privileges;
vim include/config.php
$database_type = "mysql";
$database_default = "cacti";
$database_hostname = "localhost";
$database_username = "cactiuser";
$database_password = "123";
$database_port = "3306";
$database_ssl = false;
/* load up old style plugins here */ #enable plugins
$plugins = array();
//$plugins[] = ‘thold‘;
/*
Edit this to point to the default URL of your Cacti install
ex: if your cacti install as at http://serverip/cacti/ this
would be set to /cacti/
*/
//$url_path = "/cacti/";
/* Default session name - Session name must contain alpha characters */
//$cacti_session_name = "Cacti";
?>
useradd cactiuser
chown -R cactiuser rra/ log/
echo "*/5 * * * * cactiuser php /var/www/html/cacti/poller.php > /dev/null 2>&1">>/etc/crontab
service crond restart
在浏览器中输入:http://www.yourdomain.com/cacti进入安装步骤
vim /etc/php.ini
[Date]
; Defines the default timezone used by the date functions
; http://www.php.net/manual/en/datetime.configuration.php#ini.date.timezone
date.timezone = Asia/Shanghai
vim /etc/httpd/conf/httpd.conf
redirectMatch "^/$" "cacti"
Cacti 获取主机信息的方式有两种,系统默认是选择cmd 模式,还有一种方式是Spine ,这种方法是基于C语言的,非常快速的轮询引擎,效率比cmd 高很多
tar -zxvf cacti-spine-0.8.8h.tar.gz
cd cacti-spine-0.8.8h
./configure --with-mysql=/usr/local/mysql/
make && make install
Spine的配置文件spine.conf
[root@cacti ~]# cd /usr/local/spine/etc/
[root@cacti etc]# mv spine.conf.dist spine.conf
[root@cacti etc]# vim spine.conf
DB_Host localhost
DB_Database cacti
DB_User cacti
DB_Pass cacti
DB_Port 3306
DB_PreG 0
[root@cacti tmp]# cd /usr/local/spine/bin/
[root@cacti bin]# ./spine
出现下面类似信息,说明没有问题:
Poller[0] Time: 2.1460 s, Threads: 1, Hosts: 4
前期准备:
new server要安装好mysql及rrdtool,php等cacti安装环境必须程序,才能保证迁移过来后可以顺利访问。
old server 在操作前停止php的轮循、关闭snmp、apache等。备份完毕后恢复即可。
规划:
old server操作:
cacti迁移备份需要三个文件:1、数据库文件。2、cacti目录。3、rrd图像文件。
注意点:rrd图像文件如果不转换直接拷贝到冗余服务器上,经测试出现错误,无法正常访问。所以还是一定要转换下格式后再行迁移。
new server操作:
1、cacti目录存放 。2、数据库文件导入。3、rrd图像文件导入。
步骤:
1、old server 操作步骤:
数据库备份
mysqldump -ucacti -p cacti >/root/cacti.sql
cacti目录备份
cd /var/www
tar -zcvf html.tar.gz html --exclude rra --exclude log(此处打包压缩,cacti目录中rra log目录不做备份)
rrd图像文件备份。(此处图像文件即:cacti目录中的rra目录下的所有文件)
此处备份使用脚本。内容如下:
#!/bin/bash
rrddump="/usr/bin/rrdtool dump"
xmldir=/root/rraxml
rradir=/var/www/html/rra/
for file in `ls ${rradir}`
# find rra directory 2 days change
do
${rrddump} ${rradir}${file} > ${xmldir}/${file}.xml
done
保存为:bak.sh后,赋予执行权限。
chmod u+x bak.sh
完成后重新启动apache及spine轮循。
把old server备份的文件拖到new server上。
2、new server操作步骤:
cacti目录恢复。
tar xvzf html.tar.gz
mv html /var/www/
chown -R apache.apache /var/www/html
数据库恢复。
/usr/local/mysql/bin/mysql -uroot -p
mysql>create database cacti default character set utf8;
mysql>grant all privileges on cacti.* to cacti@localhost identified by ‘123‘;
mysql>flush privileges;
mysql>source /root/cacti.sql
恢复完成后退出。
rrd文件恢复。
此处同样用shell脚本来恢复,脚本如下:
#!/bin/bash
rrdrestore="/usr/local/rrdtool/bin/rrdtool restore"
xmldir=/root/rraxml/
for file in `find ${xmldir} |awk -F\/ ‘{print $NF}‘ |sed s/.xml//g`
do
echo $file
${rrdrestore} ${xmldir}${file}.xml /data2/cacti/rra/${file}
done
保存为Recovery.sh,赋予执行权限。
chmod u+x Recovery.sh
./Recovery.sh
到此已基本迁移完成,重启服务
/etc/init.d/httpd restart
service snmpd restart
标签:cacti
原文地址:http://blog.51cto.com/chaichuan/2094108