温馨提示×

centos vnc怎么重启服务

小樊
39
2026-10-08 15:58:42
栏目: 智能运维

在 CentOS 上重启 VNC 服务,取决于你使用的是 CentOS 6(init) 还是 CentOS 7/8(systemd),以及 VNC 的配置方式。


一、CentOS 7 / 8(systemd,推荐方式)

1. 查看 VNC 服务名

通常是:

vncserver@:1.service

:1 表示显示号(5901 端口)

2. 重启指定 VNC 会话

systemctl restart vncserver@:1.service

3. 设置开机自启(可选)

systemctl enable vncserver@:1.service

4. 查看状态

systemctl status vncserver@:1.service

二、CentOS 6(init.d)

重启 VNC 服务

service vncserver restart

或:

/etc/init.d/vncserver restart

三、直接用 vncserver 命令(用户级)

如果你是普通用户启动的 VNC(没有用 systemd):

1. 先杀掉原会话

vncserver -kill :1

2. 再启动

vncserver :1

四、常见问题排查

1. 重启失败,提示端口被占用

netstat -lntp | grep 590

确认是否有残留进程。

2. 配置位置

  • 用户配置:~/.vnc/xstartup
  • 系统服务配置:/etc/systemd/system/vncserver@.service

如果你愿意,可以告诉我:

  • CentOS 版本
  • 是 root 还是普通用户
  • 报错信息

我可以给你更精确的重启命令。

0 踩