{"id":44064,"date":"2024-10-06T12:33:03","date_gmt":"2024-10-06T04:33:03","guid":{"rendered":"https:\/\/server.hk\/cnblog\/44064\/"},"modified":"2024-10-06T12:33:04","modified_gmt":"2024-10-06T04:33:04","slug":"centos-%e7%9a%84-system-v-init-%e5%95%9f%e5%8b%95%e8%85%b3%e6%9c%ac","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/44064\/","title":{"rendered":"CentOS \u7684 System V init \u555f\u52d5\u8173\u672c"},"content":{"rendered":"<h1 id=\"centos-%e7%9a%84-system-v-init-%e5%95%9f%e5%8b%95%e8%85%b3%e6%9c%ac-neaSKPogAg\">CentOS \u7684 System V init \u555f\u52d5\u8173\u672c<\/h1>\n<p>\u5728 Linux \u7cfb\u7d71\u4e2d\uff0c\u555f\u52d5\u904e\u7a0b\u662f\u81f3\u95dc\u91cd\u8981\u7684\uff0c\u56e0\u70ba\u5b83\u6c7a\u5b9a\u4e86\u7cfb\u7d71\u5982\u4f55\u52a0\u8f09\u548c\u904b\u884c\u5404\u7a2e\u670d\u52d9\u3002CentOS \u4f5c\u70ba\u4e00\u500b\u6d41\u884c\u7684 Linux \u767c\u884c\u7248\uff0c\u4f7f\u7528 System V init \u4f5c\u70ba\u5176\u555f\u52d5\u7ba1\u7406\u7cfb\u7d71\u3002\u672c\u6587\u5c07\u6df1\u5165\u63a2\u8a0e CentOS \u7684 System V init \u555f\u52d5\u8173\u672c\u7684\u7d50\u69cb\u3001\u529f\u80fd\u53ca\u5176\u4f7f\u7528\u65b9\u6cd5\u3002<\/p>\n<h2 id=\"system-v-init-%e7%b0%a1%e4%bb%8b-neaSKPogAg\">System V init \u7c21\u4ecb<\/h2>\n<p>System V init \u662f\u4e00\u7a2e\u50b3\u7d71\u7684\u555f\u52d5\u7cfb\u7d71\uff0c\u6700\u65e9\u51fa\u73fe\u5728 UNIX \u7cfb\u7d71\u4e2d\u3002\u5b83\u7684\u4e3b\u8981\u529f\u80fd\u662f\u7ba1\u7406\u7cfb\u7d71\u7684\u555f\u52d5\u904e\u7a0b\uff0c\u4e26\u63a7\u5236\u7cfb\u7d71\u904b\u884c\u7684\u5404\u7a2e\u670d\u52d9\u3002System V init \u901a\u904e\u4e00\u7d44\u8173\u672c\u4f86\u555f\u52d5\u548c\u505c\u6b62\u670d\u52d9\uff0c\u9019\u4e9b\u8173\u672c\u901a\u5e38\u4f4d\u65bc <code>\/etc\/init.d\/<\/code> \u76ee\u9304\u4e0b\u3002<\/p>\n<h2 id=\"%e5%95%9f%e5%8b%95%e8%85%b3%e6%9c%ac%e7%9a%84%e7%b5%90%e6%a7%8b-neaSKPogAg\">\u555f\u52d5\u8173\u672c\u7684\u7d50\u69cb<\/h2>\n<p>\u5728 CentOS \u4e2d\uff0c\u555f\u52d5\u8173\u672c\u901a\u5e38\u9075\u5faa\u4ee5\u4e0b\u7d50\u69cb\uff1a<\/p>\n<pre>\n#!\/bin\/bash\n# chkconfig: 2345 99 01\n# description: \u9019\u662f\u4e00\u500b\u793a\u7bc4\u555f\u52d5\u8173\u672c\n\ncase \"$1\" in\n    start)\n        echo \"\u555f\u52d5\u670d\u52d9...\"\n        # \u555f\u52d5\u670d\u52d9\u7684\u547d\u4ee4\n        ;;\n    stop)\n        echo \"\u505c\u6b62\u670d\u52d9...\"\n        # \u505c\u6b62\u670d\u52d9\u7684\u547d\u4ee4\n        ;;\n    restart)\n        echo \"\u91cd\u555f\u670d\u52d9...\"\n        # \u91cd\u555f\u670d\u52d9\u7684\u547d\u4ee4\n        ;;\n    status)\n        echo \"\u6aa2\u67e5\u670d\u52d9\u72c0\u614b...\"\n        # \u6aa2\u67e5\u670d\u52d9\u72c0\u614b\u7684\u547d\u4ee4\n        ;;\n    *)\n        echo \"\u7528\u6cd5: $0 {start|stop|restart|status}\"\n        exit 1\n        ;;\nesac\n\nexit 0\n<\/pre>\n<h3 id=\"%e8%85%b3%e6%9c%ac%e8%a7%a3%e9%87%8b-neaSKPogAg\">\u8173\u672c\u89e3\u91cb<\/h3>\n<ul>\n<li><code>#!\/bin\/bash<\/code>: \u6307\u5b9a\u8173\u672c\u4f7f\u7528\u7684\u89e3\u91cb\u5668\u3002<\/li>\n<li><code># chkconfig: 2345 99 01<\/code>: \u6307\u5b9a\u8a72\u670d\u52d9\u5728\u4e0d\u540c\u904b\u884c\u7d1a\u5225\u4e0b\u7684\u555f\u52d5\u9806\u5e8f\u3002<\/li>\n<li><code>case \"$1\" in<\/code>: \u6839\u64da\u50b3\u5165\u7684\u53c3\u6578\u57f7\u884c\u4e0d\u540c\u7684\u64cd\u4f5c\u3002<\/li>\n<li><code>start, stop, restart, status<\/code>: \u9019\u4e9b\u662f\u5e38\u898b\u7684\u64cd\u4f5c\u547d\u4ee4\u3002<\/li>\n<\/ul>\n<h2 id=\"%e5%a6%82%e4%bd%95%e5%89%b5%e5%bb%ba%e5%92%8c%e7%ae%a1%e7%90%86%e5%95%9f%e5%8b%95%e8%85%b3%e6%9c%ac-neaSKPogAg\">\u5982\u4f55\u5275\u5efa\u548c\u7ba1\u7406\u555f\u52d5\u8173\u672c<\/h2>\n<p>\u8981\u5275\u5efa\u4e00\u500b\u65b0\u7684\u555f\u52d5\u8173\u672c\uff0c\u53ef\u4ee5\u6309\u7167\u4ee5\u4e0b\u6b65\u9a5f\u9032\u884c\uff1a<\/p>\n<ol>\n<li>\u5728 <code>\/etc\/init.d\/<\/code> \u76ee\u9304\u4e0b\u5275\u5efa\u4e00\u500b\u65b0\u7684\u8173\u672c\u6587\u4ef6\uff0c\u4f8b\u5982 <code>myservice<\/code>\u3002<\/li>\n<li>\u7de8\u8f2f\u8a72\u6587\u4ef6\uff0c\u4e26\u6dfb\u52a0\u4e0a\u8ff0\u7d50\u69cb\u7684\u5167\u5bb9\u3002<\/li>\n<li>\u7d66\u4e88\u8173\u672c\u57f7\u884c\u6b0a\u9650\uff1a<code>chmod +x \/etc\/init.d\/myservice<\/code><\/li>\n<li>\u4f7f\u7528 <code>chkconfig<\/code> \u547d\u4ee4\u5c07\u670d\u52d9\u6dfb\u52a0\u5230\u555f\u52d5\u9805\u4e2d\uff1a<code>chkconfig --add myservice<\/code><\/li>\n<\/ol>\n<h2 id=\"%e7%ae%a1%e7%90%86%e6%9c%8d%e5%8b%99-neaSKPogAg\">\u7ba1\u7406\u670d\u52d9<\/h2>\n<p>\u4e00\u65e6\u555f\u52d5\u8173\u672c\u5275\u5efa\u5b8c\u6210\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u4f86\u7ba1\u7406\u670d\u52d9\uff1a<\/p>\n<ul>\n<li>\u555f\u52d5\u670d\u52d9\uff1a<code>service myservice start<\/code><\/li>\n<li>\u505c\u6b62\u670d\u52d9\uff1a<code>service myservice stop<\/code><\/li>\n<li>\u91cd\u555f\u670d\u52d9\uff1a<code>service myservice restart<\/code><\/li>\n<li>\u6aa2\u67e5\u670d\u52d9\u72c0\u614b\uff1a<code>service myservice status<\/code><\/li>\n<\/ul>\n<h2 id=\"%e7%b8%bd%e7%b5%90-neaSKPogAg\">\u7e3d\u7d50<\/h2>\n<p>CentOS \u7684 System V init \u555f\u52d5\u8173\u672c\u63d0\u4f9b\u4e86\u4e00\u7a2e\u9748\u6d3b\u7684\u65b9\u5f0f\u4f86\u7ba1\u7406\u7cfb\u7d71\u670d\u52d9\u3002\u901a\u904e\u4e86\u89e3\u5176\u7d50\u69cb\u548c\u4f7f\u7528\u65b9\u6cd5\uff0c\u7cfb\u7d71\u7ba1\u7406\u54e1\u53ef\u4ee5\u6709\u6548\u5730\u63a7\u5236\u670d\u52d9\u7684\u555f\u52d5\u548c\u505c\u6b62\u3002\u5c0d\u65bc\u9700\u8981\u7a69\u5b9a\u548c\u9ad8\u6548\u904b\u884c\u7684\u74b0\u5883\uff0c\u638c\u63e1\u9019\u4e9b\u6280\u80fd\u662f\u975e\u5e38\u91cd\u8981\u7684\u3002\u5982\u679c\u60a8\u6b63\u5728\u5c0b\u627e\u53ef\u9760\u7684 <a href=\"https:\/\/server.hk\">VPS<\/a> \u89e3\u6c7a\u65b9\u6848\uff0cServer.HK \u63d0\u4f9b\u591a\u7a2e\u9078\u64c7\u4ee5\u6eff\u8db3\u60a8\u7684\u9700\u6c42\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e86\u89e3 CentOS \u7684 System V init \u555f\u52d5\u8173\u672c\uff0c\u638c\u63e1\u670d\u52d9\u555f\u52d5\u3001\u505c\u6b62\u53ca\u7ba1\u7406\u7684\u57fa\u672c\u64cd\u4f5c\u8207\u6280\u5de7\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4924],"tags":[],"class_list":["post-44064","post","type-post","status-publish","format-standard","hentry","category-setup-tutorials"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/44064","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=44064"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/44064\/revisions"}],"predecessor-version":[{"id":44065,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/44064\/revisions\/44065"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=44064"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=44064"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=44064"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}