VNC介紹和如何遠端連線到遠端Linux介面?

來源:互聯網
上載者:User

標籤:遠端連線   vnc   gnome   iptables   linux   

今天突然需要使用VNC,但是從來沒有使用過這個玩意兒!後來通過尋找關於這方面的資訊,下面就是我粗略對VNC的理解和使用。
 

下面對VNC的來源的基本組成就不一一介紹了,我相信沒有比百度百科有更好的介紹了。

http://baike.baidu.com/link?url=Z6-B80x_mQUjxotyvIFstCc-cce2IJXKSclfwbAPz0JUMuhIBqmfRg4u2ycN7jQ4rbLTcwMwfGF2bJML5cRnfK
但是要注意一點:
    <span style="white-space:pre"></span>同樣可能遠程連入UNIX、Linux進行圖形化操作的還有流行的Xmanager,VNC與之相比——兩者工作原理不一樣,<span style="white-space:pre"></span>前者(VNC)是遠程連入作業系統,所有操作在UNIX、Linux主機服務端進行,<span style="white-space:pre"></span><span style="color:#ff0000;">即使操作過程中“本地電腦與操作主機網路斷開”,也不影響操作的順利進行;</span><span style="white-space:pre"></span>而後者(Xmanager)是通過連接埠將主機伺服器的UI介面引導到本地電腦進行展現,<span style="white-space:pre"></span><span style="color:#ff0000;">如操作過程出現“本地電腦與操作主機網路斷開”,操作將中斷失敗!如果操作中進行的工作任務非常重要,<span style="white-space:pre"></span>不能中斷,如ORACLE RAC實施,結果是災難性的!</span><span style="white-space:pre"></span>更重要的是,VNC是免費的、開源的,Xmanager你可能用的是破解註冊版的。

Linux的版本可以通過:

[[email protected] sysconfig]# cat /etc/issueRed Hat Enterprise Linux Server release 5.5 (Tikanga)Kernel \r on an \m

 
查看是否安裝了vnc:
[[email protected] sysconfig]# rpm -qa| grep vnc-servervnc-server-4.1.2-14.el5_3.1

在window中下載vnc viewer :http://download.csdn.net/detail/u011218159/8340161

在服務端配置有兩種方式:

1. 通過介面操作來配置:System——preference——遠端桌面——勾選所有選項除了(ask  you for confiromation選項)

2. 通過命令來配置:

[[email protected] ~]# vncserver :1You will require a password to access your desktops.Password:Verify:New 'localhost.localdomain:1 (root)' desktop is localhost.localdomain:1Creating default startup script /root/.vnc/xstartupStarting applications specified in /root/.vnc/xstartupLog file is /root/.vnc/localhost.localdomain:1.log

配置好了以後,通過可用戶端的vnc viewer來串連我這裡是出現了一些問題:

1. 串連被拒絕:是因為防火牆的原因哦

一種解決方案:關閉防火牆

[[email protected] ~]# /etc/init.d/iptables stopFlushing firewall rules:                                   [  OK  ]Setting chains to policy ACCEPT: filter                    [  OK  ]Unloading iptables modules:                                [  OK  ][[email protected] ~]# lsanaconda-ks.cfg  Desktop  install.log  install.log.syslog
配置到防火牆設定檔中:

基於上面的介紹,如果Linux開啟了防火牆功能,就需要手工開啟相應的連接埠,以開啟案頭號為“1”相應的連接埠為例,命令如下[[email protected] ~]# iptables -I INPUT -p tcp --dport 5901 -j ACCEPT[[email protected] ~]# iptables -I INPUT -p tcp --dport 5801 -j ACCEPT

2. 串連介面在上面的兩種中是不一樣的,解決方式:

配置VNC圖形案頭環境為KDE或GNOME案頭環境如果您是按照我的上面方法進行的配置的,登陸到案頭後效果是非常簡單的,只有一個Shell可供使用,這是為什麼呢?怎麼才能看到可愛並且美麗的KDE或GNOME案頭環境呢?回答如下之所以那麼的難看,是因為VNC服務預設使用的是twm圖形案頭環境的,可以在VNC的設定檔xstartup中對其進行修改,先看一下這個設定檔[[email protected] ~]# <span style="color:#ff0000;">vi /root/.vnc/xstartup</span>#!/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/.Xresourcesxsetroot -solid greyvncconfig -iconic &xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &twm &將這個xstartup檔案的最後一行修改為“startkde &”,再重新啟動vncserver服務後就可以登陸到KDE案頭環境將這個xstartup檔案的最後一行修改為“gnome-session &”,再重新啟動vncserver服務後就可以登陸到GNOME案頭環境重新啟動vncserver服務的方法:[[email protected] ~]# vncserver -kill :1[[email protected] ~]# vncserver :1

這樣以後就應該沒有問題了,終於寫完了!!


