首页 > 技术文章 > CentOS后台服务管理类

zyd-994264926326 2021-07-24 18:49 原文

目录

一、service 后台服务管理(临时,只对当前有效)

二、chkconfig 设置后台服务的自启配置(永久)

三、CentOS7 后添加的命令:systemctl


一、service 后台服务管理(临时,只对当前有效)

基本语法

service 服务名 status/stop/start/restart

Notes:常见服务:

firewalld:防火墙

network:网卡

案例

service network status    查看指定服务的状态
service network stop    停止指定服务
service network start    启动指定服务
service network restart    重启指定服务(刷新操作:先关闭,再开启)
service --status-all    查看系统中所有的后台服务

查看当前正在运行的服务:

service --status-all    查看系统中所有的后台服务

 

二、chkconfig 设置后台服务的自启配置(永久)

基本语法

chkconfig    查看所有服务器自启配置

案例

chkconfig firewalld off     关掉指定服务的自动启动

chkconfig firewalld on    开启指定服务的自动启动

 

三、CentOS7 后添加的命令:systemctl

该命令整合了 CentOS6 的 service 和 chkconfig

systemctl redis start

systemctl redis stop

# 开机自启动

systemctl enable redis

常用命令

查看版本号

systemctl --version

管理服务

systemctl [command] [unit]

command:

start

立刻启动后面接的 unit

stop

立刻关闭后面接的 unit

restart

立刻关闭后启动后面接的 unit,亦即执行 stop 再 start 的意思

reload

不关闭 unit 的情况下,重新载入配置文件,让设置生效

enable

设置下次开机时,后面接的 unit 会被启动。(永久)

disable

设置下次开机时,后面接的 unit 不会被启动。 (永久)

status

目前后面接的这个 unit 的状态,会列出有没有正在执行、开机时是否启动等信息。

is-active

目前有没有正在运行中。

is-enable

开机时有没有默认要启用这个 unit。

kill

向运行 unit 的进程发送信号。

show

列出 unit 的配置。

mask

注销 unit,注销后无法启动 unit

unmask

取消对 unit 的注销

 

 

推荐阅读