1 #!/bin/bash
 2 # -------------------------------------------------------------------------------
 3 # FileName:    check_mysql.sh
 4 # Revision:    1.0
 5 # Date:        2018/01/31
 6 # Author:      chunk
 7 # Email:       
 8 # Website:     
 9 # Description: 
10 # Notes:       ~
11 # -------------------------------------------------------------------------------
13 # License:     GPL
15 # 用户名
16 MYSQL_USER='root'
18 # 密码
19 MYSQL_PWD='oldboy123'
21 # 主机地址/IP
22 MYSQL_HOST='10.0.0.51'
24 # 端口
25 MYSQL_PORT='3306'
27 # 数据连接
28 MYSQL_CONN="/usr/bin/mysqladmin -u${MYSQL_USER} -p${MYSQL_PWD} -h${MYSQL_HOST} -P${MYSQL_PORT}"
30 # 参数是否正确
31 if [ $# -ne "1" ];then 
32     echo "arg error!" 
33 fi 
35 # 获取数据
36 case $1 in 
37     Uptime) 
38         result=`${MYSQL_CONN} status|cut -f2 -d":"|cut -f1 -d"T"` 
39         echo $result 
40         ;; 
41     Com_update) 
42         result=`${MYSQL_CONN} extended-status |grep -w "Com_update"|cut -d"|" -f3` 
43         echo $result 
44         ;; 
45     Slow_queries) 
46         result=`${MYSQL_CONN} status |cut -f5 -d":"|cut -f1 -d"O"` 
47         echo $result 
48         ;; 
49     Com_select) 
50         result=`${MYSQL_CONN} extended-status |grep -w "Com_select"|cut -d"|" -f3` 
51         echo $result 
52                 ;; 
53     Com_rollback) 
54         result=`${MYSQL_CONN} extended-status |grep -w "Com_rollback"|cut -d"|" -f3` 
55                 echo $result 
56                 ;; 
57     Questions) 
58         result=`${MYSQL_CONN} status|cut -f4 -d":"|cut -f1 -d"S"` 
59                 echo $result 
60                 ;; 
61     Com_insert) 
62         result=`${MYSQL_CONN} extended-status |grep -w "Com_insert"|cut -d"|" -f3` 
63                 echo $result 
64                 ;; 
65     Com_delete) 
66         result=`${MYSQL_CONN} extended-status |grep -w "Com_delete"|cut -d"|" -f3` 
67                 echo $result 
68                 ;; 
69     Com_commit) 
70         result=`${MYSQL_CONN} extended-status |grep -w "Com_commit"|cut -d"|" -f3` 
71                 echo $result 
72                 ;; 
73     Bytes_sent) 
74         result=`${MYSQL_CONN} extended-status |grep -w "Bytes_sent" |cut -d"|" -f3` 
75                 echo $result 
76                 ;; 
77     Bytes_received) 
78         result=`${MYSQL_CONN} extended-status |grep -w "Bytes_received" |cut -d"|" -f3` 
79                 echo $result 
80                 ;; 
81     Com_begin) 
82         result=`${MYSQL_CONN} extended-status |grep -w "Com_begin"|cut -d"|" -f3` 
83                 echo $result 
84                 ;; 
86         *) 
87         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)" 
88         ;; 
89 esac
View Code

4. web页面操作添加监控项

在对应的主机上创建监控项

## Same thing without a password #%wheel ALL= (ALL) NOPASSWD: ALL zabbix ALL=(ALL) NOPASSWD: ALL

停止nginx,没有远程执行命令

[root@web01 ~]# systemctl stop nginx
Jan 12 04:03:42 web01 sudo: pam_unix(sudo:auth): conversation failed
Jan 12 04:03:42 web01 sudo: pam_unix(sudo:auth): auth could not identify password for [zabbix]
Jan 12 04:03:42 web01 sudo: pam_succeed_if(sudo:auth): requirement "uid >= 1000" not met by user "zabbix"

后来改了visudo文件

[root@web01 ~]# visudo 
## Same thing without a password
#%wheel ALL=(ALL)       NOPASSWD: ALL
zabbix ALL=NOPASSWD: ALL

查看日志,远程支持命令成功

[root@web01 ~]# tail -f /var/log/secure
ticationAgent, locale en_US.UTF-8) (disconnected from bus)Jan 12 15:04:26 web01 sudo: zabbix : TTY=unknown ; PWD=/ ; USER=root ; COMMAND=/bin/systemctl restart nginx.service