Ubuntu 18.04 LTS安裝vncserver虛擬網絡控制檯

系統環境

  • 服務端:Ubuntu 18.04 Server LTS
  • 客戶端:Windows10
  • 客戶端VNC-Viewer 6.20下載地址:https://www.realvnc.com/en/connect/download/viewer/

安裝桌面環境

本實驗中安裝的系統沒有安裝桌面環境,我們需要自己安裝,如果已經安裝桌面了清跳過這一步。

我們可Ubuntu提供了許多桌面環境,可以選擇自己喜歡的桌面環境,在這裡選擇安裝Xfce4桌面:

<code>bpang@ubuntu1804:~$ sudo apt install xfce4*
/<code>

安裝VNC Server

安裝倉庫提供的vnc4server:

<code>bpang@ubuntu1804:~$ sudo apt install vnc4server
/<code>

運行vncserver命令創建一個初始配置並設置密碼:

<code>bpang@ubuntu1804:~$ vncserver

You will require a password to access your desktops.

Password:
Verify:

New 'ubuntu1804:1 (bpang)' desktop is ubuntu1804:1

Creating default startup/>Starting applications specified in /home/bpang/.vnc/xstartup
Log file is /home/bpang/.vnc/ubuntu1804:1.log
/<code>
Ubuntu 18.04 LTS安裝vncserver虛擬網絡控制檯

然後停止vncserver服務:

<code>bpang@ubuntu1804:~$ vncserver -kill :1
Killing Xvnc4 process ID 10260
/<code>
Ubuntu 18.04 LTS安裝vncserver虛擬網絡控制檯

配置VNC Server

編輯用戶家目錄下面的.vnc/xstartup文件

<code>bpang@ubuntu1804:~$ vim .vnc/xstartup

#!/bin/sh

# Uncomment the following two lines for normal desktop:
unset SESSION_MANAGER
exec /etc/X11/xinit/xinitrc

[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot -solid grey
vncconfig -iconic &
#x-terminal-emulator -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
#x-window-manager &
startxfce4 &
/<code>
Ubuntu 18.04 LTS安裝vncserver虛擬網絡控制檯

設置vncserver開機啟動

在/etc/init.d文件夾下面創建vncserver文件,export USER=’bpang’改成自己的用戶名

<code>bpang@ubuntu1804:~$ sudo vim /etc/init.d/vncserver

#!/bin/bash

export USER='bpang'

eval cd ~$USER

case "$1" in
start)
su $USER -c '/usr/bin/vncserver :1'
echo "Starting VNC server for $USER "
;;
stop)
su $USER -c '/usr/bin/vncserver -kill :1'
echo "vncserver stopped"
;;
*)
echo "Usage: /etc/init.d/vncserver {start|stop}"
exit 1
;;
esac
exit 0
/<code>

給vncserver添加執行權限

<code>bpang@ubuntu1804:~$ sudo chmod +x /etc/init.d/vncserver
/<code>

開機啟動設置

<code>bpang@ubuntu1804:~$ sudo update-rc.d vncserver defaults
bpang@ubuntu1804:~$ sudo service vncserver start
/<code>

客戶端遠程連接測試

在windows10客戶端打開VNC Viewer,輸入地址和回話端口號:

Ubuntu 18.04 LTS安裝vncserver虛擬網絡控制檯

Ubuntu 18.04 LTS安裝vncserver虛擬網絡控制檯

總結

如果需要將VNC服務器配置為多個用戶啟動顯示,請使用vncserver命令創建初始配置並設置密碼,然後使用其他端口創建新的服務文件。


分享到:


相關文章: