CentOS7.3下部署TigerVNC Server过程详解

  • A+
所属分类:网站首页 运维基础

关于TigerVNC Server的安装,可以直接使用本地yum源进行安装,安装前需要做一下准备工作,安装完成后需要配置,具体如下:

1.关闭防火墙

centos的防火墙是firewalld

  1. [root@haopython ~]# systemctl stop firewalld.service  #停止firewall  
  2. [root@haopython ~]# systemctl disable firewalld.service  #禁止firewall开机启动  
  3. [root@haopython ~]  

2.关闭SELinux

  1. [root@haopython ~]# setenforce 0 #设置SELinux 成为permissive模式 临时关闭selinux  
  2. [root@haopython ~]# getenforce  
  3. Permissive  #宽容模式  
  4. [root@haopython ~]# cat /etc/sysconfig/selinux  
  5.   
  6. SELINUX=disabled  
  7. SELINUXTYPE=targeted  
  8. [root@haopython ~]  

3.安装VNC软件

  1. [root@haopython ~]# yum install tigervnc-server tigervnc vnc vnc-server  

4.配置VNC连接

1)备份配置文件

  1. [root@haopython ~]#  cp /lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@:1.service  

其中 vncserver@:1.service 对应的端口是5901如果是2,那端口则是5902

2)编辑复制的新文件

  1. [root@haopython ~]# vi /etc/systemd/system/vncserver@:1.service  
  2. [root@haopython ~]  

找到下面部分进行修改,以root用户登录:

  1. [Service]  
  2. Type=forking  
  3.   
  4. # Clean any existing files in /tmp/.X11-unix environment  
  5. ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'  
  6. ExecStart=/usr/sbin/runuser -l <USER> -c "/usr/bin/vncserver %i"  
  7. PIDFile=/home/<USER>/.vnc/%H%i.pid  
  8. ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'  
  9.   
  10. [Install]  
  11. WantedBy=multi-user.target  

改成:

  1. ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'  
  2. ExecStart=/usr/sbin/runuser -l root -c "/usr/bin/vncserver %i"  
  3. PIDFile=/root/.vnc/%H%i.pid  
  4. ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'  
  5.   
  6. [Install]  
  7. WantedBy=multi-user.target  

3)设置VNC密码

  1. [root@haopython ~]# vncpasswd  
  2. Password:123456  
  3. Verify:123456  

5.启动VNC

  1. [root@haopython ~]# systemctl daemon-reload #重启daemon使上述配置生效  
  2. [root@haopython ~]# systemctl enable vncserver@:1.service #使服务自动启动  
  3. [root@haopython ~]# systemctl start vncserver@:1.service #启动服务  
  4. 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/ 目录,再启用一次即可

  1. [root@haopython ~]# rm -f -R /tmp/.X11-unix/  

然后重启VNC

  1. [root@haopython ~]# systemctl enable vncserver@:1.service  
  2. [root@haopython ~]#  

6.测试VNC连接

用VNC view登录测试

7.其他补充

1)重设VNC密码

  1. [root@haopython ~]# vncpasswd  
  2. Password:  
  3. Verify:  
  4. Would you like to enter a view-only password (y/n)? n  
  5. A view-only password is not used  
  6. [root@haopython ~]  

2)查看VNC状态

  1. [root@haopython ~]# systemctl status vncserver@:1.service  
  2. ● vncserver@:1.service - Remote desktop service (VNC)  
  3.    Loaded: loaded (/etc/systemd/system/vncserver@:1.service; enabled; vendor preset: disabled)  
  4.    Active: active (running) since Fri 2018-05-18 13:04:53 CST; 31s ago  
  5.   Process: 1181 ExecStart=/usr/sbin/runuser -l root -c /usr/bin/vncserver %i (code=exited, status=0/SUCCESS)  
  6.   Process: 1117 ExecStartPre=/bin/sh -c /usr/bin/vncserver -kill %i > /dev/null 2>&1 || : (code=exited, status=0/SUCCESS)  
  7.  Main PID: 3562 (Xvnc)  
  8.    CGroup: /system.slice/system-vncserver.slice/vncserver@:1.service  
  9.            ? 3562 /usr/bin/Xvnc :1 -auth /root/.Xauthority -desktop haopython.com:1 (root) -fp catalogue:...  
  10.   
  11. May 18 13:04:43 haopython.com systemd[1]: Starting Remote desktop service (VNC)...  
  12. May 18 13:04:53 haopython.com systemd[1]: Started Remote desktop service (VNC).  
  13. [root@haopython ~]  

3)kill vncserver

  1. [root@haopython ~]# vncserver -kill :1  
  2. Killing Xvnc process ID 3562  
  3. [root@haopython ~]  

4)启动VNC

  1. [root@haopython ~]# vncserver :1  
  2.   
  3. New 'haopython.com:1 (root)' desktop is haopython.com:1  
  4.   
  5. Starting applications specified in /root/.vnc/xstartup  
  6. Log file is /root/.vnc/haopython.com:1.log  
  7.   
  8. [root@haopython ~]  

5)卸载VNC

  1. [root@haopython ~]# yum remove tigervnc-server  
moonrong
  • 版权声明:本站原创文章,于2019年3月21日12:05:36,由 发表,共 3645 字。
  • 版权声明: 本文由于2019年3月21日12:05:36 发表在 好派笔记,共 3645 字。

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: