{"id":295147,"date":"2024-12-23T20:08:26","date_gmt":"2024-12-23T12:08:26","guid":{"rendered":"https:\/\/lrxjmw.cn\/srjxnmlhtyxc.html"},"modified":"2024-12-23T20:08:26","modified_gmt":"2024-12-23T12:08:26","slug":"srjxnmlhtyxc","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/srjxnmlhtyxc.html","title":{"rendered":"\u6df1\u5165\u89e3\u6790nohup\u547d\u4ee4\uff1a\u540e\u53f0\u8fd0\u884c\u7a0b\u5e8f\u4e0e\u5ffd\u7565\u6302\u65ad\u4fe1\u53f7\u7684\u5b9e\u7528\u6307\u5357"},"content":{"rendered":"

shell\u5173\u673a\u811a\u672c_linux\u5173\u673a\u524d\u6267\u884c\u547d\u4ee4_linux \u5173\u673a\u524d\u6267\u884c\u811a\u672c<\/p>\n

nohup\u89e3\u8bfb<\/p>\n

nohup\u547d\u4ee4<\/a>\u8fd0\u884c\u7531Command\u53c2\u6570\u548c\u4efb\u4f55\u76f8\u5173\u7684Arg\u53c2\u6570\u6307\u5b9a\u7684\u547d\u4ee4\uff0c\u5ffd\u89c6\u6240\u6709\u6302\u65ad\uff08SIGHUP\uff09\u8baf\u53f7\u3002\u5728\u6ce8\u9500\u540e\u4f7f\u7528nohup\u547d\u4ee4\u8fd0\u884c\u540e\u53f0\u4e2d\u7684\u7a0b\u5e8f\u3002\u8981\u8fd0\u884c\u540e\u53f0\u4e2d\u7684nohup\u547d\u4ee4\uff0c\u6dfb\u52a0&\uff08\u8868\u793a\u201cand\u201d\u7684\u7b26\u53f7\uff09\u5230\u547d\u4ee4\u7684\u5c3e\u90e8\u3002<\/p>\n

nohup\u662fnohangup\u7684\u7b80\u5199\uff0c\u5c31\u662f\u4e0d\u6302\u65ad\u7684\u610f\u601d\u3002<\/p>\n

nohup\u547d\u4ee4\uff1a\u5047\u5982\u4f60\u6b63\u5728\u8fd0\u884c\u4e00\u4e2a\u8fdb\u7a0b\uff0c\u4f46\u662f\u4f60\u8ba4\u4e3a\u5728\u9000\u51fa\u8d26\u6237\u65f6\u8be5\u8fdb\u7a0b\u8fd8\u4e0d\u4f1a\u7ed3\u675f\uff0c\u8fd9\u4e48\u53ef\u4ee5\u4f7f\u7528nohup\u547d\u4ee4\u3002\u8be5\u547d\u4ee4\u53ef\u4ee5\u5728\u4f60\u9000\u51fa\u8d26\u6237\/\u5173\u6389\u7ec8\u7aef\u4ee5\u540e\u7ee7\u7eed\u8fd0\u884c\u76f8\u5e94\u7684\u8fdb\u7a0b\u3002<\/p>\n

\u5728\u7f3a\u7701\u60c5\u51b5\u4e0b\u8be5\u4f5c\u4e1a\u7684\u6240\u6709\u8f93\u51fa\u90fd\u88ab\u91cd\u5b9a\u5411\u5230\u4e00\u4e2a\u540d\u4e3anohup.out\u7684\u6587\u4ef6\u4e2d\u3002<\/p>\n

nohup\u6848\u4f8b<\/p>\n

1.nohuppython3main.py>>main.log2>&1&<\/p>\n

\u5728\u524d\u9762\u7684\u4e8b\u4f8b\u4e2d\uff0c0\u2013stdin(standardinput)\uff0c1\u2013stdout(standardoutput)\uff0c2\u2013stderr(standarderror)\uff1b<\/p>\n

2>&1\u662f\u5c06\u6807\u51c6\u9519\u8bef\uff082\uff09\u91cd\u5b9a\u5411\u5230\u6807\u51c6\u8f93\u51fa\uff08&1\uff09\uff0c\u6807\u51c6\u8f93\u51fa\uff08&1\uff09\u518d\u88ab\u91cd\u5b9a\u5411\u8f93\u5165\u5230myout.file\u6587\u4ef6\u4e2d\u3002\u8bf8\u5982nohupcommand>myout.file2>error.txt&\u8fd9\u4e48\u9519\u8bef\u5185\u5bb9\u4f1a\u8f93\u51fa\u5230error.txt\u6587\u4ef6\u4e2d<\/p>\n

2.022***\/usr\/bin\/python\/home\/pu\/download_pdf\/download_dfcf_pdf_to_oss.py>\/home\/pu\/download_pdf\/download_dfcf_pdf_to_oss.log2>&1<\/p>\n

\u8fd9\u662f\u7f6e\u4e8ecrontab\u4e2d\u7684\u5b9a\u65f6\u4efb\u52a1\uff0c\u591c\u665a22\u70b9\u65f6\u4faf\u6015\u8fd9\u4e2a\u4efb\u52a1\uff0c\u542f\u52a8\u8fd9\u4e2apython\u7684\u811a\u672c\uff0c\u5e76\u628a\u65e5\u5fd7\u5199\u5728download_dfcf_pdf_to_oss.log\u6587\u4ef6\u4e2d<\/p>\n

nohup\u548c&\u4e8c\u8005\u7684\u533a\u522b<\/p>\n

&\uff1a\u6307\u5728\u540e\u53f0\u8fd0\u884c<\/p>\n

nohup\uff1a\u4e0d\u6302\u65ad\u7684\u8fd0\u884clinux \u5173\u673a\u524d\u6267\u884c\u811a\u672c<\/strong>\uff0c\u6ce8\u610f\u5e76\u6ca1\u6709\u540e\u53f0\u8fd0\u884c\u7684\u529f\u80fd\uff0c\uff0c\u5c31\u662f\u6307\uff0c\u7528nohup\u8fd0\u884c\u547d\u4ee4\u53ef\u4ee5\u4f7f\u547d\u4ee4\u6c38\u4e45\u7684\u6267\u884c\u4e0b\u53bb\uff0c\u548c\u7528\u6237\u7ec8\u7aef\u6ca1\u6709\u5173\u7cfb\uff0c\u6bd4\u5982\u6211\u4eec\u65ad\u6389SSH\u8054\u63a5\u90fd\u4e0d\u4f1a\u5f71\u54cd\u4ed6\u7684\u8fd0\u884c\uff0c\u6ce8\u610f\u4e86nohup\u6ca1\u6709\u540e\u53f0\u8fd0\u884c\u7684\u610f\u601d\uff1b&\u624d\u662f\u540e\u53f0\u8fd0\u884c<\/p>\n

&\u662f\u6307\u5728\u540e\u53f0\u8fd0\u884c\uff0c\u4f46\u5f53\u7528\u6237\u63a8\u51fa(\u6302\u8d77)\u7684\u65f6\u4faf\uff0c\u547d\u4ee4\u624b\u52a8\u4e5f\u8ddf\u968f\u9000\u51fa<\/p>\n

\u8fd9\u4e48\uff0c\u6211\u4eec\u53ef\u4ee5\u5de7\u5999\u7684\u5427\u5979\u4eec\u7ed3\u5408\u4e0a\u53bb\u7528\u5c31\u662f<\/p>\n

nohupCOMMAND&<\/p>\n

\u8fd9\u6837\u624d\u80fd\u4f7f\u547d\u4ee4\u6c38\u4e45\u7684\u5728\u540e\u53f0\u6267\u884c<\/p>\n

\u6bd4\u5982\uff1a<\/p>\n

1.shtest.sh&<\/p>\n

\u5c06shtest.sh\u4efb\u52a1\u653e\u5728\u540e\u53f0\uff0c\u867d\u7136\u5173\u6389xshell\u9000\u51fa\u5f53\u524dsession\u4ecd\u7136\u7ee7\u7eed\u8fd0\u884clinux\u4e0bsocket\u7f16\u7a0b\uff0c\u4f46\u6807\u51c6\u8f93\u51fa\u548c\u6807\u51c6\u9519\u8bef\u4fe1\u606f\u4f1a\u9057\u5931\uff08\u7f3a\u4e4f\u7684\u65e5\u5fd7\u7684\u8f93\u51fa\uff09<\/p>\n

\u5c06shtest.sh\u4efb\u52a1\u653e\u5728\u540e\u53f0\uff0c\u5173\u6389xshell\uff0c\u5bf9\u5e94\u7684\u4efb\u52a1\u4e5f\u8ddf\u968f\u505c\u6b62\u3002<\/p>\n

2.nohupshtest.sh<\/p>\n

\u5c06shtest.sh\u4efb\u52a1\u653e\u5728\u540e\u53f0\uff0c\u5173\u6389\u6807\u51c6\u8f93\u5165\uff0c\u7ec8\u7aef\u4e0d\u518d\u624d\u80fd\u63a5\u6536\u4efb\u4f55\u8f93\u5165\uff08\u6807\u51c6\u8f93\u5165\uff09\uff0c\u91cd\u5b9a\u5411\u6807\u51c6\u8f93\u51fa\u548c\u6807\u51c6\u9519\u8bef\u5230\u5f53\u524d\u76ee\u5f55\u4e0b\u7684nohup.out\u6587\u4ef6\uff0c\u867d\u7136\u5173\u6389xshell\u9000\u51fa\u5f53\u524dsession\u4ecd\u7136\u7ee7\u7eed\u8fd0\u884c\u3002<\/p>\n

3.nohupshtest.sh&<\/p>\n

\u5c06shtest.sh\u4efb\u52a1\u653e\u5728\u540e\u53f0\uff0c\u5e76\u4e14\u4ecd\u7136\u53ef\u4ee5\u4f7f\u7528\u6807\u51c6\u8f93\u5165\uff0c\u7ec8\u7aef\u624d\u80fd\u63a5\u6536\u4efb\u4f55\u8f93\u5165\uff0c\u91cd\u5b9a\u5411\u6807\u51c6\u8f93\u51fa\u548c\u6807\u51c6\u9519\u8bef\u5230\u5f53\u524d\u76ee\u5f55\u4e0b\u7684nohup.out\u6587\u4ef6\uff0c\u867d\u7136\u5173\u6389xshell\u9000\u51fa\u5f53\u524dsession\u4ecd\u7136\u7ee7\u7eed\u8fd0\u884c\u3002<\/p>\n

systemd\u5de5\u5177<\/p>\n

\u501f\u52a9systemd\u5de5\u5177\u7ba1\u7406\u7a0b\u5e8f\uff0c\u5b9e\u73b0\u670d\u52a1\u5f00\u673a\u81ea\u542f\u52a8<\/p>\n

1\u3001systemd\u5de5\u5177\u4ecb\u7ecd<\/p>\n

\u8bf4\u9053systemd\u5de5\u5177\uff0c\u4e0d\u5f97\u4e0d\u63d0\u53caservice\u547d\u4ee4\u3002\u5b83\u4eec\u662fLinux<\/a>\u670d\u52a1\u7ba1\u7406\u7684\u4e24\u79cd\u5f62\u5f0fservice\u548csystemctl\u3002\u4f46\u8fd8\u662f\u6709\u533a\u522b\uff0c\u53ef\u4ee5\u5982\u6b64\u8bf4\uff1asystemctl\u57fa\u672c\u4e0a\u662f\u7684\u66f4\u5f3a\u608d\u7684\u7248\u672cservice\u3002<\/p>\n

\u2460\u4ec0\u4e48\u662fservice\uff1f<\/p>\n

service\u547d\u4ee4\u662fRedhatLinux\u517c\u5bb9\u7684\u53d1\u884c\u7248\u4e2d\u62ff\u6765\u63a7\u5236\u7cfb\u7edf\u670d\u52a1\u7684\u5b9e\u7528\u5de5\u5177\uff0c\u5b83\u4ee5\u542f\u52a8\u3001\u505c\u6b62\u3001\u91cd\u65b0\u542f\u52a8\u548c\u5173\u6389\u7cfb\u7edf\u670d\u52a1linux \u5173\u673a\u524d\u6267\u884c\u811a\u672c<\/strong>\uff0c\u8fd8\u53ef\u4ee5\u663e\u793a\u6240\u6709\u7cfb\u7edf\u670d\u52a1\u7684\u5f53\u524d\u72b6\u6001\u3002<\/p>\n

service\u547d\u4ee4\u5b9e\u73b0\u7684\u539f\u7406\u4f3c\u4e4e\u662f\u53bb\/etc\/init.d\u76ee\u5f55\u4e0b\uff0c\u53bb\u6267\u884c\u811a\u672c\u6587\u4ef6\uff0cinit.d\u76ee\u5f55\u5305\u542b\u8bb8\u591a\u7cfb\u7edf\u5404\u7c7b\u670d\u52a1\u7684\u542f\u52a8\u548c\u505c\u6b62\u811a\u672c\u3002\u5f53Linux\u542f\u52a8\u65f6\uff0c\u4f1a\u627e\u5bfb\u8fd9\u79cd\u76ee\u5f55\u4e2d\u7684\u670d\u52a1\u811a\u672c\u3002<\/p>\n

\u2461\u4ec0\u4e48\u662fsystemctl\uff1f<\/p>\n

systemctl\u662f\u4e00\u4e2asystemd\u5de5\u5177\uff0c\u4e3b\u8981\u8d1f\u8d23\u63a7\u5236systemd\u7cfb\u7edf\u548c\u670d\u52a1\u7ba1\u7406\u5668\u3002<\/p>\n

\u5728systemd\u7ba1\u7406\u4f53\u7cfb\u4e2d\uff0c\u88ab\u7ba1\u7406\u7684deamon(\u5b88\u62a4\u8fdb\u7a0b)\u4e5f\u79f0unit(\u5355\u5143)\uff0c\u5bf9\u4e8e\u5355\u5143\u7684\u7ba1\u7406\u662f\u901a\u8fc7\u547d\u4ee4systemctl\u6765\u8fdb\u884c\u63a7\u5236\u7684\u3002unit\u8868\u793a\u4e0d\u540c\u7c7b\u578b\u7684systemd\u5bf9\u8c61\uff0c\u901a\u8fc7\u914d\u7f6e\u6587\u4ef6\u8fdb\u884c\u6807\u793a\u548c\u914d\u7f6e\uff1b\u6587\u4ef6\u4e3b\u8981\u5305\u542b\u4e86\u7cfb\u7edf\u670d\u52a1\u3001\u76d1\u542csocket\u3001\u4fdd\u5b58\u7684\u7cfb\u7edf\u5feb\u7167\u4ee5\u53ca\u5176\u5b83\u4e0einit\u76f8\u5173\u7684\u4fe1\u606f\u3002<\/p>\n

2\u3001\u7f16\u5199systemctl\u811a\u672c<\/p>\n

\u2460\u7f16\u5199\u7b80\u5355\u7684systemctl\u811a\u672c<\/p>\n

\u7f16\u64b0test.service\u4e22\u5230\/usr\/lib\/systemd\/system\u76ee\u5f55\u4e0b<\/p>\n

\u4f8b\u4e00\uff1a<\/p>\n

\n

\n[Unit]\n# \u670d\u52a1\u540d\u79f0\uff0c\u53ef\u81ea\u5b9a\u4e49\n

shell\u5173\u673a\u811a\u672c_linux \u5173\u673a\u524d\u6267\u884c\u811a\u672c_linux\u5173\u673a\u524d\u6267\u884c\u547d\u4ee4<\/p>\nDescription = frpc-server\nAfter = network.target syslog.target\nWants = network.target\nConditionPathExists = \/etc\/frp\/frpc-start.sh\n[Service]\nType = simple\n# \u542f\u52a8\u547d\u4ee4\uff0c\u6539\u4e3a\u5b9e\u9645\u5b58\u653efrps\u7684\u8def\u5f84\nRemainAfterExit=yes\n#KillMode=none\nWorkingDirectory=\/etc\/frp\nExecStart = \/etc\/frp\/frpc-start.sh\nExecStop=kill -9 $MAINPID\nRestart=always\n[Install]\nWantedBy = multi-user.target<\/code><\/pre>\n<\/p>\n

\u4f8b\u4e8c\uff1a<\/p>\n

\n

[Unit] \n# \u670d\u52a1\u540d\u79f0\uff0c\u53ef\u81ea\u5b9a\u4e49\nDescription=test.jar \n# \u786e\u4fdd\u8fd9\u4e9b\u670d\u52a1\u7684\u524d\u540e\u987a\u5e8f\nAfter=syslog.target network.target remote-fs.target nss-lookup.target\n \n[Service] \nUser=root\nGroup=root\n# \u542f\u52a8\u547d\u4ee4\nExecStart=\/opt\/jdk1.8.0_161\/bin\/java  -server -Xms1024m -Xmx2048m -Dspring.profiles.active=production  -jar \/root\/test.jar\nExecReload=\/bin\/kill -s HUP $MAINPID\nExecStop=\/bin\/kill -s QUIT $MAINPID\n \n[Install] \nWantedBy=multi-user.target\n<\/code><\/pre>\n<\/p>\n

\u628aservice\u540e\u7f00\u7684\u6587\u4ef6\u7f6e\u4e8e\u6307\u5b9a\u76ee\u5f55\u4e2d\u540e\uff0c\u5c31\u53ef\u4ee5\u7528systemctl\u547d\u4ee4\u6765\u7ba1\u7406\u7a0b\u5e8f\u4e86\uff01<\/p>\n

#\u542f\u52a8test.service\u670d\u52a1<\/p>\n

shell\u5173\u673a\u811a\u672c_linux \u5173\u673a\u524d\u6267\u884c\u811a\u672c_linux\u5173\u673a\u524d\u6267\u884c\u547d\u4ee4<\/p>\n

systemctlstarttest.service<\/p>\n

#\u67e5\u770b\u670d\u52a1\u72b6\u6001<\/p>\n

systemctlstatustest.service<\/p>\n

\u7597\u6548\u5982\u4e0b\uff1a<\/p>\n

\u7528\u8fd9\u4e2a\u4e5f\u53ef\u4ee5\u542f\u52a8\u670d\u52a1\uff1a<\/p>\n

serviceteststatus<\/p>\n

\u4f46\u91cd\u542f\u540e\u5c31\u7528\u4e0d\u4e86\u4e86<\/p>\n

\u5728\u4f60\u66f4\u6539\u4e86.service\u6587\u4ef6\u540e\u4f7f\u7528systemctl\u7ba1\u7406\u547d\u4ee4\uff0c\u53ef\u80fd\u4f1a\u51fa\u73b0\u8b66\u544a\u4fe1\u606f\uff1a<\/p>\n

Warning:test.servicechangedondisk.Run'systemctldaemon-reload'toreloadunits.<\/p>\n

\u8fd9\u4e2a\u65f6\u4faf\u5c31\u8981\u91cd\u65b0\u52a0\u8f7dsystemctl\u914d\u7f6e\u4e86\uff0c\u4e4b\u540e\u8fd8\u4f1a\u5e94\u7528\u6700\u65b0\u7684\u914d\u7f6e\u3002<\/p>\n

systemctldaemon-reload<\/p>\n

\u5bf9\u4e8e\u8fd9\u4e9b\u652f\u6301Systemd\u7684\u8f6f\u4ef6linux\u66f4\u6539ip\u5730\u5740\uff0c\u5b89\u88c5\u7684\u65f6\u4faf\uff0c\u4f1a\u624b\u52a8\u5728\/usr\/lib\/systemd\/system\u76ee\u5f55\u6dfb\u52a0\u4e00\u4e2a\u914d\u7f6e\u6587\u4ef6\u3002\u8fd9\u4e2a\u65f6\u4faf\u4f60\u5c31\u53ef\u4ee5\u76f4\u63a5\u7528systemctl\u547d\u4ee4\u6765\u7ba1\u7406\u4e86\u3002<\/p>\n

\u2462\u7528systemctl\u547d\u4ee4\uff0c\u8ba9\u670d\u52a1\u5b9e\u73b0\u5f00\u673a\u542f\u52a8<\/p>\n

\u5230\u7b2c\u2461\u5c0f\u8282\u7684\u6b65\u9aa4\u5c31\u65e9\u5df2\u53ef\u4ee5\u7528systemctl\u7ba1\u7406\u547d\u4ee4\u6765\u7ba1\u7406\u4f60\u81ea\u5df1\u7684\u7a0b\u5e8f\u4e86\uff0c\u82e5\u679c\u4f60\u60f3\u8ba9\u8be5\u7a0b\u5e8f\u5f00\u673a\u542f\u52a8\uff0c\u5c31\u6267\u884c\u4e0b\u8fb9\u7684\u547d\u4ee4\uff08\u4ee5test.service\u4e3a\u4f8b\uff09\u3002<\/p>\n

sudosystemctlenabletest<\/p>\n

\u91cc\u9762\u7684\u547d\u4ee4\u76f8\u5f53\u4e8e\u5728\/etc\/systemd\/system\u76ee\u5f55\u6dfb\u52a0\u4e00\u4e2a\u7b26\u53f7\u94fe\u63a5\uff0c\u6307\u5411\/usr\/lib\/systemd\/system\u4e0a\u9762\u7684test.service\u6587\u4ef6\u3002<\/p>\n

\u8fd9\u662f\u7531\u4e8e\u5f00\u673a\u65f6\uff0cSystemd\u53ea\u6267\u884c\/etc\/systemd\/system\u76ee\u5f55\u4e0a\u9762\u7684\u914d\u7f6e\u6587\u4ef6\u3002\u8fd9\u4e5f\u610f\u5473\u7740\uff0c\u5047\u5982\u628atest.service\u6587\u4ef6\u4e0d\u4f7f\u7528\u7b26\u53f7\u94fe\u63a5\u800c\u662f\u76f4\u63a5\u653e\u5728\/etc\/systemd\/system\u76ee\u5f55\u4e0b\uff0c\u5c31\u53ef\u4ee5\u5b9e\u73b0\u5f00\u673a\u542f\u52a8\u3002\u5176\u5b9e\uff0c\u5728\/usr\/lib\/systemd\/system\u82e5\u679c\u6ca1\u6709\u653etest.service\u6587\u4ef6\u5c31\u7528\u4e0d\u4e86systemctl\u547d\u4ee4\u6765\u7ba1\u7406\u7a0b\u5e8f\u4e86\uff01<\/p>\n

\u6ce8\u610f\uff1asystemctlstarttest\u4e5f\u53ef\u4ee5\u7528systemctlstarttest.service<\/p>\n

\n

#\u542f\u52a8test\nsystemctl start test\n#\u505c\u6b62test\nsystemctl stop test\n#\u91cd\u542ftest\nsystemctl restart test\n#\u67e5\u770b\u72b6\u6001test\nsystemctl status test\n#\u5982\u679c\u9700\u8981\u5f00\u673a\u542f\u52a8\nsystemctl enable test\n#\u5982\u679c\u9700\u8981\u53d6\u6d88\u5f00\u673a\u542f\u52a8\nsystemctl disable test\n#\u6740\u8fdb\u7a0b\uff0c\u5411\u6b63\u5728\u8fd0\u884c\u7684\u8fdb\u7a0b\u53d1\u51fakill\u4fe1\u53f7\u3002\nsystemctl kill test\n#\u67e5\u770btest\u76f8\u5173\u7684service\u914d\u7f6e\u6587\u4ef6\nsystemctl cat test\n##\u67e5\u770b multi-user.target \u5305\u542b\u7684\u6240\u6709\u670d\u52a1\nsystemctl list-dependencies multi-user.target\n#\u5207\u6362\u5230\u53e6\u4e00\u4e2a target\uff0cshutdown.target \u5c31\u662f\u5173\u673a\u72b6\u6001\nsudo systemctl isolate shutdown.target<\/code><\/pre>\n<\/p>\n

\n

service\u7684\u5e38\u7528\u65b9\u5f0f\uff1a\n1.\u683c\u5f0f\uff1aservice \n

shell\u5173\u673a\u811a\u672c_linux \u5173\u673a\u524d\u6267\u884c\u811a\u672c_linux\u5173\u673a\u524d\u6267\u884c\u547d\u4ee4<\/p>\n\u6253\u5370\u6307\u5b9a\u670d\u52a1\u7684\u547d\u4ee4\u884c\u4f7f\u7528\u5e2e\u52a9\u3002\n2.\u683c\u5f0f\uff1aservice start\n\u542f\u52a8\u6307\u5b9a\u7684\u7cfb\u7edf\u670d\u52a1\n3.\u683c\u5f0f\uff1aservice stop\n\u505c\u6b62\u6307\u5b9a\u7684\u7cfb\u7edf\u670d\u52a1\n4.\u683c\u5f0f\uff1aservice restart\n\u91cd\u65b0\u542f\u52a8\u6307\u5b9a\u7684\u7cfb\u7edf\u670d\u52a1\uff0c\u5373\u5148\u505c\u6b62\uff08stop\uff09\uff0c\u7136\u540e\u518d\u542f\u52a8\uff08start\uff09\u3002\n5.\u683c\u5f0f\uff1achkconfig --list\n\u67e5\u770b\u7cfb\u7edf\u670d\u52a1\u5217\u8868\uff0c\u4ee5\u53ca\u6bcf\u4e2a\u670d\u52a1\u7684\u8fd0\u884c\u7ea7\u522b\u3002\n6.\u683c\u5f0f\uff1achkconfig on\n\u8bbe\u7f6e\u6307\u5b9a\u670d\u52a1\u5f00\u673a\u65f6\u81ea\u52a8\u542f\u52a8\u3002\n7.\u683c\u5f0f\uff1achkconfig off\n\u8bbe\u7f6e\u6307\u5b9a\u670d\u52a1\u5f00\u673a\u65f6\u4e0d\u81ea\u52a8\u542f\u52a8\u3002\n8.\u683c\u5f0f\uff1antsysv\n\u4ee5\u5168\u5c4f\u5e55\u6587\u672c\u754c\u9762\u8bbe\u7f6e\u670d\u52a1\u5f00\u673a\u65f6\u662f\u5426\u81ea\u52a8\u542f\u52a8\u3002\n \n\u6253\u5f00redis\u547d\u4ee4:service redis start\n\u5173\u95edredis\u547d\u4ee4:service redis stop\n\u8bbe\u4e3a\u5f00\u673a\u542f\u52a8:chkconfig redis on<\/code><\/pre>\n<\/p>\n

\u7528sh\u811a\u672c\u8ba9\u670d\u52a1\u5f00\u673a\u81ea\u542f<\/p>\n

1\u3001\u521b\u5efash\u811a\u672c<\/p>\n

\u8bf7\u4f7f\u7528\u4e0b\u8ff0\u65b9\u6cd5\u521b\u5efash\u811a\u672c\uff1aserver.sh\uff08\u811a\u672c\u4eb2\u6d4b\u597d\u7528\uff0c\u4e0d\u7528\u989d\u5916\u914d\u7f6e\u7f16\u8f91\uff09<\/p>\n

\u6ce8\u610f\uff1a\u6587\u4ef6\u90fd\u8981\u8bbe\u7f6e\u4e3a\u53ef\u6267\u884c\u6587\u4ef6:<\/p>\n

\n

sudo chmod 755 run-server.sh<\/code><\/pre>\n<\/p>\n

\u2460\u4f7f\u7528notepad++\u8f6f\u4ef6\u8f6c\u6362\u6210unix\u683c\u5f0f\uff0c\u6216\u5219\u7528vim\u7684setff\u547d\u4ee4\u6765\u8f6c\u6362<\/p>\n

notepad++\u5b98\u65b9\u4e0b\u8f7d\u5730\u5740<\/p>\n

\u4f7f\u7528notepad++\u6253\u5f00\u6587\u4ef6---\u7f16\u8f91---\u6587\u6863\u683c\u5f0f\u8f6c\u6362---\u8f6c\u4e3aunix---\u4e0a\u4f20\u81f3linux<\/p>\n

\u2461run-server.sh\u811a\u672c\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n

\u5bf9\u4e8e\u4e00\u4e9b\u672a\u63d0\u4f9bservice\u7ba1\u7406\u7684\u7a0b\u5e8f\u6bcf\u6b21\u542f\u52a8\u548c\u5173\u6389\u90fd\u8981\u52a0\u4e0a\u5168\u90e8\u8def\u5f84\uff0c\u60f3\u5230\u53ef\u4ee5\u505a\u4e00\u4e2a\u7b80\u5355\u7684\u542f\u52a8\u548c\u5173\u6389\u63a7\u5236\u7684\u6587\u4ef6\u3002<\/p>\n

\u4e0b\u8fb9\u4ee5scrapy\u542f\u52a8server\u4e3a\u4f8b\uff1a<\/p>\n

\n

#\u7aef\u53e3\u53f7\uff0c\u6839\u636e\u6b64\u7aef\u53e3\u53f7\u786e\u5b9aPID\nPORT=6800\n#\u542f\u52a8\u547d\u4ee4\u6240\u5728\u76ee\u5f55\nHOME='\/home\/jmscra\/scrapy\/'\n \n#\u67e5\u8be2\u51fa\u76d1\u542c\u4e86PORT\u7aef\u53e3TCP\u534f\u8bae\u7684\u7a0b\u5e8f\npid=`netstat -lnopt | grep :$PORT | awk '\/python\/{gsub(\/\/python\/,\"\",$7);print $7;}'`\n \n \nstart(){\n   if [ -n \"$pid\" ]; then\n

linux\u5173\u673a\u524d\u6267\u884c\u547d\u4ee4_linux \u5173\u673a\u524d\u6267\u884c\u811a\u672c_shell\u5173\u673a\u811a\u672c<\/p>\n echo \"server already start,pid:$pid\"\n return 0\n fi\n \n #\u8fdb\u5165\u547d\u4ee4\u6240\u5728\u76ee\u5f55\n cd $HOME\n nohup scrapy server & #\u542f\u52a8scrpayd\u670d\u52a1\u5668 \u628a\u65e5\u5fd7\u8f93\u51fa\u5230HOME\u76ee\u5f55\u7684nohup.out\u6587\u4ef6\u4e2d \n echo \"start at port:$PORT\"\n}\n \nstop(){\n if [ -z \"$pid\" ]; then\n echo \"not find program on port:$PORT\"\n return 0\n fi\n \n #\u7ed3\u675f\u7a0b\u5e8f\uff0c\u4f7f\u7528\u8baf\u53f72\uff0c\u5982\u679c\u4e0d\u884c\u53ef\u4ee5\u5c1d\u8bd5\u8baf\u53f79\u5f3a\u5236\u7ed3\u675f\n kill -2 $pid \n echo \"kill program use signal 2,pid:$pid\"\n}\n \nstatus(){\n if [ -z \"$pid\" ]; then\n echo \"not find program on port:$PORT\"\n else\n echo \"program is running,pid:$pid\"\n fi\n}\n \ncase $1 in\n start)\n start\n ;;\n stop)\n stop\n ;;\n status)\n status\n ;;\n *)\n

linux\u5173\u673a\u524d\u6267\u884c\u547d\u4ee4_linux \u5173\u673a\u524d\u6267\u884c\u811a\u672c_shell\u5173\u673a\u811a\u672c<\/p>\n echo \"Usage: {start|stop|status}\"\n ;;\nesac\n \nexit 0<\/code><\/pre>\n<\/p>\n

\u6d4b\u8bd5\u4f7f\u7528\u65f6\u53ef\u4ee5<\/p>\n

\/path\/run.shstart\u542f\u52a8<\/p>\n

\/path\/run.shstop\u505c\u6b62<\/p>\n

\/path\/run.shstatus\u67e5\u770b\u8fd0\u884c\u7a0b\u5e8f\u7684pid<\/p>\n

\u628a\u524d\u9762\u8fd9\u4e2a\u811a\u672c\u8bbe\u7f6e\u4e3a\u5f00\u673a\u81ea\u542f\u7684\u670d\u52a1,\u53ef\u4ee5\u7528\u524d\u9762\u7684systemd\u5de5\u5177\uff0c\u628ash\u6587\u4ef6\u653e\u5728service\u6587\u4ef6\u4e2d\u5373\u53ef\u3002\u4e0b\u8fb9\u7528\u53e6\u4e00\u79cd\u65b9\u5f0f\u81ea\u542f\u3002<\/p>\n

\u7cfb\u7edfrc.local\u6587\u4ef6\u5b9e\u73b0\u81ea\u542f<\/p>\n

\u7f16\u8f91\u7cfb\u7edfrc.local\u6587\u4ef6\uff0c\u8ba9\u811a\u672c\u52a0\u5165\u7cfb\u7edf\u5f00\u673a\u542f\u52a8<\/p>\n

\u5728\u91cc\u9762\u7684\u7b2c\u4e00\u6b65\u5c31\u53ef\u4ee5\u4f7f\u7528\u811a\u672c\u6765\u7ba1\u7406\u7a0b\u5e8f\u4e86\uff0c\u63a5\u51fa\u6765\u662f\u8ba9\u811a\u672c\u52a0\u5165\u5230\u7cfb\u7edf\u7684\u5f00\u673a\u542f\u52a8<\/p>\n

\u8bb0\u5f55\u5f53\u524dserver.sh\u811a\u672c\u7684\u8def\u5f84,\u7f16\u8f91\/etc\/rc.d\/rc.local\u3002\u547d\u4ee4\u5982\u4e0b\uff1a<\/p>\n

cd\/etc\/rc.d<\/p>\n

virc.local<\/p>\n

\n

#!\/bin\/bash\n# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES\n#\n# It is highly advisable to create own systemd services or udev rules\n# to run scripts during boot instead of using this file.\n#\n# In contrast to previous versions due to parallel execution during boot\n# this script will NOT be run after all other services.\n#\n# Please note that you must run 'chmod +x \/etc\/rc.d\/rc.local' to ensure\n# that this script will be executed during boot.\n \n#\u5c31\u662f\u8bf4rc.local\u7684\u7a0b\u5e8f\u5df2\u7ecf\u542f\u52a8\u4e86, \u9632\u6b62\u91cd\u590d\u8fd0\u884c\ntouch \/var\/lock\/subsys\/local\n \n#\u811a\u672c\u7684\u7edd\u5bf9\u8def\u5f84\n\/root\/run-server.sh\n <\/code><\/pre>\n<\/p>\n

\u7cfb\u7edf\u91cd\u542f\uff0c\u67e5\u770b\u7597\u6548<\/p>\n

\n

sudo reboot<\/code><\/pre>\n<\/p>\n

\u67e5\u770b\u7a0b\u5e8f\uff1a<\/p>\n

\n

ps -ef | grep scrapy<\/code><\/pre><\/p>\n","protected":false},"excerpt":{"rendered":"

\u5229\u7528systemd\u5de5\u5177\u7ba1\u7406\u7a0b\u5e8f\uff0c\u5b9e\u73b0\u670d\u52a1\u5f00\u673a\u81ea\u542f\u52a8\u2462\u7528systemctl\u547d\u4ee4\uff0c\u8ba9\u670d\u52a1\u5b9e\u73b0\u5f00\u673a\u542f\u52a8\u628a\u4e0a\u9762\u8fd9\u4e2a\u811a\u672c\u8bbe\u7f6e\u4e3a\u5f00\u673a\u81ea\u542f\u7684\u670d\u52a1,\u53ef\u4ee5\u7528\u4e0a\u9762\u7684systemd\u5de5\u5177\uff0c\u628ash\u6587\u4ef6\u653e\u5230service\u6587\u4ef6\u4e2d\u5373\u53ef\u3002\u5728\u4e0a\u9762\u7684\u7b2c\u4e00\u6b65\u5c31\u53ef\u4ee5\u4f7f\u7528\u811a\u672c\u6765\u7ba1\u7406\u7a0b\u5e8f\u4e86\uff0c\u63a5\u4e0b\u6765\u662f\u8ba9\u811a\u672c\u52a0\u5165\u5230\u7cfb\u7edf\u7684\u5f00\u673a\u542f\u52a8<\/p>\n","protected":false},"author":1,"featured_media":295148,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[988],"tags":[5128,5000,4156,5129,5130],"class_list":["post-295147","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tougao","tag-nml-2","tag-slj","tag-htyx","tag-hlgdxh","tag-bzsrsccdx"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/295147","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=295147"}],"version-history":[{"count":0,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/295147\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/295148"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=295147"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=295147"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=295147"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}