Zabbix MySQL percona
服务端执行以下操作
https://www.zabbix.com/download?zabbix=4.0&os_distribution=centos&os_version=7&db=mysql
1、安装zabbix yum源
#rpm -Uvh https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm
# yum clean all
2、安装服务端
# yum -y install zabbix-server-mysql zabbix-web-mysql zabbix-agent zabbix_get
3、初始化mysql zabbix数据库
# mysql -uroot -p
password
mysql> create database zabbix character set utf8 collate utf8_bin;
mysql> grant all privileges on zabbix.* to zabbix@localhost identified by 'password';
mysql> quit;
Import initial schema and data. You will be prompted to enter your newly created password.
# zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p zabbix
4、配置Zabbix数据库
Edit file /etc/zabbix/zabbix_server.conf
DBPassword=password
5、配置PHP for Zabbix前端
Edit file /etc/httpd/conf.d/zabbix.conf, uncomment and set the right timezone for you.
# php_value date.timezone Europe/Riga
php_value date.timezone Asia/ShangHai
6. 开启 Zabbix server和代理进程
Start Zabbix server and agent processes and make it start at system boot:
# systemctl restart zabbix-server zabbix-agent httpd
# systemctl enable zabbix-server zabbix-agent httpd
7、配置Zabbix前端
Connect to your newly installed Zabbix frontend: http://server_ip_or_name/zabbix
Follow steps described in Zabbix documentation: Installing frontend
客户端执行以下操作
1、在官方下载页面下载zabbix-agent并安装
https://www.zabbix.com/download
2、安装zabbix客户端及依赖
yum -y install zabbix-agent php php-mysql
3、 安装percona-zabbix-templates
下载地址https://www.percona.com/downloads/percona-monitoring-plugins/LATEST/
rpm -ivh percona-zabbix-templates-1.1.8-1.noarch.rpm
本例在1.1.7上进行
rpm -ivh https://www.percona.com/downloads/percona-monitoring-plugins/percona-monitoring-plugins-1.1.7/binary/redhat/6/x86_64/percona-zabbix-templates-1.1.7-2.noarch.rpm
安装好了,会生成这么些文件
# cd /var/lib/zabbix/percona/
# tree
.
├── scripts
│ ├── get_mysql_stats_wrapper.sh
│ └── ss_get_mysql_stats.php
└── templates
├── userparameter_percona_mysql.conf
└── zabbix_agent_template_percona_mysql_server_ht_2.0.9-sver1.1.8.xml
2 directories, 4 files
4、复制配置文件到percona的配置目录
# chown -R zabbix.zabbix /var/lib/zabbix/percona/
# mkdir -p /var/lib/mysql
#ln -s /data/db/mysql4001/mysql4001.sock /var/lib/mysql/mysql.sock
cp /var/lib/zabbix/percona/templates/userparameter_percona_mysql.conf /etc/zabbix/zabbix_agentd.d/
5、修改配置文件
#vim /var/lib/zabbix/percona/scripts/ss_get_mysql_stats.php
$mysql_user = 'root';
$mysql_pass = '';
$mysql_port = 3306;
#注意:这里填写的用户和密码必须有localhost登录权限,否则获取不到key值。
vi /var/lib/zabbix/percona/scripts/ss_get_mysql_stats.php.cnf
<?php
$mysql_user='root';
$mysql_pass='myadmin';
sed -i 's#HOST=localhost#HOST=127.0.0.1#g' /var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh
如果监控的是zabbix-server上的数据库,那么上一步不需要执行.
chmod +x /var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh
修改zabbix-ageent 配置文件
sed -i.ori '98s#127.0.0.1#172.16.1.71#' /etc/zabbix/zabbix_agentd.conf
echo '/etc/init.d/zabbix-agent start' >>/etc/rc.local
错误案例:
客户端始终返回不了值,排查也没有发现问题
[root@TestMySQL2 ~]# /usr/bin/php -q /var/lib/zabbix/percona/scripts/ss_get_mysql_stats.php --host 127.0.0.1 --items gg
ERROR: Can't connect vim /var/lib/zabbix/percona/scripts/ss_get_mysql_stats.php
[root@TestMySQL2 ~]# /usr/bin/php -q /var/lib/zabbix/percona/scripts/ss_get_mysql_stats.php --host 127.0.0.1 --items gg
gg:6[root@TestMySQL2 /var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh gg
最终在 scripts]# vim get_mysql_stats_wrapper.sh 里发现问题
在/tmp里有这么个文件
-rw-rw-r--. 1 zabbix zabbix 1264 May 1 20:33 127.0.0.1-mysql_cacti_stats.txt:4001
在get_mysql_stats_wrapper.sh里的文件 名没有加端口号
修改后一切正常
CACHEFILE="/tmp/$HOST-mysql_cacti_stats.txt:4001"