RHCE——控制服务和守护进程

14 篇文章 0 订阅

识别自动启动的系统进程

系统启动的服务器进程由systemd系统和服务器管理器进行管理
systemctl可以缩写或者省略单元名称、进度数条目和单元说明

  • 服务单元具有.service扩展名,代表系统服务
  • 套接字单元具有.socket扩展名,代表进程之间通信
  • 路径单元具有.path扩展名,用于将服务的激活推迟到特定文件系统更改发生之后

    服务状态

[student@localhost 桌面]$ systemctl status sshd
sshd.service - OpenSSH server daemon
   Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled)
   Active: active (running) since 日 2017-07-30 22:38:24 CST; 2h 11min ago
  Process: 6723 ExecStartPre=/usr/sbin/sshd-keygen (code=exited, status=0/SUCCESS)
 Main PID: 6724 (sshd)
   CGroup: /system.slice/sshd.service
           └─6724 /usr/sbin/sshd -D

关键字描述
loaded单元配置文件已处理
active(tunning)正通过一个或多个持续进程运行
active(exited)已成功完成一次性配置
active(waiting)运行中,但是在等待事件
inactive不在运行
enable将在系统启动时启动
disabled不会iu在系统启动时启动
staic无法启用,但是可以在某一启用单元自动启动

使用systemctl列出单元文件

  1. 查询所有单元的状态,以验证系统启动
[student@localhost 桌面]$ systemctl
UNIT                        LOAD   ACTIVE SUB       DESCRIPTION
proc-sys...t_misc.automount loaded active waiting   Arbitrary Executable File Fo
sys-devi...-sda-sda1.device loaded active plugged   VMware_Virtual_S
...
  1. 仅查询服务单元的状态
[student@localhost 桌面]$ systemctl --type=service
UNIT                         LOAD   ACTIVE SUB     DESCRIPTION
abrt-ccpp.service            loaded active exited  Install ABRT coredump hook
abrt-oops.service            loaded active running ABRT kernel log watcher
abrt-xorg.service            loaded active running ABRT Xorg log watcher
...
  1. 查询处于失败或者维护的任何单元
[student@localhost 桌面]$ systemctl status rngd.service 
rngd.service - Hardware RNG Entropy Gatherer Daemon
   Loaded: loaded (/usr/lib/systemd/system/rngd.service; enabled)
   Active: active (running) since 日 2017-07-30 21:01:49 CST; 4h 14min ago
 Main PID: 911 (rngd)
   CGroup: /system.slice/rngd.service
           └─911 /sbin/rngd -f

  1. 显示特定单元的活动和启用
[student@localhost 桌面]$ systemctl is-active sshd
active
[student@localhost 桌面]$ systemctl is-enabled sshd
enabled
  1. 列出所有已加载单元的活动状态
[student@localhost 桌面]$ systemctl list-units --type=service
UNIT                         LOAD   ACTIVE SUB     DESCRIPTION
abrt-ccpp.service            loaded active exited  Install ABRT coredump hook
abrt-oops.service            loaded active running ABRT kernel log watcher
abrt-xorg.service            loaded active running ABRT Xorg log watcher
  1. 查看所有单元已启用和已禁用设置
[student@localhost 桌面]$ systemctl list-unit-files --type=service
UNIT FILE                                   STATE   
abrt-ccpp.service                           enabled 
abrt-oops.service                           enabled 
abrt-pstoreoops.service                     disabled
abrt-vmcore.service                         enabled 
abrt-xorg.service                           enabled 
abrtd.service                               enabled 
accounts-daemon.service                     enabled 
alsa-restore.service                        static  
...
  1. 仅查看失败的服务
[student@localhost 桌面]$ systemctl --failed --type=service
UNIT          LOAD   ACTIVE SUB    DESCRIPTION
kdump.service loaded failed failed Crash recovery kernel arming
rhnsd.service loaded failed failed LSB: Starts the Spacewalk Daemon

LOAD   = Reflects whether the unit definition was properly loaded.
ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
SUB    = The low-level unit activation state, values depend on unit type.

2 loaded units listed. Pass --all to see loaded but inactive units, too.
To show all installed unit files use 'systemctl list-unit-files'.

控制系统服务

1.验证进程正在运行

[student@localhost 桌面]$ ps -up 6724
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root      6724  0.0  0.0  82956   104 ?        Ss   730   0:00 /usr/sbin/sshd
[student@localhost 桌面]$ ps aux
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.5  53912  5672 ?        Ss   730   0:04 /usr/lib/syste
root         2  0.0  0.0      0     0 ?        S    730   0:00 [kthreadd]
...

2.停止服务(注意权限问题)

[root@localhost ~]# systemctl stop sshd.service 

3.启动服务(进程ID已经改变)

[root@localhost ~]# systemctl start sshd.service 

4.重启服务

[root@localhost ~]# systemctl restart sshd.service 

5.重新加载配置文件(进程ID不变)

[root@localhost ~]# systemctl reload sshd.service

5.屏蔽服务

系统中装了相互冲突的服务
屏蔽将在配置目录中创建连接,使得启动服务时什么都不会发生

[root@localhost ~]# systemctl mask sshd.service 
ln -s '/dev/null' '/etc/systemd/system/sshd.service'
[root@localhost ~]# systemctl unmask sshd.service 
rm '/etc/systemd/system/sshd.service'

使系统守护进程在系统启动时启动或停止

1.禁用服务,禁用服务并不会iu停止服务。

[root@localhost ~]# systemctl disable sshd.service 
rm '/etc/systemd/system/multi-user.target.wants/sshd.service'

2.启用服务

[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 is-enabled sshd.service 
enabled

systemctl命令摘要

任务命令
查看服务详细信息systemctl status httpd.service
停止某服务systemctl stop httpd.service
启动某服务systemctl start httpd.service
重启某服务systemctl restart httpd.service
重新加载服务配置systemctl reload httpd.service
屏蔽服务systemctl musk httpd.service
解除屏蔽systemctl unmask http.service
使某服务自动启动systemctl enable httpd.service
使某服务不自动启动systemctl disable httpd.service
检查服务状态systemctl is-active httpd.service (仅显示是否 Active)
显示所有已启动的服务systemctl list-units –type=service
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值