下面是我參考的,假如我上面寫的還不夠完整請看下面 的內容:

1.確認VNC是否安裝預設情況下,Red Hat Enterprise Linux安裝程式會將VNC服務安裝在系統上。確認是否已經安裝VNC服務及查看安裝的VNC版本[[email protected] ~]# rpm -q vnc-servervnc-server-4.1.2-9.el5[[email protected] ~]#若系統沒有安裝,可以到作業系統安裝盤的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.rpm2.啟動VNC服務使用vncserver命令啟動VNC服務,命令格式為“vncserver :案頭號”,其中“案頭號”用“數字”的方式表示,每個使用者連個需要佔用1個案頭啟動編號為1的案頭樣本如下[[email protected] ~]# vncserver :1You will require a password to access your desktops.Password:Verify:xauth:  creating new authority file /root/.XauthorityNew 'testdb:1 (root)' desktop is testdb:1Creating default startup script. /root/.vnc/xstartupStarting applications specified in /root/.vnc/xstartupLog 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”相應的連接埠為例,命令如下[[email protected] ~]# iptables -I INPUT -p tcp --dport 5901 -j ACCEPT[[email protected] ~]# iptables -I INPUT -p tcp --dport 5801 -j ACCEPT4.測試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中對其進行修改,先看一下這個設定檔[[email protected] ~]# 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/.Xresourcesxsetroot -solid greyvncconfig -iconic &xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &twm &將這個xstartup檔案的最後一行修改為“startkde &”,再重新啟動vncserver服務後就可以登陸到KDE案頭環境將這個xstartup檔案的最後一行修改為“gnome-session &”,再重新啟動vncserver服務後就可以登陸到GNOME案頭環境重新啟動vncserver服務的方法:[[email protected] ~]# vncserver -kill :1[[email protected] ~]# vncserver :16.配置多個案頭可以使用如下的方法啟動多個案頭的VNCvncserver :1vncserver :2vncserver :3……但是這種手工啟動的方法在伺服器重新啟動之後將失效,因此,下面介紹如何讓系統自動管理多個案頭的VNC,方法是將需要自動管理的資訊添加到/etc/sysconfig/vncservers設定檔中,先以案頭1為root使用者案頭2為oracle使用者為例進行配置如下:格式為:VNCSERVERS="案頭號:使用的使用者名稱 案頭號:使用的使用者名稱"[[email protected] ~]# vi /etc/sysconfig/vncserversVNCSERVERS="1:root 2:oracle"VNCSERVERARGS[1]="-geometry 1024x768"VNCSERVERARGS[2]="-geometry 1024x768"7.修改VNC訪問的密碼使用命令vncpasswd對不同使用者的VNC的密碼進行修改,一定要注意,如果配置了不同使用者的VNC需要分別到各自使用者中進行修改,例如在我的這個實驗中,root使用者和oracle使用者需要分別修改,修改過程如下:[[email protected] ~]# vncpasswdPassword:Verify:[[email protected] ~]#8.啟動和停止VNC服務1)啟動VNC服務命令[[email protected] ~]# /etc/init.d/vncserver startStarting VNC server: 1:rootNew 'testdb:1 (root)' desktop is testdb:1Starting applications specified in /root/.vnc/xstartupLog file is /root/.vnc/testdb:1.log2:oracleNew 'testdb:2 (oracle)' desktop is testdb:2Starting applications specified in /home/oracle/.vnc/xstartupLog file is /home/oracle/.vnc/testdb:2.log                                                           [  OK  ]2)停止VNC服務命令[[email protected] ~]# /etc/init.d/vncserver stopShutting down VNC server: 1:root 2:oracle                  [  OK  ]3)重新啟動VNC服務命令[[email protected] ~]# /etc/init.d/vncserver restartShutting down VNC server: 1:root 2:oracle                  [  OK  ]Starting VNC server: 1:rootNew 'testdb:1 (root)' desktop is testdb:1Starting applications specified in /root/.vnc/xstartupLog file is /root/.vnc/testdb:1.log2:oracleNew 'testdb:2 (oracle)' desktop is testdb:2Starting applications specified in /home/oracle/.vnc/xstartupLog file is /home/oracle/.vnc/testdb:2.log                                                           [  OK  ]4)設定VNC服務隨系統啟動自動載入第一種方法:使用“ntsysv”命令啟動圖形化服務配置程式,在vncserver服務前加上星號,點擊確定,配置完成。第二種方法:使用“chkconfig”在命令列模式下進行操作,命令使用如下(預知chkconfig詳細使用方法請自助式man一下)[[email protected] ~]# chkconfig vncserver on[[email protected] ~]# chkconfig --list vncservervncserver       0:off   1:off   2:on    3:on    4:on    5:on    6:off











VNC介紹和如何遠端連線到遠端Linux介面?

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.