网络监控cacti1.2.12安装部署(一)
网络监控cacti1.2.12安装部署(一)
网络监控cacti1.2.12监控配置(二)
网络监控cacti1.2.12邮件报警(三)
网络监控cacti1.2.12图形显示故障(四)
网络监控cacti1.2.12解决图像显示乱码(五)
一、cacti概述
cacti是基于php语言实现的一个软件,通过snmp协议获取信息,并将信息存储在rrdtool中,用户可以将需要查看的数据通过rrdtool生成图表显示出来。所以snmp和rrdtool是cacti的核心所在。
cacti架构:
cacti工作流程:
二、安装cacti 1.2.12
备注:本次搭建使用centos7系统,可参见centos7模板机搭建部署
1、安装软件
yum install -y httpd php php-mysql php-snmp php-xml php-ldap php-gd php-mbstring php-posix
2、设置时区
[root@localhost ~]# vim /etc/php.ini[PHP]……date.timezone = Asia/Shanghai #878行
3、开机启动httpd
systemctl start httpd && systemctl enable httpd
4、安装db
4.1 设置db yum安装源
cat >/etc/yum.repos.d/MariaDB.repo<<EOF[mariadb]name = MariaDBbaseurl = /10.3/centos7-amd64gpgkey=/RPM-GPG-KEY-MariaDBgpgcheck=1EOF
4.2 安装DB
yum install -y MariaDB-server MariaDB-client MariaDB-devel
4.3 启动db,并设置开机启动
systemctl start mariadb && systemctl enable mariadb
4.4 初始化数据库,设定密码,除了开始直接回车,其他的选择都输入Y。
[root@localhost ~]# mysql_secure_installationNOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDBSERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!......Enter current password for root (enter for none): //初始数据库密码为空,直接按回车键OK, successfully used password, moving on.........Set root password? [Y/n] Y //输入root管理员密码New password: Re-enter new password: Password updated successfully!......Remove anonymous users? [Y/n] Y //删除匿名账号... Success!......Disallow root login remotely? [Y/n] Y //禁止root管理员从远程登录... Success!.......Remove test database and access to it? [Y/n] Y //删除test数据库并取消对它的访问权限......Reload privilege tables now? [Y/n] Y //刷新授权表,让初始化后的设定立即生效... Success!
4.5 配置MariaDB参数
[root@cacti ~]# vim /etc/f.d/f[server]# this is only for the mysqld standalone daemoncharacter_set_server = utf8mb4collation-server = utf8mb4_unicode_cimax_heap_table_size = 256Mmax_allowed_packet = 16777216tmp_table_size = 64Mjoin_buffer_size = 64Minnodb_file_per_table = ONinnodb_buffer_pool_size = 1024Minnodb_doublewrite = OFFinnodb_flush_log_at_timeout = 3innodb_read_io_threads = 32innodb_write_io_threads =16innodb_file_format = Barracudainnodb_large_prefix = 1
5、安装snmp
yum install –y net-snmp net-snmp-libs net-snmp-utils net-snmp-devel net-snmp-perl
5.1 配置snmp
vim /etc/snmp/snmpd.conf......//修改default为本机(cacti服务器)的ip,修改public为自己的团体名(一般不改),42行com2sec notConfigUser 192.168.95.234 public//把systemview改成all ,供所有snmp 访问权限 64行access notConfigGroup "" any noauth exact all none none view all included .1 80 // 去掉#号 85行......
5.2 启动snmp并设置开机启动
systemctl start snmpd.service && systemctl enable snmpd.service
5.3 验证snmp是否生效
snmpwalk -v 2c -c public localhost
6、安装RRDTool 绘图工具
yum -y install lm_sensors gcc gcc-c++ libart_lgpl-devel zlib-devel libpng-devel freetype-devel gettext-devel glib2-devel pcre-devel pango-devel cairo-devel libxml2-devel perl-ExtUtils-CBuilder perl-ExtUtils-MakeMaker rrdtool
7、安装spine
7.1 安装spine编译软件
yum install -y dos2unix autoconf automake binutils libtool cpp glibc-headers glibc-devel help2man
7.2 下载cacti-spine-1.2.12,这里版本要与cacti相同,
cd /usr/local/srcwget /downloads/spine/cacti-spine-1.2.12.tar.gz
7.3 编译安装cacti-spine
tar zxvf cacti-spine-1.2.12.tar.gzcd cacti-spine-1.2.12./bootstrap./configuremake && make installchown root:root /usr/local/spine/bin/spinechmod +s /usr/local/spine/bin/spine————————————————如果make时出现/usr/bin/ld: cannot find -lmysqlclientcollect2: ld returned 1 exit statusmake: *** [spine] Error 1原因:编译你的工程代码之前之前,先处理一下mysql的库,默认查找libmysqlclient_r.so,可是mysql默认为libmysqlclient.so,内容完全一样,做个链接即可请在root下执行cd /usr/local/mysql/lib/mysql/ (库所在目录)ln -s libmysqlclient.so.15.0.0 libmysqlclient_r.so————————————————
7.4 编辑spine.conf
cp /usr/local/spine/etc/spine.conf.dist /etc/spine.conf
vim /etc/spine.conf#找到里面对应参数,根据实际情况修改,这里测试就不改了DB_Host localhostDB_Database cactiDB_User cactiuserDB_Pass cactiuserDB_Port 3306
8、 安装cacti
cd /usr/local/srcwget /downloads/cacti-1.2.12.tar.gztar zxvf cacti-1.2.12.tar.gzmv cacti-1.2.12 /var/www/html/cacti
8.1 创建cacti数据库,创建数据库用户cactiuser,设置用户相关授权
[root@localhost src]# mysql -uroot -pMariaDB [(none)]> create database cacti;Query OK, 1 row affected (0.002 sec)MariaDB [(none)]> grant all on cacti.* to cactiuser@localhost identified by "cactiuser";Query OK, 0 rows affected (0.003 sec)MariaDB [(none)]> grant select on mysql.time_zone_name to 'cactiuser'@'localhost' identified by 'cactiuser';Query OK, 0 rows affected (0.001 sec)
8.2 导入 Cacti 默认数据库
MariaDB [(none)]> use cacti;Database changedMariaDB [cacti]> source /var/www/html/cacti/cacti.sql;......MariaDB [cacti]> flush privileges;Query OK, 0 rows affected (0.00 sec)MariaDB [cacti]> quit
测试:
#出现信息/usr/local/spine/bin/spine
8.3 配置数据库时区
[root@localhost ~]# mysql_tzinfo_to_sql /usr/share/zoneinfo/ | mysql -u root -p mysqlEnter password:Warning: Unable to load '/usr/share/zoneinfo//leapseconds' as time zone. Skipping it.Warning: Unable to load '/usr/share/zoneinfo//tzdata.zi' as time zone. Skipping it.
8.4 配置config.php
[root@localhost ~]# vim /var/www/html/cacti/include/config.php......$database_type= 'mysql';$database_default = 'cacti';$database_hostname = 'localhost';$database_username = 'cactiuser';$database_password = 'cactiuser';$database_port= '3306';$database_retries = 5;$database_ssl= false;$database_ssl_key = '';$database_ssl_cert = '';$database_ssl_ca = '';......
8.5 创建日志文件,后续安装时用的到
touch /var/www/html/cacti/log/cacti.logtouch /var/www/html/cacti/log/cacti_stderr.log
9、创建用户cactiuser,并授权
useradd cactiuserchown apache.apache /var/www/html/cacti/ -Rchown cactiuser /var/www/html/cacti/{rra,log}/ -Rchmod 777 /var/www/html/cacti/{rra,log}/ -R
10、重启服务
systemctl restart httpd && systemctl restart mariadb && systemctl restart snmpd
11、配置页面
11.1 浏览器输入http://ip/cacti,默认密码admin/admin
11.2 修改密码
#注意密码复杂度
11.3 解决PHP警告
解决办法:
修改/etc/php.ini中两个告警参数
11.4 解决mysql警告
修改vi /etc/f.d/f,根据警告信息,本着没有就加,不对就改的原则配置以下参数
重启一下服务,并刷新浏览器:
systemctl restart httpd && systemctl restart mariadb && systemctl restart snmpd
ok,安装成功