{"id":523,"date":"2019-01-07T17:27:55","date_gmt":"2019-01-07T09:27:55","guid":{"rendered":"http:\/\/bj.iur.me\/?p=523"},"modified":"2022-11-06T20:14:09","modified_gmt":"2022-11-06T12:14:09","slug":"%e8%bd%ac%ef%bc%9asystemctl-%e5%91%bd%e4%bb%a4%e5%ae%8c%e5%85%a8%e6%8c%87%e5%8d%97","status":"publish","type":"post","link":"https:\/\/www.iur.me\/?p=523","title":{"rendered":"\u8f6c\uff1asystemctl \u547d\u4ee4\u5b8c\u5168\u6307\u5357"},"content":{"rendered":"\n<p>\u539f\u6587\u5730\u5740\uff1ahttp:\/\/www.linuxidc.com\/Linux\/2015-07\/120833.htm<\/p>\n\n\n\n<p>Systemctl\u662f\u4e00\u4e2asystemd\u5de5\u5177\uff0c\u4e3b\u8981\u8d1f\u8d23\u63a7\u5236systemd\u7cfb\u7edf\u548c\u670d\u52a1\u7ba1\u7406\u5668\u3002<\/p>\n\n\n\n<p>Systemd\u662f\u4e00\u4e2a\u7cfb\u7edf\u7ba1\u7406\u5b88\u62a4\u8fdb\u7a0b\u3001\u5de5\u5177\u548c\u5e93\u7684\u96c6\u5408\uff0c\u7528\u4e8e\u53d6\u4ee3System V\u521d\u59cb\u8fdb\u7a0b\u3002Systemd\u7684\u529f\u80fd\u662f\u7528\u4e8e\u96c6\u4e2d\u7ba1\u7406\u548c\u914d\u7f6e\u7c7bUNIX\u7cfb\u7edf\u3002<\/p>\n\n\n\n<p>\u5728Linux\u751f\u6001\u7cfb\u7edf\u4e2d\uff0cSystemd\u88ab\u90e8\u7f72\u5230\u4e86\u5927\u591a\u6570\u7684\u6807\u51c6Linux\u53d1\u884c\u7248\u4e2d\uff0c\u53ea\u6709\u4e3a\u6570\u4e0d\u591a\u7684\u51e0\u4e2a\u53d1\u884c\u7248\u5c1a\u672a\u90e8\u7f72\u3002Systemd\u901a\u5e38\u662f\u6240\u6709\u5176\u5b83\u5b88\u62a4\u8fdb\u7a0b\u7684\u7236\u8fdb\u7a0b\uff0c\u4f46\u5e76\u975e\u603b\u662f\u5982\u6b64\u3002<\/p>\n\n\n\n<p>Manage Linux Services Using Systemctl<\/p>\n\n\n\n<p>\u4f7f\u7528Systemctl\u7ba1\u7406Linux\u670d\u52a1<\/p>\n\n\n\n<p>\u672c\u6587\u65e8\u5728\u9610\u660e\u5728\u8fd0\u884csystemd\u7684\u7cfb\u7edf\u4e0a\u201c\u5982\u4f55\u63a7\u5236\u7cfb\u7edf\u548c\u670d\u52a1\u201d\u3002<\/p>\n\n\n\n<p>Systemd\u521d\u4f53\u9a8c\u548cSystemctl\u57fa\u7840<\/p>\n\n\n\n<p>1. \u9996\u5148\u68c0\u67e5\u4f60\u7684\u7cfb\u7edf\u4e2d\u662f\u5426\u5b89\u88c5\u6709systemd\u5e76\u786e\u5b9a\u5f53\u524d\u5b89\u88c5\u7684\u7248\u672c<\/p>\n\n\n\n<p># systemd \u2013version<br> systemd 215<br> +PAM +AUDIT +SELINUX +IMA +SYSVINIT +LIBCRYPTSETUP +GCRYPT +ACL +XZ -SECCOMP -APPARMOR<br>\u4e0a\u4f8b\u4e2d\u5f88\u6e05\u695a\u5730\u8868\u660e\uff0c\u6211\u4eec\u5b89\u88c5\u4e86215\u7248\u672c\u7684systemd\u3002<\/p>\n\n\n\n<p>2. \u68c0\u67e5systemd\u548csystemctl\u7684\u4e8c\u8fdb\u5236\u6587\u4ef6\u548c\u5e93\u6587\u4ef6\u7684\u5b89\u88c5\u4f4d\u7f6e<\/p>\n\n\n\n<p># whereis systemd<br> systemd:\/usr\/lib\/systemd \/etc\/systemd \/usr\/share\/systemd \/usr\/share\/man\/man1\/systemd.1.gz<br> # whereis systemctl<br> systemctl:\/usr\/bin\/systemctl \/usr\/share\/man\/man1\/systemctl.1.gz<\/p>\n\n\n\n<p>3. \u68c0\u67e5systemd\u662f\u5426\u8fd0\u884c<\/p>\n\n\n\n<p># ps -eaf | grep [s]ystemd<br> root 10016:27?00:00:00\/usr\/lib\/systemd\/systemd \u2013switched-root \u2013system \u2013deserialize 23<br> root 4441016:27?00:00:00\/usr\/lib\/systemd\/systemd-journald<br> root 4691016:27?00:00:00\/usr\/lib\/systemd\/systemd-udevd<br> root 5551016:27?00:00:00\/usr\/lib\/systemd\/systemd-logind<br> dbus 5561016:27?00:00:00\/bin\/dbus-daemon \u2013system \u2013address=systemd:\u2013nofork \u2013nopidfile \u2013systemd-activation<br>\u6ce8\u610f\uff1asystemd\u662f\u4f5c\u4e3a\u7236\u8fdb\u7a0b\uff08PID=1\uff09\u8fd0\u884c\u7684\u3002\u5728\u4e0a\u9762\u5e26\uff08-e\uff09\u53c2\u6570\u7684ps\u547d\u4ee4\u8f93\u51fa\u4e2d\uff0c\u9009\u62e9\u6240\u6709\u8fdb\u7a0b\uff0c\uff08-a\uff09\u9009\u62e9\u9664\u4f1a\u8bdd\u524d\u5bfc\u5916\u7684\u6240\u6709\u8fdb\u7a0b\uff0c\u5e76\u4f7f\u7528\uff08-f\uff09\u53c2\u6570\u8f93\u51fa\u5b8c\u6574\u683c\u5f0f\u5217\u8868\uff08\u5373 -eaf\uff09\u3002<\/p>\n\n\n\n<p>\u4e5f\u8bf7\u6ce8\u610f\u4e0a\u4f8b\u4e2d\u540e\u968f\u7684\u65b9\u62ec\u53f7\u548c\u4f8b\u5b50\u4e2d\u5269\u4f59\u90e8\u5206\u3002\u65b9\u62ec\u53f7\u8868\u8fbe\u5f0f\u662fgrep\u7684\u5b57\u7b26\u7c7b\u8868\u8fbe\u5f0f\u7684\u4e00\u90e8\u5206\u3002<\/p>\n\n\n\n<p>4. \u5206\u6790systemd\u542f\u52a8\u8fdb\u7a0b<\/p>\n\n\n\n<p># systemd-analyze<br> Startup finished in487ms(kernel)+2.776s(initrd)+20.229s(userspace)=23.493s<\/p>\n\n\n\n<p>5. \u5206\u6790\u542f\u52a8\u65f6\u5404\u4e2a\u8fdb\u7a0b\u82b1\u8d39\u7684\u65f6\u95f4<\/p>\n\n\n\n<p># systemd-analyze blame<br> 8.565s mariadb.service<br> 7.991s webmin.service<br> 6.095s postfix.service<br> 4.311s httpd.service<br> 3.926s firewalld.service<br> 3.780s kdump.service<br> 3.238s tuned.service<br> 1.712s network.service<br> 1.394s lvm2-monitor.service<br> 1.126s systemd-logind.service<br>\u2026.<\/p>\n\n\n\n<p>6. \u5206\u6790\u542f\u52a8\u65f6\u7684\u5173\u952e\u94fe<\/p>\n\n\n\n<p># systemd-analyze critical-chain<br> The time after the unit is active or started is printed after the \u201c@\u201d character.<br> The time the unit takes to start is printed after the \u201c+\u201d character.<br> multi-user.target @20.222s<br> \u2514\u2500mariadb.service @11.657s+8.565s<br> \u2514\u2500network.target @11.168s<br> \u2514\u2500network.service @9.456s+1.712s<br> \u2514\u2500NetworkManager.service @8.858s+596ms<br> \u2514\u2500firewalld.service @4.931s+3.926s<br> \u2514\u2500basic.target @4.916s<br> \u2514\u2500sockets.target @4.916s<br> \u2514\u2500dbus.socket @4.916s<br> \u2514\u2500sysinit.target @4.905s<br> \u2514\u2500systemd-update-utmp.service @4.864s+39ms<br> \u2514\u2500auditd.service @4.563s+301ms<br> \u2514\u2500systemd-tmpfiles-setup.service @4.485s+69ms<br> \u2514\u2500rhel-import-state.service @4.342s+142ms<br> \u2514\u2500local-fs.target @4.324s<br> \u2514\u2500boot.mount @4.286s+31ms<br> \u2514\u2500systemd-fsck@dev-disk-by\\x2duuid-79f594ad\\x2da332\\x2d4730\\x2dbb5f\\x2d85d19608096<br> \u2514\u2500dev-disk-by\\x2duuid-79f594ad\\x2da332\\x2d4730\\x2dbb5f\\x2d85d196080964.device@4<br>\u91cd\u8981\uff1aSystemctl\u63a5\u53d7\u670d\u52a1\uff08.service\uff09\uff0c\u6302\u8f7d\u70b9\uff08.mount\uff09\uff0c\u5957\u63a5\u53e3\uff08.socket\uff09\u548c\u8bbe\u5907\uff08.device\uff09\u4f5c\u4e3a\u5355\u5143\u3002<\/p>\n\n\n\n<p>7. \u5217\u51fa\u6240\u6709\u53ef\u7528\u5355\u5143<\/p>\n\n\n\n<p># systemctl list-unit-files<br> UNIT FILE STATE<br> proc-sys-fs-binfmt_misc.automount static<br> dev-hugepages.mount static<br> dev-mqueue.mount static<br> proc-sys-fs-binfmt_misc.mount static<br> sys-fs-fuse-connections.mount static<br> sys-kernel-config.mount static<br> sys-kernel-debug.mount static<br> tmp.mount disabled<br> brandbot.path disabled<br>\u2026..<\/p>\n\n\n\n<p>8. \u5217\u51fa\u6240\u6709\u8fd0\u884c\u4e2d\u5355\u5143<\/p>\n\n\n\n<p># systemctl list-units<br> UNIT LOAD ACTIVE SUB DESCRIPTION<br> proc-sys-fs-binfmt_misc.automount loaded active waiting ArbitraryExecutableFileFormatsFileSyste<br> sys-devices-pc\u20260-1:0:0:0-block-sr0.device loaded active plugged VBOX_CD-ROM<br> sys-devices-pc\u2026:00:03.0-net-enp0s3.device loaded active plugged PRO\/1000 MT DesktopAdapter<br> sys-devices-pc\u202600:05.0-sound-card0.device loaded active plugged 82801AA AC\u201997 Audio Controller<br> sys-devices-pc\u2026:0:0-block-sda-sda1.device loaded active plugged VBOX_HARDDISK<br> sys-devices-pc\u2026:0:0-block-sda-sda2.device loaded active plugged LVM PV Qzyo3l-qYaL-uRUa-Cjuk-pljo-qKtX-VgBQ8<br> sys-devices-pc\u20260-2:0:0:0-block-sda.device loaded active plugged VBOX_HARDDISK<br> sys-devices-pl\u2026erial8250-tty-ttyS0.device loaded active plugged \/sys\/devices\/platform\/serial8250\/tty\/ttyS0<br> sys-devices-pl\u2026erial8250-tty-ttyS1.device loaded active plugged \/sys\/devices\/platform\/serial8250\/tty\/ttyS1<br> sys-devices-pl\u2026erial8250-tty-ttyS2.device loaded active plugged \/sys\/devices\/platform\/serial8250\/tty\/ttyS2<br> sys-devices-pl\u2026erial8250-tty-ttyS3.device loaded active plugged \/sys\/devices\/platform\/serial8250\/tty\/ttyS3<br> sys-devices-virtual-block-dm\\x2d0.device loaded active plugged \/sys\/devices\/virtual\/block\/dm-0<br> sys-devices-virtual-block-dm\\x2d1.device loaded active plugged \/sys\/devices\/virtual\/block\/dm-1<br> sys-module-configfs.device loaded active plugged \/sys\/module\/configfs<br>\u2026<\/p>\n\n\n\n<p>9. \u5217\u51fa\u6240\u6709\u5931\u8d25\u5355\u5143<\/p>\n\n\n\n<p># systemctl \u2013failed<br> UNIT LOAD ACTIVE SUB DESCRIPTION<br> kdump.service loaded failed failed Crash recovery kernel arming<br> LOAD =Reflects whether the unit definition was properly loaded.<br> ACTIVE =The high-level unit activation state, i.e. generalization of SUB.<br> SUB =The low-level unit activation state, values depend on unit type.<br> 1 loaded units listed.Pass\u2013all to see loaded but inactive units, too.<br> To show all installed unit files use\u2019systemctl list-unit-files\u2019.<\/p>\n\n\n\n<p>10. \u68c0\u67e5\u67d0\u4e2a\u5355\u5143\uff08\u5982 cron.service\uff09\u662f\u5426\u542f\u7528<\/p>\n\n\n\n<p># systemctl is-enabled crond.service<br> enabled<\/p>\n\n\n\n<p>11. \u68c0\u67e5\u67d0\u4e2a\u5355\u5143\u6216\u670d\u52a1\u662f\u5426\u8fd0\u884c<\/p>\n\n\n\n<p># systemctl status firewalld.service<br> firewalld.service \u2013 firewalld -dynamic firewall daemon<br> Loaded: loaded (\/usr\/lib\/systemd\/system\/firewalld.service; enabled)<br> Active: active (running) since Tue2015-04-2816:27:55 IST;34min ago<br> Main PID:549(firewalld)<br> CGroup:\/system.slice\/firewalld.service<br> \u2514\u2500549\/usr\/bin\/python -Es\/usr\/sbin\/firewalld \u2013nofork \u2013nopid<br> Apr2816:27:51 tecmint systemd[1]:Starting firewalld -dynamic firewall daemon\u2026<br>Apr2816:27:55 tecmint systemd[1]:Started firewalld -dynamic firewall daemon.<\/p>\n\n\n\n<p>\u4f7f\u7528Systemctl\u63a7\u5236\u5e76\u7ba1\u7406\u670d\u52a1<\/p>\n\n\n\n<p>12. \u5217\u51fa\u6240\u6709\u670d\u52a1\uff08\u5305\u62ec\u542f\u7528\u7684\u548c\u7981\u7528\u7684\uff09<\/p>\n\n\n\n<p># systemctl list-unit-files \u2013type=service<br> UNIT FILE STATE<br> arp-ethers.service disabled<br> auditd.service enabled<br> autovt@.service disabled<br> blk-availability.service disabled<br> brandbot.service static<br> collectd.service disabled<br> console-getty.service disabled<br> console-shell.service disabled<br> cpupower.service disabled<br> crond.service enabled<br> dbus-org.Fedoraproject.FirewallD1.service enabled<br>\u2026.<\/p>\n\n\n\n<p>13. Linux\u4e2d\u5982\u4f55\u542f\u52a8\u3001\u91cd\u542f\u3001\u505c\u6b62\u3001\u91cd\u8f7d\u670d\u52a1\u4ee5\u53ca\u68c0\u67e5\u670d\u52a1\uff08\u5982 httpd.service\uff09\u72b6\u6001<\/p>\n\n\n\n<p># systemctl start httpd.service<br> # systemctl restart httpd.service<br> # systemctl stop httpd.service<br> # systemctl reload httpd.service<br> # systemctl status httpd.service<br> httpd.service -TheApache HTTP Server<br> Loaded: loaded (\/usr\/lib\/systemd\/system\/httpd.service; enabled)<br> Active: active (running) since Tue2015-04-2817:21:30 IST;6s ago<br> Process:2876ExecStop=\/bin\/kill -WINCH ${MAINPID}(code=exited, status=0\/SUCCESS)<br> Main PID:2881(httpd)<br> Status:\u201dProcessing requests\u2026\u201d<br>CGroup:\/system.slice\/httpd.service<br> \u251c\u25002881\/usr\/sbin\/httpd -DFOREGROUND<br> \u251c\u25002884\/usr\/sbin\/httpd -DFOREGROUND<br> \u251c\u25002885\/usr\/sbin\/httpd -DFOREGROUND<br> \u251c\u25002886\/usr\/sbin\/httpd -DFOREGROUND<br> \u251c\u25002887\/usr\/sbin\/httpd -DFOREGROUND<br> \u2514\u25002888\/usr\/sbin\/httpd -DFOREGROUND<br> Apr2817:21:30 tecmint systemd[1]:StartingTheApache HTTP Server\u2026<br>Apr2817:21:30 tecmint httpd[2881]: AH00558: httpd:Couldnot reliably determine the server\u2019s fully q\u2026ssage<br> Apr 28 17:21:30 tecmint systemd[1]: Started The Apache HTTP Server.<br> Hint: Some lines were ellipsized, use -l to show in full.<br>\u6ce8\u610f\uff1a\u5f53\u6211\u4eec\u4f7f\u7528systemctl\u7684start\uff0crestart\uff0cstop\u548creload\u547d\u4ee4\u65f6\uff0c\u6211\u4eec\u4e0d\u4f1a\u4ece\u7ec8\u7aef\u83b7\u53d6\u5230\u4efb\u4f55\u8f93\u51fa\u5185\u5bb9\uff0c\u53ea\u6709status\u547d\u4ee4\u53ef\u4ee5\u6253\u5370\u8f93\u51fa\u3002<\/p>\n\n\n\n<p>14. \u5982\u4f55\u6fc0\u6d3b\u670d\u52a1\u5e76\u5728\u542f\u52a8\u65f6\u542f\u7528\u6216\u7981\u7528\u670d\u52a1\uff08\u5373\u7cfb\u7edf\u542f\u52a8\u65f6\u81ea\u52a8\u542f\u52a8\u670d\u52a1\uff09<\/p>\n\n\n\n<p># systemctl is-active httpd.service<br> # systemctl enable httpd.service<br> # systemctl disable httpd.service<\/p>\n\n\n\n<p>15. \u5982\u4f55\u5c4f\u853d\uff08\u8ba9\u5b83\u4e0d\u80fd\u542f\u52a8\uff09\u6216\u663e\u793a\u670d\u52a1\uff08\u5982 httpd.service\uff09<\/p>\n\n\n\n<p># systemctl mask httpd.service<br> ln -s \u2018\/dev\/null\u201d\/etc\/systemd\/system\/httpd.service\u2019<br># systemctl unmask httpd.service<br> rm \u2018\/etc\/systemd\/system\/httpd.service\u2019<\/p>\n\n\n\n<p>16. \u4f7f\u7528systemctl\u547d\u4ee4\u6740\u6b7b\u670d\u52a1<\/p>\n\n\n\n<p># systemctl kill httpd<br> # systemctl status httpd<br> httpd.service -TheApache HTTP Server<br> Loaded: loaded (\/usr\/lib\/systemd\/system\/httpd.service; enabled)<br> Active: failed (Result:exit-code) since Tue2015-04-2818:01:42 IST;28min ago<br> Main PID:2881(code=exited, status=0\/SUCCESS)<br> Status:\u201dTotal requests: 0; Current requests\/sec: 0; Current traffic: 0 B\/sec\u201d<br>Apr2817:37:29 tecmint systemd[1]: httpd.service:Got notification message from PID 2881, but recepti\u2026bled.<br> Apr2817:37:29 tecmint systemd[1]: httpd.service:Got notification message from PID 2881, but recepti\u2026bled.<br> Apr2817:37:39 tecmint systemd[1]: httpd.service:Got notification message from PID 2881, but recepti\u2026bled.<br> Apr2817:37:39 tecmint systemd[1]: httpd.service:Got notification message from PID 2881, but recepti\u2026bled.<br> Apr2817:37:49 tecmint systemd[1]: httpd.service:Got notification message from PID 2881, but recepti\u2026bled.<br> Apr2817:37:49 tecmint systemd[1]: httpd.service:Got notification message from PID 2881, but recepti\u2026bled.<br> Apr2817:37:59 tecmint systemd[1]: httpd.service:Got notification message from PID 2881, but recepti\u2026bled.<br> Apr2817:37:59 tecmint systemd[1]: httpd.service:Got notification message from PID 2881, but recepti\u2026bled.<br> Apr2818:01:42 tecmint systemd[1]: httpd.service: control process exited, code=exited status=226<br> Apr2818:01:42 tecmint systemd[1]:Unit httpd.service entered failed state.<br> Hint:Some lines were ellipsized,use-l to show in full.<\/p>\n\n\n\n<p>\u4f7f\u7528Systemctl\u63a7\u5236\u5e76\u7ba1\u7406\u6302\u8f7d\u70b9<\/p>\n\n\n\n<p>17. \u5217\u51fa\u6240\u6709\u7cfb\u7edf\u6302\u8f7d\u70b9<\/p>\n\n\n\n<p># systemctl list-unit-files \u2013type=mount<br> UNIT FILE STATE<br> dev-hugepages.mount static<br> dev-mqueue.mount static<br> proc-sys-fs-binfmt_misc.mount static<br> sys-fs-fuse-connections.mount static<br> sys-kernel-config.mount static<br> sys-kernel-debug.mount static<br> tmp.mount disabled<\/p>\n\n\n\n<p>18. \u6302\u8f7d\u3001\u5378\u8f7d\u3001\u91cd\u65b0\u6302\u8f7d\u3001\u91cd\u8f7d\u7cfb\u7edf\u6302\u8f7d\u70b9\u5e76\u68c0\u67e5\u7cfb\u7edf\u4e2d\u6302\u8f7d\u70b9\u72b6\u6001<\/p>\n\n\n\n<p># systemctl start tmp.mount<br> # systemctl stop tmp.mount<br> # systemctl restart tmp.mount<br> # systemctl reload tmp.mount<br> # systemctl status tmp.mount<br> tmp.mount -TemporaryDirectory<br> Loaded: loaded (\/usr\/lib\/systemd\/system\/tmp.mount; disabled)<br> Active: active (mounted) since Tue2015-04-2817:46:06 IST;2min48s ago<br> Where:\/tmp<br> What: tmpfs<br> Docs: man:hier(7)<br> http:\/\/www.freedesktop.org\/wiki\/Software\/systemd\/APIFileSystems<br> Process:3908ExecMount=\/bin\/mount tmpfs \/tmp -t tmpfs -o mode=1777,strictatime (code=exited, status=0\/SUCCESS)<br> Apr2817:46:06 tecmint systemd[1]:MountingTemporaryDirectory\u2026<br>Apr2817:46:06 tecmint systemd[1]: tmp.mount:Directory\/tmp to mount over isnot empty, mounting anyway.<br> Apr2817:46:06 tecmint systemd[1]:MountedTemporaryDirectory.<\/p>\n\n\n\n<p>19. \u5728\u542f\u52a8\u65f6\u6fc0\u6d3b\u3001\u542f\u7528\u6216\u7981\u7528\u6302\u8f7d\u70b9\uff08\u7cfb\u7edf\u542f\u52a8\u65f6\u81ea\u52a8\u6302\u8f7d\uff09<\/p>\n\n\n\n<p># systemctl is-active tmp.mount<br> # systemctl enable tmp.mount<br> # systemctl disable tmp.mount<\/p>\n\n\n\n<p>20. \u5728Linux\u4e2d\u5c4f\u853d\uff08\u8ba9\u5b83\u4e0d\u80fd\u542f\u7528\uff09\u6216\u53ef\u89c1\u6302\u8f7d\u70b9<\/p>\n\n\n\n<p># systemctl mask tmp.mount<br> ln -s \u2018\/dev\/null\u201d\/etc\/systemd\/system\/tmp.mount\u2019<br># systemctl unmask tmp.mount<br> rm \u2018\/etc\/systemd\/system\/tmp.mount\u2019<\/p>\n\n\n\n<p>\u4f7f\u7528Systemctl\u63a7\u5236\u5e76\u7ba1\u7406\u5957\u63a5\u53e3<\/p>\n\n\n\n<p>21. \u5217\u51fa\u6240\u6709\u53ef\u7528\u7cfb\u7edf\u5957\u63a5\u53e3<\/p>\n\n\n\n<p># systemctl list-unit-files \u2013type=socket<br> UNIT FILE STATE<br> dbus.socket static<br> dm-event.socket enabled<br> lvm2-lvmetad.socket enabled<br> rsyncd.socket disabled<br> sshd.socket disabled<br> syslog.socket static<br> systemd-initctl.socket static<br> systemd-journald.socket static<br> systemd-shutdownd.socket static<br> systemd-udevd-control.socket static<br> systemd-udevd-kernel.socket static<br> 11 unit files listed.<\/p>\n\n\n\n<p>22. \u5728Linux\u4e2d\u542f\u52a8\u3001\u91cd\u542f\u3001\u505c\u6b62\u3001\u91cd\u8f7d\u5957\u63a5\u53e3\u5e76\u68c0\u67e5\u5176\u72b6\u6001<\/p>\n\n\n\n<p># systemctl start cups.socket<br> # systemctl restart cups.socket<br> # systemctl stop cups.socket<br> # systemctl reload cups.socket<br> # systemctl status cups.socket<br> cups.socket \u2013 CUPS PrintingServiceSockets<br> Loaded: loaded (\/usr\/lib\/systemd\/system\/cups.socket; enabled)<br> Active: active (listening) since Tue2015-04-2818:10:59 IST;8s ago<br> Listen:\/var\/run\/cups\/cups.sock (Stream)<br> Apr2818:10:59 tecmint systemd[1]:Starting CUPS PrintingServiceSockets.<br> Apr2818:10:59 tecmint systemd[1]:Listening on CUPS PrintingServiceSockets.<\/p>\n\n\n\n<p>23. \u5728\u542f\u52a8\u65f6\u6fc0\u6d3b\u5957\u63a5\u53e3\uff0c\u5e76\u542f\u7528\u6216\u7981\u7528\u5b83\uff08\u7cfb\u7edf\u542f\u52a8\u65f6\u81ea\u542f\u52a8\uff09<\/p>\n\n\n\n<p># systemctl is-active cups.socket<br> # systemctl enable cups.socket<br> # systemctl disable cups.socket<\/p>\n\n\n\n<p>24. \u5c4f\u853d\uff08\u4f7f\u5b83\u4e0d\u80fd\u542f\u52a8\uff09\u6216\u663e\u793a\u5957\u63a5\u53e3<\/p>\n\n\n\n<p># systemctl mask cups.socket<br> ln -s \u2018\/dev\/null\u201d\/etc\/systemd\/system\/cups.socket\u2019<br># systemctl unmask cups.socket<br> rm \u2018\/etc\/systemd\/system\/cups.socket\u2019<\/p>\n\n\n\n<p>\u670d\u52a1\u7684CPU\u5229\u7528\u7387\uff08\u5206\u914d\u989d\uff09<\/p>\n\n\n\n<p>25. \u83b7\u53d6\u5f53\u524d\u67d0\u4e2a\u670d\u52a1\u7684CPU\u5206\u914d\u989d\uff08\u5982httpd\uff09<\/p>\n\n\n\n<p># systemctl show -p CPUShares httpd.service<br> CPUShares=1024<br>\u6ce8\u610f\uff1a\u5404\u4e2a\u670d\u52a1\u7684\u9ed8\u8ba4CPU\u5206\u914d\u4efd\u989d=1024\uff0c\u4f60\u53ef\u4ee5\u589e\u52a0\/\u51cf\u5c11\u67d0\u4e2a\u8fdb\u7a0b\u7684CPU\u5206\u914d\u4efd\u989d\u3002<\/p>\n\n\n\n<p>26. \u5c06\u67d0\u4e2a\u670d\u52a1\uff08httpd.service\uff09\u7684CPU\u5206\u914d\u4efd\u989d\u9650\u5236\u4e3a2000 CPUShares\/<\/p>\n\n\n\n<p># systemctl set-property httpd.service CPUShares=2000<br> # systemctl show -p CPUShares httpd.service<br> CPUShares=2000<br>\u6ce8\u610f\uff1a\u5f53\u4f60\u4e3a\u67d0\u4e2a\u670d\u52a1\u8bbe\u7f6eCPUShares\uff0c\u4f1a\u81ea\u52a8\u521b\u5efa\u4e00\u4e2a\u4ee5\u670d\u52a1\u540d\u547d\u540d\u7684\u76ee\u5f55\uff08\u5982 httpd.service\uff09\uff0c\u91cc\u9762\u5305\u542b\u4e86\u4e00\u4e2a\u540d\u4e3a90-CPUShares.conf\u7684\u6587\u4ef6\uff0c\u8be5\u6587\u4ef6\u542b\u6709CPUShare\u9650\u5236\u4fe1\u606f\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u65b9\u5f0f\u67e5\u770b\u8be5\u6587\u4ef6\uff1a<\/p>\n\n\n\n<p># vi \/etc\/systemd\/system\/httpd.service.d\/90-CPUShares.conf<br> [Service]<br> CPUShares=2000<\/p>\n\n\n\n<p>27. \u68c0\u67e5\u67d0\u4e2a\u670d\u52a1\u7684\u6240\u6709\u914d\u7f6e\u7ec6\u8282<\/p>\n\n\n\n<p># systemctl show httpd<br> Id=httpd.service<br> Names=httpd.service<br> Requires=basic.target<br> Wants=system.slice<br> WantedBy=multi-user.target<br> Conflicts=shutdown.target<br> Before=shutdown.target multi-user.target<br> After=network.target remote-fs.target nss-lookup.target systemd-journald.socket basic.target system.slice<br> Description=TheApache HTTP Server<br> LoadState=loaded<br> ActiveState=active<br> SubState=running<br> FragmentPath=\/usr\/lib\/systemd\/system\/httpd.service<br>\u2026.<\/p>\n\n\n\n<p>28. \u5206\u6790\u67d0\u4e2a\u670d\u52a1\uff08httpd\uff09\u7684\u5173\u952e\u94fe<\/p>\n\n\n\n<p># systemd-analyze critical-chain httpd.service<br> The time after the unit is active or started is printed after the \u201c@\u201d character.<br> The time the unit takes to start is printed after the \u201c+\u201d character.<br> httpd.service +142ms<br> \u2514\u2500network.target @11.168s<br> \u2514\u2500network.service @9.456s+1.712s<br> \u2514\u2500NetworkManager.service @8.858s+596ms<br> \u2514\u2500firewalld.service @4.931s+3.926s<br> \u2514\u2500basic.target @4.916s<br> \u2514\u2500sockets.target @4.916s<br> \u2514\u2500dbus.socket @4.916s<br> \u2514\u2500sysinit.target @4.905s<br> \u2514\u2500systemd-update-utmp.service @4.864s+39ms<br> \u2514\u2500auditd.service @4.563s+301ms<br> \u2514\u2500systemd-tmpfiles-setup.service @4.485s+69ms<br> \u2514\u2500rhel-import-state.service @4.342s+142ms<br> \u2514\u2500local-fs.target @4.324s<br> \u2514\u2500boot.mount @4.286s+31ms<br> \u2514\u2500systemd-fsck@dev-disk-by\\x2duuid-79f594ad\\x2da332\\x2d4730\\x2dbb5f\\x2d85d196080964.service@4.092s+149ms<br> \u2514\u2500dev-disk-by\\x2duuid-79f594ad\\x2da332\\x2d4730\\x2dbb5f\\x2d85d196080964.device@4.092s<\/p>\n\n\n\n<p>29. \u83b7\u53d6\u67d0\u4e2a\u670d\u52a1\uff08httpd\uff09\u7684\u4f9d\u8d56\u6027\u5217\u8868<\/p>\n\n\n\n<p># systemctl list-dependencies httpd.service<br> httpd.service<br> \u251c\u2500system.slice<br> \u2514\u2500basic.target<br> \u251c\u2500firewalld.service<br> \u251c\u2500microcode.service<br> \u251c\u2500rhel-autorelabel-mark.service<br> \u251c\u2500rhel-autorelabel.service<br> \u251c\u2500rhel-configure.service<br> \u251c\u2500rhel-dmesg.service<br> \u251c\u2500rhel-loadmodules.service<br> \u251c\u2500paths.target<br> \u251c\u2500slices.target<br> \u2502\u251c\u2500-.slice<br> \u2502\u2514\u2500system.slice<br> \u251c\u2500sockets.target<br> \u2502\u251c\u2500dbus.socket<br>\u2026.<\/p>\n\n\n\n<p>30. \u6309\u7b49\u7ea7\u5217\u51fa\u63a7\u5236\u7ec4<\/p>\n\n\n\n<p># systemd-cgls<br> \u251c\u25001\/usr\/lib\/systemd\/systemd \u2013switched-root \u2013system \u2013deserialize 23<br> \u251c\u2500user.slice<br> \u2502\u2514\u2500user-0.slice<br> \u2502\u2514\u2500session-1.scope<br> \u2502\u251c\u25002498 sshd: root@pts\/0<br> \u2502\u251c\u25002500-bash<br> \u2502\u251c\u25004521 systemd-cgls<br> \u2502\u2514\u25004522 systemd-cgls<br> \u2514\u2500system.slice<br> \u251c\u2500httpd.service<br> \u2502\u251c\u25004440\/usr\/sbin\/httpd -DFOREGROUND<br> \u2502\u251c\u25004442\/usr\/sbin\/httpd -DFOREGROUND<br> \u2502\u251c\u25004443\/usr\/sbin\/httpd -DFOREGROUND<br> \u2502\u251c\u25004444\/usr\/sbin\/httpd -DFOREGROUND<br> \u2502\u251c\u25004445\/usr\/sbin\/httpd -DFOREGROUND<br> \u2502\u2514\u25004446\/usr\/sbin\/httpd -DFOREGROUND<br> \u251c\u2500polkit.service<br> \u2502\u2514\u2500721\/usr\/lib\/polkit-1\/polkitd \u2013no-debug<br>\u2026.<\/p>\n\n\n\n<p>31. \u6309CPU\u3001\u5185\u5b58\u3001\u8f93\u5165\u548c\u8f93\u51fa\u5217\u51fa\u63a7\u5236\u7ec4<\/p>\n\n\n\n<p># systemd-cgtop<br> PathTasks%CPU MemoryInput\/s Output\/s<br> \/831.0437.8M\u2013<br>\/system.slice -0.1\u2014<br>\/system.slice\/mariadb.service 20.1\u2014<br>\/system.slice\/tuned.service 10.0\u2014<br>\/system.slice\/httpd.service 60.0\u2014<br>\/system.slice\/NetworkManager.service 1\u2014-<br>\/system.slice\/atop.service 1\u2014-<br>\/system.slice\/atopacct.service 1\u2014-<br>\/system.slice\/auditd.service 1\u2014-<br>\/system.slice\/crond.service 1\u2014-<br>\/system.slice\/dbus.service 1\u2014-<br>\/system.slice\/firewalld.service 1\u2014-<br>\/system.slice\/lvm2-lvmetad.service 1\u2014-<br>\/system.slice\/polkit.service 1\u2014-<br>\/system.slice\/postfix.service 3\u2014-<br>\/system.slice\/rsyslog.service 1\u2014-<br>\/system.slice\/system-getty.slice\/getty@tty1.service 1\u2014-<br>\/system.slice\/systemd-journald.service 1\u2014-<br>\/system.slice\/systemd-logind.service 1\u2014-<br>\/system.slice\/systemd-udevd.service 1\u2014-<br>\/system.slice\/webmin.service 1\u2014-<br>\/user.slice\/user-0.slice\/session-1.scope3\u2014-<\/p>\n\n\n\n<p>\u63a7\u5236\u7cfb\u7edf\u8fd0\u884c\u7b49\u7ea7<\/p>\n\n\n\n<p>32. \u542f\u52a8\u7cfb\u7edf\u6551\u63f4\u6a21\u5f0f<\/p>\n\n\n\n<p># systemctl rescue<br> Broadcast message from root@tecmint on pts\/0(Wed2015-04-2911:31:18 IST):<br> The system is going down to rescue mode NOW!<\/p>\n\n\n\n<p>33. \u8fdb\u5165\u7d27\u6025\u6a21\u5f0f<\/p>\n\n\n\n<p># systemctl emergency<br> Welcome to emergency mode!After logging in, type \u201cjournalctl -xb\u201d to view<br> system logs,\u201dsystemctl reboot\u201d to reboot,\u201dsystemctl default\u201d to try again<br> to boot intodefault mode.<\/p>\n\n\n\n<p>34. \u5217\u51fa\u5f53\u524d\u4f7f\u7528\u7684\u8fd0\u884c\u7b49\u7ea7<\/p>\n\n\n\n<p># systemctl get-default<br> multi-user.target<\/p>\n\n\n\n<p>35. \u542f\u52a8\u8fd0\u884c\u7b49\u7ea75\uff0c\u5373\u56fe\u5f62\u6a21\u5f0f<\/p>\n\n\n\n<p># systemctl isolate runlevel5.target<br>\u6216<br># systemctl isolate graphical.target<\/p>\n\n\n\n<p>36. \u542f\u52a8\u8fd0\u884c\u7b49\u7ea73\uff0c\u5373\u591a\u7528\u6237\u6a21\u5f0f\uff08\u547d\u4ee4\u884c\uff09<\/p>\n\n\n\n<p># systemctl isolate runlevel3.target<br>\u6216<br># systemctl isolate multiuser.target<\/p>\n\n\n\n<p>36. \u8bbe\u7f6e\u591a\u7528\u6237\u6a21\u5f0f\u6216\u56fe\u5f62\u6a21\u5f0f\u4e3a\u9ed8\u8ba4\u8fd0\u884c\u7b49\u7ea7<\/p>\n\n\n\n<p># systemctl set-default runlevel3.target<br> # systemctl set-default runlevel5.target<\/p>\n\n\n\n<p>37. \u91cd\u542f\u3001\u505c\u6b62\u3001\u6302\u8d77\u3001\u4f11\u7720\u7cfb\u7edf\u6216\u4f7f\u7cfb\u7edf\u8fdb\u5165\u6df7\u5408\u7761\u7720<\/p>\n\n\n\n<p># systemctl reboot<br> # systemctl halt<br> # systemctl suspend<br> # systemctl hibernate<br> # systemctl hybrid-sleep<br>\u5bf9\u4e8e\u4e0d\u77e5\u8fd0\u884c\u7b49\u7ea7\u4e3a\u4f55\u7269\u7684\u4eba\uff0c\u8bf4\u660e\u5982\u4e0b\u3002<\/p>\n\n\n\n<p>Runlevel 0 : \u5173\u95ed\u7cfb\u7edf<br>Runlevel 1 : \u6551\u63f4\uff1f\u7ef4\u62a4\u6a21\u5f0f<br>Runlevel 3 : \u591a\u7528\u6237\uff0c\u65e0\u56fe\u5f62\u7cfb\u7edf<br>Runlevel 4 : \u591a\u7528\u6237\uff0c\u65e0\u56fe\u5f62\u7cfb\u7edf<br>Runlevel 5 : \u591a\u7528\u6237\uff0c\u56fe\u5f62\u5316\u7cfb\u7edf<br>Runlevel 6 : \u5173\u95ed\u5e76\u91cd\u542f\u673a\u5668<br> \u5230\u6b64\u4e3a\u6b62\u5427\u3002\u4fdd\u6301\u8fde\u7ebf\uff0c\u8fdb\u884c\u8bc4\u8bba\u3002\u522b\u5fd8\u4e86\u5728\u4e0b\u9762\u7684\u8bc4\u8bba\u4e2d\u4e3a\u6211\u4eec\u63d0\u4f9b\u4e00\u4e9b\u6709\u4ef7\u503c\u7684\u53cd\u9988\u54e6\u3002\u559c\u6b22\u6211\u4eec\u3001\u4e0e\u6211\u4eec\u5206\u4eab\uff0c\u6c42\u6269\u6563\u3002<\/p>\n\n\n\n<p>\u672c\u6587\u6c38\u4e45\u66f4\u65b0\u94fe\u63a5\u5730\u5740\uff1ahttp:\/\/www.linuxidc.com\/Linux\/2015-07\/120833.htm<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u539f\u6587\u5730\u5740\uff1ahttp:\/\/www.linuxidc.com\/Linux\/2015-07\/120833.htm S [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-523","post","type-post","status-publish","format-standard","hentry","category-it"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.iur.me\/index.php?rest_route=\/wp\/v2\/posts\/523","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.iur.me\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.iur.me\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.iur.me\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.iur.me\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=523"}],"version-history":[{"count":1,"href":"https:\/\/www.iur.me\/index.php?rest_route=\/wp\/v2\/posts\/523\/revisions"}],"predecessor-version":[{"id":706,"href":"https:\/\/www.iur.me\/index.php?rest_route=\/wp\/v2\/posts\/523\/revisions\/706"}],"wp:attachment":[{"href":"https:\/\/www.iur.me\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=523"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.iur.me\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=523"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.iur.me\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=523"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}