zabbix 4.0 LTS agent部署及percona mysql plugin安装

第一部分 agent部署
1.解压源码包到/usr/local
tar -xvf /dfile/zabbix-4.0.7.tar.gz -c /usr/local/
2.安装依赖包
yum install -y gcc
3.创建用户
useradd -r -s /sbin/nologin zabbix
4.编译并安装
./configure --prefix=/usr/local/zabbix --enable-agent
make install
5.创建目录
mkdir -p /usr/local/zabbix/{logs,tmps}
chown -R zabbix:zabbix /usr/local/zabbix/{logs,tmps}
6.修改配置文件
egrep -v "^#|^$" /usr/local/zabbix/etc/zabbix_agentd.conf
PidFile=/usr/local/zabbix/tmps/zabbix_agentd.pid
LogFile=/usr/local/zabbix/logs/zabbix_agentd.log
EnableRemoteCommands=0
Server=172.18.0.10
ListenPort=10050
StartAgents=1
ServerActive=172.18.0.10
Hostname=172.18.0.150
Timeout=30
Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/
UnsafeUserParameters=1
7.配置启动文件
cp /usr/local/zabbix-4.0.7/misc/init.d/fedora/core/zabbix_agentd /etc/init.d/zabbix_agentd
[root@dzst150 etc]# egrep "BASEDIR=|PIDFILE=" /etc/init.d/zabbix_agentd
BASEDIR=/usr/local/zabbix
PIDFILE=$BASEDIR/tmps/$BINARY_NAME.pid
8.启动 agent
/etc/init.d/zabbix_agentd start
9.在web界面添加主机信息
10.等一会,就可以查看主机负载了
第二部分  部署percona mysql plugin
1.上传监控的目标服务武器进行安装
[root@dzst150 dfile]# rpm -ivh percona-zabbix-templates-1.1.8-1.noarch.rpm
Preparing... ################################# [100%]
package percona-zabbix-templates-1.1.8-1.noarch is already installed
2.安装依赖包
yum install -y php php-mysql
2./var/lib/zabbix会有个percona目录,具体文件大概功能说明
[root@dzst150 zabbix]# tree percona/
percona/
|-- 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
scripts/get_mysql_stats_wrapper.sh ## 是监控获取MySQL状态
scripts/ss_get_mysql_stats.php ## 是配置连接数据库用户名密码等,用shell来调用该PHP文件 templates/userparameter_percona_mysql.conf ## 实际zabbix agent需要的配置文件 templates/zabbix_agent_template_percona_mysql_server_ht_2.0.9-sver1.1.8.xml ## zabbix 模板
3.将 userparameter_percona_mysql.conf 复制到/usr/local/zabbix/etc/zabbix_agentd.conf.d,注意userparameter_percona_mysql.conf这个文件里记录的脚本位置
cp /var/lib/zabbix/percona/templates/userparameter_percona_mysql.conf /usr/local/zabbix/etc/zabbix_agentd.conf.d/
4.修改zabbix agent配置文件,添加如下信息
Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/
4.修改/var/lib/zabbix/percona/ss_get_mysql_stats.php.cnf配置信息
$mysql_user = 'zabbix';
$mysql_pass = 'zabbix';
$mysql_port = 3306;
$mysql_socket = '/tmp/mysql3306.sock';
$cache_file = "$cache_dir/$sanitized_host-mysql_cacti_stats.txt.3306" . ($port != 3306 ? ":$port" : '');
5.修改get_mysql_stats_wrapper.sh 文件
CACHEFILE="/tmp/$HOST-mysql_cacti_stats.txt:3306"
RES=`HOME=~zabbix /usr/local/mysql/bin/mysql -uzabbix -pzabbix -S /tmp/mysql3306.sock -e 'SHOW SLAVE STATUS\G' | egrep '(Slave_IO_Running|Slave_SQL_Running):' | awk -F: '{print $2}' | tr '\n' ','`
TIMEFLM=`stat -c %Y /tmp/$HOST-mysql_cacti_stats.txt:3306`
6.目标db创建监控账号
GRANT SELECT, PROCESS, SUPER, REPLICATION CLIENT ON *.* TO 'zabbix'@'%' IDENTIFIED BY "zabbix";
flush privileges;
7.修改percona目录及脚本的权限
chown -R zabbix:zabbix /var/lib/zabbix/
chmod -R 755 /var/lib/zabbix/percona/scripts/*
8.创建临时文件,并授权
touch 172.18.0.150-mysql_cacti_stats.txt.3306
chown -R zabbix.zabbix /tmp/172.18.0.150-mysql_cacti_stats.txt.3306
8.重启zabbix agent
/etc/init.d/zabbix_agentd restart
9.验证
agent端验证,返回数字即可
/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh gg
64

server端验证
/usr/local/zabbix/bin/zabbix_get -s 172.18.0.150 -p 10050 -k "MySQL.Threads-connected"
3
10.配置web模板信息
官方下载的文档导入,会直接报错
11.在zabbix2.4版本导入,然后导出后,再导入4.0即可
具体操作不过多说明,搭建基于5.5版本的mysql,然后搭建2.4 zabbix server即可;可以从https://github.com/trsenzhang/db_monitor/zabbix4.0_percona_monitor_mysql_plugin下载1.1.8版本
12.可以看到buffer里的信息了