1、安装 VNC 服务
[root@hadoop102 ~]# yum install tigervnc tigervnc-server tigervnc-server-module -y
2、复制 vnc 配置文件
[root@hadoop101 ~]# cd /lib/systemd/system/
[root@hadoop101 system]# cp vncserver@.service vncserver@:1.service
3、编辑 vnc 配置文件
[root@hadoop101 system]# vim vncserver@\:1.service
ExecStart=/usr/sbin/runuser -l root -c "/usr/bin/vncserver %i"
PIDFile=/root/.vnc/%H%i.pid
4、查看 vnc 配置文件
[root@hadoop102 system]# ls -l | grep -i vnc
5、系统加载
[root@hadoop101 system]# systemctl daemon-reload
6、设置 vnc 密码
[root@hadoop101 system]# vncpasswd
7、关闭防火墙
[root@hadoop101 system]# systemctl stop firewalld
[root@hadoop101 system]# systemctl disable firewalld
8、启动 vnc 服务
[root@hadoop102 system]# systemctl start vncserver@\:1.service
[root@hadoop102 system]# systemctl status vncserver@\:1.service
[root@hadoop102 system]# systemctl enable vncserver@\:1.service
9、查看 vnc 服务
[root@hadoop102 system]# vncserver -list
10、查看 vnc 端口
[root@hadoop101 system]# netstat -anpt | grep 5901
11、赋予权限
[root@hadoop101 ~]# vim ~/.vnc/xstartup
#!/bin/shunset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS
/etc/X11/xinit/xinitrc
# Assume either Gnome or KDE will be started by default when installed
# We want to kill the session automatically in this case when user logs out. In case you modify
# /etc/X11/xinit/Xclients or ~/.Xclients yourself to achieve a different result, then you should
# be responsible to modify below code to avoid that your session will be automatically killed
if [ -e /usr/bin/gnome-session -o -e /usr/bin/startkde ]; thenvncserver -kill $DISPLAY
fi
[root@hadoop101 ~]# chmod 755 ~/.vnc/xstartup
[root@hadoop101 ~]# reboot
尖叫提示:如果vnc连接不上,再执行这一步