Linux下ZabbixモニタのMySQLモニタ追加
5831 ワード
Mysqlデータベース監視 を作成する. 配置 権限構成 を再起動する.
注意事項
このエラーは取得状態異常:
このエラーは
zabbix
ページ追加Mysql
モニタデフォルトテンプレートTemplate DB MySQL
mysqladmin
リンク構成touch /etc/zabbix/scripts/.my.cnf
[mysqladmin]
host=192.168.1.253
user=zabbix
password=zabbix
Mysql
モニタデータ取得スクリプトchk_mysql.sh
#
MYSQL_CONN="/usr/local/mysql/bin/mysqladmin --defaults-extra-file=/etc/zabbix/scripts/.my.cnf"
#
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)
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
userparameter_mysql.conf
vim /etc/zabbix/zabbix_agentd.d/userparameter_mysql.conf
UserParameter=mysql.status[*],/etc/zabbix/script/mysql/chk_mysql.sh $1 #Mysql ;
UserParameter=mysql.ping,netstat -ntpl |grep 3306|grep mysql|wc |awk '{print $1}' #Mysql ;
UserParameter=mysql.version,/usr/local/mysql/bin/mysql -V #Mysql ;
netstat ,-p root ;
chmod +s /bin/netstat
vim /etc/sudoers
#Defaults specification #
zabbix ALL=(ALL) NOPASSWD:/bin/netstat
zabbix-server
でテスト zabbix_get -s192.168.1.253 -k "mysql.ping"
1
zabbix_get -s192.168.1.253 -k "mysql.status[Uptime]"
1547
zabbix-agent
サービスsystemctl restart zabbix-agent.service
注意事項
mysqladmin
関連エラー:zabbix_get -s192.168.1.253 -k "mysql.status[Com_rollback]"
mysqladmin: connect to server at '192.168.1.253' failed
error: 'Can't connect to MySQL server on '192.168.1.253' (13)'
Check that mysqld is running on 192.168.1.253 and that the port is 3306.
You can check this by doing 'telnet 192.168.1.253 3306'
このエラーは
mysql
アカウントの権限と関係があります.mysqladmin -uroot -pXXXX -h192.168.1.253
にログインできるかどうかをテストしてください.権限がなければ認証が必要です. zabbix_get -s100.101.156.225 -k "mysql.ping"
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
0
このエラーは
netstat
権限に関連しています.「権限構成」を参照してください.Warning: Using a password on the command line interface can be insecure.
このエラーはmysql 5のためです.6以降のバージョンは、コマンドに明記されたパスワードの保護メカニズムに対して、--defaults-extra-file
でプロファイルを指定する方法で解決することができる.zabbix-agent
ローカルテストは問題なく、zabbix_get
テスト取得データ異常このエラーはmysql
とmysqladmin
コマンドが絶対パスを記入する必要がある.