{"id":1028,"date":"2017-11-30T15:12:12","date_gmt":"2017-11-30T15:12:12","guid":{"rendered":"https:\/\/peloo.net\/?p=1028"},"modified":"2017-12-02T14:10:44","modified_gmt":"2017-12-02T14:10:44","slug":"%e8%87%aa%e5%8a%a8%e6%a3%80%e6%b5%8b%e7%bd%91%e7%ab%99%e5%81%a5%e5%ba%b7shell%e8%84%9a%e6%9c%ac","status":"publish","type":"post","link":"https:\/\/peloo.net\/?p=1028","title":{"rendered":"\u81ea\u52a8\u68c0\u6d4b\u7f51\u7ad9\u5065\u5eb7shell\u811a\u672c"},"content":{"rendered":"<p>\n\t<span style=\"font-family:verdana,geneva,sans-serif\"><span style=\"font-size: 18px\"><strong>\u4e00\u3001\u80cc\u666f\u4ecb\u7ecd<\/strong><\/span><\/span>\n<\/p>\n<p>\n\t<span style=\"font-family:verdana,geneva,sans-serif\"><span style=\"font-size: 16px\">\u6211\u7684WordPress\u7f51\u7ad9\u6700\u8fd1\u8001\u662f\u5b95\u673a\u65e0\u6cd5\u63d0\u4f9b\u670d\u52a1\uff0c\u7f51\u7ad9\u67b6\u6784\u662f\u7ecf\u5178\u7684 Linux + OpenResty + MySQL + PHP \uff0c \u5b95\u673a\u540e\u5927\u591a\u6570\u60c5\u51b5\u4e0b\u4e0d\u80fd\u7acb\u5373\u5904\u7406\uff0c\u4e8e\u662f\u60f3\u5199\u4e2a\u81ea\u52a8\u68c0\u6d4b\u7f51\u7ad9\u5065\u5eb7\u7684shell\u811a\u672c\uff0c\u4e3b\u8981\u529f\u80fd\u662f\u5b9a\u65f6\u68c0\u6d4b\u7f51\u7ad9\u8fd0\u884c\u662f\u5426\u6b63\u5e38\uff0c\u5982\u679c\u5b95\u673a\uff0c\u5219\u81ea\u52a8\u521d\u59cb\u5316MySQL\u548cPHP\u670d\u52a1\uff0c\u5982\u679c\u521d\u59cb\u5316\u540e\u8fd8\u4e0d\u80fd\u8bbf\u95ee\uff0c\u5219\u90ae\u4ef6\u544a\u8b66\u901a\u77e5\u6211\u3002<\/span><\/span>\n<\/p>\n<p>\n\t<span style=\"font-family:verdana,geneva,sans-serif\"><span style=\"font-size: 18px\"><strong>\u4e8c\u3001\u5b9e\u73b0\u8fc7\u7a0b<\/strong><\/span><\/span>\n<\/p>\n<p>\n\t<span style=\"font-family:verdana,geneva,sans-serif\"><span style=\"font-size: 16px\">1&nbsp; \u7f16\u5199\u811a\u672c<\/span><\/span>\n<\/p>\n<p>\n\t<span style=\"font-family:verdana,geneva,sans-serif\"><span style=\"font-size: 16px\">\u811a\u672c\u7684\u5185\u5bb9\u5982\u4e0b\uff0c\u76ee\u524d\u8fd0\u884c\u5341\u6765\u5929\u5de6\u53f3\u8fd8\u7b97\u6b63\u5e38\u3002<\/span><\/span>\n<\/p>\n<p>\n\t<span style=\"color:#0000FF\"><span style=\"font-family: verdana, geneva, sans-serif\"><span style=\"font-size: 16px\"><em>#!\/bin\/bash<\/em><\/span><\/span><\/span>\n<\/p>\n<p>\n\t<span style=\"color:#0000FF\"><span style=\"font-family: verdana, geneva, sans-serif\"><span style=\"font-size: 16px\"><em>#Author:Attaboy<br \/>\n\t#Description:this script is made to check website health and roll back automattically.<br \/>\n\t# Modify history<br \/>\n\t#&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 20171122<br \/>\n\t#&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 20171130<\/em><\/span><\/span><\/span>\n<\/p>\n<p>\n\t<span style=\"color:#0000FF\"><span style=\"font-family: verdana, geneva, sans-serif\"><span style=\"font-size: 16px\"><em>dst_mail=&quot;xxxxxxxx@xx.com&quot;<br \/>\n\tmail_title=&quot;Linode Website Health Report&quot;<br \/>\n\tmail_content=&quot;\\nOops\uff0cYour website is still out of service after initiating!\\n\\n$(iptables -vnL)\\n\\n\\n$(netstat -nltp)\\n\\n&quot;<br \/>\n\tfree_mem=$(free -m | awk &#039;\/Mem\/ { print $4 }&#039;)<br \/>\n\tmin_mem=&quot;300&quot;<br \/>\n\techo &quot;free memory is : ${free_mem} MB&quot;<\/em><\/span><\/span><\/span>\n<\/p>\n<p>\n\t<span style=\"color:#0000FF\"><span style=\"font-family: verdana, geneva, sans-serif\"><span style=\"font-size: 16px\"><em>#function to check current website health.<br \/>\n\tchk_health(){<br \/>\n\t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; curl https:\/\/peloo.net\/?p=262 2&gt;\/dev\/null&nbsp; | grep -io &quot;routeros&quot;<br \/>\n\t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if [ $? -eq 0 ] ; then<br \/>\n\t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return 0<br \/>\n\t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else<br \/>\n\t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return 1<br \/>\n\t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fi<br \/>\n\t}<\/em><\/span><\/span><\/span>\n<\/p>\n<p>\n\t<span style=\"color:#0000FF\"><span style=\"font-family: verdana, geneva, sans-serif\"><span style=\"font-size: 16px\"><em>#function to restart mysqld and php-fpm process.<br \/>\n\tinit_service(){<\/em><\/span><\/span><\/span>\n<\/p>\n<p>\n\t<span style=\"color:#0000FF\"><span style=\"font-family: verdana, geneva, sans-serif\"><span style=\"font-size: 16px\"><em>chk_health<br \/>\n\tif [ ! $? -eq 0 ] ; then<br \/>\n\t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for((i=1;i&lt;=2;i++))<br \/>\n\t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; do<br \/>\n\t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; service php-fpm stop 2&gt;\/dev\/null<br \/>\n\t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; service php-fpm start<br \/>\n\t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo -e &quot;\\n......php-fpm started successfully !\\n&quot;<br \/>\n\t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo -e &quot;\\n++++++++++++++++++++++++++++++++++++\\n&quot;<br \/>\n\t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; service mysqld stop 2&gt;\/dev\/null<br \/>\n\t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; service mysqld start<br \/>\n\t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo -e &quot;\\n...... MySQL server started successfully !\\n&quot;<br \/>\n\t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; done<br \/>\n\telse<br \/>\n\techo -e &quot;\\n......Your website is OK !\\n&quot;<br \/>\n\tfi<\/em><\/span><\/span><\/span>\n<\/p>\n<p>\n\t<span style=\"color:#0000FF\"><span style=\"font-family: verdana, geneva, sans-serif\"><span style=\"font-size: 16px\"><em>}<\/em><\/span><\/span><\/span>\n<\/p>\n<p>\n\t<span style=\"color:#0000FF\"><span style=\"font-family: verdana, geneva, sans-serif\"><span style=\"font-size: 16px\"><em>#function to do something when backup ending.<br \/>\n\tpost_do(){<\/em><\/span><\/span><\/span>\n<\/p>\n<p>\n\t<span style=\"color:#0000FF\"><span style=\"font-family: verdana, geneva, sans-serif\"><span style=\"font-size: 16px\"><em>ping -c 30 127.1 1&gt;\/dev\/null 2&gt;&amp;1<br \/>\n\tchk_health<br \/>\n\tif [ ! $? -eq 0 ] ; then<br \/>\n\t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo -e &quot;\\n Damn it , Your website is still out of service !!! \\n&quot;<br \/>\n\t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo -e &quot;${mail_content}&quot; | mailx -v -s &quot;${mail_title}&quot; &quot;${dst_mail}&quot;<br \/>\n\tfi<\/em><\/span><\/span><\/span>\n<\/p>\n<p>\n\t<span style=\"color:#0000FF\"><span style=\"font-family: verdana, geneva, sans-serif\"><span style=\"font-size: 16px\"><em>}<\/em><\/span><\/span><\/span>\n<\/p>\n<p>\n\t<span style=\"color:#0000FF\"><span style=\"font-family: verdana, geneva, sans-serif\"><span style=\"font-size: 16px\"><em>init_service<br \/>\n\tpost_do<\/em><\/span><\/span><\/span>\n<\/p>\n<p>\n\t<span style=\"color:#0000FF\"><span style=\"font-family: verdana, geneva, sans-serif\"><span style=\"font-size: 16px\"><em>exit 0<\/em><\/span><\/span><\/span>\n<\/p>\n<p>\n\t<span style=\"font-family:verdana,geneva,sans-serif\"><span style=\"font-size: 16px\">\u89e3\u91ca\uff1a<\/span><\/span>\n<\/p>\n<p>\n\t<span style=\"font-family:verdana,geneva,sans-serif\"><span style=\"font-size: 16px\">A\uff09\u51fd\u6570chk_health()\u7528\u6765\u901a\u8fc7curl\u8bf7\u6c42\u7f51\u9875\u5185\u5bb9\uff0c\u5982\u679c\u8fd4\u56de\u7684\u5b57\u7b26\u4e32\u68c0\u6d4b\u4e0d\u5230\uff0c\u5219\u5224\u5b9a\u7f51\u7ad9\u5b95\u673a\u3002<\/span><\/span>\n<\/p>\n<p>\n\t<span style=\"font-family:verdana,geneva,sans-serif\"><span style=\"font-size: 16px\">B\uff09\u51fd\u6570 init_service()\u5148\u8c03\u7528chk_health()\uff0c\u5982\u679c\u5b95\u673a\uff0c\u5219\u91cd\u542fMySQL\u548cPHP\u670d\u52a1\u3002<\/span><\/span>\n<\/p>\n<p>\n\t<span style=\"font-family:verdana,geneva,sans-serif\"><span style=\"font-size: 16px\">C\uff09post_do()\u51fd\u6570\u7528\u6765\u505a\u540e\u7f6e\u5904\u7406\u5de5\u4f5c\uff0c\u4e3b\u8981\u662f\u518d\u6b21\u8c03\u7528chk_health()\u51fd\u6570\u6765\u68c0\u6d4b\u7f51\u7ad9\u662f\u5426\u6062\u590d\u6b63\u5e38\uff0c\u5982\u679c\u4e0d\u6b63\u5e38\uff0c\u5219\u90ae\u4ef6\u63d0\u793a\u6211\u81ea\u5df1\u3002<\/span><\/span>\n<\/p>\n<p>\n\t&nbsp;\n<\/p>\n<p>\n\t<span style=\"font-family:verdana,geneva,sans-serif\"><span style=\"font-size: 16px\">2&nbsp; \u6dfb\u52a0Linux\u5b9a\u65f6\u4efb\u52a1\u8ba1\u5212<\/span><\/span>\n<\/p>\n<p>\n\t<span style=\"font-family:verdana,geneva,sans-serif\"><span style=\"font-size: 16px\">\u6bcf\u969420\u5206\u949f\u8fd0\u884c\u5065\u5eb7\u68c0\u6d4b\u811a\u672c<\/span><\/span>\n<\/p>\n<p>\n\t<span style=\"font-family:verdana,geneva,sans-serif\"><span style=\"font-size: 16px\">echo &quot;*\/20 * * * *&nbsp;&nbsp;&nbsp; root \/bin\/bash \/srv\/sh\/init_service.sh&quot; &gt;&gt;\/etc\/crontab&nbsp;<\/span><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001\u80cc\u666f\u4ecb\u7ecd \u6211\u7684WordPress\u7f51\u7ad9\u6700\u8fd1\u8001\u662f\u5b95\u673a\u65e0\u6cd5\u63d0\u4f9b\u670d\u52a1\uff0c\u7f51\u7ad9\u67b6\u6784\u662f\u7ecf\u5178\u7684 Linux + OpenResty + MySQL + PHP \uff0c \u5b95\u673a\u540e\u5927\u591a\u6570\u60c5\u51b5\u4e0b\u4e0d\u80fd\u7acb\u5373\u5904\u7406\uff0c\u4e8e\u662f\u60f3\u5199\u4e2a\u81ea\u52a8\u68c0\u6d4b\u7f51\u7ad9\u5065\u5eb7\u7684shell\u811a\u672c\uff0c\u4e3b\u8981\u529f\u80fd\u662f\u5b9a\u65f6\u68c0\u6d4b\u7f51\u7ad9\u8fd0\u884c\u662f\u5426\u6b63\u5e38\uff0c\u5982\u679c\u5b95\u673a\uff0c\u5219\u81ea\u52a8\u521d\u59cb\u5316MySQL\u548cPHP\u670d\u52a1\uff0c\u5982\u679c\u521d\u59cb\u5316\u540e\u8fd8\u4e0d\u80fd\u8bbf\u95ee\uff0c\u5219\u90ae\u4ef6\u544a\u8b66\u901a\u77e5\u6211\u3002 \u4e8c\u3001\u5b9e\u73b0\u8fc7\u7a0b 1&nbsp; \u7f16\u5199\u811a\u672c \u811a\u672c\u7684\u5185\u5bb9\u5982\u4e0b\uff0c\u76ee\u524d\u8fd0\u884c\u5341\u6765\u5929\u5de6\u53f3\u8fd8\u7b97\u6b63\u5e38\u3002 #!\/bin\/bash #Author:Attaboy #Description:this script is made to check website health and roll back automattically. # Modify history #&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 20171122 #&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 20171130 dst_mail=&quot;xxxxxxxx@xx.com&quot; mail_title=&quot;Linode Website Health Report&quot; mail_content=&quot;\\nOops\uff0cYour website is still out of service after initiating!\\n\\n$(iptables -vnL)\\n\\n\\n$(netstat -nltp)\\n\\n&quot; free_mem=$(free -m |&#8230;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/peloo.net\/index.php?rest_route=\/wp\/v2\/posts\/1028"}],"collection":[{"href":"https:\/\/peloo.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/peloo.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/peloo.net\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/peloo.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1028"}],"version-history":[{"count":12,"href":"https:\/\/peloo.net\/index.php?rest_route=\/wp\/v2\/posts\/1028\/revisions"}],"predecessor-version":[{"id":1052,"href":"https:\/\/peloo.net\/index.php?rest_route=\/wp\/v2\/posts\/1028\/revisions\/1052"}],"wp:attachment":[{"href":"https:\/\/peloo.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1028"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/peloo.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1028"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/peloo.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1028"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}