标签:zabbix

一看必会系列:Not all processes could be identified, non-owned process info

No Comments 脚本技巧

zabbix

 

原因

zabbix_get执行的脚本中含有netstat -lantp命令报错,原因是-p参数需要root用户才能使用

解决方法 :
chmod +s /bin/netstat

chmod +s 是什么意思

为了方便普通用户执行一些特权命令,SUID/SGID程序允许普通用户以root身份暂时执行该程序,并在执行结束后再恢复身份。
zabbix 服务器测试
------中间广告---------

zabbix_get -s 4 -p 10050 -k tcp.status[established+exec.jar]

(Not all processes could be identified, non-owned process info

will not be shown, you would have to be root to see it all.)

]# zabbix_get -s 4 -p 10050 -k tcp.status[established+exec.jar]

(Not all processes could be identified, non-owned process info

will not be shown, you would have to be root to see it all.)

本端服务器,鸟用

 

通过在执行的脚本中执行chmod +s /bin/netstat 解决

一看必会系列:zabbix 3.4 图形中文乱码解决

No Comments IT必备工具

zabbix 3.4 图形中文乱码解决

1. 在windows 找到 楷体中文 simkai.ttf 复制到
cd /usr/share/zabbix/fonts/

2.修改defines.inc.php   将grahfont 替换成simkai 改两个地方
vim /usr/share/zabbix/include/defines.inc.php
cd /usr/share/zabbix/include/
cp defines.inc.php defines.inc.php.bak
vim defines.inc.php

3.刷新即可
history

zabbix 自动变成K,M,G 解决方法

No Comments IT必备工具

 

问题:zabbix在取到的值很大时会自动变成K,M,G

 

解决方法:

find / -name func.inc.php
/usr/share/zabbix/include/func.inc.php

1、修改/var/www/html/zabbix/include/func.inc.php文件(这个文件不一定在这,自己find找下)

将$blackList = [‘%’, ‘ms’, ‘rpm’, ‘RPM’];

改为$blackList = [‘%’, ‘ms’, ‘rpm’, ‘RPM’, ‘条’];

这个‘条’是我当前需要的单位,你可以根据自己的需求自定义,比如ge,mm都可以

2、将自己的监控项的单位设置成刚刚新加的“条”

zabbix 3.4 增加自定义key并出图

No Comments IT必备工具

—————安装zabbix-get
wget http://repo.zabbix.com/zabbix/3.4/ubuntu/pool/main/z/zabbix/zabbix-get_3.4.9-1%2Bxenial_amd64.deb
ll
dpkg -i zabbix-get_3.4.9-1+xenial_amd64.deb
 
 
 
————–在zabbix-agent新增配置文件
 
root@:/usr/local/zabbix/script# ll
total 16
drwxr-xr-x 2 root   root   4096 Aug 27 05:47 ./
drwxr-xr-x 8 zabbix zabbix 4096 Aug 27 05:43 ../
-rwxr-xr-x 1 root   root     35 Aug 27 05:47 btc2zabbix.sh*   自定议KEY
-rwxr-xr-x 1 root   root    157 Aug 27 05:45 btc.sh*           获取KEY脚本

内容如下
vi  btc2zabbix.sh
#!/bin/bash
tail -1 /tmp/block.log

vi btc.sh
#!/bin/bash
cli  -getinfo |grep blocks |awk ‘{print $2}’|awk -F "," ‘{print $1}’ >> /tmp/block.log

查看日志是否正常
root@:/usr/local/zabbix/script# tail -f /tmp/block.log
538679
538679
xxx
538681
538681
538681

新增 /etc/zabbix_agentd.conf.d/block.conf文件
UserParameter=custom.prd.btc.block,/usr/local/zabbix/script/btc2zabbix.sh

修改 /etc/zabbix_agentd.conf.d/zabbix-agent.conf文件
vim ../zabbix_agentd.conf
Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/*.conf

重启服务
/etc/init.d/zabbix_agentd restart

在zabbix-server 上使用zabbix-get 调用
root@ip-ccie:/tmp# zabbix_get -s 172.31.18.164 -p 10050 -k custom.prd.btc.block
538681   ———有值说明正常

————修改Crontab 增加定时任备
crontab -e
*/1 * * * *  /usr/local/zabbix/script/btc.sh

