{"id":184,"date":"2022-04-29T14:53:53","date_gmt":"2022-04-29T06:53:53","guid":{"rendered":"https:\/\/www.qiangzhenshuai.com\/?p=184"},"modified":"2022-08-02T13:22:24","modified_gmt":"2022-08-02T05:22:24","slug":"linux-%e8%bf%90%e8%a1%8c%e7%ba%a7%e5%88%ab","status":"publish","type":"post","link":"https:\/\/www.qiangzhenshuai.com\/?p=184","title":{"rendered":"Linux-\u8fd0\u884c\u7ea7\u522bCentOS 7"},"content":{"rendered":"<!--more-->\r\n\r\n<div class=\"wp-container-1 wp-block-group\"><div class=\"wp-block-group__inner-container\">\r\n<h1><strong>\u8fd0\u884c\u7ea7\u522b<\/strong>\u00a0<\/h1>\r\n<figure class=\"wp-block-table is-style-regular\">\r\n<table>\r\n<tbody>\r\n<tr>\r\n<td>\u00a0<strong>System\u00a0\u8fd0\u884c\u7ea7\u522b<\/strong><\/td>\r\n<td>\u00a0<strong>systemd\u76ee\u6807\u540d\u79f0<\/strong><br \/><strong>(CentOS7)<\/strong><\/td>\r\n<td>\u00a0<strong>\u4f5c\u7528<\/strong><\/td>\r\n<\/tr>\r\n<tr>\r\n<td>\u00a00<\/td>\r\n<td>runlevel0.target<br \/>poweroff.target<\/td>\r\n<td>\u5173\u673a<\/td>\r\n<\/tr>\r\n<tr>\r\n<td>1<\/td>\r\n<td>runlevel1.target<br \/>rescue.target<\/td>\r\n<td>\u6551\u63f4\u6a21\u5f0f<\/td>\r\n<\/tr>\r\n<tr>\r\n<td>2<\/td>\r\n<td>runlevel2.target<br \/>multi-user.target<\/td>\r\n<td>\u591a\u7528\u6237\u6a21\u5f0f(\u6587\u672c\u6a21\u5f0f,\u547d<br \/>\u4ee4\u884c\u6a21\u5f0f)<\/td>\r\n<\/tr>\r\n<tr>\r\n<td>3<\/td>\r\n<td>runlevel3.target<br \/>multi-user.target<\/td>\r\n<td>\u591a\u7528\u6237\u7684\u6587\u672c\u754c\u9762(\u6587\u672c\u6a21<br \/>\u5f0f,\u547d\u4ee4\u884c\u6a21\u5f0f)<\/td>\r\n<\/tr>\r\n<tr>\r\n<td>4<\/td>\r\n<td>runlevel4.target<br \/>multi-user.target<\/td>\r\n<td>\u591a\u7528\u6237\u6a21\u5f0f,\u4e0e3\u4e00\u81f4<\/td>\r\n<\/tr>\r\n<tr>\r\n<td>5<\/td>\r\n<td>runlevel5.target<br \/>graphical.target<\/td>\r\n<td>\u591a\u7528\u6237\u7684\u56fe\u5f62\u754c\u9762(\u684c\u9762\u6a21<br \/>\u5f0f)<\/td>\r\n<\/tr>\r\n<tr>\r\n<td>6<\/td>\r\n<td>runlevel6.target<br \/>reboot.target<\/td>\r\n<td>\u91cd\u542f<\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n<\/figure>\r\n<\/div><\/div>\r\n<p>&nbsp;<\/p>\r\n<h1>centos7\u7cfb\u7edf<\/h1>\r\n<p>\u67e5\u770b\u7cfb\u7edf\u542f\u52a8\u8fd0\u884c\u7ea7\u522b<br \/>[root@dmxsp ~]# systemctl get-default<br \/>multi-user.target<\/p>\r\n<p>\u4fee\u6539\u9ed8\u8ba4\u542f\u52a8\u8fd0\u884c\u7ea7\u522b<br \/>[root@dmxsp ~]# systemctl set-default graphical.target<br \/>Removed symlink \/etc\/systemd\/system\/default.target. Created symlink from \/etc\/systemd\/system\/default.target to \/usr\/lib\/systemd\/system\/graphical.target.<\/p>\r\n<p>[root@dmxsp ~]# systemctl get-default<br \/>graphical.target<\/p>\r\n<h1>\u7cfb\u7edf\u7684systemd<\/h1>\r\n<h3>1.systemd\u7684\u7531\u6765<\/h3>\r\n<p>Linux\u4e00\u76f4\u4ee5\u6765\u90fd\u662f\u91c7\u7528init\u8fdb\u7a0b\u4f5c\u4e3a\u7956\u5b97\u8fdb\u7a0b\uff0c\u4f46\u662finit\u6709\u4e24\u4e2a\u7f3a\u70b9\uff1a<br \/>1\u3001\u542f\u52a8\u65f6\u95f4\u957f\u3002Init\u8fdb\u7a0b\u662f\u4e32\u884c\u542f\u52a8\uff0c\u53ea\u6709\u524d\u4e00\u4e2a\u8fdb\u7a0b\u542f\u52a8\u5b8c\uff0c\u624d\u4f1a\u542f\u52a8\u4e0b\u4e00\u4e2a\u8fdb\u7a0b\u3002<br \/>2\u3001\u542f\u52a8\u811a\u672c\u590d\u6742\uff0c\u521d\u59cb\u5316\u5b8c\u6210\u540e\u7cfb\u7edf\u4f1a\u52a0\u8f7d\u5f88\u591a\u811a\u672c\uff0c\u811a\u672c\u90fd\u4f1a\u5904\u7406\u5404\u81ea\u7684\u60c5\u51b5\uff0c\u8fd9\u4f1a\u8ba9\u811a\u672c\u591a\u800c\u590d\u6742\u3002<br \/>Centos5 \u662f\u542f\u52a8\u901f\u5ea6\u6700\u6162\u7684\uff0c\u4e32\u884c\u542f\u52a8\u8fc7\u7a0b\uff0c\u65e0\u8bba\u8fdb\u7a0b\u76f8\u4e92\u4e4b\u95f4\u6709\u65e0\u4f9d\u8d56\u5173\u7cfb\u3002<br \/>Centos6 \u76f8\u5bf9\u542f\u52a8\u901f\u5ea6\u6709\u6240\u6539\u8fdb\u3002\u6709\u4f9d\u8d56\u7684\u8fdb\u7a0b\u4e4b\u95f4\u4f9d\u6b21\u542f\u52a8\u800c\u5176\u4ed6\u4e0e\u4e4b\u6ca1\u6709\u4f9d\u8d56\u5173\u7cfb\u7684\u5219\u5e76\u884c\u540c\u6b65\u542f\u52a8\u3002<br \/>Centos7 \u6240\u6709\u8fdb\u7a0b\u65e0\u8bba\u6709\u65e0\u4f9d\u8d56\u5173\u7cfb\u5219\u90fd\u662f\u5e76\u884c\u542f\u52a8\uff08\u5f53\u7136\u5f88\u591a\u65f6\u5019\u8fdb\u7a0b\u6ca1\u6709\u771f\u6b63\u542f\u52a8\u800c\u662f\u53ea\u6709\u4e00\u4e2a\u4fe1\u53f7\u6216\u8005\u8bf4\u662f\u6807\u8bb0\u800c\u5df2\uff0c\u5728\u771f\u6b63\u5229\u7528\u7684\u65f6\u5019\u624d\u4f1a\u771f\u6b63\u542f\u52a8\u3002\uff09<\/p>\r\n<h3>2.\u4ec0\u4e48\u662fsystemd<\/h3>\r\n<p>systemd\u5373\u4e3asystem daemon,\u662flinux\u4e0b\u7684\u4e00\u79cdinit\u8f6f\u4ef6,\u7531Lennart Poettering\u5e26\u5934\u5f00\u53d1,\u5e76\u5728LGPL 2.1\u53ca\u5176\u540e\u7eed\u7248\u672c\u8bb8\u53ef\u8bc1\u4e0b\u5f00\u6e90\u53d1\u5e03,\u5f00\u53d1\u76ee\u6807\u662f\u63d0\u4f9b\u66f4\u4f18\u79c0\u7684\u6846\u67b6\u4ee5\u8868\u793a\u7cfb\u7edf\u670d\u52a1\u95f4\u7684\u4f9d\u8d56\u5173\u7cfb\uff0c\u5e76\u4f9d\u6b64\u5b9e\u73b0\u7cfb\u7edf\u521d\u59cb\u5316\u65f6\u670d\u52a1\u7684\u5e76\u884c\u542f\u52a8\uff0c\u540c\u65f6\u8fbe\u5230\u964d\u4f4eShell\u7684\u7cfb\u7edf\u5f00\u9500\u7684\u6548\u679c\uff0c\u6700\u7ec8\u4ee3\u66ff\u5e38\u7528\u7684System V\u4e0eBSD\u98ce\u683cinit\u7a0b\u5e8f\u3002<br \/>\u4e0e\u591a\u6570\u53d1\u884c\u7248\u4f7f\u7528\u7684System V\u98ce\u683cinit\u76f8\u6bd4\uff0csystemd\u91c7\u7528\u4e86\u4ee5\u4e0b\u65b0\u6280\u672f\uff1a<br \/>(1) \u91c7\u7528Socket\u6fc0\u6d3b\u5f0f\u4e0e\u603b\u7ebf\u6fc0\u6d3b\u5f0f\u670d\u52a1\uff0c\u4ee5\u63d0\u9ad8\u76f8\u4e92\u4f9d\u8d56\u7684\u5404\u670d\u52a1\u7684\u5e76\u884c\u8fd0\u884c\u6027\u80fd<br \/>(2) \u7528Cgroups\u4ee3\u66ffPID\u6765\u8ffd\u8e2a\u8fdb\u7a0b\uff0c\u56e0\u6b64\u5373\u4f7f\u662f\u4e24\u6b21fork\u4e4b\u540e\u751f\u6210\u7684\u5b88\u62a4\u8fdb\u7a0b\u4e5f\u4e0d\u4f1a\u8131\u79bbsystemd\u7684\u63a7\u5236\u3002<\/p>\r\n<h3>3.systemd\u7684\u4f18\u52bf<\/h3>\r\n<p>1\u3001\u6700\u65b0\u7cfb\u7edf\u90fd\u91c7\u7528systemd\u7ba1\u7406\uff08RedHat7,CentOS7,Ubuntu15\u7b49\uff09 systemctl<br \/>2\u3001Centos7\u652f\u6301\u5f00\u673a\u5e76\u884c\u542f\u52a8\u670d\u52a1\uff0c\u663e\u8457\u63d0\u9ad8\u5f00\u673a\u542f\u52a8\u6548\u7387\u3002<br \/>3\u3001Centos7\u5173\u673a\u53ea\u5173\u95ed\u6b63\u5728\u8fd0\u884c\u7684\u670d\u52a1\uff0c\u800cCentos6\u5168\u90e8\u90fd\u5173\u95ed\u4e00\u6b21\u3002<br \/>4\u3001Centos7\u670d\u52a1\u7684\u542f\u52a8\u4e0e\u505c\u6b62\u4e0d\u5728\u4f7f\u7528\u811a\u672c\u8fdb\u884c\u7ba1\u7406,C7\u4e0b\u9762\u90fd\u662f\u914d\u7f6e(\/usr\/lib\/systemd\/system\/xxxx.service)\uff0c\u4e5f\u5c31\u662f\/etc\/init.d(CentOS 6)\u4e0b\u4e0d\u5728\u6709\u811a\u672c\u3002<br \/>5\u3001Centos7\u4f7f\u7528systemd\u89e3\u51b3\u539f\u6709\u6a21\u5f0f\u7f3a\u9677\uff0c\u6bd4\u5982\u539f\u6709service\u4e0d\u4f1a\u5173\u95ed\u7a0b\u5e8f\u4ea7\u751f\u7684\u5b50\u8fdb\u7a0b\u3002<\/p>\r\n<h3>4.systemd\u76f8\u5173\u914d\u7f6e\u6587\u4ef6<\/h3>\r\n<p>\/usr\/lib\/systemd\/system\/\uff1a\u7c7b\u4f3cCentos6\u7cfb\u7edf\u7684\u542f\u52a8\u811a\u672c\uff0c\/etc\/init.d\/<br \/>\/etc\/systemd\/system\/\uff1a\u7cfb\u7edf\u914d\u7f6e\u5b58\u653e\uff0c\u7c7b\u4f3cCentos6\u7cfb\u7edf\u7684\/etc\/rc.d\/rcN.d\/<br \/>\/etc\/systemd\/system\/multi-user.target.wants\/\uff1a\u7cfb\u7edf\u914d\u7f6e\u5b58\u653e<\/p>\r\n<h3>5.systemd\u7ba1\u7406\u670d\u52a1\u76f8\u5173\u547d\u4ee4<\/h3>\r\n<p>systemctl\u7ba1\u7406\u670d\u52a1\u7684\u542f\u52a8\u3001\u91cd\u542f\u3001\u505c\u6b62\u3001\u91cd\u8f7d\u3001\u67e5\u770b\u72b6\u6001\u7b49\u5e38\u7528\u547d\u4ee4<\/p>\r\n<p>&nbsp;<\/p>\r\n\r\n<figure class=\"wp-block-table\">\r\n<table>\r\n<tbody>\r\n<tr>\r\n<td><strong>systemctl\u547d\u4ee4\uff087\u7cfb<\/strong><br \/><strong>\u7edf\uff09<\/strong><\/td>\r\n<td><strong>\u4f5c\u7528<\/strong><\/td>\r\n<\/tr>\r\n<tr>\r\n<td>systemctl start<br \/>crond.service<\/td>\r\n<td>\u542f\u52a8\u670d\u52a1,\u5f53\u524d\u6b63\u5728\u8fd0\u884c<\/td>\r\n<\/tr>\r\n<tr>\r\n<td>systemctl stop<br \/>crond.service<\/td>\r\n<td>\u505c\u6b62\u670d\u52a1<\/td>\r\n<\/tr>\r\n<tr>\r\n<td>systemctl restart<br \/>crond.service<\/td>\r\n<td>\u91cd\u542f\u670d\u52a1<\/td>\r\n<\/tr>\r\n<tr>\r\n<td>systemctl reload<br \/>crond.service<\/td>\r\n<td>\u4f18\u96c5\u7684\u91cd\u542f\uff0c\u91cd\u65b0\u52a0\u8f7d\u914d\u7f6e(\u4e0d\u7ec8\u6b62\u670d\u52a1,\u4e0d\u5f71\u54cd\u6b63\u5728\u5904\u7406\u7684\u8bf7\u6c42\/\u7528\u6237)<\/td>\r\n<\/tr>\r\n<tr>\r\n<td>systemctl status<br \/>crond.servre<\/td>\r\n<td>\u67e5\u770b\u670d\u52a1\u8fd0\u884c\u72b6\u6001<\/td>\r\n<\/tr>\r\n<tr>\r\n<td>systemctl is-active<br \/>sshd.service<\/td>\r\n<td>\u67e5\u770b\u670d\u52a1\u662f\u5426\u5728\u8fd0\u884c\u4e2d<\/td>\r\n<\/tr>\r\n<tr>\r\n<td>systemctl mask<br \/>crond.servre<\/td>\r\n<td>\u7981\u6b62\u670d\u52a1\u8fd0\u884c<\/td>\r\n<\/tr>\r\n<tr>\r\n<td>systemctl unmask<br \/>crond.servre<\/td>\r\n<td>\u53d6\u6d88\u7981\u6b62\u670d\u52a1\u8fd0\u884c<\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n<\/figure>\r\n\r\n<p>&nbsp;<\/p>\r\n<h3>systemctl \u8bbe\u7f6e\u670d\u52a1\u5f00\u673a\u542f\u52a8\u3001\u4e0d\u542f\u52a8\u3001\u67e5\u770b\u5404\u7ea7\u522b\u4e0b\u670d\u52a1\u542f\u52a8\u72b6\u6001\u7b49\u5e38\u7528\u547d\u4ee4<\/h3>\r\n\r\n<figure class=\"wp-block-table\">\r\n<table>\r\n<tbody>\r\n<tr>\r\n<td>systemctl\u547d\u4ee4\uff087\u7cfb\u7edf\uff09<\/td>\r\n<td>\u4f5c\u7528<\/td>\r\n<\/tr>\r\n<tr>\r\n<td>systemctl enable<br \/>crond.service<\/td>\r\n<td>\u5f00\u673a\u81ea\u52a8\u542f\u52a8<\/td>\r\n<\/tr>\r\n<tr>\r\n<td>systemctl disable<br \/>crond.service<\/td>\r\n<td>\u5f00\u673a\u4e0d\u8981\u81ea\u52a8\u542f\u52a8<\/td>\r\n<\/tr>\r\n<tr>\r\n<td>systemctl list-unit-files<\/td>\r\n<td>\u67e5\u770b\u5404\u4e2a\u7ea7\u522b\u4e0b\u670d\u52a1\u7684\u542f\u52a8\u4e0e\u7981\u7528<\/td>\r\n<\/tr>\r\n<tr>\r\n<td>systemctl is-enabled<br \/>crond.service<\/td>\r\n<td>\u67e5\u770b\u7279\u5b9a\u670d\u52a1\u662f\u5426\u4e3a\u5f00\u673a\u81ea\u542f\u52a8<\/td>\r\n<\/tr>\r\n<tr>\r\n<td>systemctl daemon\u0002<br \/>reload<\/td>\r\n<td>\u521b\u5efa\u65b0\u670d\u52a1\u6587\u4ef6\u6216\u8005\u53d8\u66f4\u8bbe\u7f6e<\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n<\/figure>\r\n<p>&nbsp;<\/p>\r\n\r\n<h3>systemctl \u670d\u52a1\u72b6\u6001\u8bf4\u660e<\/h3>\r\n\r\n<figure class=\"wp-block-table\">\r\n<table>\r\n<tbody>\r\n<tr>\r\n<td><strong>\u670d\u52a1\u72b6\u6001<\/strong><\/td>\r\n<td><strong>\u72b6\u6001\u8bf4\u660e<\/strong><\/td>\r\n<\/tr>\r\n<tr>\r\n<td>loaded<\/td>\r\n<td>\u670d\u52a1\u5355\u5143\u7684\u914d\u7f6e\u6587\u4ef6\u5df2\u7ecf\u88ab\u5904\u7406, \u914d\u7f6e\u653e\u5728\u4e86 \/usr\/lib\/systemd\/system\/<\/td>\r\n<\/tr>\r\n<tr>\r\n<td>active(running)<\/td>\r\n<td>\u670d\u52a1\u7684\u4e00\u4e2a\u6216\u591a\u4e2a\u8fdb\u7a0b\u5728\u8fd0\u884c\u4e2d \u6700\u5e38\u89c1\u7684\u72b6\u6001 start<\/td>\r\n<\/tr>\r\n<tr>\r\n<td>active(exited)<\/td>\r\n<td>\u4e00\u6b21\u6027\u8fd0\u884c\u7684\u670d\u52a1\u6210\u529f\u88ab\u6267\u884c\u5e76\u9000\u51fa(\u670d\u52a1\u8fd0\u884c\u540e\u5b8c\u6210\u4efb\u52a1,\u76f8\u5173\u8fdb\u7a0b\u4f1a\u81ea\u52a8\u9000\u51fa)<\/td>\r\n<\/tr>\r\n<tr>\r\n<td>active(waiting)<\/td>\r\n<td>\u670d\u52a1\u5df2\u7ecf\u8fd0\u884c\u4f46\u5728\u7b49\u5f85\u67d0\u4e2a\u4e8b\u4ef6<\/td>\r\n<\/tr>\r\n<tr>\r\n<td>inactive<\/td>\r\n<td>\u670d\u52a1\u6ca1\u6709\u5728\u8fd0\u884c stop<\/td>\r\n<\/tr>\r\n<tr>\r\n<td>enabled<\/td>\r\n<td>\u670d\u52a1\u8bbe\u5b9a\u4e3a\u5f00\u673a\u8fd0\u884c<\/td>\r\n<\/tr>\r\n<tr>\r\n<td>disabled<\/td>\r\n<td>\u670d\u52a1\u8bbe\u5b9a\u4e3a\u5f00\u673a\u4e0d\u8fd0\u884c<\/td>\r\n<\/tr>\r\n<tr>\r\n<td>static<\/td>\r\n<td>\u670d\u52a1\u4e0d\u80fd\u88ab\u8bbe\u5b9a\u5f00\u673a\u542f\u52a8,\u4f46\u53ef\u4ee5\u7531\u5176\u4ed6\u670d\u52a1\u542f\u52a8\u8be5\u670d\u52a1<\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n<\/figure>\r\n<p>&nbsp;<\/p>\r\n\r\n<h2>systemctl\u7684journalctl\u65e5\u5fd7<\/h2>\r\n<p>systemctl \u542f\u52a8\/\u91cd\u542f\/\u5173\u95ed \u670d\u52a1\u5931\u8d25,\u62a5\u9519 <br \/>journalctl -xe \u00a0 -e\u6309\u9875\u663e\u793a \u00a0 -x\u8fdb\u884c\u4e00\u4e9b\u7ffb\u8bd1,\u6307\u51fa\u4e00\u4e9b\u6545\u969c\u63d0\u793a <br \/>\u627eerror \u6216 err \u6216warn \u6216fail <br \/>journalctl -n 20 \u00a0 \u00a0\u67e5\u770b\u6700\u540e20\u884c <br \/>journalctl -f \u00a0 \u00a0 \u00a0 \u52a8\u6001\u67e5\u770b\u65e5\u5fd7 <br \/>journalctl -p err \u00a0 \u67e5\u770b\u65e5\u5fd7\u7684\u7ea7\u522b <br \/>journalctl -u crond \u67e5\u770b\u67d0\u4e2a\u670d\u52a1\u7684\u5355\u5143\u7684\u65e5\u5fd7<\/p>","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":""},"categories":[8],"tags":[],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.qiangzhenshuai.com\/index.php?rest_route=\/wp\/v2\/posts\/184"}],"collection":[{"href":"https:\/\/www.qiangzhenshuai.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.qiangzhenshuai.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.qiangzhenshuai.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.qiangzhenshuai.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=184"}],"version-history":[{"count":21,"href":"https:\/\/www.qiangzhenshuai.com\/index.php?rest_route=\/wp\/v2\/posts\/184\/revisions"}],"predecessor-version":[{"id":747,"href":"https:\/\/www.qiangzhenshuai.com\/index.php?rest_route=\/wp\/v2\/posts\/184\/revisions\/747"}],"wp:attachment":[{"href":"https:\/\/www.qiangzhenshuai.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=184"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.qiangzhenshuai.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=184"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.qiangzhenshuai.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=184"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}