基础环境:CentOS 7 步骤如下: 1、如果防火墙有运行,需要放行vnc服务 firewall-cmd --permanent --add-service vnc-server systemctl restart firewalld.service 关闭SELinux,将/etc/selinux中的 Enforcing 改成 disable vi /etc/sysconfig/selinux 2、更改启动模式【命令行模式、桌面模式】 查看目前的启动模式: systemctl get-default # multi-user.target: analogous to runlevel 3 //命令行模式 # graphical.target: analogous to runlevel 5 //图形界面模式 更改启动模式为图形界面模式: systemctl set-default graphical.target 更改启动模式为命令行界面: systemctl set-default multi-user.target 3、检查是否已经安装必须的软件:tigervnc-server vnc vnc-server e.g rpm -qa tigervnc-server 如果没有安装则使用yum进行安装 yum install -y tigervnc-server tigervnc vnc vnc-server 4、安装桌面 yum groupinstall "GNOME Desktop" "X Window System" "Desktop" 5、配置vnc连接 [root@localhost ~]# cp /lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@:1.service 修改/etc/systemd/system/vncserver@:1.service 找到这一行 ExecStart=/sbin/runuser -l <USER> -c "/usr/bin/vncserver %i" PIDFile=/home/<USER>/.vnc/%H%i.pid 6、为vnc设置密码,至少6位 [root@localhost ~]# vncpasswd Password: Verify: Would you like to enter a view-only password (y/n)? n #注意表示"是否输入一个只能查看的密码,选择否",否则连接vnc会出现黑屏 A view-only password is not used

[root@localhost ~]# vim /etc/libvirt/qemu.conf vnc_password = "123456" vnc_listen = "0.0.0.0" 7、更改完配置后,重载systemd [root@localhost ~]# systemctl daemon-reload 8、启动vnc服务,并设置为开机启动 systemctl start vncserver@:1.service systemctl enable vncserver@:1.service 9、关闭vnc服务 /usr/bin/vncserver -kill :1

可以通过noVNC来测试vnc服务 1、确认服务器已经装了git,如果没有安装的话,可以使用yum进行安装 yum install -y git 2、把noVNC的项目克隆下来 git clone git://github.com/kanaka/noVNC cd noVNC 3、启动VNC服务 vncserver :1 执行vncserver :1设置为1时,下面要运行noVNC是的端口号应该是5900+1,那就是5901. 4、VNC本身网络传输是明文的,所以可以通过openssl进行加密 openssl req -new -x509 -days 365 -nodes -out self.pem -keyout self.pem 并非所有的信息都需要填,hostname可以填一下 self.pem生成好后需要放置到noVNC/utils目录,当启动noVNC时,websockify将自动装载证书。 5、运行noVNC ./utils/launch.sh --vnc localhost:5901 服务启动后,会显示一个链接地址,例如: http://localhost:6080/vnc.html?host=localhost&port=6080 通过在浏览器输入url地址可以访问到noVNC http://IP:6080/vnc.html 如果无法访问的话,可能是防火墙的问题,此时需要放行6080端口和5901端口 firewall-cmd --zone=public --add-port=6080/tcp --permanent firewall-cmd --zone=public --add-port=5901/tcp --permanent firewall-cmd --reload 再次访问,输入密码即可 6、此时就可以看到服务器的图形界面并进行操作