{"id":2464,"date":"2015-08-02T13:49:50","date_gmt":"2015-08-02T05:49:50","guid":{"rendered":"http:\/\/ixyzero.com\/blog\/?p=2464"},"modified":"2015-08-02T13:49:50","modified_gmt":"2015-08-02T05:49:50","slug":"linux%e7%9a%84systemd%e7%9b%b8%e5%85%b3%e7%9f%a5%e8%af%86%e5%ad%a6%e4%b9%a0","status":"publish","type":"post","link":"https:\/\/ixyzero.com\/blog\/archives\/2464.html","title":{"rendered":"Linux\u7684systemd\u76f8\u5173\u77e5\u8bc6\u5b66\u4e60"},"content":{"rendered":"<p>Linux\u4e2d\u6709\u5f88\u591a\u547d\u4ee4\u5df2\u7ecf\u5b58\u5728\u4e86N\u591a\u5e74\uff0c\u6e10\u6e10\u6709\u4e9b\u5df2\u88ab\u4e00\u4e9b\u65b0\u7684\u547d\u4ee4\u6240\u4ee3\u66ff\uff0c\u4e0d\u8fc7\u7531\u4e8e\u4e60\u60ef\u7684\u539f\u56e0\uff0c\u5f88\u591a\u65f6\u5019\u6211\u4eec\u5e76\u4e0d\u80fd\u4e00\u4e0b\u5b50\u9002\u5e94\u8fc7\u6765\uff0c\u4f8b\u5982\uff1aifconfig\u4e4b\u4e8eip\u547d\u4ee4\u3002<\/p>\n<p>\u6700\u8fd1\u5728\u4f7f\u7528ArchLinux\u7684\u65f6\u5019\u7528\u5230\u4e86systemctl\u547d\u4ee4\uff0c\u867d\u7136\u4e4b\u524d\u5728 &#8220;Linux\u4e2d\u56fd&#8221; \u4e0a\u770b\u5230\u4e86\u5173\u4e8e systemd \u7684\u6587\u7ae0\uff0c\u4e0d\u8fc7\u5f53\u65f6\u6ca1\u6709\u4ec0\u4e48\u611f\u89c9\uff0c\u8ba4\u4e3a\u81ea\u5df1\u4e00\u65f6\u534a\u4f1a\u662f\u4e0d\u4f1a\u7528\u5230\u8fd9\u4e2a\u5de5\u5177\u7684\uff0c\u4f46\u4e16\u4e8b\u96be\u6599\uff0c\u6ca1\u60f3\u5230\u8fd9\u4e48\u5feb\u6211\u5c31\u8981\u82b1\u65f6\u95f4\u7814\u7a76\u8fd9\u4e2a\u547d\u4ee4\u5e76\u5728\u5b9e\u9645\u4e2d\u4f7f\u7528\u4e86\u3002<\/p>\n<p>systemctl\u662fsystemd\u4e0b\u7684\u4e00\u4e2a\u5de5\u5177\u3002\u7f51\u4e0a\u67e5\u4e86\u4e0b\uff0c\u8be5\u547d\u4ee4\u662f\u7528\u6765\u66ff\u4ee3service\u548cchkconfig\u4e24\u4e2a\u547d\u4ee4\u7684\u3002<\/p>\n<h5>\u53c2\u8003\u94fe\u63a5\uff1a<\/h5>\n<ul>\n<li><a href=\"https:\/\/fedoraproject.org\/wiki\/Systemd\/zh-cn\" target=\"_blank\">https:\/\/fedoraproject.org\/wiki\/Systemd\/zh-cn<\/a><\/li>\n<li><a href=\"http:\/\/www.ibm.com\/developerworks\/cn\/linux\/1407_liuming_init3\/\" target=\"_blank\">http:\/\/www.ibm.com\/developerworks\/cn\/linux\/1407_liuming_init3\/<\/a><\/li>\n<li><a href=\"https:\/\/wiki.archlinux.org\/index.php\/Systemd\" target=\"_blank\">https:\/\/wiki.archlinux.org\/index.php\/Systemd<\/a><\/li>\n<li><a href=\"https:\/\/linux.cn\/article-3801-1.html\" target=\"_blank\">https:\/\/linux.cn\/article-3801-1.html<\/a><\/li>\n<li><a href=\"https:\/\/linux.cn\/article-5926-1.html\" target=\"_blank\">https:\/\/linux.cn\/article-5926-1.html<\/a><\/li>\n<li><a href=\"http:\/\/www.tecmint.com\/manage-services-using-systemd-and-systemctl-in-linux\/\" target=\"_blank\">http:\/\/www.tecmint.com\/manage-services-using-systemd-and-systemctl-in-linux\/<\/a><\/li>\n<li><a href=\"http:\/\/linoxide.com\/linux-command\/linux-systemd-commands\/\" target=\"_blank\">http:\/\/linoxide.com\/linux-command\/linux-systemd-commands\/<\/a><\/li>\n<li>=<\/li>\n<li><a href=\"http:\/\/www.111cn.net\/sys\/linux\/65797.htm\" target=\"_blank\">http:\/\/www.111cn.net\/sys\/linux\/65797.htm<\/a><\/li>\n<li><a href=\"http:\/\/blog.csdn.net\/julius819\/article\/details\/7665679\" target=\"_blank\">http:\/\/blog.csdn.net\/julius819\/article\/details\/7665679<\/a><\/li>\n<li><a href=\"http:\/\/blog.csdn.net\/jiangzhengdong\/article\/details\/9070093\" target=\"_blank\">http:\/\/blog.csdn.net\/jiangzhengdong\/article\/details\/9070093<\/a><\/li>\n<li><a href=\"http:\/\/godontop.com\/systemctl%E5%91%BD%E4%BB%A4%E7%94%A8%E6%B3%95%E8%AF%A6%E8%A7%A3-234\/\" target=\"_blank\">http:\/\/godontop.com\/systemctl%E5%91%BD%E4%BB%A4%E7%94%A8%E6%B3%95%E8%AF%A6%E8%A7%A3-234\/<\/a><\/li>\n<\/ul>\n<h5>\u53c2\u8003\u89e3\u7b54\uff1a<\/h5>\n<ul>\n<li>\u7cfb\u7edf\u73af\u5883\uff1a4.0.7-2-ARCH<\/li>\n<li>\u6240\u5728\u8def\u5f84\uff1a\/usr\/bin\/systemctl<\/li>\n<\/ul>\n<h6>#\u5c06httpd\u670d\u52a1<span style=\"color: #ff0000;\">\u8bbe\u4e3a\u5f00\u673a\u81ea\u52a8\u542f\u52a8<\/span>\uff08enable\uff09<\/h6>\n<p><code>systemctl enable httpd.service<\/code><\/p>\n<h6>#\u68c0\u67e5httpd\u670d\u52a1<span style=\"color: #ff0000;\">\u662f\u5426\u4e3a\u5f00\u673a\u542f\u52a8<\/span>\uff08is-enabled\uff09<\/h6>\n<p><code>systemctl is-enabled httpd.service<\/code><\/p>\n<h6>#<span style=\"color: #ff0000;\">\u7981\u6b62<\/span>httpd\u670d\u52a1<span style=\"color: #ff0000;\">\u5f00\u673a\u81ea\u52a8\u542f\u52a8<\/span>\uff08disable\uff09<\/h6>\n<p><code>systemctl disable httpd.service<\/code><\/p>\n<h6>#\u67e5\u770bhttpd\u670d\u52a1\u7684<span style=\"color: #ff0000;\">\u8fd0\u884c\u72b6\u6001<\/span>\uff08status\uff09<\/h6>\n<p>systemctl status httpd.service<\/p>\n<h6>#<span style=\"color: #ff0000;\">\u542f\u52a8<\/span>httpd\u670d\u52a1\uff08start\uff09<\/h6>\n<p><code>systemctl start httpd.service<\/code><\/p>\n<h6>#<span style=\"color: #ff0000;\">\u68c0\u67e5<\/span>httpd\u670d\u52a1<span style=\"color: #ff0000;\">\u662f\u5426\u5904\u4e8e\u6d3b\u52a8\u72b6\u6001<\/span>\uff08is-active\uff09<\/h6>\n<p><code>systemctl is-active httpd.service<\/code><\/p>\n<h6>#<span style=\"color: #ff0000;\">\u505c\u6b62<\/span>httpd\u670d\u52a1\uff08stop\uff09<\/h6>\n<p><code>systemctl stop httpd.service<\/code><\/p>\n<h6>#<span style=\"color: #ff0000;\">\u91cd\u65b0\u52a0\u8f7d<\/span>httpd\u670d\u52a1\uff08reload\uff09<\/h6>\n<p><code>systemctl reload httpd.service<\/code><\/p>\n<h6>#<span style=\"color: #ff0000;\">\u91cd\u65b0\u542f\u52a8<\/span>httpd\u670d\u52a1\uff08restart\uff09<\/h6>\n<p><code>systemctl restart httpd.service<\/code><\/p>\n<h6>#<span style=\"color: #ff0000;\">\u663e\u793a\u542f\u52a8\u5931\u8d25\u7684<\/span>\u670d\u52a1\uff08<code>--failed<\/code>\uff09<\/h6>\n<pre class=\"lang:default decode:true \"># systemctl --failed\n\nLOAD \u00a0 = Reflects whether the unit definition was properly loaded.\nACTIVE = The high-level unit activation state, i.e. generalization of SUB.\nSUB \u00a0 \u00a0= The low-level unit activation state, values depend on unit type.<\/pre>\n<p>==<\/p>\n<h6>1.\u66f4\u5feb\u7684\u542f\u52a8\u901f\u5ea6\/\u7cbe\u51c6\u5206\u6790<\/h6>\n<pre class=\"lang:default decode:true\"># systemd-analyze  #\u67e5\u770b\u7cfb\u7edf\u5f15\u5bfc\u7528\u65f6\nStartup finished in 1.520s (kernel) + 709ms (userspace) = 2.229s\n\n# systemd-analyze blame #\u4ee5\u8fdb\u7a0b\u521d\u59cb\u5316\u6240\u5360\u7528\u65f6\u95f4\u6392\u5e8f\n\n# systemd-analyze critical-chain    #\u5206\u6790\u542f\u52a8\u65f6\u7684\u5173\u952e\u94fe\n\n# systemd-analyze critical-chain httpd.service  #\u5206\u6790\u67d0\u4e2a\u670d\u52a1(httpd)\u7684\u5173\u952e\u94fe<\/pre>\n<h6>2.\u5217\u51fa\u6b63\u5728\u8fd0\u884c\/\u53ef\u7528\/\u6240\u6709\u7684units<\/h6>\n<pre class=\"lang:default decode:true\"># systemctl\n# systemctl list-units      #\u5217\u51fa\u6240\u6709\u8fd0\u884c\u4e2d\u5355\u5143\n# systemctl list-unit-files #\u5217\u51fa\u6240\u6709\u53ef\u7528\u5355\u5143\n\n# systemctl list-unit-files --type=service  #\u5217\u51fa\u6240\u6709\u670d\u52a1(\u5305\u62ec\u542f\u7528\u7684\u548c\u7981\u7528\u7684)\n# systemctl list-unit-files --type=mount    #\u5217\u51fa\u6240\u6709\u7cfb\u7edf\u6302\u8f7d\u70b9\n# systemctl list-unit-files --type=socket   #\u5217\u51fa\u6240\u6709\u53ef\u7528\u7cfb\u7edf\u5957\u63a5\u53e3<\/pre>\n<h6>3.\u5217\u51fa\u5931\u8d25\u7684units<\/h6>\n<pre class=\"lang:default decode:true\">systemctl --failed<\/pre>\n<h6><span style=\"line-height: 1.5;\">4.systemd\u548csysVinit<\/span><\/h6>\n<p>Systemd\u6709\u4e00\u4e2a\u5b8c\u6210\u4e0esysVinit\u7684runlevels\u76f8\u4f3c\u4efb\u52a1\u7684\u6784\u60f3\u3002<\/p>\n<p>sysVinit\u7684runlevels\u5927\u591a\u662f\u4ee5\u6570\u5b57\u5206\u7ea7\u7684\uff0c\u4e0b\u9762\u662frunlevels\u5728systemd\u4e2d\u7684\u5bf9\u5e94\u5143\u7d20\uff1a<\/p>\n<ul>\n<li>\u00a0 0 runlevel0.target, poweroff.target<\/li>\n<li>\u00a0 1, s, single runlevel1.target, rescue.target<\/li>\n<li>\u00a0 2, 4 runlevel2.target, runlevel4.target, multi-user.target<\/li>\n<li>\u00a0 3 runlevel3.target, multi-user.target<\/li>\n<li>\u00a0 5 runlevel5.target, graphical.target<\/li>\n<li>\u00a0 6 runlevel6.target, reboot.target<\/li>\n<li>\u00a0 emergency emergency.target<\/li>\n<\/ul>\n<h6>5.systemd\u7684\u65e5\u5fd7<\/h6>\n<p>#journald\u662fsystemd\u72ec\u6709\u7684\u65e5\u5fd7\u7cfb\u7edf\uff0c\u66ff\u6362\u4e86sysVinit\u4e2d\u7684syslog\u5b88\u62a4\u8fdb\u7a0b\u3002\u53ef\u4ee5\u7528\u547d\u4ee4journalctl\u6765\u8bfb\u53d6\u65e5\u5fd7<\/p>\n<p><code>journald<\/code><\/p>\n<p>#\u8fd0\u884cjournalctl -b\u547d\u4ee4\u6765\u67e5\u770b\u6240\u6709<strong><span style=\"color: #ff0000;\">\u5f15\u5bfc\u65e5\u5fd7<\/span><\/strong><\/p>\n<p><code>journalctl -b<\/code><\/p>\n<p>#<span style=\"color: #ff0000;\"><strong>\u5b9e\u65f6\u663e\u793a\u7cfb\u7edf\u65e5\u5fd7\uff08\u7c7b\u4f3ctail -f\uff09<\/strong><\/span><\/p>\n<p><code>journalctl -f<\/code><\/p>\n<p>#<strong><span style=\"color: #ff0000;\">\u67e5\u770b\u7279\u5b9a\u670d\u52a1\u7684\u65e5\u5fd7<\/span><\/strong><\/p>\n<p><code>journalctl \/usr\/bin\/dhcpcd<\/code><\/p>\n<h6>6.\u7535\u6e90\u7ba1\u7406<\/h6>\n<p>#systemctl\u547d\u4ee4\u4e5f\u53ef\u4ee5\u7528\u6765\u5173\u673a\uff0c\u91cd\u542f\u6216\u8005\u4f11\u7720\u3002\u8981\u5173\u673a\u3001\u91cd\u542f\u3001\u6302\u8d77\u548c\u4f11\u7720\uff0c\u5206\u522b\u4f7f\u7528\u5982\u4e0b\u547d\u4ee4\uff1a<\/p>\n<ul>\n<li><code>systemctl poweroff<\/code><\/li>\n<li><code>systemctl reboot<\/code><\/li>\n<li><code>systemctl suspend<\/code><\/li>\n<li><code>systemctl hibernate<\/code><\/li>\n<\/ul>\n<h6>7.\u5728systemd\u4e2d\u663e\u793a\u7cfb\u7edf\u4fe1\u606f\u7684\u65b0\u65b9\u6cd5<\/h6>\n<p><code>hostnamectl<\/code><\/p>\n<h6>8.\u5176\u5b83<\/h6>\n<pre class=\"lang:default decode:true \"># systemctl get-default     #\u5217\u51fa\u5f53\u524d\u4f7f\u7528\u7684\u8fd0\u884c\u7b49\u7ea7\n\n# systemctl show httpd  #\u68c0\u67e5\u67d0\u4e2a\u670d\u52a1\u7684\u6240\u6709\u914d\u7f6e\u7ec6\u8282\n\n# systemd-analyze critical-chain httpd.service  #\u5206\u6790\u67d0\u4e2a\u670d\u52a1(httpd)\u7684\u5173\u952e\u94fe\n\n# systemctl list-dependencies httpd.service #\u83b7\u53d6\u67d0\u4e2a\u670d\u52a1(httpd)\u7684\u4f9d\u8d56\u6027\u5217\u8868<\/pre>\n<p>=EOF=<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Linux\u4e2d\u6709\u5f88\u591a\u547d\u4ee4\u5df2\u7ecf\u5b58\u5728\u4e86N\u591a\u5e74\uff0c\u6e10\u6e10\u6709\u4e9b\u5df2\u88ab\u4e00\u4e9b\u65b0\u7684\u547d\u4ee4\u6240\u4ee3\u66ff\uff0c\u4e0d\u8fc7\u7531\u4e8e\u4e60\u60ef\u7684\u539f\u56e0\uff0c\u5f88\u591a\u65f6\u5019\u6211\u4eec\u5e76\u4e0d\u80fd [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23,11],"tags":[533,547,548],"class_list":["post-2464","post","type-post","status-publish","format-standard","hentry","category-knowledgebase-2","category-linux","tag-archlinux","tag-systemctl","tag-systemd"],"views":9158,"_links":{"self":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/2464","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/comments?post=2464"}],"version-history":[{"count":0,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/2464\/revisions"}],"wp:attachment":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/media?parent=2464"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/categories?post=2464"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/tags?post=2464"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}