在Linux 7 之前的版本中,管理Linux 服务有2个命令:service 和 chkconfig,而在Linux 7中,则由systemctl 命令来代替。 systemctl 命令就是service 和 chkconfig命令的合体。
可以使用如下命令查看systemctl命令的使用帮助:
[root@cndba.cn ~]# systemctl --help systemctl [OPTIONS...] {COMMAND} ... Query or send control commands to the systemd manager. -h --help Show this help --version Show package version --system Connect to system manager -H --host=[USER@]HOST Operate on remote host -M --machine=CONTAINER Operate on local container -t --type=TYPE List units of a particular type --state=STATE List units with particular LOAD or SUB or ACTIVE state -p --property=NAME Show only properties by this name -a --all Show all loaded units/properties, including dead/empty ones. To list all units installed on the system, use the 'list-unit-files' command instead. -l --full Don't ellipsize unit names on output -r --recursive Show unit list of host and local containers --reverse Show reverse dependencies with 'list-dependencies' --job-mode=MODE Specify how to deal with already queued jobs, when queueing a new job --show-types When showing sockets, explicitly show their type ……
可以使用如下命令查看当前所有的service:
[root@cndba.cn ~]# systemctl list-unit-files --type=service UNIT FILE STATE abrt-ccpp.service enabled abrt-oops.service enabled alsa-restore.service static alsa-state.service static alsa-store.service static anaconda-noshell.service static anaconda-shell@.service static anaconda-sshd.service static anaconda-tmux@.service static …… [root@cndba.cn ~]# systemctl --type=service UNIT LOAD ACTIVE SUB DESCRIPTION abrt-ccpp.service loaded active exited Install ABRT coredump hook colord.service loaded active running Manage, Install and Generate Color Profiles crond.service loaded active running Command Scheduler cups.service loaded active running CUPS Printing Service dbus.service loaded active running D-Bus System Message Bus firewalld.service loaded active running firewalld - dynamic firewall daemon gdm.service loaded active running GNOME Display Manager ……
--查看服务状态:
[root@cndba.cn ~]# systemctl status nfs-config.service ● nfs-config.service - Preprocess NFS configuration Loaded: loaded (/usr/lib/systemd/system/nfs-config.service; static; vendor preset: disabled) Active: active (exited) since Tue 2016-03-01 17:40:37 CST; 3h 10min ago Process: 694 ExecStart=/usr/lib/systemd/scripts/nfs-utils_env.sh (code=exited, status=0/SUCCESS) Main PID: 694 (code=exited, status=0/SUCCESS) CGroup: /system.slice/nfs-config.service Mar 01 17:40:37 dave systemd[1]: Starting Preprocess NFS configuration... Mar 01 17:40:37 dave systemd[1]: Started Preprocess NFS configuration. [root@cndba.cn ~]#
注意:不加.service 也是一样的:
[root@cndba.cn ~]# systemctl status nfs-config.service
--停止服务:
[root@cndba.cn ~]# systemctl stop nfs-config [root@cndba.cn ~]# systemctl status nfs-config ● nfs-config.service - Preprocess NFS configuration Loaded: loaded (/usr/lib/systemd/system/nfs-config.service; static; vendor preset: disabled) Active: inactive (dead) since Tue 2016-03-01 21:02:51 CST; 4s ago Process: 23605 ExecStart=/usr/lib/systemd/scripts/nfs-utils_env.sh (code=exited, status=0/SUCCESS) Main PID: 23605 (code=exited, status=0/SUCCESS) Mar 01 21:01:55 dave systemd[1]: Starting Preprocess NFS configuration... Mar 01 21:01:55 dave systemd[1]: Started Preprocess NFS configuration. Mar 01 21:02:51 dave systemd[1]: Stopped Preprocess NFS configuration. Mar 01 21:02:51 dave systemd[1]: Stopping Preprocess NFS configuration... [root@cndba.cn ~]#
--启动服务:
[root@cndba.cn ~]# systemctl start nfs-config.service [root@cndba.cn ~]# systemctl status nfs-config.service ● nfs-config.service - Preprocess NFS configuration Loaded: loaded (/usr/lib/systemd/system/nfs-config.service; static; vendor preset: disabled) Active: active (exited) since Tue 2016-03-01 20:52:38 CST; 1s ago Process: 22467 ExecStart=/usr/lib/systemd/scripts/nfs-utils_env.sh (code=exited, status=0/SUCCESS) Main PID: 22467 (code=exited, status=0/SUCCESS) Mar 01 20:52:38 dave systemd[1]: Starting Preprocess NFS configuration... Mar 01 20:52:38 dave systemd[1]: Started Preprocess NFS configuration. [root@cndba.cn ~]#
--重启服务:
[root@cndba.cn ~]# systemctl restart nfs-config.service [root@cndba.cn ~]# systemctl status nfs-config.service ● nfs-config.service - Preprocess NFS configuration Loaded: loaded (/usr/lib/systemd/system/nfs-config.service; static; vendor preset: disabled) Active: active (exited) since Tue 2016-03-01 20:54:02 CST; 1s ago Process: 22523 ExecStart=/usr/lib/systemd/scripts/nfs-utils_env.sh (code=exited, status=0/SUCCESS) Main PID: 22523 (code=exited, status=0/SUCCESS) Mar 01 20:54:02 dave systemd[1]: Starting Preprocess NFS configuration... Mar 01 20:54:02 dave systemd[1]: Started Preprocess NFS configuration. [root@cndba.cn ~]#
--禁止开机自启动:
[root@cndba.cn ~]# systemctl disable NetworkManager Removed symlink /etc/systemd/system/dbus-org.freedesktop.nm-dispatcher.service. Removed symlink /etc/systemd/system/multi-user.target.wants/NetworkManager.service. Removed symlink /etc/systemd/system/dbus-org.freedesktop.NetworkManager.service. [root@cndba.cn ~]# systemctl status NetworkManager ● NetworkManager.service - Network Manager Loaded: loaded (/usr/lib/systemd/system/NetworkManager.service; disabled; vendor preset: enabled) Active: active (running) since Tue 2016-03-01 17:40:39 CST; 3h 24min ago Main PID: 866 (NetworkManager) CGroup: /system.slice/NetworkManager.service ├─ 866 /usr/sbin/NetworkManager --no-daemon └─1183 /sbin/dhclient -d -q -sf /usr/libexec/nm-dhcp-helper -pf /var/run/dhclient-enp0s25.pid -lf /var/lib/NetworkManager/dhclient-21f89071-c79...
--设置开机自启动:
[root@cndba.cn ~]# systemctl enable NetworkManager Created symlink from /etc/systemd/system/dbus-org.freedesktop.NetworkManager.service to /usr/lib/systemd/system/NetworkManager.service. Created symlink from /etc/systemd/system/multi-user.target.wants/NetworkManager.service to /usr/lib/systemd/system/NetworkManager.service. Created symlink from /etc/systemd/system/dbus-org.freedesktop.nm-dispatcher.service to /usr/lib/systemd/system/NetworkManager-dispatcher.service. [root@cndba.cn ~]# systemctl status NetworkManager ● NetworkManager.service - Network Manager Loaded: loaded (/usr/lib/systemd/system/NetworkManager.service; enabled; vendor preset: enabled) Active: active (running) since Tue 2016-03-01 17:40:39 CST; 3h 24min ago Main PID: 866 (NetworkManager) CGroup: /system.slice/NetworkManager.service ├─ 866 /usr/sbin/NetworkManager --no-daemon └─1183 /sbin/dhclient -d -q -sf /usr/libexec/nm-dhcp-helper -pf /var/run/dhclient-enp0s25.pid -lf /var/lib/NetworkManager/dhclient-21f89071-c79...
版权声明:本文为博主原创文章,未经博主允许不得转载。
linux7