签到成功

知道了

CNDBA社区CNDBA社区

Linux 7 中Service 服务管理 说明

2016-09-02 14:01 3969 0 原创 Linux
作者: dave



http://www.cndba.cn/dave/article/152


在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
……


http://www.cndba.cn/dave/article/152


--查看服务状态:http://www.cndba.cn/dave/article/152

[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 ~]#


http://www.cndba.cn/dave/article/152http://www.cndba.cn/dave/article/152

注意:不加.service 也是一样的:

http://www.cndba.cn/dave/article/152
http://www.cndba.cn/dave/article/152

[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 ~]#


http://www.cndba.cn/dave/article/152


--重启服务:

[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 ~]#



http://www.cndba.cn/dave/article/152

--禁止开机自启动:

[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...


--设置开机自启动:http://www.cndba.cn/dave/article/152

[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

用户评论
* 以下用户言论只代表其个人观点,不代表CNDBA社区的观点或立场
dave

dave

关注

人的一生应该是这样度过的:当他回首往事的时候,他不会因为虚度年华而悔恨,也不会因为碌碌无为而羞耻;这样,在临死的时候,他就能够说:“我的整个生命和全部精力,都已经献给世界上最壮丽的事业....."

  • 2239
    原创
  • 3
    翻译
  • 547
    转载
  • 186
    评论
  • 访问:6656798次
  • 积分:4249
  • 等级:核心会员
  • 排名:第1名
精华文章
    最新问题
    查看更多+
    热门文章
      热门用户
      推荐用户
        Copyright © 2016 All Rights Reserved. Powered by CNDBA · 皖ICP备2022006297号-1·

        QQ交流群

        注册联系QQ