好好爱己 發表於 2015-10-19 10:45:24

shell脚本监控MySQL服务是否正常

<p>监控MySQL服务是否正常,通常的思路为:检查3306端口是否启动,ps查看mysqld进程是否启动,命令行登录mysql执行语句返回结果,php或jsp程序检测(需要开发人员开发程序)等等;</p>
<p><strong>方法1:监听3306端口</strong></p>
<p align="center"><img id="theimg" onclick="window.open(this.src)" src="https://img.jbzj.com/file_images/article/201510/20151019104942565.jpg?2015919104952" alt="" /></p>
<p><strong>方法2:查看mysqld进程</strong></p>
<p>注意注意:如果使用进程过滤的话,脚本名称如果里面包含mysql的话,脚本执行有坑,切记!!!因为会把脚本也grep了一次,导致结果不准确;</p>
<p align="center"><img id="theimg" onclick="window.open(this.src)" src="https://img.jbzj.com/file_images/article/201510/20151019105017628.jpg?2015919105030" alt="" /></p>
<p>执行结果如下:</p>
<p align="center"><img id="theimg" onclick="window.open(this.src)" src="https://img.jbzj.com/file_images/article/201510/20151019105058425.jpg?201591910517" alt="" /></p>
<p><strong>方法3:双保险,进程和端口都成功才算mysql服务正常</strong></p>
<p align="center"><img id="theimg" onclick="window.open(this.src)" src="https://img.jbzj.com/file_images/article/201510/20151019105121496.jpg?2015919105135" alt="" /></p>
<p align="left"><strong>方法4:使用客户端登录mysql执行命令,查看返回结果测试服务是否启动,理论上此方法最可靠。</strong></p>
<p align="center"><img id="theimg" onclick="window.open(this.src)" src="https://img.jbzj.com/file_images/article/201510/20151019105213407.jpg?2015919105224" alt="" /></p>
<p>执行结果如下:<br /><font color="#3366ff"><strong># sh check_db_client.sh<br />MySQL is running</strong></font></p>
<p>以上就是shell脚本如何监控MySQL服务是否正常的四种方法,希望对大家的学习有所帮助。</p>
頁: [1]
查看完整版本: shell脚本监控MySQL服务是否正常