《LINUX入門:Ubuntu 16.10安裝Xfce桌面與VNC遠程連接》要點:
本文介紹了LINUX入門:Ubuntu 16.10安裝Xfce桌面與VNC遠程連接,希望對您有用。如果有疑問,可以聯(lián)系我們。
在長途服務(wù)器上運行桌面
通常在遠程Linux服務(wù)器上工作時,您可以使用ssh終端. 但是,有時您需要在服務(wù)器上運行GUI應(yīng)用程序,并堅持運行一段時間.
最近我不得不做類似的事情,所以我設(shè)置一個Ubuntu服務(wù)器與桌面,并通過VNC拜訪它.
這個想法實現(xiàn)很簡單. 在服務(wù)器上安裝您選擇的任何桌面情況. 在本教程中,我們將使用Xfce,因為它與Gnome和KDE相比更具小巧.
然后使用vnc服務(wù)器啟動桌面環(huán)境,并創(chuàng)建一個X顯示會話,我們將通過vnc客戶端從本地臺式機拜訪.
安裝桌面情況和VNC服務(wù)器
Xfce是一款輕量級桌面,非常適合在長途服務(wù)器上使用. 首先安裝xfce軟件包和tightvnc服務(wù)器. 在進行實際安裝之前,最好先更新包緩存.
sudo apt-get update
sudo apt-get install xfce4 xfce4-goodies tightvncserver
請注意,這將只安裝包,而不是啟動任何器械. 我們將在本指南后面自行啟動具體設(shè)置的vncserver.
如果dpkg進程意外退出,則可能必需運行以下命令 -
#sudo dpkg --configure -a
為vnc創(chuàng)立一個新用戶
接下來要做的是創(chuàng)立一個將在vnc會話期間使用的unix用戶. 用戶名可以是任何東西. 使用adduser命令.
# adduser mike
Adding user `mike' ...
Adding new group `mike' (1001) ...
Adding new user `mike' (1001) with group `mike' ...
Creating home directory `/home/mike' ...
Copying files from `/etc/skel' ...
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Changing the user information for mike
Enter the new value, or press ENTER for the default
? ? ? ? Full Name []:
? ? ? ? Room Number []:
? ? ? ? Work Phone []:
? ? ? ? Home Phone []:
? ? ? ? Other []:
Is the information correct? [Y/n]
#
vncserver將使用此unix用戶啟動桌面環(huán)境. 這意味著,在長途桌面上工作時,您將成為此用戶
為用戶設(shè)置“vnc暗碼”
vnc服務(wù)器維護一個單獨的暗碼,用于通過vnc客戶端登錄到vnc服務(wù)器. 該暗碼與unix用戶暗碼不同. 它使用vncpasswd命令配置.
首先切換到上一步中創(chuàng)建的用戶“mike”,并設(shè)置vnc服務(wù)器暗碼.
su - mike
接下來使用vncpasswd敕令
$ vncpasswd
Using password file /home/mike/.vnc/passwd
VNC directory /home/mike/.vnc does not exist, creating.
Password:
Verify:?
Would you like to enter a view-only password (y/n)?
mike@bunty:~$
請注意,passwd文件不存在,并在此步調(diào)中首次創(chuàng)建.
如果您以前已經(jīng)運行vncserver命令,那么它將創(chuàng)立文件. 當(dāng)您第一次運行vncserver時,它會創(chuàng)立一個默認啟動腳本
$ vncserver
You will require a password to access your desktops.
Password:? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
Password too short
enlightened@desktop:~$ vncserver
You will require a password to access your desktops.
Password:
Verify:?
Would you like to enter a view-only password (y/n)? n
New 'X' desktop is desktop:1
Creating default startup script /home/enlightened/.vnc/xstartup
Starting applications specified in /home/enlightened/.vnc/xstartup
Log file is /home/enlightened/.vnc/desktop:1.log
但是,我們不必要運行vncserver命令. 它將使用啟動腳本自動啟動.
創(chuàng)立xstartup腳本
下一個重要的文件是xstartup腳本. 它包括有關(guān)哪些X應(yīng)用程序開始的說明. 桌面環(huán)境是我們必須開始的X應(yīng)用程序.
如果文件已經(jīng)存在,起首要備份該文件
mv ~/.vnc/xstartup ~/.vnc/xstartup.bak
現(xiàn)在用nano編纂它
vnc@server:~$ nano .vnc/xstartup
注 - 這是用戶vnc的主目次,即/home/mike/.vnc/xstartup
在xstartup劇本中輸入以下幾行
#!/bin/bash
xrdb $HOME/.Xresources
startxfce4 &
startxfce4命令將啟動xfce桌面. 保留文件并關(guān)閉它.
使xstartup文件可執(zhí)行. 這是需要的,以便vncserver可以執(zhí)行此文件.
$ chmod +x ~/.vnc/xstartup
創(chuàng)立vnc服務(wù)文件
下一步是創(chuàng)立vnc服務(wù)文件,以便我們可以使用service命令啟動vnc服務(wù)器,而不必每次都運行vncserver命令.
確保在USER變量中輸入正確的用戶名. 這是vnc服務(wù)器將用于啟動桌面會話的用戶.
root@linuxidc:~# sudo nano /etc/init.d/vncserver
粘貼以下劇本
#!/bin/bash
PATH="$PATH:/usr/bin/"
export USER="mike"
DISPLAY="1"
DEPTH="16"
GEOMETRY="1024x768"
OPTIONS="-depth ${DEPTH} -geometry ${GEOMETRY} :${DISPLAY}"
. /lib/lsb/init-functions
case "$1" in
start)
log_action_begin_msg "Starting vncserver for user '${USER}' on localhost:${DISPLAY}"
su ${USER} -c "/usr/bin/vncserver ${OPTIONS}"
;;
stop)
log_action_begin_msg "Stoping vncserver for user '${USER}' on localhost:${DISPLAY}"
su ${USER} -c "/usr/bin/vncserver -kill :${DISPLAY}"
;;
restart)
$0 stop
$0 start
;;
esac
exit 0
保留文件并關(guān)閉它. 使其可執(zhí)行
# chmod +x /etc/init.d/vncserver
開端服務(wù)
開始并測試我們的步調(diào).
首先重新加載systemctl,以便它可以使用vncserver啟動腳本.
systemctl守護過程重新加載
如今啟動vncserver. 它在端口5901上啟動服務(wù)器
#service vncserver start
反省它的運行
root@linuxidc:~# service vncserver status
● vncserver.service
? Loaded: loaded (/etc/init.d/vncserver; bad; vendor preset: enabled)
? Active: active (exited) since Thu 2017-03-02 05:36:42 UTC; 6s ago
? ? Docs: man:systemd-sysv-generator(8)
? Process: 24877 ExecStart=/etc/init.d/vncserver start (code=exited, status=0/SUCCESS)
Mar 02 05:36:40 linuxidc systemd[1]: Starting vncserver.service...
Mar 02 05:36:40 linuxidc vncserver[24877]:? * Starting vncserver for user 'vnc' on localhost:1...
Mar 02 05:36:40 linuxidc su[24885]: Successful su for vnc by root
Mar 02 05:36:40 linuxidc su[24885]: + ??? root:vnc
Mar 02 05:36:40 linuxidc su[24885]: pam_unix(su:session): session opened for user vnc by (uid=0)
Mar 02 05:36:42 linuxidc vncserver[24877]: New 'X' desktop is linuxidc:1
Mar 02 05:36:42 linuxidc vncserver[24877]: Starting applications specified in /home/vnc/.vnc/xstartup
Mar 02 05:36:42 linuxidc vncserver[24877]: Log file is /home/vnc/.vnc/linuxidc:1.log
Mar 02 05:36:42 linuxidc systemd[1]: Started vncserver.service.$ cat ~/.vnc/*.pid
18577
18731# ps -ef | grep tightvnc
vnc? ? ? 24574? ? 1? 0 05:32 ?? ? ? ? 00:00:00 Xtightvnc :1 -desktop X -auth /home/vnc/.Xauthority -geometry 1024x768 -depth 16 -rfbwait 120000 -rfbauth /home/vnc/.vnc/passwd -rfbport 5901 -fp /usr/share/fonts/X11/misc/,/usr/share/fonts/X11/Type1/,/usr/share/fonts/X11/75dpi/,/usr/share/fonts/X11/100dpi/ -co /etc/X11/rgb
root? ? 24744 10412? 0 05:33 pts/0? ? 00:00:00 grep --color=auto tightvnc
root@linuxidc:~#
檢查vnc服務(wù)器的打開端口. 從vnc客戶端連接時,必要正確的端口號
# netstat -nlp | grep vnc
tcp? ? ? ? 0? ? ? 0 0.0.0.0:5901? ? ? ? ? ? 0.0.0.0:*? ? ? ? ? ? ? LISTEN? ? ? 24574/Xtightvnc
tcp? ? ? ? 0? ? ? 0 0.0.0.0:6001? ? ? ? ? ? 0.0.0.0:*? ? ? ? ? ? ? LISTEN? ? ? 24574/Xtightvnc
unix? 2? ? ? [ ACC ]? ? STREAM? ? LISTENING? ? 5225386? 24574/Xtightvnc? ? /tmp/.X11-unix/X1
Vnc server can also be started by calling the script directly.
也可以通過直接調(diào)用腳原來啟動Vnc服務(wù)器.
# /etc/init.d/vncserver start
[ ok ] Starting vncserver (via systemctl): vncserver.service.
root@linuxidc:~#
結(jié)束vncserver
# service vncserver stop
在桌面上安裝vncviewer客戶端
現(xiàn)在,我們將vnc服務(wù)器啟動并運行GUI桌面情況.
在Ubuntu上安裝xtightvncviewer.
$ sudo apt-get install xtightvncviewer
現(xiàn)在使用vncviewer命令連接到長途vnc服務(wù)器.
$ vncviewer -quality 5 -encodings“copyrect tight hextile zlib corre rre raw”-compresslevel 5 IPADDR:5901
我們使用較低質(zhì)量和緊縮編碼來緊縮正在傳輸?shù)膱D像數(shù)據(jù)并使其更快.
使用像KRDC這樣的其他vnc查看器可能會更慢.
?
CentOS7.1安裝VNC,讓W(xué)in7長途桌面Linux?
CentOS 7 安裝設(shè)置裝備擺設(shè) VNC 詳解?
Ubuntu下安裝配置VNC長途工具?
更多Ubuntu相關(guān)信息見Ubuntu 專題頁面 /topicnews.aspx?tid=2
本文永遠更新鏈接地址:
維易PHP培訓(xùn)學(xué)院每天發(fā)布《LINUX入門:Ubuntu 16.10安裝Xfce桌面與VNC遠程連接》等實戰(zhàn)技能,PHP、MYSQL、LINUX、APP、JS,CSS全面培養(yǎng)人才。
轉(zhuǎn)載請注明本頁網(wǎng)址:
http://www.snjht.com/jiaocheng/9809.html