target介紹
- 系統爲了方便管理target來管理unit
- systemctl list-unit-files --type=target //列出系統中全部的target
- systemctl list-dependencies multi-user.target //查看指定target下面有哪些unit
- systemctl get-default //查看系統默認的target
- systemctl set-default multi-user.target
- 一個service屬於一種類型的unit
- 多個unit組成了一個target
- 一個target裏面包含了多個service
- cat /usr/lib/systemd/system/sshd.service 看[install]部分
target相關命令
- systemctl list-unit-files --type=target //列出系統中全部的target
[root@hf-01 system]# systemctl list-unit-files --type=target //列出系統中全部的target
UNIT FILE STATE
basic.target static
bluetooth.target static
cryptsetup-pre.target static
cryptsetup.target static
ctrl-alt-del.target disabled
default.target enabled
emergency.target static
等等等,只截取了一部分
- systemctl list-dependencies multi-user.target //查看指定target下面有哪些unit
- systemctl get-default //查看系統默認的target
- systemctl set-default multi-user.target //設置默認的target
[root@hf-01 system]# systemctl set-default multi-user.target
Removed symlink /etc/systemd/system/default.target.
Created symlink from /etc/systemd/system/default.target to /usr/lib/systemd/system/multi-user.target.
[root@hf-01 system]# ls /etc/systemd/system/default.target
/etc/systemd/system/default.target
[root@hf-01 system]# ls -l !$
ls -l /etc/systemd/system/default.target
lrwxrwxrwx 1 root root 41 12月 5 07:49 /etc/systemd/system/default.target -> /usr/lib/systemd/system/multi-user.target
[root@hf-01 system]#
- 一個service屬於一種類型的unit
- 多個unit組成了一個target
- 一個target裏面包含了多個service
- cat /usr/lib/systemd/system/sshd.service 看[install]部分
[root@hf-01 system]# cat /usr/lib/systemd/system/sshd.service
[Unit]
Description=OpenSSH server daemon
After=syslog.target network.target auditd.service
[Service]
EnvironmentFile=/etc/sysconfig/sshd
ExecStartPre=/usr/sbin/sshd-keygen
ExecStart=/usr/sbin/sshd -D $OPTIONS
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=on-failure
RestartSec=42s
[Install]
WantedBy=multi-user.target
[root@hf-01 system]#
- 只有multi-user.target 裏面的service能夠設置開機啓動。其餘的target設置成默認啓動沒法正常啓動。