diff --git "a/42 \345\210\230\350\213\217\350\220\214/20240622_\346\234\215\345\212\241\347\256\241\347\220\206.md" "b/42 \345\210\230\350\213\217\350\220\214/20240622_\346\234\215\345\212\241\347\256\241\347\220\206.md" new file mode 100644 index 0000000000000000000000000000000000000000..5b611c2f5b9952f973a2d54a66c17bd7c525d674 --- /dev/null +++ "b/42 \345\210\230\350\213\217\350\220\214/20240622_\346\234\215\345\212\241\347\256\241\347\220\206.md" @@ -0,0 +1,105 @@ +### 服务管理 + +##### 使用命令 service 管理系统服务 + +1. service 命令是使用 System V 作为 init 系统的 Linux 发行版中用来控制系统服务的实用工具,service 命令的作用是去 /etc/init.d 目录下寻找相应的服务,可以启动、停止、重启系统服务,还可以显示所有系统服务的当前状态 +2. service 其实是一个 shell 脚本文件,你可以使用命令 cat 查看其中的脚本源码内容。 + +##### **命令用法:** + +1. 启动 + + ```bash + service 服务名 start + ``` + +2. 停止 + + ```bash + service 服务名 stop + ``` + +3. 查看状态 + + ```bash + service 服务名 status + ``` + +4. 重启 + + ```bash + service 服务名 restart + ``` + +5. 重新载入 + + ```bash + service 服务名 reload + ``` + +6. 开机自启动 + + ```bash + service 服务名 enable + ``` + + + +##### 使用命令 systemctl 管理系统服务 + +1. (例如:7.0 版本之后的CentOS)是使用新的管理命令 `systemctl` 来启动、停止、重启、禁用、查看系统服务,该命令集成了命令 `service`、`chkconfig`、`setup`、`init` 的大部分功能于一身 +2. 为了向前兼容,旧命令 `service` 在新版本的 Linux 中仍然可以使用,只是会被重定向到新的 `systemctl` 工具 + +**命令用法:** + +1. 启动 + + ```bash + systemctl start 服务名 + ``` + +2. 停止 + + ```bash + systemctl stop 服务名 + ``` + +3. 查看状态 + + ```bash + systemctl status 服务名 + ``` + +4. 重启 + + ```bash + systemctl restart 服务名 + ``` + +5. 重新载入 + + ```bash + systemctl reload 服务名 + ``` + +6. 开机自启动 + + ```bash + systemctl enable 服务名 + ``` + +7. 取消某个服务的开机启动 + + ```bash + systemctl disable 服务名 + ``` + +​ **双击Tab键,查看更多选项** + +**单独查看服务状态** + +```bash +systemctl is-active nginx +# 查看nginx是否在运行状态 +``` +