CentOS搭建VNC服务
安装
安装tigervnc-server
1
yum install tigervnc-server
配置密码
1
vncpasswd
配置VNC
1
cp /lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@:1.service
编辑此文件如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
[Unit]
Description=Remote desktop service (VNC)
After=syslog.target network.target
[Service]
Type=forking
# Clean any existing files in /tmp/.X11-unix environment
ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
ExecStart=/usr/sbin/runuser -l root -c "/usr/bin/vncserver %i -geometry 1280x1024"
PIDFile=/root/.vnc/%H%i.pid
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
[Install]
WantedBy=multi-user.target
启动VNC
1
2
3
4systemctl daemon-reload
systemctl start vncserver@:1
systemctl status vncserver@:1
systemctl enable vncserver@:1为了允许外部VNC客户端连接到CentOS中的VNC服务器,您需要确保允许正确的VNC开放端口通过防火墙。如果只启动了一个VNC服务器实例,您只需打开第一个分配的VNC端口:5901 / TCP,通过发出以下命令在运行时应用防火墙配置。
1
2firewall-cmd --add-port=5901/tcp --permanent
firewall-cmd --reload
卸载
1 | yum remove tigervnc-server |
常见问题
在Windows端用VNC Viewer连接测试, 若出现蓝屏
1
yum groupinstall "GNOME Desktop" "Graphical Administration Tools"
启动服务时报错: “Job for vncserver@:1.service failed because a configured resource limit was exceeded. See “systemctl status vncserver@:1.service” and “journalctl -xe” for details.”
1
rm -f /tmp/.X11-unix/X1
在CentOS 7上出现 “runuser: user
does not exist”的错误 1
2
3pkill vnc
systemctl enable vncserver@:1
systemctl start vncserver@:1