{"id":865,"date":"2024-07-24T18:26:19","date_gmt":"2024-07-24T10:26:19","guid":{"rendered":"https:\/\/keyi.eu.org\/?p=865"},"modified":"2024-07-24T18:31:06","modified_gmt":"2024-07-24T10:31:06","slug":"pm2%e5%a4%9a%e9%80%b2%e7%a8%8b%e7%ae%a1%e7%90%86%e5%92%8cserv00%e4%bf%9d%e8%99%9f","status":"publish","type":"post","link":"https:\/\/keyi.eu.org\/?p=865","title":{"rendered":"pm2\u591a\u9032\u7a0b\u7ba1\u7406\u548cserv00\u4fdd\u865f"},"content":{"rendered":"\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"716\" height=\"297\" src=\"https:\/\/keyi.eu.org\/wp-content\/uploads\/2024\/07\/QQ_1721814290291.png\" alt=\"\" class=\"wp-image-866\" srcset=\"https:\/\/keyi.eu.org\/wp-content\/uploads\/2024\/07\/QQ_1721814290291.png 716w, https:\/\/keyi.eu.org\/wp-content\/uploads\/2024\/07\/QQ_1721814290291-300x124.png 300w\" sizes=\"(max-width: 716px) 100vw, 716px\" \/><\/figure>\n\n\n\n<p>\u9019\u662f\u5006\u4e26\u4e0d\u76f4\u63a5\u95dc\u806f\u7684\u8a71\u984c\uff0c\u5beb\u5728\u4e00\u8d77\uff0c\u662f\u56e0\u7232\u90fd\u662f\u5728\u540c\u4e00\u500b\u661f\u671f\u5167\u89e3\u6c7a\u7684\u554f\u984c\uff0c\u4e00\u8d77\u505a\u7b46\u8a18\u3002<\/p>\n\n\n\n<p>1\u3001\u6211\u5728wap.ac\u4ee53\u7f8e\u51431\u5e74\u7684\u4fc3\u92b7\u6d3b\u52d5\u50f9\u683c\uff0c\u8cfc\u8cb7\u4e861C1G\u7684VPS\uff0c\u7528\u4f86\u642d\u5efaTG\u8f49\u767c\u3002<\/p>\n\n\n\n<p>\u76ee\u524d\u9019\u88cf\u67093\u9805\u4efb\u52d9\uff0c\u5206\u5225\u662f\uff1a<\/p>\n\n\n\n<p>\u76e3\u807d\u82e5\u5e72\u500b\u7fa3\u7d44\u4e2d\u7684\u6240\u6709\u6d88\u606f\uff0c\u7be9\u9078\u51fa\u6709\u6587\u4ef6\u4ee3\u78bc\u7684\u6d88\u606f\uff0c\u8f49\u767c\u7d66\u4ee3\u78bc\u6a5f\u5668\u4eba\u3002<\/p>\n\n\n\n<p>\u76e3\u807d\u76e3\u807d\u4ee3\u78bc\u6a5f\u5668\u4eba\u7684\u6d88\u606f\uff0c\u5728\u9700\u8981\u9ede\u64ca\u5c0d\u8a71\u6309\u9215\u9078\u64c7\u201c\u7e7c\u7e8c\u52a0\u8f09\u201d\u7684\u6642\u5019\uff0c\u53bb\u9ede\u4e00\u4e0b\u4ee5\u4fbf\u7372\u53d6\u5f8c\u9762\u672a\u5b8c\u6210\u767c\u9001\u7684\u5a92\u9ad4\u6587\u4ef6\u3002<\/p>\n\n\n\n<p>\u76e3\u807d\u4ee3\u78bc\u6a5f\u5668\u4eba\u7684\u6d88\u606f\uff0c\u628a\u6240\u7372\u5f97\u7684\u5a92\u9ad4\u548c\u6587\u4ef6\uff0c\u8f49\u767c\u5230\u5c0f\u5925\u4f34\u7684\u7fa3\u7d44\u88e1\u3002<\/p>\n\n\n\n<p>\u9019\u4e09\u9805\u4efb\u52d9\uff0c\u5206\u5225\u7531\u4e00\u500bpy\u8173\u672c\u4f86\u9032\u884c\u3002\u5206\u5225\u7528pm2\u4f86\u5553\u52d5\u5b83\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pm2 start myScript.py --interpreter python3 --name mingzi<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p>\u7b493\u9805\u90fd\u5553\u52d5\u8d77\u4f86\u4e86\uff0c\u6aa2\u67e5\u4e00\u4e0b\u72c0\u6cc1\uff1a<\/p>\n\n\n\n<p>pm2 list<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"1024\" height=\"212\" src=\"https:\/\/keyi.eu.org\/wp-content\/uploads\/2024\/07\/QQ_1721815594072-1024x212.png\" alt=\"\" class=\"wp-image-867\" srcset=\"https:\/\/keyi.eu.org\/wp-content\/uploads\/2024\/07\/QQ_1721815594072-1024x212.png 1024w, https:\/\/keyi.eu.org\/wp-content\/uploads\/2024\/07\/QQ_1721815594072-300x62.png 300w, https:\/\/keyi.eu.org\/wp-content\/uploads\/2024\/07\/QQ_1721815594072-768x159.png 768w, https:\/\/keyi.eu.org\/wp-content\/uploads\/2024\/07\/QQ_1721815594072-1536x319.png 1536w, https:\/\/keyi.eu.org\/wp-content\/uploads\/2024\/07\/QQ_1721815594072.png 1586w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><figcaption>\u78ba\u8a8d\u7121\u8aa4\uff0c\u5c31\u4fdd\u6301\u4e26\u4e14\u8a2d\u7f6e\u81ea\u52d5\u5553\u52d5\uff1a<\/figcaption><\/figure>\n\n\n\n<p>pm2 startup<br>pm2 save<\/p>\n\n\n\n<p>\u5982\u679c\u6c92\u6709\u6b63\u78ba\u7684\u5553\u52d5\uff0c\u4e5f\u53ef\u4ee5\u6536\u5de5\u8f38\u5165\uff1a<\/p>\n\n\n\n<p>pm2 resurrect<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>2\u3001\u81ea\u52d5\u5c0dserv00\u7684VPS\u9032\u884cSSH\u9023\u63a5\u4ee5\u4fdd\u865f\uff0c\u4e26\u4e14\u6aa2\u67e5\u90a3\u4e0a\u9762\u662f\u5426\u6b63\u78ba\u5553\u52d5\u4e86\u54ea\u5412\u76e3\u63a7\u7684\u5ba2\u6236\u7aef\u3002\u5982\u679c\u6c92\u6709\uff0c\u901a\u904epm2\u4f86\u5553\u52d5\u5b83\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/bash\n\nfor i in {1..2}\ndo\n    echo \"Execution round $i\"\n\n    # \u7b2c\u4e00\u53f0\u4e3b\u6a5f\n    sshpass -p '\u5bc6\u78bc' ssh -t -o StrictHostKeyChecking=no -o UserKnownHostsFile=\/dev\/null \u8cec\u6236\u540d@s7.serv00.com &lt;&lt; 'EOF1'\n    if pgrep -x \"nezha-agent\" &gt; \/dev\/null\n    then\n        echo \"nezha-agent is running on \u8cec\u6236\u540d\"\n    else\n        \/home\/\u8cec\u6236\u540d\/.npm-global\/bin\/pm2 resurrect\n        echo \"pm2 resurrect command executed on \u8cec\u6236\u540d\"\n    fi\n    exit\nEOF1\n\n    # \u7b2c\u4e8c\u53f0\u4e3b\u6a5f\n    sshpass -p '\u5bc6\u78bc' ssh -t -o StrictHostKeyChecking=no -o UserKnownHostsFile=\/dev\/null \u8cec\u6236\u540d@s7.serv00.com &lt;&lt; 'EOF2'\n    if pgrep -x \"nezha-agent\" &gt; \/dev\/null\n    then\n        echo \"nezha-agent is running on \u8cec\u6236\u540d\"\n    else\n        \/home\/\u8cec\u6236\u540d\/.npm-global\/bin\/pm2 resurrect\n        echo \"pm2 resurrect command executed on \u8cec\u6236\u540d\"\n    fi\n    exit\nEOF2\n\n    # \u7b2c\u4e09\u53f0\u4e3b\u6a5f\n    sshpass -p '\u5bc6\u78bc' ssh -t -o StrictHostKeyChecking=no -o UserKnownHostsFile=\/dev\/null \u8cec\u6236\u540d@s7.serv00.com &lt;&lt; 'EOF3'\n    if pgrep -x \"nezha-agent\" &gt; \/dev\/null\n    then\n        echo \"nezha-agent is running on \u8cec\u6236\u540d\"\n    else\n        \/home\/\u8cec\u6236\u540d\/.npm-global\/bin\/pm2 resurrect\n        echo \"pm2 resurrect command executed on \u8cec\u6236\u540d\"\n    fi\n    exit\nEOF3\n\n\n    # \u7b2c\u56db\u53f0\u4e3b\u6a5f\n    sshpass -p '\u5bc6\u78bc' ssh -t -o StrictHostKeyChecking=no -o UserKnownHostsFile=\/dev\/null \u8cec\u6236\u540d@s7.serv00.com &lt;&lt; 'EOF4'\n    if pgrep -x \"nezha-agent\" &gt; \/dev\/null\n    then\n        echo \"nezha-agent is running on \u8cec\u6236\u540d\"\n    else\n        \/home\/\u8cec\u6236\u540d\/.npm-global\/bin\/pm2 resurrect\n        echo \"pm2 resurrect command executed on \u8cec\u6236\u540d\"\n    fi\n    exit\nEOF4\n\n    # \u7b2c\u4e94\u53f0\u4e3b\u6a5f\n    sshpass -p '\u5bc6\u78bc' ssh -t -o StrictHostKeyChecking=no -o UserKnownHostsFile=\/dev\/null \u8cec\u6236\u540d@s7.serv00.com &lt;&lt; 'EOF5'\n    if pgrep -x \"nezha-agent\" &gt; \/dev\/null\n    then\n        echo \"nezha-agent is running on \u8cec\u6236\u540d\"\n    else\n        \/home\/\u8cec\u6236\u540d\/.npm-global\/bin\/pm2 resurrect\n        echo \"pm2 resurrect command executed on \u8cec\u6236\u540d\"\n    fi\n    exit\nEOF5\ndone\n\necho \"Script execution completed\"\n<\/code><\/pre>\n\n\n\n<p>\u9019\u500b\u8173\u672c\uff0c\u5faa\u74b0\u57f7\u884c\u5169\u6b21\uff0c\u6bcf\u6b21\u57f7\u884c\u6642\uff0c\u4f9d\u6b21\u767b\u93045\u81faserv00\u4e3b\u6a5f\uff0c\u4e26\u4e14\u6aa2\u6e2c\u662f\u5426\u6709 &#8220;nezha-agent&#8221; \u5728\u904b\u884c\u4e2d\u3002\u5982\u679c\u6709\uff0c\u5c31\u9000\u51fa\u767b\u9304\uff0c\u6aa2\u6e2c\u4e0b\u4e00\u81fa\u3002\u5982\u679c\u6c92\u6709\uff0c\u5247\u901a\u904e\u559a\u9192pm2\u4f86\u5553\u52d5\u5b83\u3002<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>\u4f7f\u7528cron\u4f86\u5b9a\u6642\u57f7\u884c\u9019\u500bsh\u8173\u672c\uff1a<\/p>\n\n\n\n<p>\u7f16\u8f91 <code>crontab<\/code> \u6587\u4ef6\uff1a<\/p>\n\n\n\n<p>crontab -e<\/p>\n\n\n\n<p>\u5728 <code>crontab<\/code> \u6587\u4ef6\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u884c\uff1a<\/p>\n\n\n\n<p>*\/15 * * * * \/bin\/bash \/root\/serv00-renew.sh<\/p>\n\n\n\n<p>\u8fd9\u91cc\u7684 <code>*\/15 * * * *<\/code> \u8868\u793a\u6bcf 15 \u5206\u949f\u6267\u884c\u4e00\u6b21\u3002<\/p>\n\n\n\n<p>\u8fd9\u6837\u8bbe\u7f6e\u540e\uff0c<code>cron<\/code> \u4f1a\u6bcf 15 \u5206\u949f\u6267\u884c\u4e00\u6b21 <code>\/root\/serv00-renew.sh<\/code> \u811a\u672c\u3002\u786e\u4fdd\u811a\u672c\u6709\u6267\u884c\u6743\u9650\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u8bbe\u7f6e\u6743\u9650\uff1a<\/p>\n\n\n\n<p>chmod +x \/root\/serv00-renew.sh<\/p>\n<p>\u8f6c\u8f7d\u8bf7\u6ce8\u660e\uff1a<a href=\"https:\/\/keyi.eu.org\">\u5218\u592a\u76d1\u7684\u79c1\u85cf<\/a> &raquo; <a href=\"https:\/\/keyi.eu.org\/?p=865\">pm2\u591a\u9032\u7a0b\u7ba1\u7406\u548cserv00\u4fdd\u865f<\/a><\/p>","protected":false},"excerpt":{"rendered":"<p>\u9019\u662f\u5006\u4e26\u4e0d\u76f4\u63a5\u95dc\u806f\u7684\u8a71\u984c\uff0c\u5beb\u5728\u4e00\u8d77\uff0c\u662f\u56e0\u7232\u90fd\u662f\u5728\u540c\u4e00\u500b\u661f\u671f\u5167\u89e3\u6c7a\u7684\u554f\u984c\uff0c\u4e00\u8d77\u505a\u7b46\u8a18\u3002 1\u3001\u6211\u5728wap.ac\u4ee53 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[4],"tags":[],"_links":{"self":[{"href":"https:\/\/keyi.eu.org\/index.php?rest_route=\/wp\/v2\/posts\/865"}],"collection":[{"href":"https:\/\/keyi.eu.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/keyi.eu.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/keyi.eu.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/keyi.eu.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=865"}],"version-history":[{"count":3,"href":"https:\/\/keyi.eu.org\/index.php?rest_route=\/wp\/v2\/posts\/865\/revisions"}],"predecessor-version":[{"id":870,"href":"https:\/\/keyi.eu.org\/index.php?rest_route=\/wp\/v2\/posts\/865\/revisions\/870"}],"wp:attachment":[{"href":"https:\/\/keyi.eu.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=865"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/keyi.eu.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=865"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/keyi.eu.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=865"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}