监控Mysql主从复制状态
三、监控Mysql主从复制状态
捕捉状态码
服务端接口支持:
利用客户端命令、工具:
利用操作系统命令:
#!/bin/bash
Resettem=$(tput sgr0)
Nginxserver='http://10.156.11.173/nginx_status'
Check_Nginx_Server()
{
Status_Code=$(curl -m 5 -s -w %{http_code} ${Nginxserver} -o /dev/null)
if [ $Status_Code -eq 000 -o $Status_Code -ge 500 ]
then
echo -e '\E[32m' "Check http server error! Response status code is" $Resettem $Status_code
else
Http_content=$(curl -s ${Nginxserver})
echo -e '\E[32m' "Check http server ok! \n" $Resettem $Http_content
fi
}
Mysql_Slave_Server='10.156.11.233'
Mysql_User='rep'
Mysql_Pass='immoc'
Check_Mysql_Server()
{
#检查MySQL的从机的端口为3306通不通
nc -z -w2 ${Mysql_Slave_Server} 3306 &>/dev/null
echo -e '\E[32m'"The connnections to mysql server succeeded! \n" $Rsesttem
#通过show slave status查看MySQL机器状态信息,其中Slave_IO_Running为主从是否连接
if [ $? -eq 0 ];then
mysql -u${Mysql_User} -p${Mysql_Pass} -h${Mysql_Slave_Server} -e
"show slave status|G"|grep "Slave_IO_Running"|awk '{if($2 !="Yes"){print "Slave thread not running!";exit 1}}'
#Seconds_Behind_Master为主从同步的延时
if [$? -eq 0];then
mysql -u${Mysql_User} -p${Mysql_Pass} -h${Mysql_Slave_Server} -e "show slave status\G"|grep"Seconds_Behind_Master"
fi
else
echo "Connect Mysql Slave Server not succeeded"
fi
}
Check_Mysql_Server
Check_Nginx_Server
#!/bin/bash
#Program function: To check nginx and mysql's running status
reset=$(tput sgr0)
standarndColor='\e[32m'
errorColor='\e[31m'
warnColor='\e[33m'
nginxServer=192.168.199.245/nginx_status
Mysql_Slave_Server='192.168.199.245'
Check_Nginx_Server(){
status_code=$(curl -I -m 5 -o /dev/null -s -w %{http_code} ${nginxServer})
if [ $status_code -eq 000 -o $status_code -ge 500 ];then
echo -e $warnColor "check http server error! Response status code is" $errorColor $status_code $reset
else
http_content=$(curl -s ${nginxServer})
echo -e $standarndColor "check http server ok! \n" $reset $http_content
fi
}
Check_Mysql_Server(){
# nc -z -w2 ${Mysql_Slave_Server} 3306 &>/dev/null
# centos7 已取消 nc 中的 z 可使用以下写法代替。
nc -w 1 192.168.199.245 3306 < /dev/null && echo " tcp port ok" >
if [ $? -eq 0 ];then
echo -e $standarndColor "contect ${Mysql_Slave_Server} ok!"
fi
}
Check_Mysql_Server
Check_Nginx_Server
mysql> show slave status\G;
Slave_IO_Running-IO线程是否有连接到主服务器上
Seconds_Behind_Master 主从同步的延时时间
操作系统命令来查看应用运行状态
三.服务端接口支持
nginx- http_stub_status_module
nutcracker监控集群(redis,memcache)状态
Mongodb
....
二.客户端命令及工具:
应用客户端mysql,ab,mongo,php,jstack
第三方工具包:nginxstatus,nagios-libexec
一.常用检查应用状态的命令:
网络命令:ping nslookup tracertroute telnet nc curl nm-tool dig
监控进程:ps netstat pgrep
监控mysql主从复制状态
show slave status\G
这一节还没有认真看
网络命令: ping ,nslookup,nm-tool, tracertroute ,dig,telnet ,nc ,curl
监控进程: ps , netstat , pgrep