Centos7.7安裝vncserver虛擬網路控制檯
阿新 • • 發佈:2021-07-02
- 服務端:Centos7.7 Minimal
- 客戶端:Windows10
- 客戶端VNC-Viewer 6.20下載地址:https://www.realvnc.com/en/connect/download/viewer/
本實驗中安裝的系統沒有安裝桌面環境,我們需要自己安裝,如果已經安裝桌面了清跳過這一步。Centos7提供了"Cinnamon Desktop","MATE Desktop","GNOME Desktop","KDE Plasma Workspaces","LXQt Desktop","Xfce"讓我們安裝。
下面的命令列出可用環境組:
[root@localhost ~]# yum grouplist Loaded plugins: fastestmirror There is no installed groups file. Maybe run: yum groups mark convert (see man yum) Loading mirror speeds from cached hostfile * base: mirrors.tuna.tsinghua.edu.cn * epel: mirrors.aliyun.com * extras: mirrors.aliyun.com * updates: mirrors.aliyun.com Available Environment Groups: Minimal Install Compute Node Infrastructure Server File and Print Server Cinnamon Desktop MATE Desktop Basic Web Server Virtualization Host Server with GUI GNOME Desktop KDE Plasma Workspaces Development and Creative Workstation Available Groups: Cinnamon Compatibility Libraries Console Internet Tools Development Tools Educational Software Electronic Lab Fedora Packager General Purpose Desktop Graphical Administration Tools Haskell LXQt Desktop Legacy UNIX Compatibility MATE Milkymist Scientific Support Security Tools Smart Card Support System Administration Tools System Management TurboGears application framework Xfce Done
我們可以選擇自己喜歡的桌面環境,在這裡選擇安裝Xfce桌面:
[root@localhost ~]# yum -y install epel-release && yum groupinstall Xfce建立一個使用者
[root@localhost ~]# useradd user1 [root@localhost ~]# echo '123456'|passwd --stdin user1 [root@localhost ~]# usermod -a -G wheel user1安裝VNC Server
在Centos倉庫預設提供的是TigerVNC安裝包,我們就安裝這個:
[root@localhost ~]# yum -y install tigervnc-server tigervnc-server-module
切換到user1使用者,執行vncserver命令建立一個初始配置並設定密碼:
[root@localhost ~]# su - user1 [user1@localhost ~]$ vncserver :2 You will require a password to access your desktops. Password: Verify: Would you like to enter a view-only password (y/n)? n A view-only password is not used New 'localhost.localdomain:2 (user1)' desktop is localhost.localdomain:2 Starting applications specified in /home/user1/.vnc/xstartup Log file is /home/user1/.vnc/localhost.localdomain:2.log
然後停止vncserver服務,目的就是建立密碼和.vnc下面的檔案。
[user1@localhost ~]$ vncserver -kill :2配置VNC Server
編輯使用者家目錄下面的.vnc/xstartup檔案
[user1@localhost ~]$ vim ~/.vnc/xstartup #!/bin/sh xrdb $HOME/.Xresources #xsetroot -solid grey #xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" & #twm & startxfce4 &
如果需要修改螢幕解析度,可以修改~/.vnc/config檔案,取消gemoetry前面的註釋。
[user1@localhost ~]$ vim .vnc/config ## Supported server options to pass to vncserver upon invocation can be listed ## in this file. See the following manpages for more: vncserver(1) Xvnc(1). ## Several common ones are shown below. Uncomment and modify to your liking. ## # securitytypes=vncauth,tlsvnc # desktop=sandbox geometry=1920x1080 # localhost # alwaysshared建立 Systemd Unit檔案
Unit檔案方便快速的啟動,停止,重啟服務
[user1@localhost ~]$ sudo cp /usr/lib/systemd/system/[email protected] /etc/systemd/system/vncserver@:2.service
編輯vncserver@:2.service,替換檔案裡面的<user>為user1使用者, Type由預設的forking改為simple
[user1@localhost ~]$ vim /etc/systemd/system/vncserver\@\:2.service [Unit] Description=Remote desktop service (VNC) After=syslog.target network.target [Service] Type=simple ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :' ExecStart=/usr/sbin/runuser -l user1 -c "/usr/bin/vncserver %i" PIDFile=/home/user1/.vnc/%H%i.pid ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :' [Install] WantedBy=multi-user.target
啟動vncserver服務
#重新載入管理器配置 [user1@localhost ~]$ sudo systemctl daemon-reload #啟動vncserver [user1@localhost ~]$ sudo systemctl start vncserver@:2客戶端遠端連線測試
在windows10客戶端開啟VNC Viewer,輸入地址和會話埠號:
如果需要將VNC伺服器配置為多個使用者啟動顯示,請使用vncserver命令建立初始配置並設定密碼,然後使用其他埠建立新的服務檔案。
5901=exportDISPLAY:1
5902=exportDISPLAY:2