歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> 關於Linux >> Redhat 6.0中VNC Server的配置方法

Redhat 6.0中VNC Server的配置方法

日期:2017/3/1 15:17:07   编辑:關於Linux
Redhat 6.0中VNC Server的配置方法 關於在Linux系統中配置VNC Server的方法,網上有很多的教程或者文章,但應用在我們的環境中時都不能完整解決我們的問題,所以這裡我將在Redhat 6.0中配置VNC Server中的方法,以及可能遇到問題的解決辦法總結在這裡,供大家參考。 1、 查詢系統是否安裝vnc-server [root@localhost ~]# rpm –qa | grep vnc 如果有返回值,類似於vnc-server-的值,說明已經安裝了vnc-server 2、 安裝vnc-server 網上大都搜到的方法是輸入 [root@localhost ~]# yum install tigervnc-server 但是在我們的環境中執行時卻提示:No package tigervnc-server available. 所以只能采用另一種辦法,就是先執行 [root@localhost ~]# yum search vnc 在返回結果中找到可用的包,再相應執行對應的包即可。 [root@localhost ~]# yum install vnc-server 3、 配置vnc-server的配置文件 輸入 [root@localhost ~]# vi /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" 按照注釋的說明就可以知道該如何配置了。 在文件最後加上 VNCSERVERS="1:root" 這樣即完成了root用戶的配置,VNCSERVERARGS參數這一行可以不進行設置。 這裡有兩點要注意: 1)VNCSERVERS=後面可以支持多用戶,以空格隔開。如: VNCSERVERS="1:myusername 15:otheruser"--->這裡的1 和15是端口號,用於連接時的端口 2)VNCSERVERARGS後面的[]裡面的數據要與VNCSERVERS後面對應用戶的值要一致。 VNCSERVERARGS基本參數有: -geometry 桌面大小,缺省是1024x768 -nohttpd 不監聽HTTP端口 -nolisten tcp 不監聽X端口 -localhost 只允許從本機訪問 -AlwaysShared 默認的, 同時只能有一個vncviewer連接(跟客戶端配置也有關), 一旦第2個連上去, 第1個就被斷開了. 此參數允許同時連多個vncviewer -SecurityTypes None登錄不需要密碼認證 VncAuth默認值,要密碼認證 4、 設定VNC連接密碼 上一步配置好配置文件之後,我們要用vncpasswd來設置vnc連接時候的認證密碼。 [root@localhost ~]# vncpasswd Password: Verify: 注意,這裡的vncpass只能在vnc本用戶下面來運行。比如要是想配置用戶名為oracle的vnc認證密碼,需要先切換到oracle用戶,之後再運行vncpasswd命令。 [root@localhost ~]# su - oracle [oracle@localhost ~]$ vncpasswd Password: Verify: 5、 啟動vncserver 以上介紹了VNC Server的安裝以及配置過程,下面介紹對該服務的常規管理方法。 [root@localhost ~]# service vncserver start 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 [ OK ] 關閉該服務的命令為 [root@localhost ~]# service vncserver stop 也可以通過以下命令查看vncserver的運行狀態 [root@localhost ~]# service vncserver status 這裡,將vncserver設置為開機默認啟動。 [root@localhost ~]# chkconfig vncserver on 6、 防火牆配置 盡管以上過程已經完成,並且vncserver服務也啟動,但卻還是連不上,這時,可能的原因就是該請求被防火牆屏蔽了。所以這裡介紹下防火牆的配置方法。 vnc服務運行時,使用netstat -antpl查看可以發現有三個端口在監聽。 5901 5801 6001 默認的,vnc 服務監聽3個TCP端口 RFB(Remote FrameBuffer)協議 默認端口:5900+顯示器號 HTTP協議默認端口:5800+顯示器號 X協議 默認端口:6000+顯示器號 vncserver使用的顯示器編號默認從1開始,依次使用,也可以參數指定端口號。 因為我們需要建立遠程連接,所以只需要RFB協議就可以了。 下面介紹配置防火牆的過程。 [root@localhost ~]# vi /etc/sysconfig/iptables 文件內容為 # Firewall configuration written by system-config-firewall # Manual customization of this file is not recommended. *filter :INPUT ACCEPT [0:0] :FORWARD ACCEPT [0:0] :OUTPUT ACCEPT [0:0] -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT -A INPUT -p icmp -j ACCEPT -A INPUT -i lo -j ACCEPT -A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT -A INPUT -j REJECT --reject-with icmp-host-prohibited -A FORWARD -j REJECT --reject-with icmp-host-prohibited COMMIT 按照/etc/sysconfig/vncservers文件中的配置,我們需要打開5901的端口號,只需在 -A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT 下面加入一行 -A INPUT -m state --state NEW -m tcp -p tcp --dport 5901 -j ACCEPT 即開啟了5901的端口。 當使用VNC-Viewer進行連接時, 192.168.10.131:1——這裡的:1就是端口號,指的是5900+1,這個1是在/etc/sysconfig/vncservers裡面指定的,這個數字在100以下,不含100的時候可以直接用192.168.10.131:1來表示,如果在vncservers裡面指定的數值大於100 包含100的時候,在連接的時候就需要用到完整的端口數值。如:在vncservers裡面指定的是100,那麼在連接的時候就應該是這樣的:192.168.10.131:6000 vnc裡面默認是以5900這個端口為基礎的,這個應該是可以更改的,不過得改源代碼。 7、 配置VNC圖形桌面環境為KDE或GNOME桌面環境 有人可能遇到這種情況,vnc都配置完畢並且正常運行,但是用VNC-Viewer登錄後顯示的屏幕卻為灰色(也有黑色的),並且無法進行任何操作,這是什麼原因呢。(遇上了是你的不幸,需要好好閱讀下面的內容並進行配置。沒遇上你也別幸災樂禍,搞清楚原理,有備無患。) 原來VNC xstartup程序中默認的設定值是啟動twm,而不是GNOME或KDE。 所以需要對xstart文件做小小的修改, [root@localhost ~]# vi .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 & xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" & twm & 我在設置時是將最後兩行注釋掉並且加上 gnome-session & 之後再重啟vncserver [root@localhost ~]# service vncserver restart 再次登錄VNC-Viewer,出現了可愛的Redhat桌面,成功解決灰屏問題。
Copyright © Linux教程網 All Rights Reserved