1. 程式人生 > >在 CentOS 7 1804 中 安裝使用 VNC

在 CentOS 7 1804 中 安裝使用 VNC

 


  1. 安裝VNC:
    [[email protected] ~]# yum -y install tigervnc-server
  2. 啟動VNC並設定密碼:
    [[email protected] ~]# vncserver
    
    You will require a password to access your desktops.
    
    Password:
    Verify:
    Would you like to enter a view-only password (y/n)? y
    Password:
    Verify:
    xauth:  file /root/.Xauthority does not exist
    
    New 'CentOS-x86-64-DVD-1804-Desktop:1 (root)' desktop is CentOS-x86-64-DVD-1804-Desktop:1
    
    Creating default startup script /root/.vnc/xstartup
    Creating default config /root/.vnc/config
    Starting applications specified in /root/.vnc/xstartup
    Log file is /root/.vnc/CentOS-x86-64-DVD-1804-Desktop:1.log
    
  3. 建立視窗1的開機啟動:
    [[email protected] ~]# cp /lib/systemd/system/[email protected] /etc/systemd/system/[email protected]:1.service
    
  4. 修改視窗1的開機啟動:
    [[email protected] ~]# vim /etc/systemd/system/[email protected]:1.service
    原始內容:
    [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"
    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
    修改為(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 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
  5. 設定視窗1的開機啟動:
    [[email protected] ~]# systemctl enable [email protected]:1.service
  6. 開啟視窗1:
    [[email protected] ~]# systemctl start [email protected]:1.service
  7. 開啟5900+?埠:
    開啟視窗1,開放埠5901(即5900+1):
    開啟埠5901(需要開啟防火牆):
    [[email protected] ~]# firewall-cmd --zone=public --add-port=5901/tcp --permanent
    
    重啟防火牆:
    [[email protected] ~]# systemctl restart firewalld.service

    檢視已開放埠:
    [[email protected] ~]# firewall-cmd --list-ports
    5901/tcp
  8. 開啟VNC客戶端:
    輸入地址後點回車:

     
  9. 輸入密碼:

     
  10. 連線後如圖所示:

     

  11.