Red Hat Enterprise Linux 8 的新玩意 第5篇tigervnc

Red Hat Enterprise Linux 8 的新玩意 第5篇tigervnc



1. 环境

  • Red Hat Enterprise Linux release 8.2 (Ootpa)
  • 4.18.0-193.el8.x86_64
  • tigervnc-server-1.10.1-9.el8_3.x86_64


    2. 安装需要的 VNC 组件

    1
    # yum install -y tigervnc tigervnc-server


    3. 配置vncserver访问的password

    1
    # vncpasswd


    4. 创建需要的systemd文件 (使用tigervnc-server自带的例子文件就可以了)

    1
    # cp /usr/lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@\:1.service


    5. 添加需要访问的用户

    1
    # echo ":1=root" >> /etc/tigervnc/vncserver.users


    6. 重新加载daemon然后启动vncserver (可以配置enable)

    1
    2
    3
    4
    # systemctl daemon-reload
    # systemctl start vncserver@\:1.service
    # 可选
    # systemctl enable vncserver@\:1.service


    附录 1: 配置文件 /usr/lib/systemd/system/vncserver@\:1.service

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    # egrep -v "^#|^$" -r /usr/lib/systemd/system/vncserver@\:1.service
    [Unit]
    Description=Remote desktop service (VNC)
    After=syslog.target network.target
    [Service]
    Type=forking
    ExecStart=/usr/libexec/vncsession-start %i
    PIDFile=/var/run/vncsession-%i.pid
    SELinuxContext=system_u:system_r:vnc_session_t:s0
    [Install]
    WantedBy=multi-user.target


    附录 2: 配置文件 /etc/tigervnc/vncserver.users

    1
    2
    3
    4
    5
    6
    7
    8
    # TigerVNC User assignment
    #
    # This file assigns users to specific VNC display numbers.
    # The syntax is <display>=<username>. E.g.:
    #
    # :2=andrew
    # :3=lisa
    :1=root


    附录 3: 可能会碰到的错误

  • 使用了错误的vncserver@:1.service 文件 (因为cp了原来 RHEL7 的配置文件, 使用tigervnc-server自带的例子文件就可以了)
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    # systemctl status  vncserver@\:1.service
    ● vncserver@:1.service - Remote desktop service (VNC)
    Loaded: loaded (/etc/systemd/system/vncserver@:1.service; disabled; vendor preset: disabled)
    Active: failed (Result: protocol) since Fri 2021-02-19 17:00:12 CST; 5s ago
    Process: 34992 ExecStart=/usr/sbin/runuser -l root -c /usr/bin/vncserver :1 (code=exited, status=0/SUCCESS)
    Process: 34990 ExecStartPre=/bin/sh -c /usr/bin/vncserver -kill :1 > /dev/null 2>&1 || : (code=exited, status=0/SUCCESS)

    Feb 19 17:00:12 rhel82 systemd[1]: Starting Remote desktop service (VNC)...
    Feb 19 17:00:12 rhel82 systemd[1]: vncserver@:1.service: Can't open PID file /root/.vnc/rhel82:1.pid (yet?) after start: No such file or di>
    Feb 19 17:00:12 rhel82 systemd[1]: vncserver@:1.service: Failed with result 'protocol'.
    Feb 19 17:00:12 rhel82 systemd[1]: Failed to start Remote desktop service (VNC).
  • 没有添加vnc用户到 /etc/tigervnc/vncserver.users (增加对应的用户就可以了)
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    # systemctl status vncserver@\:1.service -l
    ● vncserver@:1.service - Remote desktop service (VNC)
    Loaded: loaded (/etc/systemd/system/vncserver@:1.service; disabled; vendor preset: disabled)
    Active: failed (Result: exit-code) since Fri 2021-02-19 17:09:37 CST; 3s ago
    Process: 35662 ExecStart=/usr/libexec/vncsession-start :1 (code=exited, status=1/FAILURE)

    Feb 19 17:09:37 rhel82 systemd[1]: Starting Remote desktop service (VNC)...
    Feb 19 17:09:37 rhel82 vncsession-start[35662]: No user configured for display :1
    Feb 19 17:09:37 rhel82 systemd[1]: vncserver@:1.service: Control process exited, code=exited status=1
    Feb 19 17:09:37 rhel82 systemd[1]: vncserver@:1.service: Failed with result 'exit-code'.
    Feb 19 17:09:37 rhel82 systemd[1]: Failed to start Remote desktop service (VNC).