{"id":42848,"date":"2024-10-04T06:22:08","date_gmt":"2024-10-03T22:22:08","guid":{"rendered":"https:\/\/server.hk\/cnblog\/42848\/"},"modified":"2024-10-04T06:22:08","modified_gmt":"2024-10-03T22:22:08","slug":"centos-7-%e4%b8%ad-systemd-%e8%a9%b3%e8%a7%a3","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/42848\/","title":{"rendered":"CentOS 7 \u4e2d Systemd \u8a73\u89e3"},"content":{"rendered":"<h1 id=\"centos-7-%e4%b8%ad-systemd-%e8%a9%b3%e8%a7%a3-zELBgtydsj\">CentOS 7 \u4e2d Systemd \u8a73\u89e3<\/h1>\n<p>\u5728 CentOS 7 \u4e2d\uff0cSystemd \u662f\u4e00\u500b\u91cd\u8981\u7684\u7cfb\u7d71\u548c\u670d\u52d9\u7ba1\u7406\u5668\uff0c\u53d6\u4ee3\u4e86\u50b3\u7d71\u7684 SysVinit\u3002Systemd \u7684\u8a2d\u8a08\u76ee\u7684\u662f\u70ba\u4e86\u63d0\u9ad8\u555f\u52d5\u901f\u5ea6\u3001\u7c21\u5316\u670d\u52d9\u7ba1\u7406\u4ee5\u53ca\u63d0\u4f9b\u66f4\u5f37\u5927\u7684\u529f\u80fd\u3002\u672c\u6587\u5c07\u6df1\u5165\u63a2\u8a0e Systemd \u7684\u57fa\u672c\u6982\u5ff5\u3001\u529f\u80fd\u4ee5\u53ca\u5982\u4f55\u5728 CentOS 7 \u4e2d\u4f7f\u7528\u5b83\u3002<\/p>\n<h2 id=\"systemd-%e7%9a%84%e5%9f%ba%e6%9c%ac%e6%a6%82%e5%bf%b5-zELBgtydsj\">Systemd \u7684\u57fa\u672c\u6982\u5ff5<\/h2>\n<p>Systemd \u662f\u4e00\u500b\u7cfb\u7d71\u548c\u670d\u52d9\u7ba1\u7406\u5668\uff0c\u8ca0\u8cac\u555f\u52d5\u548c\u7ba1\u7406\u7cfb\u7d71\u670d\u52d9\u3002\u5b83\u4f7f\u7528\u55ae\u4e00\u7684\u914d\u7f6e\u6587\u4ef6\u683c\u5f0f\uff0c\u7a31\u70ba\u55ae\u5143\uff08unit\uff09\uff0c\u4f86\u63cf\u8ff0\u670d\u52d9\u3001\u5957\u4ef6\u3001\u639b\u8f09\u9ede\u7b49\u3002\u9019\u4e9b\u55ae\u5143\u6587\u4ef6\u901a\u5e38\u4f4d\u65bc <code>\/etc\/systemd\/system<\/code> \u548c <code>\/usr\/lib\/systemd\/system<\/code> \u76ee\u9304\u4e2d\u3002<\/p>\n<h3 id=\"%e5%96%ae%e5%85%83%e6%96%87%e4%bb%b6%e7%9a%84%e9%a1%9e%e5%9e%8b-zELBgtydsj\">\u55ae\u5143\u6587\u4ef6\u7684\u985e\u578b<\/h3>\n<ul>\n<li><strong>Service Units<\/strong>\uff1a\u7528\u65bc\u5b9a\u7fa9\u670d\u52d9\u7684\u555f\u52d5\u548c\u7ba1\u7406\u3002<\/li>\n<li><strong>Socket Units<\/strong>\uff1a\u7528\u65bc\u5b9a\u7fa9 socket \u76e3\u807d\u3002<\/li>\n<li><strong>Target Units<\/strong>\uff1a\u7528\u65bc\u7d44\u7e54\u5176\u4ed6\u55ae\u5143\u7684\u96c6\u5408\u3002<\/li>\n<li><strong>Mount Units<\/strong>\uff1a\u7528\u65bc\u5b9a\u7fa9\u6587\u4ef6\u7cfb\u7d71\u7684\u639b\u8f09\u9ede\u3002<\/li>\n<\/ul>\n<h2 id=\"systemd-%e7%9a%84%e4%b8%bb%e8%a6%81%e5%8a%9f%e8%83%bd-zELBgtydsj\">Systemd \u7684\u4e3b\u8981\u529f\u80fd<\/h2>\n<p>Systemd \u63d0\u4f9b\u4e86\u8a31\u591a\u5f37\u5927\u7684\u529f\u80fd\uff0c\u4f7f\u5176\u6210\u70ba\u73fe\u4ee3 Linux \u7cfb\u7d71\u7684\u6838\u5fc3\u7d44\u4ef6\uff1a<\/p>\n<h3 id=\"%e4%b8%a6%e8%a1%8c%e5%95%9f%e5%8b%95-zELBgtydsj\">\u4e26\u884c\u555f\u52d5<\/h3>\n<p>Systemd \u53ef\u4ee5\u540c\u6642\u555f\u52d5\u591a\u500b\u670d\u52d9\uff0c\u9019\u6a23\u53ef\u4ee5\u986f\u8457\u7e2e\u77ed\u7cfb\u7d71\u555f\u52d5\u6642\u9593\u3002\u9019\u662f\u901a\u904e\u5206\u6790\u670d\u52d9\u4e4b\u9593\u7684\u4f9d\u8cf4\u95dc\u4fc2\u4f86\u5be6\u73fe\u7684\u3002<\/p>\n<h3 id=\"%e4%be%9d%e8%b3%b4%e7%ae%a1%e7%90%86-zELBgtydsj\">\u4f9d\u8cf4\u7ba1\u7406<\/h3>\n<p>Systemd \u5141\u8a31\u7528\u6236\u5b9a\u7fa9\u670d\u52d9\u4e4b\u9593\u7684\u4f9d\u8cf4\u95dc\u4fc2\uff0c\u78ba\u4fdd\u5728\u555f\u52d5\u670d\u52d9\u6642\uff0c\u6240\u6709\u4f9d\u8cf4\u7684\u670d\u52d9\u90fd\u5df2\u7d93\u555f\u52d5\u3002\u4f8b\u5982\uff0c\u5728\u4e00\u500b Web \u4f3a\u670d\u5668\u555f\u52d5\u4e4b\u524d\uff0c\u6578\u64da\u5eab\u670d\u52d9\u5fc5\u9808\u5148\u555f\u52d5\u3002<\/p>\n<pre><code>[Unit]\nDescription=My Web Server\nAfter=network.target\nRequires=mysql.service\n\n[Service]\nExecStart=\/usr\/bin\/my_web_server\n\n[Install]\nWantedBy=multi-user.target\n<\/code><\/pre>\n<h3 id=\"%e6%97%a5%e8%aa%8c%e7%ae%a1%e7%90%86-zELBgtydsj\">\u65e5\u8a8c\u7ba1\u7406<\/h3>\n<p>Systemd \u5305\u542b\u4e00\u500b\u5167\u5efa\u7684\u65e5\u8a8c\u7cfb\u7d71\uff0c\u7a31\u70ba journal\u3002\u9019\u4f7f\u5f97\u7528\u6236\u53ef\u4ee5\u8f15\u9b06\u5730\u67e5\u770b\u548c\u7ba1\u7406\u7cfb\u7d71\u65e5\u8a8c\uff0c\u4e26\u4e14\u652f\u6301\u4e8c\u9032\u5236\u683c\u5f0f\uff0c\u63d0\u4f9b\u66f4\u9ad8\u6548\u7684\u65e5\u8a8c\u5b58\u5132\u548c\u6aa2\u7d22\u3002<\/p>\n<h2 id=\"%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8-systemd-zELBgtydsj\">\u5982\u4f55\u4f7f\u7528 Systemd<\/h2>\n<p>\u5728 CentOS 7 \u4e2d\uff0c\u4f7f\u7528 Systemd \u9032\u884c\u670d\u52d9\u7ba1\u7406\u975e\u5e38\u7c21\u55ae\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u7528\u7684\u547d\u4ee4\uff1a<\/p>\n<ul>\n<li><code>systemctl start <\/code>\uff1a\u555f\u52d5\u6307\u5b9a\u7684\u670d\u52d9\u3002<\/li>\n<li><code>systemctl stop <\/code>\uff1a\u505c\u6b62\u6307\u5b9a\u7684\u670d\u52d9\u3002<\/li>\n<li><code>systemctl restart <\/code>\uff1a\u91cd\u555f\u6307\u5b9a\u7684\u670d\u52d9\u3002<\/li>\n<li><code>systemctl enable <\/code>\uff1a\u8a2d\u7f6e\u670d\u52d9\u5728\u555f\u52d5\u6642\u81ea\u52d5\u555f\u52d5\u3002<\/li>\n<li><code>systemctl disable <\/code>\uff1a\u7981\u6b62\u670d\u52d9\u5728\u555f\u52d5\u6642\u81ea\u52d5\u555f\u52d5\u3002<\/li>\n<li><code>systemctl status <\/code>\uff1a\u67e5\u770b\u670d\u52d9\u7684\u7576\u524d\u72c0\u614b\u3002<\/li>\n<\/ul>\n<h2 id=\"%e7%b5%90%e8%ab%96-zELBgtydsj\">\u7d50\u8ad6<\/h2>\n<p>Systemd \u5728 CentOS 7 \u4e2d\u7684\u5f15\u5165\uff0c\u70ba\u7cfb\u7d71\u7ba1\u7406\u5e36\u4f86\u4e86\u986f\u8457\u7684\u6539\u9032\u3002\u5b83\u4e0d\u50c5\u63d0\u9ad8\u4e86\u555f\u52d5\u901f\u5ea6\uff0c\u9084\u7c21\u5316\u4e86\u670d\u52d9\u7ba1\u7406\uff0c\u4e26\u63d0\u4f9b\u4e86\u5f37\u5927\u7684\u65e5\u8a8c\u529f\u80fd\u3002\u96a8\u8457 Linux \u7cfb\u7d71\u7684\u767c\u5c55\uff0c\u638c\u63e1 Systemd \u7684\u4f7f\u7528\u5c07\u6210\u70ba\u7cfb\u7d71\u7ba1\u7406\u54e1\u5fc5\u5099\u7684\u6280\u80fd\u3002<\/p>\n<p>\u5982\u679c\u60a8\u6b63\u5728\u5c0b\u627e\u9ad8\u6548\u7684 <a href=\"https:\/\/server.hk\">VPS<\/a> \u89e3\u6c7a\u65b9\u6848\uff0cServer.HK \u63d0\u4f9b\u591a\u7a2e\u9078\u64c7\uff0c\u6eff\u8db3\u60a8\u7684\u9700\u6c42\u3002\u7121\u8ad6\u662f <a href=\"https:\/\/server.hk\">\u9999\u6e2f\u4f3a\u670d\u5668<\/a> \u9084\u662f\u5176\u4ed6\u670d\u52d9\uff0c\u6211\u5011\u90fd\u80fd\u70ba\u60a8\u63d0\u4f9b\u652f\u6301\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6df1\u5165\u63a2\u8ba8 CentOS 7 \u4e2d\u7684 Systemd\uff0c\u4e86\u89e3\u5176\u529f\u80fd\u3001\u914d\u7f6e\u548c\u7ba1\u7406\u670d\u52a1\u7684\u6700\u4f73\u5b9e\u8df5\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-42848","post","type-post","status-publish","format-standard","hentry","category-setup-tutorials"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/42848","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=42848"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/42848\/revisions"}],"predecessor-version":[{"id":42849,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/42848\/revisions\/42849"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=42848"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=42848"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=42848"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}