- A+
关于TigerVNC Server的安装,可以直接使用本地yum源进行安装,安装前需要做一下准备工作,安装完成后需要配置,具体如下:
1.关闭防火墙
centos的防火墙是firewalld
- [root@haopython ~]# systemctl stop firewalld.service #停止firewall
- [root@haopython ~]# systemctl disable firewalld.service #禁止firewall开机启动
- [root@haopython ~]#
2.关闭SELinux
- [root@haopython ~]# setenforce 0 #设置SELinux 成为permissive模式 临时关闭selinux
- [root@haopython ~]# getenforce
- Permissive #宽容模式
- [root@haopython ~]# cat /etc/sysconfig/selinux
- SELINUX=disabled
- SELINUXTYPE=targeted
- [root@haopython ~]#
3.安装VNC软件
- [root@haopython ~]# yum install tigervnc-server tigervnc vnc vnc-server
4.配置VNC连接
1)备份配置文件
- [root@haopython ~]# cp /lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@:1.service
其中 vncserver@:1.service 对应的端口是5901如果是2,那端口则是5902
2)编辑复制的新文件
- [root@haopython ~]# vi /etc/systemd/system/vncserver@:1.service
- [root@haopython ~]#
找到下面部分进行修改,以root用户登录:
- [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 || :'
- [Install]
- WantedBy=multi-user.target
改成:
- ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
- ExecStart=/usr/sbin/runuser -l root -c "/usr/bin/vncserver %i"
- PIDFile=/root/.vnc/%H%i.pid
- ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
- [Install]
- WantedBy=multi-user.target
3)设置VNC密码
- [root@haopython ~]# vncpasswd
- Password:123456
- Verify:123456
5.启动VNC
- [root@haopython ~]# systemctl daemon-reload #重启daemon使上述配置生效
- [root@haopython ~]# systemctl enable vncserver@:1.service #使服务自动启动
- [root@haopython ~]# systemctl start vncserver@:1.service #启动服务
- Job for vncserver@:1.service failed because a configured resource limit was exceeded. See "systemctl status vncserver@:1.service" and "journalctl -xe" for details.
以上出错的解决办法: 删除/tmp/.X11-unix/ 目录,再启用一次即可
- [root@haopython ~]# rm -f -R /tmp/.X11-unix/
然后重启VNC
- [root@haopython ~]# systemctl enable vncserver@:1.service
- [root@haopython ~]#
6.测试VNC连接
用VNC view登录测试
7.其他补充
1)重设VNC密码
- [root@haopython ~]# vncpasswd
- Password:
- Verify:
- Would you like to enter a view-only password (y/n)? n
- A view-only password is not used
- [root@haopython ~]#
2)查看VNC状态
- [root@haopython ~]# 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 Fri 2018-05-18 13:04:53 CST; 31s ago
- Process: 1181 ExecStart=/usr/sbin/runuser -l root -c /usr/bin/vncserver %i (code=exited, status=0/SUCCESS)
- Process: 1117 ExecStartPre=/bin/sh -c /usr/bin/vncserver -kill %i > /dev/null 2>&1 || : (code=exited, status=0/SUCCESS)
- Main PID: 3562 (Xvnc)
- CGroup: /system.slice/system-vncserver.slice/vncserver@:1.service
- ? 3562 /usr/bin/Xvnc :1 -auth /root/.Xauthority -desktop haopython.com:1 (root) -fp catalogue:...
- May 18 13:04:43 haopython.com systemd[1]: Starting Remote desktop service (VNC)...
- May 18 13:04:53 haopython.com systemd[1]: Started Remote desktop service (VNC).
- [root@haopython ~]#
3)kill vncserver
- [root@haopython ~]# vncserver -kill :1
- Killing Xvnc process ID 3562
- [root@haopython ~]#
4)启动VNC
- [root@haopython ~]# vncserver :1
- New 'haopython.com:1 (root)' desktop is haopython.com:1
- Starting applications specified in /root/.vnc/xstartup
- Log file is /root/.vnc/haopython.com:1.log
- [root@haopython ~]#
5)卸载VNC
- [root@haopython ~]# yum remove tigervnc-server