溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

VNC安裝配置詳細說明

發(fā)布時間:2020-08-10 01:03:13 來源:ITPUB博客 閱讀:203 作者:datapeng 欄目:建站服務器

VNC概述

   VNC (Virtual Network Computing)虛擬網(wǎng)絡計算機的縮寫。VNC 是一款優(yōu)秀的遠程控制工具軟件,由著名的 AT&T的歐洲研究實驗室開發(fā)的。VNC 是在基于 UNIXLinux操作系統(tǒng)的免費的開源軟件,遠程控制能力強大,高效實用,其性能可以和 WindowsMAC中的任何遠程控制軟件媲美。在 Linux 中,VNC 包括以下四個命令:vncserver,vncviewer,vncpasswd,和 vncconnect。大多數(shù)情況下只需要其中的兩個命令:vncserver vncviewer。目前,原來的AT&T版本已經(jīng)不再使用,因為更多有重大改善的分支版本已經(jīng)出現(xiàn), 像是RealVNC VNC tight UltraVNC。 Real VNC 是當前最活躍和強大的主流應用。

 RealVNC官方網(wǎng)址  :  http://www.realvnc.com/

 Tight VNC官方網(wǎng)址http://www.tightvnc.com/

 UltraVNC官方網(wǎng)址http://www.uvnc.com/

 

VNC原理

VNC系統(tǒng)由客戶端,服務端和一個協(xié)議組成。VNC的服務端目的是分享其所運行機器的屏幕, 服務端被動的允許客戶端控制它。 VNC客戶端(或Viewer) 觀察控制服務端,與服務端交互。 VNC 協(xié)議 Protocol (RFB)是一個簡單的協(xié)議,傳送服務端的原始圖像到客戶端(一個X,Y 位置上的正方形的點陣數(shù)據(jù)), 客戶端傳送事件消息到服務端。

服務器發(fā)送小方塊的幀緩存給客戶端,在最簡單的情況,VNC協(xié)議使用大量的帶寬,因此各種各樣的方法被發(fā)明出來減少通訊的開支,舉例來說,有各種各樣的編碼方法來決定最有效率的方法來傳送這些點陣方塊)

協(xié)議允許客戶端和服務端去協(xié)議哪種編碼會被使用,最簡單的編碼,被大多數(shù)客戶端和服務端所支持的是, 從左到右的像素掃描數(shù)據(jù)的原始編碼, 當原始的滿屏被發(fā)送后,只發(fā)送變化的方塊區(qū)域。這種編碼在幁間只有小部分屏幕變化的情況下工作的非常好(像是鼠標鍵在桌面移動的情況,或在光標處敲擊文字),不過如果大量的像素同時變化帶寬將會增加的非常高,像是拖動一個窗口或觀看全屏錄像。

VNC默認使用TCP端口59005906,而JAVAVNC客戶端使用58005806。一個服務端可以在5500口用“監(jiān)聽模式”連接一個客戶端,使用監(jiān)聽模式的一個好處是服務端不需要設置防火墻。

UNIX上的VNC稱為xvnc,同時扮演兩種角色,對X窗口系統(tǒng)的應用程序來說它是X server,對于VNC客戶端來說它是VNC服務器程序。

 

實驗環(huán)境

     VNC服務端:

             操作系統(tǒng):Red Hat Enterprise Linux Server release 5.7 (Tikanga)

     VNC客戶端:

             操作系統(tǒng):Windows 7專業(yè)版  64位操作系統(tǒng)

 

VNC安裝配置

1、安裝VNC

[root@localhost /]# cd  /depot/os/mnt/cdrom/Server

[root@localhost /]# rpm -ivh vnc-server-4.1.2-14.el5_6.6.x86_64.rpm

[root@localhost /]# rpm -ivh vnc-4.1.2-14.el5_6.6.x86_64.rpm

驗證vnc-server包是否安裝成功:

[root@localhost /]# rpm -qa vnc-server

vnc-server-4.1.2-14.el5_6.6

2、配置vncservers文件

修改/etc/sysconfig/vncservers文件,未經(jīng)修改的vncservers文件如下所示:

[root@localhost ~]# more /etc/sysconfig/vncservers

# The VNCSERVERS variable is a list of display:user pairs.

#

# Uncomment the lines below to start a VNC server on display :2

# as my 'myusername' (adjust this to your own).  You will also

# need to set a VNC password; run 'man vncpasswd' to see how

# to do that. 

#

# DO NOT RUN THIS SERVICE if your local area network is

# untrusted!  For a secure way of using VNC, see

# <URL:http://www.uk.research.att.com/archive/vnc/sshvnc.html>.

# Use "-nolisten tcp" to prevent X connections to your VNC server via TCP.

# Use "-nohttpd" to prevent web-based VNC clients connecting.

# Use "-localhost" to prevent remote VNC clients connecting except when

# doing so through a secure tunnel.  See the "-via" option in the

# `man vncviewer' manual page.

# VNCSERVERS="2:myusername"

# VNCSERVERARGS[2]="-geometry 800x600 -nolisten tcp -nohttpd -localhost"

將最后兩行配置信息取消注釋,添加系統(tǒng)賬號

VNCSERVERS="1:root 2etl"

VNCSERVERARGS[1]="-geometry 1024x768 -nolisten tcp -nohttpd "

VNCSERVERARGS[2]="-geometry 1024x768 -nolisten tcp -nohttpd "

VNCSERVERS 是用來設定可以使用VNC的服務器賬號,可以設定多個,例如上面root、etl,但是中間要用空格隔開。使用VNCVIEWER登錄時,192.168.48.128:1表示是以root賬號登錄,以此類推。

關于參數(shù)配置說明:

1-geometry 表示桌面分辨率,默認為1024x768,所以上面的1024x768也可以不寫。

2-nohttpd  表示不監(jiān)聽HTTP端口(58xx)。

3-nolisten tcp 表示不監(jiān)聽TCP端口(60xx

4-localhost 只運行從本機訪問。

5AlwaysShared 默認只允許一個VNCVIEWER連接,此參數(shù)表示同一個顯示端口允許多用戶同時登錄.

6-depth  表示色深,參數(shù)有8,16,24,32.

7: SecurityTypes None 登錄不需要密碼認證VncAuth默認值,要密碼認證。

3、設置VNC用戶密碼

如果此時不設置VNC用戶密碼,啟動vncserver服務,則會報如下錯誤:

[root@localhost ~]# service vncserver start

Starting VNC server: 1:root [FAILED]

[root@localhost /]# vncpasswd

Password:

Verify:

[root@localhost /]# su - etl

[etl@localhost ~]$ vncpasswd

Password:

Verify:

[etl@localhost ~]$

4、啟動vncserver服務

[root@localhost ~]# service vncserver start

Starting VNC server: 1:root

New 'localhost.localdomain:1 (root)' desktop is localhost.localdomain:1

Creating default startup script /root/.vnc/xstartup

Starting applications specified in /root/.vnc/xstartup

Log file is /root/.vnc/localhost.localdomain:1.log

2:etl

New 'localhost.localdomain:2 (etl)' desktop is localhost.localdomain:2

Creating default startup script /home/etl/.vnc/xstartup

Starting applications specified in /home/etl/.vnc/xstartup

Log file is /home/etl/.vnc/localhost.localdomain:2.log

[  OK  ]

VNC會在用戶根目錄($HOME)下的".vnc"文件夾下生成一系列文件。其中passwdvnc用戶密碼文件,由vncpasswd生成。其他的都由vnc初次啟動時生成,xstartupVNC客戶端連接時啟動的腳本

5、配置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 &

xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &

twm &

切換到etl賬號,依法炮制

[root@localhost ~]# su - etl

[etl@localhost ~]$ vi /home/etl/.vnc/xstartup

[root@localhost ~]# service vncserver restart

Shutting down VNC server: 1:root 2:etl [  OK  ]

Starting VNC server: 1:root

New 'localhost.localdomain:1 (root)' desktop is localhost.localdomain:1

Starting applications specified in /root/.vnc/xstartup

Log file is /root/.vnc/localhost.localdomain:1.log

2:etl

New 'localhost.localdomain:2 (etl)' desktop is localhost.localdomain:2

Starting applications specified in /home/etl/.vnc/xstartup

Log file is /home/etl/.vnc/localhost.localdomain:2.log

[  OK  ]

6、配置防火墻

如果你不配置防火墻,此時用VNC Viewer連接的話,一般會報:"connectConnection timed out(10060)"錯誤,如下所示:

一般這種情況要么關閉防火墻,要么需要配置防火墻。

[root@localhost ~]# service iptables stop

Flushing firewall rules: [  OK  ]

Setting chains to policy ACCEPT: filter [  OK  ]

Unloading iptables modules: [  OK  ]

關閉防火墻后,用VNCView連接服務器沒有問題,但是一般不建議關閉防火墻,

[root@localhost ~]# service iptables restart

Flushing firewall rules: [  OK  ]

Setting chains to policy ACCEPT: filter [  OK  ]

Unloading iptables modules: [  OK  ]

Applying iptables firewall rules: [  OK  ]

Loading additional iptables modules: ip_conntrack_netbios_ns [  OK  ]

[root@localhost ~]# iptables -I INPUT -p tcp --dport 5901 -j ACCEPT

[root@localhost ~]# iptables -I INPUT -p tcp --dport 5902 -j ACCEPT

OK,可以通過VNC連接到服務器了

 

關于VNC服務使用的端口號與桌面號相關,VNC使用TCP端口從5900開始,對應關系如下
桌面號為“1 ---- 端口號為5901
桌面號為“2 ---- 端口號為5902
桌面號為“3 ---- 端口號為5903
……
基于JavaVNC客戶程序Web服務TCP端口從5800開始,也是與桌面號相關,對應關系如下
桌面號為“1 ---- 端口號為5801
桌面號為“2 ---- 端口號為5802
桌面號為“3 ---- 端口號為5803
基于上面的介紹,如果Linux開啟了防火墻功能,就需要手工開啟相應的端口,以開啟桌面號為“1”相應的端口為例,命令如下

開機自啟動vncserver服務
# chkconfig vncserver on

 

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權內容。

AI