2019.11.2 Zabbix agent端監控及自定義監控項配置

1、Linux-agent端的操做:mysql

vim /etc/hostnamec++

HOSTNAME=agent.zabbix.comsql

hoastname agent.zabbix.com數據庫

bashvim

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 windows10windows

iptables -Fbash

systemctl stop firewalld服務器

setenforce 0dom

ping server.zabbix.com -c 4curl

ping www.baidu.com

一、源碼安裝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

下一步就能夠作監控了

2、作監控

 

 點擊agent.zabbix.com——>選擇模板

 

 

 3、zabbix監控mysql數據庫

一、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

二、編輯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'

三、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]            //會有一個數字,這裏我沒作出來

四、爲server.zabbix.com添加服務模板

網頁上:配置——>主機——>選擇server.zabbix.com——>模板——>選擇

 點擊選擇——>添加——>更新

五、建立MySQL服務圖形

配置——>主機——>server.zabbix.com下的圖形——>建立圖形——>名稱是:mysql.status、點擊添加,找到MYSQL.status選擇

 

 

 

 

 

相關文章
相關標籤/搜索