开启crontab 日志,并监控
root@ip-:/usr/local/zabbix/script# tail -f /var/log/cron.log

Aug 27 06:19:01 ip-ccie CRON[27523]: (root) CMD (/usr/local/zabbix/script/btc.sh) —-说明已执行
Aug 27 06:19:01 ip-ccie CRON[27523]: (root) CMD (/usr/local/zabbix/script/btc.sh)
Aug 27 06:20:01 ip-ccie CRON[27544]: (root) CMD (/usr/local/zabbix/script/btc.sh)
Aug 27 06:21:01 ip-ccie CRON[27562]: (root) CMD (/usr/local/zabbix/script/btc.sh)

————-然后去zabbix-server 上出图

——–图出后发现 超过数值超过1000会变成K 的情况,无法显示真实数据

查找
root@ip-ccie:/data/soft/zabbix-3.4.9/frontends/php/include# !f
find / -name func.inc.php
/data/zabbix/include/func.inc.php
备份
root@ip-ccie:/data/zabbix/include# cp func.inc.php func.inc.php0827
修改配置
root@ip-ccie:/data/zabbix/include# vim func.inc.php
修改前
$blackList = [‘%’, ‘ms’, ‘rpm’, ‘RPM’];
修改后  增加一个单位即可,并在item里面进行匹配
$blackList = [‘%’, ‘ms’, ‘rpm’, ‘RPM’, ‘BH’];

修改后即可显示所有数据

ERROR: cannot add user parameter

No Comments IT必备工具

zabbix_agentd [24999]: ERROR: cannot add user parameter "custom.prd.block,bitcoin-cli -rpcuser=test -rpcpassword=123456 -rpcport=18333 -getinfo |grep blocks|awk ‘{print $2}’|awk -F "," ‘{print $1}’": key "custom.prd.block" already exists

