linux系統中VNC安裝配置方法詳解

來源:互聯網
上載者:User

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 ~]# cat /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"
VNCSERVERARGS[2]="-geometry 1024x768"

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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.