1.確認VNC是否安裝
默認狀況下,Red Hat Enterprise Linux安裝程序會將VNC服務安裝在系統上。
確認是否已經安裝VNC服務及查看安裝的VNC版本
[root@testdb ~]# rpm -q vnc-server
vnc-server-4.1.2-9.el5
[root@testdb ~]#
若系統沒有安裝,能夠到操做系統安裝盤的Server目錄下找到VNC服務的RPM安裝包vnc-server-4.1.2-9.el5.x86_64.rpm,安裝命令以下
rpm -ivh /mnt/Server/vnc-server-4.1.2-9.el5.x86_64.rpm
2.啓動VNC服務
使用vncserver命令啓動VNC服務,命令格式爲「vncserver :桌面號」,其中「桌面號」用「數字」的方式表示,每一個用戶連個須要佔用1個桌面
啓動編號爲1的桌面示例以下
[root@testdb ~]# vncserver :1
You will require a password to access your desktops.
Password:
Verify:
xauth: creating new authority file /root/.Xauthority
New 'testdb:1 (root)' desktop is testdb:1
Creating default startup script. /root/.vnc/xstartup
Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/testdb:1.log
以上命令執行的過程當中,由於是第一次執行,須要輸入密碼,這個密碼被加密保存在用戶主目錄下的.vnc子目錄(/root/.vnc/passwd)中;同時在用戶主目錄下的.vnc子目錄中爲用戶自動創建xstartup配置文件(/root/.vnc/xstartup),在每次啓動VND服務時,都會讀取該文件中的配置信息。
BTW:/root/.vnc/目錄下還有一個「testdb:1.pid」文件,這個文件記錄着啓動VNC後對應後天操做系統的進程號,用於中止VNC服務時準肯定位進程號。
3.VNC服務使用的端口號與桌面號的關係
VNC服務使用的端口號與桌面號相關,VNC使用TCP端口從5900開始,對應關係以下
桌面號爲「1」 ---- 端口號爲5901
桌面號爲「2」 ---- 端口號爲5902
桌面號爲「3」 ---- 端口號爲5903
……
基於Java的VNC客戶程序Web服務TCP端口從5800開始,也是與桌面號相關,對應關係以下
桌面號爲「1」 ---- 端口號爲5801
桌面號爲「2」 ---- 端口號爲5802
桌面號爲「3」 ---- 端口號爲5803
……
基於上面的介紹,若是Linux開啓了防火牆功能,就須要手工開啓相應的端口,以開啓桌面號爲「1」相應的端口爲例,命令以下
[root@testdb ~]# iptables -I INPUT -p tcp --dport 5901 -j ACCEPT
[root@testdb ~]# iptables -I INPUT -p tcp --dport 5801 -j ACCEPT
4.測試VNC服務
第一種方法是使用VNC Viewer軟件登錄測試,操做流程以下
啓動VNC Viewer軟件 --> Server輸入「144.194.192.183:1」 --> 點擊「OK」 --> Password輸入登錄密碼 --> 點擊「OK」登錄到X-Window圖形桌面環境 --> 測試成功
第二種方法是使用Web瀏覽器(如Firefox,IE,Safari)登錄測試,操做流程以下
地址欄輸入http://144.194.192.183:5801/ --> 出現VNC viewer for Java(此工具是使用Java編寫的VNC客戶端程序)界面,同時跳出VNC viewer對話框,在Server處輸入「144.194.192.183:1」點擊「OK」 --> Password輸入登錄密碼 --> 點擊「OK」登錄到X-Window圖形桌面環境 --> 測試成功
(注:VNC viewer for Java須要JRE支持,若是頁面沒法顯示,表示沒有安裝JRE,能夠到http://java.sun.com/javase/downloads/index_jdk5.jsp這裏下載最新的JRE進行安裝)
5.配置VNC圖形桌面環境爲KDE或GNOME桌面環境
若是您是按照個人上面方法進行的配置的,登錄到桌面後效果是很是簡單的,只有一個Shell可供使用,這是爲何呢?怎麼才能看到可愛而且美麗的KDE或GNOME桌面環境呢?回答以下
之因此那麼的難看,是由於VNC服務默認使用的是twm圖形桌面環境的,能夠在VNC的配置文件xstartup中對其進行修改,先看一下這個配置文件
[root@testdb ~]# vi /root/.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 &
將這個xstartup文件的最後一行修改成「startkde &」,再從新啓動vncserver服務後就能夠登錄到KDE桌面環境
將這個xstartup文件的最後一行修改成「gnome-session &」,再從新啓動vncserver服務後就能夠登錄到GNOME桌面環境
從新啓動vncserver服務的方法:
[root@testdb ~]# vncserver -kill :1
[root@testdb ~]# vncserver :1
6.配置多個桌面
可使用以下的方法啓動多個桌面的VNC
vncserver :1
vncserver :2
vncserver :3
……
可是這種手工啓動的方法在服務器從新啓動以後將失效,所以,下面介紹如何讓系統自動管理多個桌面的VNC,方法是將須要自動管理的信息添加到/etc/sysconfig/vncservers配置文件中,先以桌面1爲root用戶桌面2爲oracle用戶爲例進行配置以下:
格式爲:VNCSERVERS="桌面號:使用的用戶名 桌面號:使用的用戶名"
[root@testdb ~]# vi /etc/sysconfig/vncservers
VNCSERVERS="1:root 2:oracle"
VNCSERVERARGS[1]="-geometry 1024x768 –alwaysshared -depth 16"
7.修改VNC訪問的密碼
使用命令vncpasswd對不一樣用戶的VNC的密碼進行修改,必定要注意,若是配置了不一樣用戶的VNC須要分別到各自用戶中進行修改,例如在個人這個實驗中,root用戶和oracle用戶須要分別修改,修改過程以下:
[root@testdb ~]# vncpasswd
Password:
Verify:
[root@testdb ~]#
8.啓動和中止VNC服務
1)啓動VNC服務命令
[root@testdb ~]# /etc/init.d/vncserver start
Starting VNC server: 1:root
New 'testdb:1 (root)' desktop is testdb:1
Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/testdb:1.log
2:oracle
New 'testdb:2 (oracle)' desktop is testdb:2
Starting applications specified in /home/oracle/.vnc/xstartup
Log file is /home/oracle/.vnc/testdb:2.log
[ OK ]
2)中止VNC服務命令
[root@testdb ~]# /etc/init.d/vncserver stop
Shutting down VNC server: 1:root 2:oracle [ OK ]
3)從新啓動VNC服務命令
[root@testdb ~]# /etc/init.d/vncserver restart
Shutting down VNC server: 1:root 2:oracle [ OK ]
Starting VNC server: 1:root
New 'testdb:1 (root)' desktop is testdb:1
Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/testdb:1.log
2:oracle
New 'testdb:2 (oracle)' desktop is testdb:2
Starting applications specified in /home/oracle/.vnc/xstartup
Log file is /home/oracle/.vnc/testdb:2.log
[ OK ]
4)設置VNC服務隨系統啓動自動加載
第一種方法:使用「ntsysv」命令啓動圖形化服務配置程序,在vncserver服務前加上星號,點擊肯定,配置完成。
第二種方法:使用「chkconfig」在命令行模式下進行操做,命令使用以下(預知chkconfig詳細使用方法請自助式man一下)
[root@testdb ~]# chkconfig vncserver on
[root@testdb ~]# chkconfig --list vncserver
vncserver 0:off 1:off 2:on 3:on 4:on 5:on 6:off
9.小結
VNC的詳細配置方法到此已經寫完,但願能對你們有幫助。VNC對於遠程調用圖形化界面來講很是的輕巧和便捷,善用之!java