vim ../zabbix_agentd.conf
Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/
Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/*.conf

 
这两个只能出现一个,出现两个就冲突
注释掉一个

改成

# Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/
Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/*.conf

重启恢复正常
 
:/usr/local/zabbix/etc/zabbix_agentd.conf.d# /etc/init.d/zabbix_agentd restart

Zabbix agent started.

一看必会系列:zabbix-server 安装配置

No Comments Linux

直接操作

1

 

rpm -ivh http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-release-3.2-1.el7.noarch.rpm
yum install -y zabbix-server-mysql zabbix-web-mysql
getenforce
setenforce 0
getenforce
setsebool -P httpd_can_connect_zabbix on
systemctl enable zabbix-server
systemctl start zabbix-server
netstat -ntlp
systemctl status zabbix-server
netstat -ntlp
systemctl start httpd
netstat -ntlp
vim /etc/httpd/conf.d/zabbix.conf
vim /etc/httpd/conf.d/welcome.conf
systemctl status firewalld
systemctl stop firewalld

 

2

http://192.168.142.103/zabbix/setup.php

报错,
PHP option "date.timezone" unknown  Fail
解决
"/etc/httpd/conf.d/zabbix.conf" 38L, 877C 
   php_value date.timezone Asia/Shanghai #开启并修改

 

3

登陆数据库
mysql -u root -p  回车 回车

输入以下命令
create database zabbix character set utf8 collate utf8_bin;
grant all privileges on zabbix.* to zabbix@’%’ identified by ‘zabbix’;
flush privileges

4

初始化
zcat /usr/share/doc/zabbix-server-mysql-3.2.11/create.sql.gz | mysql -u zabbix -p -h服务器IP -P3307

进页面直接操作
http://192.168.142.103/zabbix/setup.php
完成安装

Congratulations! You have successfully installed Zabbix frontend.

Configuration file "/etc/zabbix/web/zabbix.conf.php" created.

vi /etc/zabbix/zabbix_server.conf
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=2wsxVFR$

 

5 登陆

关闭selinux

vi /etc/setlinux/config

改成disable

 

6管理登陆

默认密码 Admin zabbix

——————————————
监控模版
http://www.zabbix.org/wiki/Zabbix_Templates#Network_devices

 

# vim /etc/zabbix/zabbix_agentd.conf 
Server=127.0.0.1 
ServerActive=127.0.0.1 
Hostname=Zabbix server 

AGENT配置

安装
rpm -ivh http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-release-3.2-1.el7.noarch.rpm
rpm -ivh http://repo.zabbix.com/zabbix/3.2/rhel/6/x86_64/zabbix-agent-3.2.4-1.el6.x86_64.rpm
rpm -ivh https://mirrors.aliyun.com/zabbix/zabbix/3.2/rhel/7/x86_64/zabbix-agent-3.2.4-1.el7.x86_64.rpm
rpm -ivh https://mirrors.aliyun.com/zabbix/zabbix/3.2/rhel/6/x86_64/zabbix-agent-3.2.4-1.el6.x86_64.rpm

直接上传也可

关闭selinux

getsebool -a |grep zabbix 查bool值
setsebool -P httpd_can_connect_zabbix on 重启后生效
setsebool -P zabbix_can_network on  重启后生效
setsebool  zabbix_can_network on 临时生效
setsebool httpd_can_connect_zabbix on 临时生效

开放 iptables
iptables -I  INPUT 1 -p tcp –dport 10050 -j ACCEPT
保存
service iptables save

7.0配置

PidFile=/var/run/zabbix/zabbix_agentd.pid
LogFile=/var/log/zabbix-agent/zabbix_agentd.log
LogFileSize=0

LogFileSize=0
Server=被动服务器IP

ServerActive=主动服务器IP

Hostname=datacentercrawer03
Include=/etc/zabbix/zabbix_agentd.conf.d/*.conf

6.0 配置
PidFile=/var/run/zabbix/zabbix_agentd.pid
LogFile=/var/log/zabbix/zabbix_agentd.log
LogFileSize=0
Server=被动服务器IP

ServerActive=主动服务器IP

Include=/etc/zabbix/zabbix_agentd.d/*.conf

chkconfig zabbix-agent on
chkconfig |grep zabbix
service zabbix-agent start

ubuntu配置
sudo apt-get install zabbix-agent
sudo vi /etc/zabbix/zabbix_agentd.conf
sudo service zabbix-agent start

exmind@datacentercrawer02:~$sudo service zabbix-agent status
● zabbix-agent.service – Zabbix Agent
   Loaded: loaded (/lib/systemd/system/zabbix-agent.service; enabled; vendor preset: enabled)
   Active: active (running) since 一 2017-03-06 18:08:37 CST; 9min ago

一看必会系列:zabbix-server 安装配置

No Comments Linux

直接操作

1

 

rpm -ivh http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-release-3.2-1.el7.noarch.rpm
yum install -y zabbix-server-mysql zabbix-web-mysql
getenforce
setenforce 0
getenforce
setsebool -P httpd_can_connect_zabbix on
systemctl enable zabbix-server
systemctl start zabbix-server
netstat -ntlp
systemctl status zabbix-server
netstat -ntlp
systemctl start httpd
netstat -ntlp
vim /etc/httpd/conf.d/zabbix.conf
vim /etc/httpd/conf.d/welcome.conf
systemctl status firewalld
systemctl stop firewalld

 

2

http://192.168.142.103/zabbix/setup.php

报错,
PHP option "date.timezone" unknown  Fail
解决
"/etc/httpd/conf.d/zabbix.conf" 38L, 877C 
   php_value date.timezone Asia/Shanghai #开启并修改

 

3

登陆数据库
mysql -u root -p  回车 回车

输入以下命令
create database zabbix character set utf8 collate utf8_bin;
grant all privileges on zabbix.* to zabbix@’%’ identified by ‘zabbix’;
flush privileges

4

初始化
zcat /usr/share/doc/zabbix-server-mysql-3.2.11/create.sql.gz | mysql -u zabbix -p -h服务器IP -P3307

进页面直接操作
http://192.168.142.103/zabbix/setup.php
完成安装

Congratulations! You have successfully installed Zabbix frontend.

Configuration file "/etc/zabbix/web/zabbix.conf.php" created.

vi /etc/zabbix/zabbix_server.conf
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=2wsxVFR$

 

5 登陆

关闭selinux

vi /etc/setlinux/config

改成disable

 

6管理登陆

默认密码 Admin zabbix

——————————————
监控模版
http://www.zabbix.org/wiki/Zabbix_Templates#Network_devices

 

# vim /etc/zabbix/zabbix_agentd.conf 
Server=127.0.0.1 
ServerActive=127.0.0.1 
Hostname=Zabbix server 

AGENT配置

安装
rpm -ivh http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-release-3.2-1.el7.noarch.rpm
rpm -ivh http://repo.zabbix.com/zabbix/3.2/rhel/6/x86_64/zabbix-agent-3.2.4-1.el6.x86_64.rpm
rpm -ivh https://mirrors.aliyun.com/zabbix/zabbix/3.2/rhel/7/x86_64/zabbix-agent-3.2.4-1.el7.x86_64.rpm
rpm -ivh https://mirrors.aliyun.com/zabbix/zabbix/3.2/rhel/6/x86_64/zabbix-agent-3.2.4-1.el6.x86_64.rpm

直接上传也可

关闭selinux

getsebool -a |grep zabbix 查bool值
setsebool -P httpd_can_connect_zabbix on 重启后生效
setsebool -P zabbix_can_network on  重启后生效
setsebool  zabbix_can_network on 临时生效
setsebool httpd_can_connect_zabbix on 临时生效

开放 iptables
iptables -I  INPUT 1 -p tcp –dport 10050 -j ACCEPT
保存
service iptables save

7.0配置

PidFile=/var/run/zabbix/zabbix_agentd.pid
LogFile=/var/log/zabbix-agent/zabbix_agentd.log
LogFileSize=0

LogFileSize=0
Server=被动服务器IP

ServerActive=主动服务器IP

Hostname=datacentercrawer03
Include=/etc/zabbix/zabbix_agentd.conf.d/*.conf

6.0 配置
PidFile=/var/run/zabbix/zabbix_agentd.pid
LogFile=/var/log/zabbix/zabbix_agentd.log
LogFileSize=0
Server=被动服务器IP

ServerActive=主动服务器IP

Include=/etc/zabbix/zabbix_agentd.d/*.conf

chkconfig zabbix-agent on
chkconfig |grep zabbix
service zabbix-agent start

ubuntu配置
sudo apt-get install zabbix-agent
sudo vi /etc/zabbix/zabbix_agentd.conf
sudo service zabbix-agent start

exmind@datacentercrawer02:~$sudo service zabbix-agent status
● zabbix-agent.service – Zabbix Agent
   Loaded: loaded (/lib/systemd/system/zabbix-agent.service; enabled; vendor preset: enabled)
   Active: active (running) since 一 2017-03-06 18:08:37 CST; 9min ago

一看必会系列:zabbix-server 安装配置

No Comments Linux

直接操作

1

 

rpm -ivh http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-release-3.2-1.el7.noarch.rpm
yum install -y zabbix-server-mysql zabbix-web-mysql
getenforce
setenforce 0
getenforce
setsebool -P httpd_can_connect_zabbix on
systemctl enable zabbix-server
systemctl start zabbix-server
netstat -ntlp
systemctl status zabbix-server
netstat -ntlp
systemctl start httpd
netstat -ntlp
vim /etc/httpd/conf.d/zabbix.conf
vim /etc/httpd/conf.d/welcome.conf
systemctl status firewalld
systemctl stop firewalld

 

2

http://192.168.142.103/zabbix/setup.php

报错,
PHP option "date.timezone" unknown  Fail
解决
"/etc/httpd/conf.d/zabbix.conf" 38L, 877C 
   php_value date.timezone Asia/Shanghai #开启并修改

 

3

创建数据库, 可本地,可分离

create database zabbix character set utf8 collate utf8_bin;
grant all privileges on zabbix.* to zabbix@’%’ identified by ‘zabbix’;

4

初始化
zcat /usr/share/doc/zabbix-server-mysql-3.2.11/create.sql.gz | mysql -u zabbix -p -h服务器IP -P3307

进页面直接操作
http://192.168.142.103/zabbix/setup.php
完成安装

Congratulations! You have successfully installed Zabbix frontend.

Configuration file "/etc/zabbix/web/zabbix.conf.php" created.

vi /etc/zabbix/zabbix_server.conf
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=2wsxVFR$

 

5 登陆

关闭selinux

vi /etc/setlinux/config

改成disable

 

6管理登陆

默认密码 Admin zabbix

——————————————
监控模版
http://www.zabbix.org/wiki/Zabbix_Templates#Network_devices

 

# vim /etc/zabbix/zabbix_agentd.conf 
Server=127.0.0.1 
ServerActive=127.0.0.1 
Hostname=Zabbix server 

AGENT配置

安装
rpm -ivh http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-release-3.2-1.el7.noarch.rpm
rpm -ivh http://repo.zabbix.com/zabbix/3.2/rhel/6/x86_64/zabbix-agent-3.2.4-1.el6.x86_64.rpm
rpm -ivh https://mirrors.aliyun.com/zabbix/zabbix/3.2/rhel/7/x86_64/zabbix-agent-3.2.4-1.el7.x86_64.rpm
rpm -ivh https://mirrors.aliyun.com/zabbix/zabbix/3.2/rhel/6/x86_64/zabbix-agent-3.2.4-1.el6.x86_64.rpm

直接上传也可

关闭selinux

getsebool -a |grep zabbix 查bool值
setsebool -P httpd_can_connect_zabbix on 重启后生效
setsebool -P zabbix_can_network on  重启后生效
setsebool  zabbix_can_network on 临时生效
setsebool httpd_can_connect_zabbix on 临时生效

开放 iptables
iptables -I  INPUT 1 -p tcp –dport 10050 -j ACCEPT
保存
service iptables save

7.0配置

PidFile=/var/run/zabbix/zabbix_agentd.pid
LogFile=/var/log/zabbix-agent/zabbix_agentd.log
LogFileSize=0

LogFileSize=0
Server=被动服务器IP

ServerActive=主动服务器IP

Hostname=datacentercrawer03
Include=/etc/zabbix/zabbix_agentd.conf.d/*.conf

6.0 配置
PidFile=/var/run/zabbix/zabbix_agentd.pid
LogFile=/var/log/zabbix/zabbix_agentd.log
LogFileSize=0
Server=被动服务器IP

ServerActive=主动服务器IP

Include=/etc/zabbix/zabbix_agentd.d/*.conf

chkconfig zabbix-agent on
chkconfig |grep zabbix
service zabbix-agent start

ubuntu配置
sudo apt-get install zabbix-agent
sudo vi /etc/zabbix/zabbix_agentd.conf
sudo service zabbix-agent start

exmind@datacentercrawer02:~$sudo service zabbix-agent status
● zabbix-agent.service – Zabbix Agent
   Loaded: loaded (/lib/systemd/system/zabbix-agent.service; enabled; vendor preset: enabled)
   Active: active (running) since 一 2017-03-06 18:08:37 CST; 9min ago

zabbix mysql mariadb多实例监控

No Comments mysql_mariadb

http://blog.csdn.net/qq942477618/article/details/60960865

1、定义每个实例的端口

cat mysql_port
3325
3346
 

2、给所有实例创建一个zabbix用户只允许本地访问,生产环境具体权限各位看官自己看着给吧O(∩_∩)O

登陆:
@shtsmysql02 script]#  mysql -u root -p -S /tmp/mysql3346.sock

MySQL [(none)]> GRANT ALL PRIVILEGES ON *.* TO zabbix@’127.0.0.1′ IDENTIFIED BY ‘zabbix’;
Query OK, 0 rows affected (0.01 sec)

MySQL [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)

 

3、创建自动发现MySQL端口脚本
cat /opt/zabbixscript/mysqlzabbix/discovery_mysql.sh

#!/bin/bash
# ——————————————————————————-
# Script_name: discovery_mysql.sh
# Vision:    1.0
# ——————————————————————————-

res=`cat /opt/zabbixscript/mysqlzabbix/mysqlport|grep -v "^#"`
port=($res)
printf ‘{\n’
printf ‘\t"data":[\n’
for key in ${!port[@]}
do
    if [[ "${#port[@]}" -gt 1 && "${key}" -ne "$((${#port[@]}-1))" ]];then
        printf ‘\t {\n’
        printf "\t\t\t\"{#MYSQLPORT}\":\"${port[${key}]}\"},\n"
    else [[ "${key}" -eq "((${#port[@]}-1))" ]]
        printf ‘\t {\n’
        printf "\t\t\t\"{#MYSQLPORT}\":\"${port[${key}]}\"}\n"
    fi
done
printf ‘\t ]\n’
printf ‘}\n’

4、创建MySQL检测脚本

# cat /data/PRG/zabbix/scripts/check_Multimysql.sh
#!/bin/bash
# ——————————————————————————-
# FileName:    check_Multimysql.sh
# Vision:    1.0
# ——————————————————————————-
 
# 用户名
MYSQL_USER=’zabbix’
 
# 密码
MYSQL_PWD=’zabbix’
 
# 主机地址/IP
MYSQL_HOST=’127.0.0.1′
 
# 端口
MYSQL_PORT=$2
 
# 数据连接
MYSQL_CONN="/usr/bin/mysqladmin -u${MYSQL_USER} -p${MYSQL_PWD} -h${MYSQL_HOST} -P${MYSQL_PORT}"

##help函数
help() {
        echo "Usage:$0  [ping|Uptime|Com_update|Slow_queries|Com_select|Com_rollback|Questions|Com_insert|Com_delete|Com_commit|Bytes_sent|Bytes_received|Com_begin]  port"
}

# 参数是否正确
if [ $# -lt "2" ];then
    echo "参数缺失!"
    help
    exit 2
fi
 
# 获取数据 脚本是错的需要修证
case $1 in
    ping)
        result=`${MYSQL_CONN} ping | grep -c alive`
        echo $result
        ;;
    Uptime)
        result=`${MYSQL_CONN} status|cut -f2 -d":"|cut -f1 -d"T"`
        echo $result
        ;;
    Com_update)
        result=`${MYSQL_CONN} extended-status |grep -w "Com_update"|cut -d"|" -f3`
        echo $result
        ;;
    Slow_queries)
        result=`${MYSQL_CONN} status |cut -f5 -d":"|cut -f1 -d"O"`
        echo $result
        ;;
    Com_select)
        result=`${MYSQL_CONN} extended-status |grep -w "Com_select"|cut -d"|" -f3`
        echo $result
                ;;
    Com_rollback)
        result=`${MYSQL_CONN} extended-status |grep -w "Com_rollback"|cut -d"|" -f3`
                echo $result
                ;;
    Questions)
        result=`${MYSQL_CONN} status|cut -f4 -d":"|cut -f1 -d"S"`
                echo $result
                ;;
    Com_insert)
        result=`${MYSQL_CONN} extended-status |grep -w "Com_insert"|cut -d"|" -f3`
                echo $result
                ;;
    Com_delete)
        result=`${MYSQL_CONN} extended-status |grep -w "Com_delete"|cut -d"|" -f3`
                echo $result
                ;;
    Com_commit)
        result=`${MYSQL_CONN} extended-status |grep -w "Com_commit"|cut -d"|" -f3`
                echo $result
                ;;
    Bytes_sent)
        result=`${MYSQL_CONN} extended-status |grep -w "Bytes_sent" |cut -d"|" -f3`
                echo $result
                ;;
    Bytes_received)
        result=`${MYSQL_CONN} extended-status |grep -w "Bytes_received" |cut -d"|" -f3`
                echo $result
                ;;
    Com_begin)
        result=`${MYSQL_CONN} extended-status |grep -w "Com_begin"|cut -d"|" -f3`
                echo $result
                ;;
                       
        *)
        help
        ;;
esac
——————验证用户———————
MariaDB [mysql]> select user,host from user where user= "zabbix"
    -> ;
+——–+———–+
| user   | host      |
+——–+———–+
| zabbix | 127.0.0.1 |
+——–+———–+
1 row in set (0.00 sec)

MariaDB [mysql]>
—————-验证脚本——————–
[root@shtsapp03 ~]# zabbix_get -s 192.168.9.62 -k mysqlmulti.ping[3325]
1

————————–多实例多版本修改—————————
以上脚本多版本多实例服务不好用需要进行修改
连接串按这列格式进行修改
[root@shtsmysql02 mysqlzabbix]# mysql -uzabbix -pzabbix -h127.0.0.1 -P3346 -S /tmp/mysql3346.sock -e status
————–
mysql  Ver 15.1 Distrib 5.5.56-MariaDB, for Linux (x86_64) using readline 5.1

Connection id:        310364
Current database:   
Current user:        zabbix@127.0.0.1
SSL:            Not in use
Current pager:        stdout

extended-status: 显示mysqld的所有服务器变量和他们的当前值
mariadb不支持 extended-status 所以脚本也要改
[root@shtsmysql02 mysqlzabbix]# mysql -uzabbix -pzabbix -h127.0.0.1 -P3346 -S /tmp/mysql3346.sock -e extended-status
ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘extended-status’ at line 1

修改成如下命令
[root@shtsmysql02 mysqlzabbix]# mysqladmin -uzabbix -pzabbix -h127.0.0.1 -P3346 -S /tmp/mysql3346.sock  extended-status
+———————————————–+———————+
| Variable_name                                 | Value               |
+———————————————–+———————+
| Aborted_clients                               | 10                  |

按测试结果来看。mysql 可以替换成mysqladmin命令
[root@shtsmysql02 mysqlzabbix]# mysqladmin -uzabbix -pzabbix -h127.0.0.1 -P3346 -S /tmp/mysql3346.sock  status
Uptime: 1863765  Threads: 5  Questions: 4422  Slow queries: 0  Opens: 167  Flush tables: 1  Open tables: 115  Queries per second avg: 0.002
[root@shtsmysql02 mysqlzabbix]#
————————–多实例多版本修改—————————
 
5、测试脚本是否正常
mysqlzabbix/discovery_mysql.sh
{
    "data":[
     {
            "{#MYSQLPORT}":"3325"},
     {
            "{#MYSQLPORT}":"3346"}
     ]
}

 

check_Mmysql.sh脚本测试结果
[root@ ]# sh  mysql /check_Mmysql.sh Bytes_sent 3346
1726305
[root@ ]# sh  mysql /check_Mmysql.sh Bytes_received 3346
370292
[root@ ]# sh  mysql /check_Mmysql.sh Com_begin 3346
 

6、zabbix agent配置文件添加自定义脚本,并重启zabbix agent

vim /data/PRG/zabbix/etc/zabbix_agentd.conf

UserParameter=mysql_discovery[*],/bin/bash /opt/zabbixscript/mysqlzabbix/discovery_mysql.sh
#####$1==command   $2===port
UserParameter=mysql.status[*],/opt/zabbixscript/mysqlzabbix/check_Mmysql.sh $1 $2
UserParameter=mysql.ping[*],/opt/zabbixscript/mysqlzabbix/check_Mmysql.sh ping $1
 

/etc/init.d/zabbix_agentd restart

 

7、使用zabbix_get检查定义的key是否生效

# /usr/local/zabbix/bin/zabbix_get -s 192.168.62.200 -k mysql.ping[3307]  
1
# /usr/local/zabbix/bin/zabbix_get -s 192.168.62.200 -k mysql.status[Uptime,3307]
18180813
# /usr/local/zabbix/bin/zabbix_get -s 192.168.62.200 -k mysql.status[Uptime,3306]
18180842
# /usr/local/zabbix/bin/zabbix_get -s 192.168.62.200 -k mysql.status[Uptime,3310]
18180847
# /usr/local/zabbix/bin/zabbix_get -s 192.168.62.200 -k mysql.status[Bytes_sent,3310]
58803854473
 

8、导入模板Template Multi Mysql.xml 

左右这个x下载保存成xml

9、被监控主机关联模板

10、完成