标签:result systemctl mysql数据库 started enable top moni iptables wal
一、Linux-agent端的操作:
vim /etc/hostname
HOSTNAME=agent.zabbix.com
hoastname agent.zabbix.com
bash
cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.200.111 server.zabbix.com
192.168.200.112 agent.zabbix.com
192.168.200.110 windows10
iptables -F
systemctl stop firewalld
setenforce 0
ping server.zabbix.com -c 4
ping www.baidu.com
1、源码安装zabbix
yum -y install gcc gcc-c++ make
yum -y install libxml2-devel libcurl-devel pcre-devel ntpdate
ntpdate s1a.time.edu.cn
将zabbix-3.4.11.tar.gz 这个包上传并解压
tar xf zabbix-3.4.11.tar.gz -C /usr/src/
cd /usr/src/zabbix-3.4.11/
./configure --prefix=/usr/local/zabbix --enable-agent --with-net-snmp --with-libcurl --with-libxml2 && make-j2 && make install
cp misc/init.d/tru64/zabbix_agentd /etc/init.d/
vim /etc/init.d/zabbix_agentd /稍微修改
DAEMON=/usr/local/zabbix/sbin/zabbix_agentd
chmod +x /etc/init.d/zabbix_agentd
cd
useradd -M -s /sbin/nologin zabbix
chown -R zabbix:zabbix /usr/local/zabbix/
cd /usr/local/zabbix/
mkdir logs
chown -R zabbix:zabbix logs/
cp /usr/local/zabbix/etc/zabbix_agentd.conf{,.bak}
vim /usr/local/zabbix/etc/zabbix_agentd.conf
PidFile=/tmp/zabbix_agent.pid
Server=192.168.200.111
ServerActive=192.168.200.111
Hostname=agnet.zabbix.com
LogFile=/usr/local/zabbix/logs/zabbix_agentd.log
Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/*.conf
UnsafeUserParameters=1
UserParameter=mysql.version,mysql -V
UserParameter=mysql.status[*],/usr/local/zabbix/etc/chk_mysql.sh $1
UserParameter=mysql.ping,mysqladmin -uroot -p123 -P3306 -h192.168.200.112 ping | grep -c alive
service zabbix_agentd start
Zabbix agent started.
netstat -anpt | grep 10050
tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 83251/zabbix_agentd
下一步就可以做监控了
二、做监控
点击agent.zabbix.com——>选择模板
三、zabbix监控mysql数据库
1、server.zabbix.com服务器操作
cd /usr/local/zabbix/etc/
vim zabbix_agentd.conf
PidFile=/tmp/zabbix_agentd.pid
Server=127.0.0.1,192.168.200.111
ServerActive=192.168.200.111
Hostname=server.zabbix.com
LogFile=/usr/local/zabbix/logs/zabbix_agentd.log
Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/*.conf
UnsafeUserParameters=1
UserParameter=mysql.version,mysql -V
UserParameter=mysql.ststus[*],/usr/local/zabbix/etc/chk_mysql.sh $1
UserParameter=mysql.ping,mysqladmin -uroot -p123 -P3306 -h192.168.200.111 ping | grep -c aliv
2、编辑chk_mysql.sh脚本
vim /usr/local/zabbix/etc/chk_mysql.sh
#!/bin/bash
#FileName: check_mysql.sh
# Revision: 1.0
# Date: 2015/06/09
# Author: DengYun
# Email: dengyun@ttlsa.com
# Website: www.ttlsa.com
# Description:
# Notes: ~
# -------------------------------------------------------------------------------
# Copyright: 2015 (c) DengYun
# License: GPL
# 用户名
MYSQL_USER=‘root‘
# 密码
MYSQL_PWD=‘123123‘
# 主机地址/IP
MYSQL_HOST=‘192.168.200.111‘
# 端口
MYSQL_PORT=‘3306‘
# 数据连接
MYSQL_CONN="/usr/bin/mysqladmin -u${MYSQL_USER} -p${MYSQL_PWD} -h${MYSQL_HOST} -P${MYSQL_PORT}"
# 参数是否正确
if [ $# -ne "1" ];then
echo "arg error!"
fi
# 获取数据
case $1 in
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
;;
*)
echo "Usage:$0(Uptime|Com_update|Slow_queries|Com_select|Com_rollback|Questions|Com_insert|Com_delete|Com_commit|Bytes_sent|Bytes_received|Com_begin)"
;;
esac
chmod 777 chk_mysql.sh //为脚本加权
mysql -uroot -p123 //mysql授权
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 5277
Server version: 5.5.64-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.
MariaDB [(none)]> grant all on *.* to ‘root‘@‘server.zabbix.com‘ identified by ‘123‘;
Query OK, 0 rows affected (0.01 sec)
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.01 sec)
MariaDB [(none)]>exit
killall -9 zabbix_agentd
killall -9 zabbix_server
/usr/local/zabbix/sbin/zabbix_agentd
/usr/local/zabbix/sbin/zabbix_server
netstat -anpt | egrep ‘:10050|10051‘
3、server.zabbix.com测试
[root@server etc]# ln -s /usr/local/zabbix/bin/* /usr/local/bin/
[root@server etc]# zabbix_get -s 192.168.200.111 -k mysql.ping
1
[root@server etc]# zabbix_get -s 192.168.200.111 -k mysql.status[Com_update] //会有一个数字,这里我没做出来
4、为server.zabbix.com添加服务模板
网页上:配置——>主机——>选择server.zabbix.com——>模板——>选择
点击选择——>添加——>更新
5、创建MySQL服务图形
配置——>主机——>server.zabbix.com下的图形——>创建图形——>名称是:mysql.status、点击添加,找到MYSQL.status选择
2019.11.2 Zabbix agent端监控及自定义监控项配置
标签:result systemctl mysql数据库 started enable top moni iptables wal
原文地址:https://www.cnblogs.com/990624lty-jhc/p/11781514.html