目錄
一、監(jiān)控mysql數(shù)據(jù)庫(kù)及httpd服務(wù)
1、為server.Zabbix.com添加服務(wù)模板
2、server.zabbix.com服務(wù)端?操作
3、編輯chk_mysql.sh腳本
4、server.zabbix.com測(cè)試
?二、監(jiān)控apache
1、獲取鍵值
2、服務(wù)器操作
3、zabbix監(jiān)控web端導(dǎo)入監(jiān)控模板
4、server.zabbix.com添加apache模板
?三、監(jiān)控ftp
1、這里用agent.zabbix.com的主機(jī)
2、為ftp添加模板
一、監(jiān)控mysql數(shù)據(jù)庫(kù)及httpd服務(wù)
1、為server.Zabbix.com添加服務(wù)模板
?
?
?
?
?
?
2、server.zabbix.com服務(wù)端?操作
[root@server ~] cd /usr/local/zabbix/etc/
[root@server etc] vim zabbix_agentd.conf
PidFile=/tmp/zabbix_agentd.pid
Server=127.0.0.1,192.168.147.135
ServerActive=192.168.147.135
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.status[*],/usr/local/zabbix/etc/chk_mysql.sh $1
UserParameter=mysql.ping,mysqladmin -uroot -p123123 -P3306 -h192.168.147.135 ping | grep -c alive
#解釋
#UnsafeUserParameters=1 //允許所有字符的參數(shù)傳遞給用戶定義的參數(shù)。
#UserParameter=mysql.version,mysql -V //定義鍵值mysql.version,以及鍵值的值mysql -V
#UserParameter=mysql.status[*],/usr/local/zabbix/etc/chk_mysql.sh $1 //定義鍵值#mysql.status[*]
#UserParameter=mysql.ping,mysqladmin -uroot -p123123 -P3306 -h192.168.200.111 ping | grep #-c alive ///定義鍵值mysql.ping,指定chk_mysql.sh腳本,使用此腳本檢查mysql的運(yùn)行狀態(tài),#使用mysqladmin命令指定agent端的數(shù)據(jù)庫(kù)連接用戶密碼ip地址,注意保證mysqladmin命令的鏈接;
3、編輯chk_mysql.sh腳本
[root@server etc] pwd
/usr/local/zabbix/etc
[root@server etc] vim 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'
# 主機(jī)地址/IP
MYSQL_HOST='192.168.147.135'
# 端口
MYSQL_PORT='3306'
# 數(shù)據(jù)連接
MYSQL_CONN="/usr/bin/mysqladmin -u${MYSQL_USER} -p${MYSQL_PWD} -h${MYSQL_HOST} -P${MYSQL_PORT}"
# 參數(shù)是否正確
if [ $# -ne "1" ];then
echo "arg error!"
fi
# 獲取數(shù)據(jù)
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
[root@server etc] chmod 777 chk_mysql.sh //為腳本加權(quán)
[root@server etc] mysql -u root -p123123 //mysql授權(quán)
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 4111
Server version: 5.5.56-MariaDB MariaDB Server
Copyright (c) 2000, 2017, 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 '123123';
Query OK, 0 rows affected (0.10 sec)
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> \q
Bye
[root@server etc] killall -9 zabbix_agentd
[root@server etc] killall -9 zabbix_server
[root@server etc] /usr/local/zabbix/sbin/zabbix_agentd
[root@server etc] /usr/local/zabbix/sbin/zabbix_server
[root@server etc] netstat -anpt | egrep ':10050|10051'
tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 34683/zabbix_agentd
tcp 0 0 0.0.0.0:10051 0.0.0.0:* LISTEN 34691/zabbix_server
tcp6 0 0 :::10050 :::* LISTEN 34683/zabbix_agentd
4、server.zabbix.com測(cè)試
[root@server etc] zabbix_get -s 192.168.147.135 -k mysql.ping
1
[root@server etc] zabbix_get -s 192.168.147.135 -k mysql.status[Com_update]
452
?二、監(jiān)控apache
1、獲取鍵值
[root@server ~] vim /opt/check_httpd.sh
#!/bin/bash
#
netstat -lnpt |grep -q :80
if [ $? -eq 0 ]
then
echo "1"
else
echo "0"
fi
[root@server ~]chmod +x /opt/check_httpd.sh
[root@server ~] vim /usr/local/zabbix/etc/zabbix_agentd.conf
UnsafeUserParameters=1
UserParameter=httpd.status,/opt/check_httpd.sh
[root@server ~]killall -9 zabbix_agentd
[root@server ~]zabbix_agentd
[root@server ~] ln -s /usr/local/zabbix/bin/zabbix_get /usr/local/bin/zabbix_get
[root@server ~] zabbix_get -s 192.168.200.111 -p 10050 -k httpd.status
[root@serve ~] which netstat
/usr/bin/netstat
[root@serve~] chmod u+s /usr/bin/netstat
[root@server ~] zabbix_get -s 192.168.200.111 -p 10050 -k httpd.status
[root@server ~]systemctl stop httpd
2、服務(wù)器操作
首先在本機(jī)下載模板:https://github.com/rdvn/zabbix-templates/archive/master.zip?
該zip包有apache、memcache、redis、varnish模板,我們解壓后使用其中的apache模板。
[root@server ~] wget https://github.com/rdvn/zabbix-templates/archive/master.zip
[root@server ~] ls
anaconda-ks.cfg jdk-8u91-linux-x64.tar.gz 圖片
apache-tomcat-8.5.16.tar.gz master.zip 文檔
catalina-jmx-remote.jar zabbix-3.4.11.tar.gz 下載
dead.letter 公共 音樂(lè)
grafana-4.2.0-1.x86_64.rpm 模板 桌面
initial-setup-ks.cfg 視頻
[root@server ~] mv master.zip /usr/local/src/ //該文件夾沒(méi)有文件方便查看
[root@server ~] cd /usr/local/src/
[root@server src] unzip master.zip //解壓下載的zip壓縮包
[root@server src] ls
master.zip zabbix-templates-master
[root@server src] cd zabbix-templates-master/
[root@server zabbix-templates-master] ls
apache memcached README redis varnish //apache中有我們需要的文件
[root@server zabbix-templates-master] cd apache/
[root@server apache] ls
apache_status.sh apache.xml README
//apache_status.sh 該文件時(shí)apache的agent監(jiān)控需要的腳本文件
//apache.xml文件是zabbix需要的模板
[root@server apache] cp apache_status.sh /usr/local/zabbix/sbin/
[root@server apache] vim /usr/local/zabbix/etc/zabbix_agentd.conf
UserParameter=apache[*],/usr/local/zabbix/sbin/apache_status.sh $1
//末行追加引用apache_status.sh的監(jiān)控腳本
[root@server apache] cd
[root@server ~] chmod +x /usr/local/zabbix/sbin/apache_status.sh //為腳本加執(zhí)行權(quán)限
[root@server ~] ll /usr/local/zabbix/sbin/
總用量 7264
-rwxr-xr-x 1 zabbix zabbix 248 8月 9 14:03 apache_status.sh
-rwxr-xr-x 1 zabbix zabbix 1477216 8月 7 15:00 zabbix_agentd
drwxr-xr-x 4 zabbix zabbix 84 8月 8 05:57 zabbix_java
-rwxr-xr-x 1 zabbix zabbix 5954120 8月 7 15:00 zabbix_server
?
?文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-591234.html
3、zabbix監(jiān)控web端導(dǎo)入監(jiān)控模板
?
?
?導(dǎo)入
?自此模板就導(dǎo)入成功了 現(xiàn)在為server.zabbix.com添加我們導(dǎo)入的模板
4、server.zabbix.com添加apache模板
?
?三、監(jiān)控ftp
1、這里用agent.zabbix.com的主機(jī)
[root@agent ~] yum install -y vsftpd
[root@agent ~] systemctl start vsftpd //啟動(dòng)ftp服務(wù)
[root@agent ~] systemctl enable vsftpd //設(shè)置ftp服務(wù)開(kāi)機(jī)自啟
Created symlink from /etc/systemd/system/multi-user.target.wants/vsftpd.service to /usr/lib/systemd/system/vsftpd.service.
2、為ftp添加模板
?
?
?
?
?
?
?文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-591234.html
?
到了這里,關(guān)于zabbix-server監(jiān)控mysql數(shù)據(jù)庫(kù)及httpd服務(wù)、監(jiān)控apache、監(jiān)控ftp的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!