CentOS 8 配置 VNC Server


CentOS 8 配置 VNC Server

前言

CentOS 8 配置 VNC Server, 使用戶可以遠程訪問,本例介紹安裝和配置流程。

環境說明

CentOS 8(Desktop Install)

因為使用圖形用戶界面,本例使用 GNOME 桌面環境。

$ cat /etc/centos-release CentOS Linux release 8.3.2011 

本例中 Linux(CentOS 8) 系統用戶有兩個 root 和 admin,VNC Viewer 使用 admin 進行訪問。

安裝

安裝桌面環境

如果沒有安裝 Desktop 版本,需要先安裝 X Windows。

注意

安裝桌面環境,未測試。

$ sudo dnf groupinstall "workstation" $ sudo dnf groupinstall "Server with GUI" 

設置默認啟動圖形界面

$ sudo systemctl set-default graphical 

重啟服務器

$ sudo reboot 

重啟之后,應該有 CentOS 8 的桌面環境了。

安裝 VNC Server

yum 安裝 tigervnc-server

$ sudo dnf install tigervnc-server tigervnc-server-module 

配置

VNC Server 支持多種配置,如:

  • 單用戶單界面配置(一個用戶訪問,使用一個界面)
  • 多用戶單界面配置(多個用戶訪問,使用同一個界面)
  • 多用戶多界面配置(多個用戶訪問,使用各自的界面)

本例比較簡單,只介紹單用戶單界面配置。

配置單用戶單界面

可以查看一下幫助文檔

注意
CentOS 8 安裝與 CentOS 7 不同,可以參考這個文檔

$ less /usr/share/doc/tigervnc/HOWTO.md 

拷貝模板

$ sudo cp /usr/lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@.service 

不需要編輯這個模版,根據 HOWTO.md 的描述,直接編輯配置文件即可

重新加載 systemd

$ sudo systemctl daemon-reload 

編輯用戶配置文件

$ sudo vi /etc/tigervnc/vncserver.users 

編輯后看起來是這樣的

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

說明

  1. :1 表示這個啟動的端口為。5901,之后一次類推 :2 為 5902;
  2. :1=admin 表示 5901 為 admin 用戶的遠程連接;

:wq 保存

配置 Xvnc 選項

$ sudo vi /etc/tigervnc/vncserver-config-defaults 

本例如下

## Default settings for VNC servers started by the vncserver service # # Any settings given here will override the builtin defaults, but can # also be overriden by ~/.vnc/config and vncserver-config-mandatory. # # See the following manpages for more details: vncserver(1) Xvnc(1) # # Several common settings are shown below. Uncomment and modify to your # liking.  # securitytypes=vncauth,tlsvnc # desktop=sandbox # geometry=2000x1200 # localhost # alwaysshared  session=gnome geometry=1024x768 

說明

  1. session=gnome 表示為使用 gnome 桌面
  2. geometry=1024x768 表示桌面的分辨率

這樣服務的主要配置就完成了

配置訪問密碼

本例使用 admin 用戶的桌面環境,如果使用其他用戶,請先切換到 admin 用戶

# su admin $ vncpasswd Password: Verify: Would you like to enter a view-only password (y/n)? n 

開啟服務

$ sudo systemctl start vncserver@:1 

這樣就開啟了第一個界面

注意

  1. 服務的文件 /etc/systemd/system/vncserver@.service沒有 :1
  2. :1 使當參數啟動服務器,表示啟動第一個界面

設置開機啟動

$ sudo systemctl enable vncserver@:1 

打開防火牆

我們需要配置防火牆, 打開 VNC 服務

$ sudo firewall-cmd --permanent --add-service vnc-server success $ sudo firewall-cmd --reload success 

客戶端訪問

下載 VNC Viewer

設置如下:

VNC Server: YOUR_SERVER_IP:1
Name: YOUR_Display_1

連接之后,輸入 admin 的 vpnpasswd,既可看到界面了。

參考資料

How to Install and Configure VNC Server on Centos 8 / RHEL 8
VNC Viewer

分類:  Linux |  評論


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM