diff --git "a/\347\216\213\345\217\213\351\221\253/20240622-\346\234\215\345\212\241\347\256\241\347\220\206.md" "b/\347\216\213\345\217\213\351\221\253/20240622-\346\234\215\345\212\241\347\256\241\347\220\206.md" new file mode 100644 index 0000000000000000000000000000000000000000..08a71891fd236cafce3ed42a6df8bd11c64edca0 --- /dev/null +++ "b/\347\216\213\345\217\213\351\221\253/20240622-\346\234\215\345\212\241\347\256\241\347\220\206.md" @@ -0,0 +1,55 @@ +## 什么是服务 + +常驻内存在后台运行,响应用户或其他进程的请求,并提供对某种功能服务的程序 + +## 服务管理管什么 + +| 相关命令 | 启用 | 关闭 | 重启 | 重新加载 | 开机自启动 | 查看状态 | 语法 | +| ------------ | ----- | ---- | ------- | -------- | ---------- | -------- | ----------------------- | +| systemctl | start | stop | restart | reload | enable | status | systemctl start nginx | +| service | start | stop | restart | reload | enable | status | service nginx start | +| /etc/init.d/ | start | stop | restart | reload | enable | status | /etc/init.d/nginx start | + +service --status -all :列出所有正在运行的服务 + +## systemctl + +```bash +systemctl start nginx # 启动服务 + +systemctl stop nginx # 关闭服务 + +systemctl restart nginx # 重启服务 + +systemctl status nginx# 显示服务的状态 + +systemctl enable nginx # 在开机时启用服务 + +systemctl disable nginx # 在开机时禁用服务 + +systemctl is-enabled nginx # 查看服务是否开机启动 + +systemctl list-unit-files|grep enabled # 查看已启动的服务列表 + +systemctl list-unit-files # 列出已经安装的服务 + +systemctl --failed # 查看启动失败的服务列表 + +systemctl --version # 查看版本号 +``` + +## service + +服务(service) 本质就是进程,但是是运行在后台的,通常都会监听某个端口,等待其它程序的请求,比如(mysqld , sshd、防火墙等),因此我们又称为**守护进程**,是 Linux 中非常重要的知识点。 + +### service管理指令 + +- 请使用 `service` 指令,查看,关闭,启动 `network` [注意:在虚拟系统演示,因为网络连接会关闭] + 指令: + +```shell +service network status +service network stop +service network start +``` +