Centos7搭建新版本cacti1.2.10

新版本cacti刚刚放出来,正好遇上旧版本的cacti用着不给力,就重新搭建了一个新版本。

 

环境:
系统:Centos7.6
cacti版本:v1.2.10

需要安装的组件:

php 7.3
mysql 5.7
rrdtool 1.7
spine1.2.10
nginx

 

一、yum源添加

添加epel源

cd /etc/yum.repos.d/
mkdir repo_bak
mv *.repo repo_bak/
yum install wget
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum celan all
yum makecache
yum install epel-release

  

添加wlnmp一键包源,如果无法直接安装,可以尝试不同网络下载,然后再传到服务器上

rpm -ivh http://mirrors.whsir.com/centos/whsir-release-centos.noarch.rpm
rpm -ivh http://mirrors.wlnmp.com/centos/wlnmp-release-centos.noarch.rpm

  

二、安装nginx、php、mysql

yum install wnginx wphp71 wmysql57
yum install wphp71-ldap wphp71-snmp wrrdtool wnet-snmp sendmail

设置库文件的两个软链接

ln -sv /usr/local/mysql/lib/libmysqlclient.so.20 /usr/lib64/libmysqlclient.so.20 
ln -sv /usr/local/mysql/lib/libmysqlclient.so /usr/lib64/libmysqlclient.so

  

1、php相关配置

  vi /usr/local/php/etc/php.ini  
##找到disable_functions行,删除所有关于exec与popen的值
##修改时区如下:
date.timezone = Asia/Shanghai

 启动php

/etc/init.d/php-fpm71 start

  

2、mysql相关配置

修改默认MySQL密码,创建cacti数据库,并添加相应权限

mysql -uroot -p
set password = password('yourpassword'); ##设置mysql的root密码
CREATE DATABASE cacti DEFAULT CHARACTER SET utf8;  ##字符集utf-8
GRANT ALL ON cacti.* TO cacti@localhost IDENTIFIED BY 'yourpassword';  ##新建cacti用户,授权管理数据库cacti
GRANT SELECT ON mysql.time_zone_name TO cacti@localhost IDENTIFIED BY 'yourpassword'; 
ALTER DATABASE cacti CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
flush privileges;
quit

解决MySQL TimeZone database is not populated问题,如果导入失败,跳过即可

/usr/local/mysql/bin/mysql_tzinfo_to_sql /usr/share/zoneinfo/ | mysql -uroot -pmeiyoumima@ mysql

启动mysql

/etc/init.d/mysql start 

  

3、ngixn相关配置

新建站点文件

mv /usr/local/nginx/conf/vhost/demo.conf  /usr/local/nginx/conf/vhost/cacti.conf

  


修改root路径为你的web文件存储的位置,我这里是 /Apps/www;,取消php注释include enable-php71.conf;,修改下server_name为本机IP,或者自己填个域名,自行hosts,

    server
        {
            listen 80 default_server;
            server_name 192.168.1.6;
            index index.html index.htm index.php;
            root /Apps/www;
    
            error_page   500 502 503 504  /50x.html;
    
            #include enable-php56.conf;
            #include enable-php70.conf;
            include enable-php71.conf;
            #include enable-php72.conf;
            #include enable-php73.conf;
            #include enable-php74.conf;
    
            location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
            {
                expires      30d;
            }
    
            location ~ .*\.(js|css)?$
            {
                expires      12h;
            }
    
            access_log  /Apps/www/cacti/log/cacti_access.log;
            error_log /Apps/www/cacti/log/cacti_error.log;
    }

添加相关软链接

ln -sv /usr/local/rrdtool/bin/rrdtool /usr/local/bin/rrdtool
ln -sv /usr/local/php/bin/php /usr/bin/php
ln -sv /usr/local/snmp/bin/snmpwalk /usr/local/bin/snmpwalk
ln -sv /usr/local/snmp/bin/snmpget /usr/local/bin/snmpget
ln -sv /usr/local/snmp/bin/snmpbulkwalk /usr/local/bin/snmpbulkwalk
ln -sv /usr/local/snmp/bin/snmpgetnext /usr/local/bin/snmpgetnext
ln -sv /usr/local/snmp/bin/snmptrap /usr/local/bin/snmptrap 

