{"id":1455,"date":"2023-03-23T22:27:31","date_gmt":"2023-03-23T14:27:31","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=1455"},"modified":"2023-04-28T20:43:05","modified_gmt":"2023-04-28T12:43:05","slug":"introduction-and-use-of-systemctl-command","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/03\/23\/introduction-and-use-of-systemctl-command\/","title":{"rendered":"systemctl\u547d\u4ee4\u4ecb\u7ecd\u548c\u4f7f\u7528"},"content":{"rendered":"<h2>Systemd\u7a0b\u5e8f<\/h2>\n<p>Systemd\u5176\u5b9e\u662fLinux\u7cfb\u7edf\u7528\u6765\u7ba1\u7406\u7cfb\u7edf\u7684\u4e00\u4e2a\u7a0b\u5e8f\uff0c\u7528\u6765\u4ee3\u66ff\u539f\u6765\u7684init\u8fdb\u7a0b(\u7528\u6765\u7ba1\u7406\u542f\u52a8\u7cfb\u7edf\u5176\u5b83\u7684\u670d\u52a1\u8fdb\u7a0b)\uff0c\u73b0\u5728\u5f88\u591aLinux\u53d1\u884c\u7248\u90fd\u5df2\u7ecf\u81ea\u5e26Systemd\u7a0b\u5e8f\u3002<\/p>\n<h2>systemctl\u547d\u4ee4<\/h2>\n<p><!-- more --><\/p>\n<h3>Unit<\/h3>\n<p>systemctl\u547d\u4ee4\u662fSystemd\u4e2d\u6700\u91cd\u8981\u7684\u4e00\u4e2a\u547d\u4ee4\uff0c\u7528\u4e8e\u5bf9\u670d\u52a1\u8fdb\u884c\u542f\u52a8\uff0c\u505c\u6b62\u7b49\u64cd\u4f5c\uff0c\u5728Systemd\u4e2d\u6709Unit\u7684\u6982\u5ff5\uff0c\u6bcf\u4e2a\u8fdb\u7a0b\u90fd\u662f\u4e00\u4e2aUnit\uff0c\u603b\u5171\u6709\u5341\u4e8c\u79cdUnit\u7c7b\u578b\u3002<\/p>\n<ul>\n<li>Service unit\uff0c\u7cfb\u7edf\u670d\u52a1<\/li>\n<li>Target unit\uff0c\u591a\u4e2a Unit \u6784\u6210\u7684\u4e00\u4e2a\u7ec4<\/li>\n<li>Device Unit\uff0c\u786c\u4ef6\u8bbe\u5907<\/li>\n<li>Mount Unit\uff0c\u6587\u4ef6\u7cfb\u7edf\u7684\u6302\u8f7d\u70b9<\/li>\n<li>Automount Unit\uff0c\u81ea\u52a8\u6302\u8f7d\u70b9<\/li>\n<li>Path Unit\uff0c\u6587\u4ef6\u6216\u8def\u5f84<\/li>\n<li>Scope Unit\uff0c\u4e0d\u662f\u7531 Systemd \u542f\u52a8\u7684\u5916\u90e8\u8fdb\u7a0b<\/li>\n<li>Slice Unit\uff0c\u8fdb\u7a0b\u7ec4<\/li>\n<li>Snapshot Unit\uff0cSystemd \u5feb\u7167\uff0c\u53ef\u4ee5\u5207\u56de\u67d0\u4e2a\u5feb\u7167<\/li>\n<li>Socket Unit\uff0c\u8fdb\u7a0b\u95f4\u901a\u4fe1\u7684 socket<\/li>\n<li>Swap Unit\uff0cswap \u6587\u4ef6<\/li>\n<li>Timer Unit\uff0c\u5b9a\u65f6\u5668<\/li>\n<\/ul>\n<h3>\u5e38\u7528\u547d\u4ee4<\/h3>\n<pre><code class=\"language-bash\"># \u5217\u51fa\u6b63\u5728\u8fd0\u884c\u7684Unit\nsystemctl list-units\uff0c\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528systemctl\n\n# \u5217\u51fa\u6240\u6709Unit\uff0c\u5305\u62ec\u6ca1\u6709\u627e\u5230\u914d\u7f6e\u6587\u4ef6\u7684\u6216\u8005\u542f\u52a8\u5931\u8d25\u7684\nsystemctl list-units --all\n\n# \u5217\u51fa\u6240\u6709\u6ca1\u6709\u8fd0\u884c\u7684 Unit\nsystemctl list-units --all --state=inactive\n\n# \u5217\u51fa\u6240\u6709\u52a0\u8f7d\u5931\u8d25\u7684 Unit\nsystemctl list-units --failed\n\n# \u5217\u51fa\u6240\u6709\u6b63\u5728\u8fd0\u884c\u7684\u3001\u7c7b\u578b\u4e3aservice\u7684Unit\nsystemctl list-units --type=service\n\n# \u663e\u793a\u67d0\u4e2a Unit \u662f\u5426\u6b63\u5728\u8fd0\u884c\nsystemctl is-active application.service\n\n# \u663e\u793a\u67d0\u4e2a Unit \u662f\u5426\u5904\u4e8e\u542f\u52a8\u5931\u8d25\u72b6\u6001\nsystemctl is-failed application.service\n\n# \u663e\u793a\u67d0\u4e2a Unit \u670d\u52a1\u662f\u5426\u5efa\u7acb\u4e86\u542f\u52a8\u94fe\u63a5\nsystemctl is-enabled application.service\n\n# \u7acb\u5373\u542f\u52a8\u4e00\u4e2a\u670d\u52a1\nsudo systemctl start apache.service\n\n# \u7acb\u5373\u505c\u6b62\u4e00\u4e2a\u670d\u52a1\nsudo systemctl stop apache.service\n\n# \u91cd\u542f\u4e00\u4e2a\u670d\u52a1\nsudo systemctl restart apache.service\n\n# \u91cd\u65b0\u52a0\u8f7d\u4e00\u4e2a\u670d\u52a1\u7684\u914d\u7f6e\u6587\u4ef6\nsudo systemctl reload apache.service\n\n# \u91cd\u8f7d\u6240\u6709\u4fee\u6539\u8fc7\u7684\u914d\u7f6e\u6587\u4ef6\nsudo systemctl daemon-reload<\/code><\/pre>\n<h2>systemctl\u4e2dUnit\u7684\u914d\u7f6e\u6587\u4ef6<\/h2>\n<p>\u4e0a\u9762\u63d0\u5230\u6bcf\u4e2a\u670d\u52a1\u90fd\u662f\u4e00\u4e2aUnit\uff0c\u90a3\u6bcf\u4e2aUnit\u90fd\u4f1a\u6709\u5b83\u7684\u914d\u7f6e\u6587\u4ef6\uff0c\u8fd9\u6837\u542f\u52a8\u7684\u65f6\u5019\u624d\u77e5\u9053\u8981\u6309\u7167\u4ec0\u4e48\u65b9\u5f0f\u53bb\u542f\u52a8\u3002Systemd\u9ed8\u8ba4\u4ece\u76ee\u5f55<code>\/etc\/systemd\/system\/<\/code>\u8bfb\u53d6\u914d\u7f6e\u6587\u4ef6\u3002\u4f46\u662f\u91cc\u9762\u5b58\u653e\u7684\u5927\u90e8\u5206\u6587\u4ef6\u90fd\u662f\u7b26\u53f7\u94fe\u63a5\uff0c\u6307\u5411\u76ee\u5f55<code>\/usr\/lib\/systemd\/system\/<\/code>\uff0c<code>\/usr\/lib\/systemd\/system\/<\/code>\u624d\u662f\u771f\u6b63\u7684\u914d\u7f6e\u6587\u4ef6\u5b58\u653e\u76ee\u5f55\u3002<\/p>\n<h3>\u67e5\u770bUnit\u7684\u914d\u7f6e\u6587\u4ef6<\/h3>\n<p>\u53ef\u4ee5\u4f7f\u7528<code>systemctl cat<\/code>\u547d\u4ee4\u6765\u67e5\u770b\u670d\u52a1\u7684\u914d\u7f6e\u6587\u4ef6\uff0c\u4ee5\u4e0b\u662fMysql\u7684\u914d\u7f6e\u6587\u4ef6\uff0c\u5f88\u591a\u8f6f\u4ef6\u5df2\u7ecf\u652f\u6301Systemd\u7a0b\u5e8f\uff0c\u5b89\u88c5\u65f6\u4f1a\u81ea\u52a8\u914d\u7f6e\u5176Unit\u914d\u7f6e\u6587\u4ef6\uff0c\u4f8b\u5982Mysql\u548cNginx\u7b49\u7b49\u3002<\/p>\n<pre><code class=\"language-bash\"># systemctl cat mysqld\n# \/usr\/lib\/systemd\/system\/mysqld.service\n\n[Unit]\nDescription=MySQL Server\nDocumentation=man:mysqld(8)\nDocumentation=http:\/\/dev.mysql.com\/doc\/refman\/en\/using-systemd.html\nAfter=network.target\nAfter=syslog.target\n\n[Install]\nWantedBy=multi-user.target\n\n[Service]\nUser=mysql\nGroup=mysql\nType=forking\nPIDFile=\/var\/run\/mysqld\/mysqld.pid\n# Disable service start and stop timeout logic of systemd for mysqld service.\nTimeoutSec=0\n# Execute pre and post scripts as root\nPermissionsStartOnly=true\n# Needed to create system tables\nExecStartPre=\/usr\/bin\/mysqld_pre_systemd\n# Start main service\nExecStart=\/usr\/sbin\/mysqld --daemonize --pid-file=\/var\/run\/mysqld\/mysqld.pid $MYSQLD_OPTS\n# Use this to switch malloc implementation\nEnvironmentFile=-\/etc\/sysconfig\/mysql\n# Sets open_files_limit\nLimitNOFILE = 5000\nRestart=on-failure\nRestartPreventExitStatus=1\nPrivateTmp=false<\/code><\/pre>\n<h3>Unit\u914d\u7f6e\u6587\u4ef6\u7684\u542b\u4e49<\/h3>\n<p>\u53ef\u4ee5\u770b\u5230Unit\u914d\u7f6e\u6587\u4ef6\u6709\u5f88\u591a\u6807\u7b7e\uff0c\u4e0d\u540c\u7684\u6807\u7b7e\u4ee3\u8868\u4e0d\u540c\u7684\u610f\u601d\uff0c\u8fd9\u91cc\u53ea\u5217\u51fa\u90e8\u5206\u4ecb\u7ecd\uff0c\u53ef\u4ee5\u53bb\u5b98\u7f51\u67e5\u770bUnit\u914d\u7f6e\u6587\u4ef6\u6587\u6863\u4ecb\u7ecd:<a target=\"_blank\" rel=\"noopener\" href=\"https:\/\/www.freedesktop.org\/software\/systemd\/man\/systemd.unit.html\">https:\/\/www.freedesktop.org\/software\/systemd\/man\/systemd.unit.html<\/a>\u3002<\/p>\n<pre><code>- Unit\n   - Description\uff0c\u670d\u52a1\u7684\u63cf\u8ff0\n   - Documentation\uff0c\u6587\u6863\u4ecb\u7ecd\n   - After\uff0c\u8be5\u670d\u52a1\u8981\u5728\u4ec0\u4e48\u670d\u52a1\u542f\u52a8\u4e4b\u540e\u542f\u52a8\uff0c\u6bd4\u5982Mysql\u9700\u8981\u5728network\u548csyslog\u542f\u52a8\u4e4b\u540e\u518d\u542f\u52a8\n- Install\n   - WantedBy\uff0c\u503c\u662f\u4e00\u4e2a\u6216\u591a\u4e2aTarget\uff0c\u5f53\u524dUnit\u6fc0\u6d3b\u65f6(enable)\u7b26\u53f7\u94fe\u63a5\u4f1a\u653e\u5165\/etc\/systemd\/system\u76ee\u5f55\u4e0b\u9762\u4ee5Target\u540d+.wants\u540e\u7f00\u6784\u6210\u7684\u5b50\u76ee\u5f55\u4e2d\n   - RequiredBy\uff0c\u5b83\u7684\u503c\u662f\u4e00\u4e2a\u6216\u591a\u4e2aTarget\uff0c\u5f53\u524dUnit\u6fc0\u6d3b(enable)\u65f6\uff0c\u7b26\u53f7\u94fe\u63a5\u4f1a\u653e\u5165\/etc\/systemd\/system\u76ee\u5f55\u4e0b\u9762\u4ee5Target\u540d+.required\u540e\u7f00\u6784\u6210\u7684\u5b50\u76ee\u5f55\u4e2d\n   - Alias\uff0c\u5f53\u524dUnit\u53ef\u7528\u4e8e\u542f\u52a8\u7684\u522b\u540d\n   - Also\uff0c\u5f53\u524dUnit\u6fc0\u6d3b(enable)\u65f6\uff0c\u4f1a\u88ab\u540c\u65f6\u6fc0\u6d3b\u7684\u5176\u4ed6Unit\n- Service\n   - Type\uff0c\u5b9a\u4e49\u542f\u52a8\u65f6\u7684\u8fdb\u7a0b\u884c\u4e3a\u3002\u5b83\u6709\u4ee5\u4e0b\u51e0\u79cd\u503c\u3002\n   - Type=simple\uff0c\u9ed8\u8ba4\u503c\uff0c\u6267\u884cExecStart\u6307\u5b9a\u7684\u547d\u4ee4\uff0c\u542f\u52a8\u4e3b\u8fdb\u7a0b\n   - Type=forking\uff0c\u4ee5 fork \u65b9\u5f0f\u4ece\u7236\u8fdb\u7a0b\u521b\u5efa\u5b50\u8fdb\u7a0b\uff0c\u521b\u5efa\u540e\u7236\u8fdb\u7a0b\u4f1a\u7acb\u5373\u9000\u51fa\n   - Type=oneshot\uff0c\u4e00\u6b21\u6027\u8fdb\u7a0b\uff0cSystemd \u4f1a\u7b49\u5f53\u524d\u670d\u52a1\u9000\u51fa\uff0c\u518d\u7ee7\u7eed\u5f80\u4e0b\u6267\u884c\n   - Type=dbus\uff0c\u5f53\u524d\u670d\u52a1\u901a\u8fc7D-Bus\u542f\u52a8\n   - Type=notify\uff0c\u5f53\u524d\u670d\u52a1\u542f\u52a8\u5b8c\u6bd5\uff0c\u4f1a\u901a\u77e5Systemd\uff0c\u518d\u7ee7\u7eed\u5f80\u4e0b\u6267\u884c\n   - Type=idle\uff0c\u82e5\u6709\u5176\u4ed6\u4efb\u52a1\u6267\u884c\u5b8c\u6bd5\uff0c\u5f53\u524d\u670d\u52a1\u624d\u4f1a\u8fd0\u884c\n   - ExecStart\uff0c\u542f\u52a8\u5f53\u524d\u670d\u52a1\u7684\u547d\u4ee4\n   - ExecStartPre\uff0c\u542f\u52a8\u5f53\u524d\u670d\u52a1\u4e4b\u524d\u6267\u884c\u7684\u547d\u4ee4\n   - ExecStartPost\uff0c\u542f\u52a8\u5f53\u524d\u670d\u52a1\u4e4b\u540e\u6267\u884c\u7684\u547d\u4ee4\n   - ExecReload\uff0c\u91cd\u542f\u5f53\u524d\u670d\u52a1\u65f6\u6267\u884c\u7684\u547d\u4ee4\n   - ExecStop\uff0c\u505c\u6b62\u5f53\u524d\u670d\u52a1\u65f6\u6267\u884c\u7684\u547d\u4ee4\n   - ExecStopPost\uff0c\u505c\u6b62\u5f53\u5176\u670d\u52a1\u4e4b\u540e\u6267\u884c\u7684\u547d\u4ee4\n   - RestartSec\uff0c\u81ea\u52a8\u91cd\u542f\u5f53\u524d\u670d\u52a1\u95f4\u9694\u7684\u79d2\u6570\n   - Restart\uff0c\u5b9a\u4e49\u4f55\u79cd\u60c5\u51b5 Systemd \u4f1a\u81ea\u52a8\u91cd\u542f\u5f53\u524d\u670d\u52a1\uff0c\u53ef\u80fd\u7684\u503c\u5305\u62ecalways\uff08\u603b\u662f\u91cd\u542f\uff09\u3001on-success\u3001on-failure\u3001on-abnormal\u3001on-abort\u3001on-watchdog\n   - TimeoutSec\uff0c\u5b9a\u4e49 Systemd \u505c\u6b62\u5f53\u524d\u670d\u52a1\u4e4b\u524d\u7b49\u5f85\u7684\u79d2\u6570\n   - Environment\uff0c\u6307\u5b9a\u73af\u5883\u53d8\u91cf<\/code><\/pre>\n<h2>\u81ea\u5b9a\u4e49\u670d\u52a1\u542f\u52a8<\/h2>\n<p>\u65e2\u7136Systemd\u7684\u4f5c\u7528\u5c31\u662f\u63a7\u5236\u670d\u52a1\u7684\u542f\u52a8\uff0c\u90a3\u4e48\u5c31\u53ef\u4ee5\u628a\u81ea\u5df1\u7684\u670d\u52a1\u6dfb\u52a0\u8fdb\u53bb\uff0c\u5c31\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528systemctl\u547d\u4ee4\u6765\u63a7\u5236\u670d\u52a1\u7684\u542f\u52a8\uff0c\u6216\u8005\u662f\u8bbe\u7f6e\u5f00\u673a\u81ea\u52a8\u542f\u52a8\u7b49\u7b49\u3002<\/p>\n<h3>\u521b\u5efaUnit\u914d\u7f6e\u6587\u4ef6<\/h3>\n<p>\u5728<code>\/usr\/lib\/systemd\/system<\/code>\u76ee\u5f55\u4e2d\u521b\u5efa\u81ea\u5df1\u7684\u914d\u7f6e\u6587\u4ef6\uff0c\u4e00\u822c\u90fd\u662f<code>.service<\/code>\u7ed3\u5c3e\uff0c\u4f8b\u5982\u8fd9\u91cc\u521b\u5efa\u4e86\u4e00\u4e2a<code>test-sh.service<\/code>\u914d\u7f6e\u6587\u4ef6\uff0c\u8fd9\u4e2aUnit\u662f\u542f\u52a8\u6211\u4eec\u81ea\u5b9a\u4e49\u670d\u52a1\u7684\u4e00\u4e2ashell\u811a\u672c\u3002<\/p>\n<pre><code class=\"language-bash\"># \/usr\/lib\/systemd\/system\/test-sh.service\n[Unit]\nDescription=test sh log\n\n[Service]\nExecStart=\/opt\/dev\/shell\/test.sh\nType=forking\nKillMode=process\nRestart=on-failure\nRestartSec=30s\n\n[Install]\nWantedBy=multi-user.target<\/code><\/pre>\n<h3>\u521b\u5efa\u811a\u672c<\/h3>\n<p>\u5728\u4e0a\u9762\u914d\u7f6e\u6587\u4ef6\u6307\u5b9a\u7684\u542f\u52a8\u8def\u5f84<code>\/opt\/dev\/shell\/<\/code>\u4e0b\u521b\u5efashell\u811a\u672c\uff0c\u8fd9\u91cc\u53ea\u662f\u6bcf\u79d2\u6253\u5370\u5f53\u524d\u65f6\u95f4\uff0c\u5e76\u8f93\u51fa\u5230\u4e00\u4e2a\u6587\u672c\u4e2d\u3002<\/p>\n<pre><code class=\"language-bash\">#!\/bin\/bash\nwhile true\ndo\nsleep 1\n  date=`date -d today +&quot;%Y-%m-%d %T&quot;`\n  echo ${date} &gt;&gt; \/opt\/dev\/shell\/test.txt\ndone<\/code><\/pre>\n<h3>\u8f7d\u5165\u914d\u7f6e\u6587\u4ef6\u5e76\u542f\u52a8<\/h3>\n<p>\u4f7f\u7528<code>systemctl daemon-reload<\/code>\u547d\u4ee4\u6765\u8f7d\u5165\u65b0\u6dfb\u52a0\u7684\u914d\u7f6e\u6587\u4ef6\uff0c\u7136\u540e\u4f7f\u7528<code>systemctl start test-sh.service<\/code>\u547d\u4ee4\u542f\u52a8\uff0c\u518d\u4f7f\u7528<code>systemctl status test-sh.service<\/code>\u547d\u4ee4\u6765\u67e5\u770b\u72b6\u6001\uff0c\u53ef\u4ee5\u770b\u5230\u5df2\u7ecf\u542f\u52a8\uff0c<code>\/opt\/dev\/shell\/test.txt<\/code>\u4e5f\u786e\u5b9e\u5728\u4e0d\u505c\u7684\u5199\u5165\u5185\u5bb9\uff0c\u6700\u540e\u4f7f\u7528<code>systemctl stop test-sh.service<\/code>\u547d\u4ee4\u505c\u6b62\u670d\u52a1\uff0c\u53ef\u4ee5\u770b\u5230\u72b6\u6001\u4e3a\u505c\u6b62\u3002<\/p>\n<p>\u6ce8\u610f\u7684\u662f\u4fee\u6539\u914d\u7f6e\u6587\u4ef6\u540e\u4e00\u5b9a\u8981\u4f7f\u7528<code>systemctl daemon-reload<\/code>\u547d\u4ee4\u6765\u8f7d\u5165\u65b0\u6dfb\u52a0\u7684\u914d\u7f6e\u6587\u4ef6\uff0c\u7136\u540e\u518d\u542f\u52a8\u670d\u52a1\u3002<\/p>\n<pre><code class=\"language-bash\"># systemctl start test-sh.service\n\n# systemctl status test-sh.service\n\u25cf test-sh.service - test sh log\n   Loaded: loaded (\/usr\/lib\/systemd\/system\/test-sh.service; enabled; vendor preset: disabled)\n   Active: activating (start) since Fri 2020-06-26 05:46:45 CST; 11s ago\n   Control: 9295 (test.sh)\n   CGroup: \/system.slice\/test-sh.service\n       \u251c\u25009295 \/bin\/bash \/opt\/dev\/shell\/test.sh\n       \u2514\u25009343 sleep 1\n\nJun 26 05:46:45 appblog-web systemd[1]: Starting test sh log...\n\n# systemctl stop test-sh.service\n\n# systemctl status test-sh.service\n\u25cf test-sh.service - test sh log\n   Loaded: loaded (\/usr\/lib\/systemd\/system\/test-sh.service; enabled; vendor preset: disabled)\n   Active: inactive (dead) since Fri 2020-06-26 05:47:52 CST; 2s ago\n  Process: 9295 ExecStart=\/opt\/dev\/shell\/test.sh (code=killed, signal=TERM)\n\nJun 26 05:46:45 appblog-web systemd[1]: Starting test sh log...<\/code><\/pre>\n<h2>\u67e5\u770bUnit\u542f\u52a8\u65e5\u5fd7<\/h2>\n<p>Systemd\u7edf\u4e00\u7ba1\u7406\u4e86\u6240\u6709Unit\u7684\u542f\u52a8\u65e5\u5fd7\uff0c\u56e0\u6b64\u53ea\u9700\u8981\u4f7f\u7528journalctl\u547d\u4ee4\u5c31\u53ef\u4ee5\u67e5\u770b\u5230\u670d\u52a1\u7684\u65e5\u5fd7<\/p>\n<pre><code class=\"language-bash\"># \u67e5\u770b\u6240\u6709\u65e5\u5fd7\uff08\u9ed8\u8ba4\u60c5\u51b5\u4e0b \uff0c\u53ea\u4fdd\u5b58\u672c\u6b21\u542f\u52a8\u7684\u65e5\u5fd7\uff09\njournalctl\n\n# \u67e5\u770b\u6307\u5b9a\u65f6\u95f4\u7684\u65e5\u5fd7\njournalctl --since=&quot;2019-10-30 18:16:12&quot;\njournalctl --since &quot;20 min ago&quot;\njournalctl --since yesterday\njournalctl --since &quot;2015-01-10&quot; --until &quot;2019-01-11 03:00&quot;\njournalctl --since 09:00 --until &quot;1 hour ago&quot;\n\n# \u663e\u793a\u5c3e\u90e8\u7684\u6700\u65b010\u884c\u65e5\u5fd7\njournalctl -n\n\n# \u663e\u793a\u5c3e\u90e8\u6307\u5b9a\u884c\u6570\u7684\u65e5\u5fd7\njournalctl -n 20\n\n# \u5b9e\u65f6\u6eda\u52a8\u663e\u793a\u6700\u65b0\u65e5\u5fd7\njournalctl -f\n\n# \u67e5\u770b\u6307\u5b9a\u670d\u52a1\u7684\u65e5\u5fd7\njournalctl \/usr\/lib\/systemd\/systemd\n\n# \u67e5\u770b\u6307\u5b9a\u8fdb\u7a0b\u7684\u65e5\u5fd7\njournalctl _PID=1\n\n# \u67e5\u770b\u67d0\u4e2a\u8def\u5f84\u7684\u811a\u672c\u7684\u65e5\u5fd7\njournalctl \/usr\/bin\/bash\n\n# \u67e5\u770b\u6307\u5b9a\u7528\u6237\u7684\u65e5\u5fd7\njournalctl _UID=33 --since today\n\n# \u67e5\u770b\u67d0\u4e2a Unit \u7684\u65e5\u5fd7\njournalctl -u nginx.service\njournalctl -u nginx.service --since today\n\n# \u5b9e\u65f6\u6eda\u52a8\u663e\u793a\u67d0\u4e2a Unit \u7684\u6700\u65b0\u65e5\u5fd7\njournalctl -u nginx.service -f\n\n# \u5408\u5e76\u663e\u793a\u591a\u4e2a Unit \u7684\u65e5\u5fd7\n$ journalctl -u nginx.service -u php-fpm.service --since today<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Systemd\u7a0b\u5e8f Systemd\u5176\u5b9e\u662fLinux\u7cfb\u7edf\u7528\u6765\u7ba1\u7406\u7cfb\u7edf\u7684\u4e00\u4e2a\u7a0b\u5e8f\uff0c\u7528\u6765\u4ee3\u66ff\u539f\u6765\u7684init\u8fdb\u7a0b(\u7528\u6765 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[331],"tags":[],"class_list":["post-1455","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1455","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=1455"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1455\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=1455"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=1455"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=1455"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}