如果服务器为centos7_minimal版本,则需要安装desktop(服务器系统为centos7_desktop则忽略)
yum groupinstall -y "GNOME Desktop"
关闭防火墙
systemctl stop firewalld
systemctl disable firewalld[root@localhost ~]# firewall-cmd --state #查看防火墙是否关闭
not running
1.安装vnc server
yum install -y tigervnc-server tigervnc-server-module
2.复制vnc server的配置文件
vncserver@:1.service、vncserver@:2.service为连接不同的远程桌面,连接ip为ip:1、ip:2
(即为提供2个远程连接方式,VNC Server:ip:1、ip:2)
cp /lib/systemd/system/vncserver@.service /lib/systemd/system/vncserver@:1.service
cp /lib/systemd/system/vncserver@.service /lib/systemd/system/vncserver@:2.service
3.修改vncserver@:1.service、vncserver@:2.service配置文件
[root@localhost ~]# vi /lib/systemd/system/vncserver@:1.service
...
[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 <USER> -c "/usr/bin/vncserver %i"
#use root to login --GUY_GO
ExecStart=/usr/sbin/runuser -l root -c "/usr/bin/vncserver %i"
#use root to login --GUY_GO
#PIDFile=/home/<USER>/.vnc/%H%i.pid
PIDFile=/root/.vnc/%H%i.pid
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'[Install]
WantedBy=multi-user.target
4.重新加载启动配置
systemctl daemon-reload
5.设置vnc server密码
[root@localhost ~]# vncpasswd
Password:
Verify:
Passwords don't match - try again
Password:
[root@localhost ~]# vncpasswd
Password:
Verify:
Would you like to enter a view-only password (y/n)? n
A view-only password is not used
6.启动vnc server
[root@localhost ~]# vncserver #启动第一个远程桌面New 'localhost.localdomain:1 (root)' desktop is localhost.localdomain:1Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/localhost.localdomain:1.log[root@localhost ~]# vncserver #启动第二个远程桌面New 'localhost.localdomain:2 (root)' desktop is localhost.localdomain:2Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/localhost.localdomain:2.log
[root@localhost ~]#
或使用以下命令启动
systemctl start vncserver@:1.service
systemctl start vncserver@:2.service
7.关闭vncserver
pkill -9 vnc 或 systemctl stop vncserver@:1.service
8.使用VNC Viewer连接
windows下载vnc viewer并安装;