如何在CentOS 7上安装和配置VNC Server

安装GNOME Desktop Packages

1
yum groupinstall "GNOME Desktop"

安装Tigervnc和依赖包

1
yum install tigervnc-server xorg-x11-fonts-Type1

创建VNC Server配置文件

复制VNC配置文件模板/lib/systemd/system/[email protected]/etc/systemd/system/vncserver@:<Port_Number>.service
我们希望VNC Server监听5903端口<Port_Number>为3,如果监听VNC Server监听5904端口<Port_Number>则为4,以此类推:

1
cp /lib/systemd/system/[email protected] /etc/systemd/system/vncserver@:3.service

修改VNC Server配置文件

修改配置文件/etc/systemd/system/vncserver@:3.service

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[Unit]
Description=Remote desktop service (VNC)
After=syslog.target network.target

[Service]
Type=forking

ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
ExecStart=/usr/sbin/runuser -l <USER> -c "/usr/bin/vncserver %i"
PIDFile=/home/<USER>/.vnc/%H%i.pid
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'

[Install]
WantedBy=multi-user.target

替换文本中的**<USER>**为你的VNC用户。

firewall添加端口

1
2
firewall-cmd --permanent --zone=public --add-port=5903/tcp
firewall-cmd --reload

设置VNC密码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
[root@vm ~]# su - test
Last login: Tue Jul 23 08:47:39 CST 2019 on pts/0
[test@vm ~]$ vncserver

You will require a password to access your desktops.

Password:
Verify:
Would you like to enter a view-only password (y/n)? n
A view-only password is not used
xauth: file /home/test/.Xauthority does not exist

New 'vm:3 (test)' desktop is vm:3

Creating default startup script /home/test/.vnc/xstartup
Creating default config /home/test/.vnc/config
Starting applications specified in /home/test/.vnc/xstartup
Log file is /home/test/.vnc/vm:3.log

启动VNC Server和设置开机启动

1
2
3
systemctl daemon-reload
systemctl start vncserver@:3.service
systemctl enable vncserver@:3.service
作者

Junle

发布于

2019-07-23

更新于

2024-03-22

许可协议

评论