zoukankan      html  css  js  c++  java
  • CentOS 7部署vncserver,通过vncviewer远程查看图形界面

    一、简介

    VNC (Virtual Network Console)是虚拟网络控制台的缩写。它 是一款优秀的远程控制工具软件,由著名的 AT&T 的欧洲研究实验室开发的。VNC 是在基于 UNIX 和 Linux 操作系统的免费的开源软件,远程控制能力强大,高效实用,其性能可以和 Windows 和 MAC 中的任何远程控制软件媲美。 在 Linux 中,VNC 包括以下四个命令:vncserver,vncviewer,vncpasswd,和 vncconnect。大多数情况下用户只需要其中的两个命令:vncserver 和 vncviewer。

    二、前期准备

    系统环境:CentOS 7、Windows(用于测试远程连接,版本不做要求)
    软件环境:VNC Viewer(Windows版),VNC Server(用yum安装即可)

    三、Linux 安装部署VNC Server

    1、安装图形化界面插件

    [root@micle ~]:yum groupinstall "GNOME Desktop" "Graphical Administration Tools" //过程有点慢,耐心等待
    ...
    //此处省略好多行代码...
    ...
    Dependency Updated:
      NetworkManager.x86_64 1:1.18.0-5.el7_7.2            NetworkManager-libnm.x86_64 1:1.18.0-5.el7_7.2              NetworkManager-team.x86_64 1:1.18.0-5.el7_7.2   NetworkManager-tui.x86_64 1:1.18.0-5.el7_7.2 
      NetworkManager-wifi.x86_64 1:1.18.0-5.el7_7.2       alsa-lib.x86_64 0:1.1.8-1.el7                               audit.x86_64 0:2.8.5-4.el7                      audit-libs.x86_64 0:2.8.5-4.el7
      bind-libs-lite.x86_64 32:9.11.4-9.P2.el7            bind-license.noarch 32:9.11.4-9.P2.el7                      cryptsetup-libs.x86_64 0:2.0.3-5.el7            cups-client.x86_64 1:1.6.3-40.el7
      cups-libs.x86_64 1:1.6.3-40.el7                     device-mapper.x86_64 7:1.02.158-2.el7_7.2                   device-mapper-libs.x86_64 7:1.02.158-2.el7_7.2  dhclient.x86_64 12:4.2.5-77.el7.centos
      dhcp-common.x86_64 12:4.2.5-77.el7.centos           dhcp-libs.x86_64 12:4.2.5-77.el7.centos                     elfutils-libelf.x86_64 0:0.176-2.el7            elfutils-libs.x86_64 0:0.176-2.el7
      firewalld.noarch 0:0.6.3-2.el7_7.3                  firewalld-filesystem.noarch 0:0.6.3-2.el7_7.3               kpartx.x86_64 0:0.4.9-127.el7                   krb5-libs.x86_64 0:1.15.1-37.el7_7.2
      linux-firmware.noarch 0:20190429-72.gitddde598.el7  nspr.x86_64 0:4.21.0-1.el7                                  nss.x86_64 0:3.44.0-7.el7_7                     nss-softokn.x86_64 0:3.44.0-8.el7_7
      nss-softokn-freebl.x86_64 0:3.44.0-8.el7_7          nss-sysinit.x86_64 0:3.44.0-7.el7_7                         nss-tools.x86_64 0:3.44.0-7.el7_7               nss-util.x86_64 0:3.44.0-4.el7_7
      plymouth.x86_64 0:0.8.9-0.32.20140113.el7.centos    plymouth-core-libs.x86_64 0:0.8.9-0.32.20140113.el7.centos  policycoreutils.x86_64 0:2.5-33.el7             python-firewall.noarch 0:0.6.3-2.el7_7.3
      systemd.x86_64 0:219-67.el7_7.3                     systemd-libs.x86_64 0:219-67.el7_7.3                        systemd-sysv.x86_64 0:219-67.el7_7.3
    
    Failed:
      python-urllib3.noarch 0:1.10.2-7.el7
    
    Complete!
    [root@iZ2zef2r37ijinyvlpu77lZ ~]# //以上信息说明"GNOME Desktop" "Graphical Administration Tools" 安装完毕
    

    2、登陆Linux系统(root用户)安装配置VNC Server

    [root@micle ~]:yum list | grep tigervnc //检测可以下载哪些vncserver
    tigervnc.x86_64                           1.8.0-17.el7                 base
    tigervnc-icons.noarch                     1.8.0-17.el7                 base
    tigervnc-license.noarch                   1.8.0-17.el7                 base
    tigervnc-server.x86_64                    1.8.0-17.el7                 base
    tigervnc-server-applet.noarch             1.8.0-17.el7                 base
    tigervnc-server-minimal.x86_64            1.8.0-17.el7                 base
    tigervnc-server-module.x86_64             1.8.0-17.el7                 base
    [root@micle ~]# yum -y install tigervnc-server //开始安装
    Loaded plugins: fastestmirror
    Loading mirror speeds from cached hostfile
    Resolving Dependencies
    --> Running transaction check
    ---> Package tigervnc-server.x86_64 0:1.8.0-17.el7 will be installed
    --> Processing Dependency: xorg-x11-xinit for package: tigervnc-server-1.8.0-17.el7.x86_64
    --> Processing Dependency: xorg-x11-xauth for package: tigervnc-server-1.8.0-17.el7.x86_64
    --> Processing Dependency: tigervnc-server-minimal for package: tigervnc-server-1.8.0-17.el7.x86_64
    --> Processing Dependency: libjpeg.so.62(LIBJPEG_6.2)(64bit) for package: tigervnc-server-1.8.0-17.el7.x86_64
    --> Processing Dependency: libgnutls.so.28(GNUTLS_2_12)(64bit) for package: tigervnc-server-1.8.0-17.el7.x86_64
    --> Processing Dependency: libgnutls.so.28(GNUTLS_1_4)(64bit) for package: tigervnc-server-1.8.0-17.el7.x86_64
    --> Processing Dependency: libjpeg.so.62()(64bit) for package: tigervnc-server-1.8.0-17.el7.x86_64
    --> Processing Dependency: libgnutls.so.28()(64bit) for package: tigervnc-server-1.8.0-17.el7.x86_64
    --> Processing Dependency: libXtst.so.6()(64bit) for package: tigervnc-server-1.8.0-17.el7.x86_64
    --> Processing Dependency: libXext.so.6()(64bit) for package: tigervnc-server-1.8.0-17.el7.x86_64
    --> Processing Dependency: libXdamage.so.1()(64bit) for package: tigervnc-server-1.8.0-17.el7.x86_64
    --> Processing Dependency: libX11.so.6()(64bit) for package: tigervnc-server-1.8.0-17.el7.x86_64
    --> Processing Dependency: libSM.so.6()(64bit) for package: tigervnc-server-1.8.0-17.el7.x86_64
    --> Processing Dependency: libICE.so.6()(64bit) for package: tigervnc-server-1.8.0-17.el7.x86_64
    --> Running transaction check
    ---> Package gnutls.x86_64 0:3.3.29-9.el7_6 will be installed
    --> Processing Dependency: trousers >= 0.3.11.2 for package: gnutls-3.3.29-9.el7_6.x86_64
    --> Processing Dependency: libnettle.so.4()(64bit) for package: gnutls-3.3.29-9.el7_6.x86_64
    //代码太多,此处省略...
    Installed:
      tigervnc-server.x86_64 0:1.8.0-17.el7
    
    Dependency Installed:
      gnutls.x86_64 0:3.3.29-9.el7_6                        libICE.x86_64 0:1.0.9-9.el7                      libSM.x86_64 0:1.2.2-2.el7                         libX11.x86_64 0:1.6.7-2.el7
      libX11-common.noarch 0:1.6.7-2.el7                    libXau.x86_64 0:1.0.8-2.1.el7                    libXcursor.x86_64 0:1.1.15-1.el7                   libXdamage.x86_64 0:1.1.4-4.1.el7
      libXdmcp.x86_64 0:1.1.2-6.el7                         libXext.x86_64 0:1.3.3-3.el7                     libXfixes.x86_64 0:5.0.3-1.el7                     libXfont2.x86_64 0:2.0.3-1.el7
      libXi.x86_64 0:1.7.9-1.el7                            libXinerama.x86_64 0:1.1.3-2.1.el7               libXmu.x86_64 0:1.1.2-2.el7                        libXrandr.x86_64 0:1.5.1-2.el7
      libXrender.x86_64 0:0.9.10-1.el7                      libXt.x86_64 0:1.1.5-3.el7                       libXtst.x86_64 0:1.2.3-1.el7                       libXxf86misc.x86_64 0:1.0.3-7.1.el7
      libXxf86vm.x86_64 0:1.1.4-1.el7                       libfontenc.x86_64 0:1.1.3-3.el7                  libglvnd.x86_64 1:1.0.1-0.8.git5baa1e5.el7         libglvnd-glx.x86_64 1:1.0.1-0.8.git5baa1e5.el7
      libjpeg-turbo.x86_64 0:1.2.90-8.el7                   libxcb.x86_64 0:1.13-1.el7                       libxkbfile.x86_64 0:1.0.9-3.el7                    libxshmfence.x86_64 0:1.2-1.el7
      llvm-private.x86_64 0:7.0.1-1.el7                     mesa-dri-drivers.x86_64 0:18.3.4-6.el7_7         mesa-filesystem.x86_64 0:18.3.4-6.el7_7            mesa-libGL.x86_64 0:18.3.4-6.el7_7
      mesa-libglapi.x86_64 0:18.3.4-6.el7_7                 nettle.x86_64 0:2.7.1-8.el7                      pixman.x86_64 0:0.34.0-1.el7                       tigervnc-license.noarch 0:1.8.0-17.el7
      tigervnc-server-minimal.x86_64 0:1.8.0-17.el7         trousers.x86_64 0:0.3.14-2.el7                   xkeyboard-config.noarch 0:2.24-1.el7               xorg-x11-server-utils.x86_64 0:7.7-20.el7
      xorg-x11-xauth.x86_64 1:1.0.9-1.el7                   xorg-x11-xinit.x86_64 0:1.3.4-2.el7              xorg-x11-xkb-utils.x86_64 0:7.7-14.el7
    
    Complete!
    //到此vncserver安装完毕,接下来开始配置vncserver
    
    
    

    3、配置VNC Server

    [root@micle ~]# vim /lib/systemd/system/vncserver@.service //编辑该文件,将<USER> 替换为root,保存并退出编辑
    [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"
    ExecStart=/sbin/runuser -l root -c "/usr/bin/vncserver %i"
    # 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 || :'
    
    //下面这一步,网上很多博客建议是件/lib/systemd/system/vncserver@.service 重命名为/lib/systemd/system/vncserver@:1.service
    //这里我不太建议,因为按此命名会出现一个异常:localhost.localdomain systemd[1]: PID file /root/.vnc/localhost.localdomain:1.pid not readable (yet?) after start.
    //检查 /root/.vnc/,发现没有localhost.localdomain:1.pid
    //他们给的解释是:
    //原来目录/tmp/下有一个/.X11-unix目录会占用这个pid序号资源。
    //把这个目录改名/.X11-unix.bak后,再次执行
    //#vncserver,系统正常生成了1.pid。
    
    //然并卵,因此为了避免这个问题,个人建议设置为2,亲测有效
    
    [root@micle ~]# mv /lib/systemd/system/vncserver@.service /lib/systemd/system/vncserver@:2.service
    [root@micle ~]# systemctl daemon-reload //重启systemd
    [root@micle ~]# vncpasswd //按界面要求设置vncserver服务密码,一定记住该密码,在远程连接时会用到
    Password:
    Verify:
    Would you like to enter a view-only password (y/n)? y
    Password:
    Verify:
    [root@micle ~]# systemctl enable vncserver@:2.service       //设置开机启动,这不根据个人需要开启,建议开启
    Created symlink from /etc/systemd/system/multi-user.target.wants/vncserver@:2.service to /usr/lib/systemd/system/vncserver@:2.service.
    [root@micle ~]# systemctl start vncserver@:2.service       //开启vncserver服务
    [root@micle ~]# ps -ef | grep vnc               //看到有5902端口服务,说明vncserver服务运行起来了
    root      1518     1  0 16:10 ?        00:00:00 /usr/bin/Xvnc :2 -auth /root/.Xauthority -desktop iZ2zef2r37ijinyvlpu77lZ:2 (root) -fp catalogue:/etc/X11/fontpath.d -geometry 1024x768 -pn -rfbauth /root/.vnc/passwd -rfbport 5902 -rfbwait 30000
    root      1538  1236  0 16:10 pts/1    00:00:00 grep --color=auto vnc
    [root@micle ~]#
    

    4、将vncserver服务端口加入防火墙,具体参考《CentOS 6、CentOS 7系统设置防火墙及区别》

    四、安装VNC Viewer(Windows)

    1、进入官网下载vncviewer安装程序,官网地址:

    https://www.realvnc.com/de/connect/download/viewer/

    2、双击安装程序,默认往下安装

    3、选择语言,因为我下载的英文版,所以选择“English”

    4、继续往下走

    5、接受协议继续往下

    6、选择安装目录,默认即可

    7、开始安装

    8、完成

    9、在开始打开VNC Viewer,只需输入ip、端口即可。端口就是在安装vncserver是开启的5902,也可以用2,连接名随意输入,保存

    10、双击刚才新建的连接,出现如下画面说明服务能够正常连接,如果出现链接超时提示,确认下服务名、IP、端口是否正确

    11、输入此前安装vncseerver时设置的密码

    12、接下来就是见证奇迹的时刻了,

    至此,vncserver、vncviewer 服务端和客户端都安装完毕,进入你的Liunx世界吧!!!

  • 相关阅读:
    docker架构的详解
    docker的核心原理-cgroup
    网络运维面试题
    100道linux运维笔试题
    运维岗位面试题集合
    python——筛子游戏
    同道前辈
    delphi中使用SocketStream读写数据的技巧
    百度地图API
    HTML中小meta的大作用
  • 原文地址:https://www.cnblogs.com/MicleZhou2020/p/12383010.html
Copyright © 2011-2022 走看看