2、Services linux
[root@localhost ~]# chkconfig服務器
Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by native
systemd configuration.ssh
If you want to list systemd services use 'systemctl list-unit-files'.
To see services enabled on particular target use
'systemctl list-dependencies [target]'.socket
iprdump 0:off 1:off 2:on 3:on 4:on 5:on 6:off
iprinit 0:off 1:off 2:on 3:on 4:on 5:on 6:off
iprupdate 0:off 1:off 2:on 3:on 4:on 5:on 6:off
livesys 0:off 1:off 2:off 3:on 4:on 5:on 6:off
livesys-late 0:off 1:off 2:off 3:on 4:on 5:on 6:off
netconsole 0:off 1:off 2:off 3:off 4:off 5:off 6:off
network 0:off 1:off 2:off 3:off 4:off 5:off 6:off
rhnsd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
vboxadd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
vboxadd-service 0:off 1:off 2:on 3:on 4:on 5:on 6:off
vboxadd-x11 0:off 1:off 2:off 3:on 4:off 5:on 6:offtcp
SysV已經快退居二線了,想配置服務得用systemctl,先看看默認啓動的服務吧。(若是不用grep過濾一下,輸出結果有260多行)post
[root@localhost ~]# systemctl list-unit-files|grep enabled
tmp.mount enabled
accounts-daemon.service enabled
atd.service enabled
auditd.service enabled
avahi-daemon.service enabled
bluetooth.service enabled
chronyd.service enabled
crond.service enabled
dbus-org.bluez.service enabled
dbus-org.Fedoraproject.FirewallD1.service enabled
dbus-org.freedesktop.Avahi.service enabled
dbus-org.freedesktop.NetworkManager.service enabled
dbus-org.freedesktop.nm-dispatcher.service enabled
display-manager.service enabled
dmraid-activation.service enabled
firewalld.service enabled
gdm.service enabled
getty@.service enabled
irqbalance.service enabled
iscsi.service enabled
kdump.service enabled
libstoragemgmt.service enabled
lvm2-monitor.service enabled
mdmonitor.service enabled
microcode.service enabled
multipathd.service enabled
NetworkManager-dispatcher.service enabled
NetworkManager.service enabled
packagekit-offline-update.service enabled
postfix.service enabled
rngd.service enabled
rsyslog.service enabled
rtkit-daemon.service enabled
smartd.service enabled
spice-vdagentd.service enabled
sysstat.service enabled
systemd-readahead-collect.service enabled
systemd-readahead-drop.service enabled
systemd-readahead-replay.service enabled
tuned.service enabled
avahi-daemon.socket enabled
dm-event.socket enabled
iscsid.socket enabled
iscsiuio.socket enabled
lvm2-lvmetad.socket enabled
default.target enabled
multi-user.target enabled
remote-fs.target enabledui
默認竟然沒有啓動sshd,暈!看看監聽端口:spa
[root@localhost ~]# netstat -lntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 2090/masterrest
果真沒有22,試試老辦法:code
[root@localhost ~]# chkconfig sshd on
Note: Forwarding request to 'systemctl enable sshd.service'.
ln -s '/usr/lib/systemd/system/sshd.service' '/etc/systemd/system/multi-user.target.wants/sshd.service'
能用,可是指令被轉發到 systemctl enable sshd.service ,之後控制服務就用這個指令了。試試:
禁用sshd:
[root@localhost ~]# systemctl disable sshd.service
rm '/etc/systemd/system/multi-user.target.wants/sshd.service'
啓用sshd:
[root@localhost ~]# systemctl enable sshd.service
ln -s '/usr/lib/systemd/system/sshd.service' '/etc/systemd/system/multi-user.target.wants/sshd.service'
看看:
[root@localhost ~]# systemctl list-unit-files|grep sshd.service
anaconda-sshd.service static
sshd.service enabled
[root@localhost ~]# netstat -lntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 2090/master
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 2758/sshd
tcp6 0 0 :::22 :::* LISTEN 2758/sshd
其實啓用和禁用服務就是在當前「runlevel」的配置文件目錄(/etc/systemd/system/multi-user.target.wants/)裏,
創建/usr/lib/systemd/system 裏面對應服務配置文件的軟連接;禁用服務就是刪除此軟連接。
有興趣就本身看看 /usr/lib/systemd/system 裏的文件,語法跟舊版/etc/init.d/ 裏的服務腳本徹底不一樣,也不能再用 /etc/init.d/sshd restart 之類的指令啓動服務器了。
先試試舊方法啓動服務:
[root@localhost ~]# service sshd start
Redirecting to /bin/systemctl start sshd.service
用新方法折騰一下:
[root@localhost ~]# systemctl start sshd.service
[root@localhost ~]# systemctl stop sshd.service
[root@localhost ~]# systemctl restart sshd.service
[root@localhost ~]#
若是沒有錯誤,就不會輸出任何信息,這個,,,,得習慣一下。