Docker容器与虚拟化技术——服务器监控Cacti

                                                        服务器监控Cacti

一、简介
Cacti是一款用PHP开发的性能与流量监测工具,监测对象可以使Linux或Windows服务器,也可以是路由器、交换机等网络设备,主要基于SNMP来搜集CPU占用、内存使用、运行进程数、磁盘空间、网卡流量等各种数据。
Cacti通过调用Net-SNMP工具采集监测数据,并结合RRDTool记录数据并绘制图片,最终以Web形式展现给用户

二、配置
1、服务器配置
(1)构建LAMP或LNMP
①yum install -y httpd php php-mysql php-snmp php-xml php-ldap php-gd php-mbstring php-posix
②mariadb源配置

cat >> /etc/yum.repos.d/mariadb.repo << "EOF"
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.3/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
EOF

③yum install -y MariaDB-server MariaDB-client MariaDB-devel
④systemctl start mariadb && systemctl enable mariadb
⑤mysql_secure_installation
⑥vim /etc/my.cnf.d/server.cnf

[server]
character_set_server = utf8mb4
collation-server = utf8mb4_unicode_ci
max_heap_table_size = 256M
max_allowed_packet = 16777216
tmp_table_size = 64M
join_buffer_size = 64M
innodb_file_per_table = ON
innodb_buffer_pool_size = 1024M
innodb_doublewrite = OFF
innodb_flush_log_at_timeout = 3
innodb_read_io_threads = 32
innodb_write_io_threads =16
innodb_file_format = Barracuda
innodb_large_prefix = 1

⑦systemctl restart mariadb
(2)支持包安装(Net-SNMP及RRDtool)
①yum install -y net-snmp net-snmp-libs net-snmp-utils net-snmp-devel net-snmp-perl
②yum install -y rrdtool rrdtool-devel rrdtool-php rrdtool-perl perl-devel perl-CPAN perl-YAML
(3)安装cacti
①官网下载安装包
②解包到/var/www/html/cacti目录
(4)配置
①数据库配置
1)create database cacti;
2)grant all on cacti.* to cactiuser@localhost identified by "cactiuser";
3)GRANT SELECT ON mysql.time_zone_name TO 'cactiuser'@'localhost' IDENTIFIED BY 'cactiuser';
4)mysql_tzinfo_to_sql /usr/share/zoneinfo/ | mysql -u root -p mysql
5)mysql -uroot -p111111 cacti < /var/www/html/cacti/cacti.sql
②打开网页按说明修改php及mysql配置文件
1)默认用户及密码均为admin
(5)数据采集
①添加cron计划任务
每5分钟执行一次php /var/www/html/cacti/poller.php> /dev/null 2>&1
2、添加其他客户端
(1)Linux系统
①安装net-snmp及lm_sensors软件包
yum -y install net-snmp lm_sensors
②修改snmpd.conf
1)41行:…… 192.168.11.151 public
2)62行:…… all none none
3)85行:去掉#
③启动snmpd服务
(2)Windows系统
①启用snmp服务

②启动服务

③防火墙设置

④通过服务管理界面双击SNMP打开SNMP服务设置

⑤重启SNMP服务
(3)服务器添加客户端

 

三、模板导入
1、下载模板
wget https://www.percona.com/downloads/percona-monitoring-plugins/1.1.6/percona-monitoring-plugins-1.1.6.tar.gz
2、解包
3、将目录中的ss_get_mysql_stats.php复制到cacti的scripts目录
cp ss_get_mysql_stats.php /var/www/html/cacti/scripts/
4、在web中导入tar包中的cacti_host_template_percona_mysql_server_ht_0.8.6i-sver1.1.4.xml文件


四、插件安装
1、下载插件:https://github.com/Cacti/
wget https://github.com/Cacti/plugin_thold/archive/develop.zip
2、解压并复制到cacti目录内
unzip develop.zip
mv plugin_thold-develop/ thold
mv thold /var/www/html/cacti/plugins
3、web页面安装并启用插件


五、设置邮件报警

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章