启动nginx

/etc/init.d/nginx start 

  

三、安装cacti、spine

1、cacti安装

wget https://www.cacti.net/downloads/cacti-1.2.10.tar.gz
tar xf cacti-1.2.10.tar.gz
mkdir -p /Apps/www/
mv cacti-1.2.10 /Apps/www/cacti
chown -R www:www /Apps/www/cacti

修改配置

cd /Apps/www/cacti/include
vi config.php

$database_type = 'mysql';
$database_default = 'cacti';
$database_hostname = 'localhost';
$database_username = 'cacti';
$database_password = 'yourpassword';
$database_port = '3306';
$database_ssl = false;

  

导入初始数据文件

mysql -uroot -pmeiyoumima@ cacti < /Apps/www/cacti/cacti.sql

  

解决中文乱码问题:

yum -y install wqy-microhei-fonts
cp /usr/share/fonts/wqy-microhei/wqy-microhei.ttc /usr/share/fonts/dejavu/DejaVuSans.ttf

mysql的 /etc/my.cnf配置文件添加:

[mysqld]
log_bin_trust_function_creators=1

 

至此cacti已经安装完毕,访问http://your-ip/cacti 即可访问站点

安装到这一步的时候,有个bug,记得去掉最下面的打钩,否则安装会卡住

页面安装的同时,我们来安装spine

2、 spine安装

[root@cacti-server ~]# wget https://www.cacti.net/downloads/spine/cacti-spine-1.2.10.tar.gz
[root@cacti-server ~]# yum -y install  dos2unix autoconf automake binutils libtool gcc cpp glibc-headers glibc-devel help2man openssl-devel
[root@cacti-server ~]# tar -xf cacti-spine-1.2.10.tar.gz
[root@cacti-server ~]# cp -R cacti-spine-1.2.10 /usr/local/spine
[root@cacti-server ~]# cd /usr/local/spine
[root@cacti-server spine]# ln -s /usr/lib64/libmysqlclient.so.18.0.0 /usr/lib64/libmysqlclient.so
[root@cacti-server spine]# sh bootstrap
[root@cacti-server spine]# ./configure
[root@cacti-server spine]# make &&make install
[root@cacti-server spine]# chown root:root /usr/local/spine/bin/spine
[root@cacti-server spine]# chmod +s /usr/local/spine/bin/spine

[root@cacti-server spine]# cp  /usr/local/spine/etc/spine.conf.dist /etc/spine.conf
#修改/etc/spine.conf如下部分
[root@cacti-server spine]# vim /etc/spine.conf
......
DB_Host                 localhost
DB_Database             cacti
DB_User                 cactiuser
DB_Pass                 cactiuser
DB_Port                 3306

安装完成后测试一下:

/usr/local/spine/bin/spine

安装完成后将后台轮询器改为spine即可(Thold忽略即可,这个是阙值报警插件,有兴趣的可以参考我另外一篇关于cacti邮件报警的文章)

 

 

 

poller采集周期按需求设定即可,我这边是每分钟轮询一次

[root@localhost ~]# crontab -l
* * * * * /usr/bin/php /Apps/www/cacti/poller.php > /dev/null 2>&1

写在结尾:

在安装学习cacti的过程中的一些参考资料,这边也顺便提一下:

github介绍文档:
https://github.com/Cacti/documentation/blob/develop/README.md

九五配置说明文档:
https://docs.cacti.net/manual:100:6_reference.variables#variables
Rrdtool http://www.360doc.com/content/07/0302/20/15540_382048.shtml 插件说明 https://github.com/Cacti/documentation/blob/develop/Plugins.md

 

 

 

 

 

 

posted @ 2020-04-17 22:09  运维军火库  阅读(2203)  评论(0编辑  收藏  举报