{"id":12846,"date":"2020-12-07T00:37:56","date_gmt":"2020-12-06T16:37:56","guid":{"rendered":"http:\/\/blog.idc.net\/12846\/"},"modified":"2020-12-07T00:37:56","modified_gmt":"2020-12-06T16:37:56","slug":"ubuntu-16-04%e8%ae%be%e7%bd%aerc-local%e5%bc%80%e6%9c%ba%e5%90%af%e5%8a%a8%e5%91%bd%e4%bb%a4-%e8%84%9a%e6%9c%ac%e7%9a%84%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"https:\/\/idc.net\/help\/12846\/","title":{"rendered":"Ubuntu 16.04\u8bbe\u7f6erc.local\u5f00\u673a\u542f\u52a8\u547d\u4ee4\/\u811a\u672c\u7684\u65b9\u6cd5"},"content":{"rendered":"<div class=\"idc_table\">\n<p>Ubuntu 16.04\u8bbe\u7f6erc.local\u5f00\u673a\u542f\u52a8\u547d\u4ee4\/\u811a\u672c\u7684\u65b9\u6cd5\uff08\u901a\u8fc7update-rc.d\u7ba1\u7406Ubuntu\u5f00\u673a\u542f\u52a8\u7a0b\u5e8f\/\u670d\u52a1\uff09<\/p>\n<p><strong>\u4e00\u3001rc.local\u811a\u672c<\/strong><\/p>\n<p>rc.local\u811a\u672c\u662f\u4e00\u4e2aUbuntu\u5f00\u673a\u540e\u4f1a\u81ea\u52a8\u6267\u884c\u7684\u811a\u672c\uff0c\u6211\u4eec\u53ef\u4ee5\u5728\u8be5\u811a\u672c\u5185\u6dfb\u52a0\u547d\u4ee4\u884c\u6307\u4ee4\u3002\u8be5\u811a\u672c\u4f4d\u4e8e\/etc\/\u8def\u5f84\u4e0b\uff0c\u9700\u8981root\u6743\u9650\u624d\u80fd\u4fee\u6539\u3002<\/p>\n<p>\u8be5\u811a\u672c\u5177\u4f53\u683c\u5f0f\u5982\u4e0b\uff1a<\/p>\n<pre>#!\/bin\/<span style=\"color: #000000\">sh -e\r\n<\/span>#\r\n# rc.<span style=\"color: #000000\">local\r\n<\/span>#\r\n# This script is executed at the <span style=\"color: #0000ff\">end<\/span> of each multiuser runlevel.\r\n# Make sure that the script will \"exit 0\" <span style=\"color: #0000ff\">on<\/span><span style=\"color: #000000\"> success or any other\r\n<\/span># value <span style=\"color: #0000ff\">on<\/span> error.\r\n#\r\n#<span style=\"color: #000000\"> In order to enable or disable this script just change the execution\r\n<\/span># bits.\r\n#\r\n# By default this script does nothing.\r\n  \r\n<span style=\"color: #0000ff\">exit<\/span> 0<\/pre>\n<p><strong>\u6ce8\u610f:&nbsp;<\/strong>\u4e00\u5b9a\u8981\u5c06\u547d\u4ee4\u6dfb\u52a0\u5728exit 0\u4e4b\u524d\u3002\u91cc\u9762\u53ef\u4ee5\u76f4\u63a5\u5199\u547d\u4ee4\u6216\u8005\u6267\u884cShell\u811a\u672c\u6587\u4ef6sh\u3002<\/p>\n<p><strong>\u4e8c\u3001\u5173\u4e8e\u653e\u5728rc.local\u91cc\u9762\u65f6\u4e0d\u542f\u52a8\u7684\u95ee\u9898\uff1a<\/strong><\/p>\n<p>1\u3001\u53ef\u4ee5\u5148\u589e\u52a0\u65e5\u5fd7\u8f93\u51fa\u529f\u80fd\uff0c\u6765\u67e5\u770b\u6700\u7ec8\u4e3a\u4ec0\u4e48\u8fd9\u4e2a\u811a\u672c\u4e0d\u542f\u52a8\u7684\u539f\u56e0\uff0c\u8fd9\u4e2a\u662fMemcached\u542f\u52a8\u65f6\u7684\u6837\u4f8b\u6587\u4ef6\uff1a<\/p>\n<pre>#!\/bin\/<span style=\"color: #000000\">sh -e\r\n<\/span>#\r\n# rc.<span style=\"color: #000000\">local\r\n<\/span>#\r\n# This script is executed at the <span style=\"color: #0000ff\">end<\/span> of each multiuser runlevel.\r\n# Make sure that the script will \"exit 0\" <span style=\"color: #0000ff\">on<\/span><span style=\"color: #000000\"> success or any other\r\n<\/span># value <span style=\"color: #0000ff\">on<\/span> error.\r\n#\r\n#<span style=\"color: #000000\"> In order to enable or disable this script just change the execution\r\n<\/span># bits.\r\n#\r\n# By default this script does nothing.\r\n\r\n<span style=\"color: #ff0000\"><strong>#log exec 2&gt; \/tmp\/rc.local.log # send stderr from rc.local to a log file exec 1&gt;&amp;2 # send stdout to the same log file set -x #<\/strong><strong> tell sh to display commands before execution<\/strong> \r\n\r\n<\/span><strong>#<span style=\"color: #000000\">Memcached <\/span>\/usr\/local\/memcache\/bin\/memcached -p 11211<span style=\"color: #000000\"> -m 64m -d -u root <\/span><\/strong><span style=\"color: #0000ff\">exit<\/span> 0<\/pre>\n<p>2\u3001rc.local\u6587\u4ef6\u5934\u90e8\/bin\/sh\u4fee\u6539\u4e3a\/bin\/bash<\/p>\n<p>3\u3001\u5982\u679c\u662f\u6267\u884csh\u6587\u4ef6\uff0c\u90a3\u4e48\u8981\u8d4b\u4e88\u6267\u884c\u6743\u9650sudo chmod +x xxx.sh\uff0c\u7136\u540e\u542f\u52a8\u65f6\u52a0\u4e0asudo sh xxx.sh<\/p>\n<p><strong>\u4e09\u3001 update-rc.d\u589e\u52a0\u5f00\u673a\u542f\u52a8\u670d\u52a1<\/strong><\/p>\n<p><strong>\u7ed9Ubuntu\u6dfb\u52a0\u4e00\u4e2a\u5f00\u673a\u542f\u52a8\u811a\u672c\uff0c\u64cd\u4f5c\u5982\u4e0b\uff1a<\/strong><\/p>\n<p><strong>1\u3001\u65b0\u5efa\u4e2a\u811a\u672c\u6587\u4ef6new_service.sh<\/strong><\/p>\n<pre>#!\/bin\/<span style=\"color: #000000\">bash\r\n<\/span># <span style=\"color: #0000ff\">command<\/span><span style=\"color: #000000\"> content\r\n  \r\n<\/span><span style=\"color: #0000ff\">exit<\/span> 0<\/pre>\n<p><strong>2\u3001\u8bbe\u7f6e\u6743\u9650<\/strong><\/p>\n<pre>sudo chmod 755 new_service.<span style=\"color: #000000\">sh\r\n<\/span>#<span style=\"color: #000000\">\u6216\u8005\r\nsudo chmod <\/span>+x new_service.sh<\/pre>\n<p><strong>3\u3001\u628a\u811a\u672c\u653e\u7f6e\u5230\u542f\u52a8\u76ee\u5f55\u4e0b<\/strong><\/p>\n<pre>sudo mv new_service.sh \/etc\/init.d\/<\/pre>\n<p><strong>4\u3001\u5c06\u811a\u672c\u6dfb\u52a0\u5230\u542f\u52a8\u811a\u672c<\/strong><\/p>\n<p>\u6267\u884c\u5982\u4e0b\u6307\u4ee4\uff0c\u5728\u8fd9\u91cc90\u8868\u660e\u4e00\u4e2a\u4f18\u5148\u7ea7\uff0c\u8d8a\u9ad8\u8868\u793a\u6267\u884c\u7684\u8d8a\u665a<\/p>\n<pre><span style=\"color: #0000ff\">cd<\/span> \/etc\/init.d\/<span style=\"color: #000000\">\r\nsudo update-rc<\/span>.d new_service.sh defaults 90<\/pre>\n<p><strong>5\u3001\u79fb\u9664Ubuntu\u5f00\u673a\u811a\u672c<\/strong><\/p>\n<pre>sudo update-rc.d -f new_service.sh remove<\/pre>\n<p><strong>6\u3001\u901a\u8fc7sysv-rc-conf\u6765\u7ba1\u7406\u4e0a\u9762\u542f\u52a8\u670d\u52a1\u7684\u542f\u52a8\u7ea7\u522b\u7b49\uff0c\u8fd8\u662f\u5f00\u673a\u4e0d\u542f\u52a8<\/strong><\/p>\n<pre>sudo sysv-rc-conf&nbsp;<\/pre>\n<p><strong>7\u3001update-rc.d\u7684\u8be6\u7ec6\u53c2\u6570<\/strong><\/p>\n<p><span>\u4f7f\u7528<span>update<span>-<span>rc<span>.<span>d<span>\u547d\u4ee4\u9700\u8981\u6307\u5b9a\u811a\u672c\u540d\u79f0\u548c\u4e00\u4e9b\u53c2\u6570\uff0c\u5b83\u7684\u683c\u5f0f\u770b\u8d77\u6765\u662f\u8fd9\u6837\u7684\uff08\u9700\u8981\u5728<span> root <span>\u6743\u9650\u4e0b\uff09\uff1a<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/p>\n<pre>update-rc.d [-n] [-f] &lt;basename&gt;<span style=\"color: #000000\"> remove\r\nupdate-rc<\/span>.d [-n] &lt;basename&gt;<span style=\"color: #000000\"> defaults\r\nupdate-rc<\/span>.d [-n] &lt;basename&gt; disable|enable [S|2|3|4|5<span style=\"color: #000000\">]\r\nupdate-rc<\/span>.d &lt;basename&gt; <span style=\"color: #0000ff\">start<\/span>|stop &lt;NN&gt; &lt;runlevels&gt;<span style=\"color: #000000\">\r\n-n: <\/span><span style=\"color: #0000ff\">not<\/span><span style=\"color: #000000\"> really\r\n-f: force<\/span><\/pre>\n<p><span>\u5176\u4e2d\uff1a<\/span><\/p>\n<ul>\n<li><span>disable<span>|<span>enable\uff1a<span>\u4ee3\u8868\u811a\u672c\u8fd8\u5728<span><span>\/<span>etc<span>\/<span>init<span>.<span>d<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span>\u4e2d\uff0c\u5e76\u8bbe\u7f6e\u5f53\u524d\u72b6\u6001\u662f\u624b\u52a8\u542f\u52a8\u8fd8\u662f\u81ea\u52a8\u542f\u52a8\u3002<\/li>\n<li><span><span><span><span><span><span><span><span><span><span><span><span><span>start<span>|<span>stop\uff1a<span>\u4ee3\u8868\u811a\u672c\u8fd8\u5728<span><span>\/<span>etc<span>\/<span>init<span>.<span>d<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span>\u4e2d\uff0c\u5f00\u673a\uff0c\u5e76\u8bbe\u7f6e\u5f53\u524d\u72b6\u6001\u662f\u5f00\u59cb\u8fd0\u884c\u8fd8\u662f\u505c\u6b62\u8fd0\u884c\u3002\uff08\u542f\u7528\u540e\u53ef\u914d\u7f6e\u5f00\u59cb\u8fd0\u884c\u4e0e\u5426\uff09<\/li>\n<li><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span>NN\uff1a<span>\u662f\u4e00\u4e2a\u51b3\u5b9a\u542f\u52a8\u987a\u5e8f\u7684\u4e24\u4f4d\u6570\u5b57\u503c\u3002\uff08\u4f8b\u5982<span><span>90<span><span>\u5927\u4e8e<span><span>80<span>\uff0c\u56e0\u6b64<span><span>80<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span>\u5bf9\u5e94\u7684\u811a\u672c\u5148\u542f\u52a8\u6216\u5148\u505c\u6b62\uff09<\/li>\n<li><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span>runlevels\uff1a<span>\u5219\u6307\u5b9a\u4e86\u8fd0\u884c\u7ea7\u522b\u3002<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/li>\n<\/ul>\n<p><span>\u5b9e\u4f8b\uff1a<\/span><\/p>\n<p><span>\uff081\uff09\u3001\u6dfb\u52a0\u4e00\u4e2a\u65b0\u7684\u542f\u52a8\u811a\u672c<span>sample_init_script<span>\uff0c\u5e76\u4e14\u6307\u5b9a\u4e3a\u9ed8\u8ba4\u542f\u52a8\u987a\u5e8f\u3001\u9ed8\u8ba4\u8fd0\u884c\u7ea7\u522b\uff08\u8fd8\u8bb0\u5f97\u524d\u9762\u8bf4\u7684\u5417\uff0c\u9996\u5148\u8981\u6709\u5b9e\u9645\u7684\u6587\u4ef6\u5b58\u5728\u4e8e<span><span>\/<span>etc<span>\/<span>init<span>.<span>d<span>\uff0c\u5373\u82e5\u6587\u4ef6<span><span>\/<span>etc<span>\/<span>init<span>.<span>d<span>\/<span>sample_init_script<span>\u4e0d\u5b58\u5728\uff0c\u5219\u8be5\u547d\u4ee4\u4e0d\u4f1a\u6267\u884c\uff09\uff1a<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/p>\n<pre>update-rc.d sample_init_script defaults<\/pre>\n<p><span>\u4e0a\u4e00\u6761\u547d\u4ee4\u7b49\u6548\u4e8e\uff08\u4e2d\u95f4\u662f\u4e00\u4e2a\u82f1\u6587\u53e5\u70b9\u7b26\u53f7\uff09\uff1a<\/span><\/p>\n<pre>update-rc.d sample_init_script <span style=\"color: #0000ff\">start<\/span> 20 2 3 4 5 . stop 20 0 1 6<\/pre>\n<p><span>\uff082\uff09\u3001\u5b89\u88c5\u4e00\u4e2a\u542f\u52a8\u811a\u672c<span>sample_init_script<span>\uff0c\u6307\u5b9a\u9ed8\u8ba4\u8fd0\u884c\u7ea7\u522b\uff0c\u4f46\u542f\u52a8\u987a\u5e8f\u4e3a<span><span>50<span>\uff1a<\/span><\/span><\/span><\/span><\/span><\/span><\/p>\n<pre>update-rc.d sample_init_script defaults 50<\/pre>\n<p><span>\uff083\uff09\u3001\u5b89\u88c5\u4e24\u4e2a\u542f\u52a8\u811a\u672c<span>A<span>\u3001<span>B<span>\uff0c\u8ba9<span>A<span>\u5148\u4e8e<span>B<span>\u542f\u52a8\uff0c\u540e\u4e8e<span>B<span>\u505c\u6b62\uff1a<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/p>\n<pre>update-rc.d A 10 40<span style=\"color: #000000\">\r\nupdate-rc<\/span>.d B 20 30<\/pre>\n<p><span>\uff084\uff09\u3001\u5220\u9664\u4e00\u4e2a\u542f\u52a8\u811a\u672c<span>sample_init_script<span>\uff0c\u5982\u679c\u811a\u672c\u4e0d\u5b58\u5728\u5219\u76f4\u63a5\u8df3\u8fc7\uff1a<\/span><\/span><\/span><\/p>\n<pre>update-rc.d -f sample_init_script remove<\/pre>\n<p><span>\u8fd9\u4e00\u6761\u547d\u4ee4\u5b9e\u9645\u4e0a\u505a\u7684\u5c31\u662f\u4e00\u4e00\u5220\u9664\u6240\u6709\u4f4d\u4e8e<span><span>\/<span>etc<span>\/<span>rcX<span>.<span>d<span>\u76ee\u5f55\u4e0b\u6307\u5411<span><span>\/<span>etc<span>\/<span>init<span>.<span>d<span>\u4e2d<span>sample_init_script<span>\u7684\u94fe\u63a5\uff08\u53ef\u80fd\u5b58\u5728\u591a\u4e2a\u94fe\u63a5\u6587\u4ef6\uff09\uff0c<span>update<span>-<span>rc<span>.<span>d<span>\u53ea\u4e0d\u8fc7\u7b80\u5316\u4e86\u8fd9\u4e00\u6b65\u9aa4\u3002<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/p>\n<p>\uff085\uff09\u7981\u6b62<span><span>Apache<span>\/<span>MySQL<span><span>\u76f8\u5173\u7ec4\u4ef6\u5f00\u673a\u81ea\u542f\uff1a<\/span><\/span><\/span><\/span><\/span><\/span><\/p>\n<pre>update-rc.<span style=\"color: #000000\">d -f apache2 remove\r\nupdate-rc<\/span>.d -f mysql remove<\/pre>\n<p><strong>8\u3001\u670d\u52a1\u7684\u542f\u52a8\u505c\u6b62\u72b6\u6001<\/strong><\/p>\n<pre>#<span style=\"color: #000000\">\u901a\u8fc7service\uff0c\u6bd4\u5982\r\nsudo service xxx status\r\nsudo service xxx <\/span><span style=\"color: #0000ff\">start<\/span><span style=\"color: #000000\">\r\nsudo service xxx stop\r\nsudo service xxx restart<\/span><\/pre>\n<p><strong>9\u3001\u67e5\u770b\u5168\u90e8\u670d\u52a1\u5217\u8868<\/strong><\/p>\n<pre>sudo service --status-all<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Ubuntu 16.04\u8bbe\u7f6erc.local\u5f00\u673a\u542f\u52a8\u547d\u4ee4\/\u811a\u672c\u7684\u65b9\u6cd5\uff08\u901a\u8fc7update-rc.d\u7ba1\u7406Ubunt [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[28],"tags":[],"class_list":["post-12846","post","type-post","status-publish","format-standard","hentry","category-ubuntu"],"_links":{"self":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/12846","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/comments?post=12846"}],"version-history":[{"count":0,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/12846\/revisions"}],"wp:attachment":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/media?parent=12846"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/categories?post=12846"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/tags?post=12846"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}