安装
[root@localhost ~]# yum install tigervnc-server
配置
1.拷贝模板
[root@localhost ~]# cp /lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@:1.service
2.编辑
vi /etc/systemd/system/vncserver@:1.service
3.找到如下位置的内容,把 USER 替换成你自己的用户
[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"
PIDFile=/home/<USER>/.vnc/%H%i.pid
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
例如
[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 fwj -c "/usr/bin/vncserver %i"
PIDFile=/home/fwj/.vnc/%H%i.pid
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
然后设置防火墙
[root@localhost ~]# firewall-cmd --permanent --zone=public --add-service vnc-server
success
[root@localhost ~]# firewall-cmd --reload
success
然后切换到需要远程的用户下
[root@localhost ~]# su fwj
[fwj@localhost root]$ vncserver
You will require a password to access your desktops.
Password:
Verify:
xauth: file /home/fwj/.Xauthority does not exist
New 'localhost.localdomain:1 (fwj)' desktop is localhost.localdomain:1
Creating default startup script /home/fwj/.vnc/xstartup
Starting applications specified in /home/fwj/.vnc/xstartup
Log file is /home/fwj/.vnc/localhost.localdomain:1.log
然后设置开机启动,并且启动进程
[root@localhost ~]# systemctl daemon-reload
[root@localhost ~]# systemctl enable vncserver@:1.service
Created symlink from /etc/systemd/system/multi-user.target.wants/vncserver@:1.service to /etc/systemd/system/vncserver@:1.service.
[root@localhost ~]# systemctl start vncserver@:1.service
这里最好重启下
[root@localhost ~]#reboot
然后
[root@localhost ~]# systemctl status vncserver@\:1.service
● vncserver@:1.service - Remote desktop service (VNC)
Loaded: loaded (/etc/systemd/system/vncserver@:1.service; enabled; vendor preset: disabled)
Active: active (running) since Mon 2017-04-24 19:55:03 CST; 56s ago
Process: 8411 ExecStart=/usr/sbin/runuser -l fwj -c /usr/bin/vncserver %i (code=exited, status=0/SUCCESS)
Process: 8400 ExecStartPre=/bin/sh -c /usr/bin/vncserver -kill %i > /dev/null 2>&1 || : (code=exited, status=0/SUCCESS)
Main PID: 7647 (Xvnc)
CGroup: /system.slice/system-vncserver.slice/vncserver@:1.service
‣ 7647 /bin/Xvnc :1 -desktop localhost.localdomain:1 (fwj) -auth /home/fwj/.Xauthority -geometry 1024...
Apr 24 19:55:00 localhost.localdomain systemd[1]: Starting Remote desktop service (VNC)...
Apr 24 19:55:03 localhost.localdomain systemd[1]: Started Remote desktop service (VNC).
连接
1.使用 vnc chrome 的插件
2.远程桌面
通过图形界面安装 虚拟机都还好,不是特别卡(局域网内)
本文参考https://www.howtoforge.com/vnc-server-installation-on-centos-7 配置