在 Linux 系统中,重启服务的命令取决于所使用的初始化系统(init system)。以下是常见的几种方式:
# 重启服务
sudo systemctl restart <服务名>
# 示例:重启 Nginx
sudo systemctl restart nginx
相关操作:
- 启动服务:sudo systemctl start <服务名>
- 停止服务:sudo systemctl stop <服务名>
- 查看状态:sudo systemctl status <服务名>
- 设置开机自启:sudo systemctl enable <服务名>
- 禁用开机自启:sudo systemctl disable <服务名>
# 重启服务
sudo service <服务名> restart
# 或使用脚本路径
sudo /etc/init.d/<服务名> restart
# 示例:重启 Apache
sudo service httpd restart
# 或
sudo /etc/init.d/httpd restart
相关操作:
- 启动服务:sudo service <服务名> start
- 停止服务:sudo service <服务名> stop
- 查看状态:sudo service <服务名> status
bash
sudo restart <服务名>
nginx
、mysql
、apache2
等)。sudo
或 root 权限。bash
systemctl list-unit-files --type=service # systemd
service --status-all # SysVinit
如果不确定系统使用的初始化系统,可通过以下命令确认:
ps -p 1 -o comm=
systemd
→ 使用 systemctl
init
→ 可能是 SysVinit 或 Upstart重启 Nginx(假设系统为 Ubuntu 18.04+)
sudo systemctl restart nginx
sudo systemctl status nginx # 确认状态
根据你的系统选择对应的命令即可。如果有其他需求,欢迎补充说明!