zabbix3.2安装Percona Monitoring Plugins

系统要求

  • Zabbix版本2.0.x. 实际测试在2.0.9版本可行
  • zabbix-agent端环境需要zabbix-agent php php-mysql packages

zabbix客户端

安装环境包和percona插件

yum install zabbix-agent php php-mysql -y
yum install percona-zabbix-templates -y

配置zabbix_agentd.conf

#配置zabbixServer端地址
sed -i 's/Server=.*/Server='192.168.1.1'/g' /etc/zabbix/zabbix_agentd.conf
sed -i 's/ServerActive=.*/ServerActive='192.168.1.1'/g' /etc/zabbix/zabbix_agentd.conf
#配置client注册的名字
sed -i 's/Hostname=.*/Hostname='mysql'/g' /etc/zabbix/zabbix_agentd.conf
#开机启动
chkconfig zabbix-agent on
#启动agent
service zabbix-agent start

拷贝percona配置文件

cp /var/lib/zabbix/percona/templates/userparameter_percona_mysql.conf /etc/zabbix/zabbix_agentd.conf.d/

确认配置文件被包含在zabbix_agentd.conf

grep '^Include' /etc/zabbix/zabbix_agentd.conf
#Include=/etc/zabbix/zabbix_agentd.d/*.conf

Agent端配置Mysql连接

vim  /var/lib/zabbix/percona/scripts/ss_get_mysql_stats.php.cnf

TEST

sh /var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh gg

配置~zabbix/.my.cnf

vim ~zabbix/.my.cnf
[client]
user = root
password = s3cret

TEST

sudo -u zabbix -H /var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh running-slave
#0

如果遇到zabbix用户权限问题,解决方法:

chown -R zabbix:zabbix /tmp/localhost-mysql_cacti_stats.txt
service zabbix-agent restart

zabbix服务端

  • 安装完percona-zabbix-templates后,在/var/lib/zabbix/percona/templates目录有xml模板。
  • 进入zabbixUI界面,(配置 - >模板 - >导入)导入XML模板。
  • 通过为主机分配“Percona模板”组并链接模板“Percona MySQL服务器模板”(模板选项卡)来创建/编辑主机。

zabbix3.0版本环境不能直接导入,解决方法是:找个zabbix2.2或2.4版本环境中转一下,即从2.2版本中导出后,再导入到3.0版本。

下载地址:percona_mysql_template

客户端脚本安装

为了方便批量、简洁安装,写了个shell脚本,将tar包解压后,直接运行./install.sh,根据提示输入,即可完成安装。
下载地址:脚本安装

此脚本只适用于端口为3306的mysql,想要匹配任意版本,可以自行修改部分页面接口值。

#!/bin/bash
## Date:                2018-09-17
## Author               Browser
## Describtion          Install percona_mysql Plugins
## Version:             1.0

install_rpm()
{
num_php=$(rpm -qa | grep php | wc -l)
num_zabbix=$(rpm -qa | grep zabbix-agent | wc -l)
num_percona=$(rpm -qa | grep percona | wc -l)

if [[ $num_php -ge 5 ]];then
                echo "============================================================"
                echo -e "\e[1;42m The PHP environment has allready installed \e[0m"
                echo "============================================================"
        else
                echo "============================================================"
                echo -e "\e[1;41m Need to install PHP environment \e[0m"
                echo "============================================================"
                yum install  php php-mysql
fi

if [[ $num_zabbix -ne 0 ]];then
                echo "============================================================"
                echo -e "\e[1;42m The zabbix-agent has allready installed \e[0m"
                echo "============================================================"
        else
                echo "============================================================"
                echo -e "\e[1;41m Need to install zabbix-agent \e[0m"
                echo "============================================================"
                yum install  zabbix-agent-3.2.6-1.el6.x86_64.rpm
fi

if [[ $num_percona -ne 0 ]];then
                echo "============================================================"
                echo -e "\e[1;42m The percona_mysql_template has allready installed \e[0m"
                echo "============================================================"
        else
                echo "============================================================"
                echo -e "\e[1;41m Need to install percona_mysql_template \e[0m"
                echo "============================================================"
                yum install  percona-zabbix-templates-1.1.8-1.noarch.rpm
fi

}

configure_zabbix_agent()
{
        read -p "Please Enter Zabbix_Server IP Address:" zabbix_server_address
        read -p "Please Enter hostname for the system:" hostname
        sed -i 's/Server=.*/Server='${zabbix_server_address}'/g' /etc/zabbix/zabbix_agentd.conf
        sed -i 's/ServerActive=.*/ServerActive='${zabbix_server_address}'/g' /etc/zabbix/zabbix_agentd.conf
        sed -i 's/Hostname=.*/Hostname='${hostname}'/g' /etc/zabbix/zabbix_agentd.conf
        chkconfig zabbix-agent on
        service zabbix-agent start
}

configure_pecona_mysql()
{
        cp -rf /var/lib/zabbix/percona/templates/userparameter_percona_mysql.conf /etc/zabbix/zabbix_agentd.d/userparameter_percona_mysql.conf

if [[ ! -f /var/lib/zabbix/percona/scripts/ss_get_mysql_stats.php.cnf ]];then
                touch /var/lib/zabbix/percona/scripts/ss_get_mysql_stats.php.cnf
fi 
        read -p "Please Enter the mysql_user:" mysql_user
        read -p "Please Enter the mysql_pass:" mysql_pass
        echo "
msyql_user = $mysql_user
mysql_pass = $mysql_pass" > /var/lib/zabbix/percona/scripts/ss_get_mysql_stats.php.cnf

if [[ ! -f ~/zabbix/.my.cnf ]];then
                touch ~zabbix/.my.cnf
fi
        read -p "Please enter the root password for the system:" password
        echo "[client] 
user = root
password = $password" > ~zabbix/.my.cnf

        service zabbix-agent restart 
        sleep 5s
        bash /var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh gg 
        sudo -u zabbix -H /var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh running-slave
if [[ $? -ne 0 ]];then
                echo -e "\e[1;43 mysql test was successful \e[0m"
        else
                echo -e "\e[1;41 mysql test was failed \e[0m"
fi

chown -R zabbix:zabbix /tmp/localhost-mysql_cacti_stats.txt

}
####main####
install_rpm
configure_zabbix_agent
configure_pecona_mysql

你可能感兴趣的:(zabbix3.2安装Percona Monitoring Plugins)