基於vnc實現通過web訪問遠程服務器或虛擬機的方法

            guacamole環境搭建

guacamole 是一個通過web訪問vncserver(包括kvm產生的虛擬機的vnc)的開源項目,它是基於html5的,所以只要瀏覽器支持html5就可以訪問。

相關源碼:

http://sourceforge.net/projects/guacamole/files/current/source/

官網:http://guac-dev.org/

幫助文檔:http://guac-dev.org/doc/gug/

Api文檔:http://guac-dev.org/doc/

開發所需的源碼包:http://guac-dev.org/repo/net/sourceforge/guacamole/

搭建服務器端:

http://sourceforge.net/projects/guacamole/files/current/source/

在以上地址下載相關包:

libguac-0.7.0.tar.gz

guacd-0.7.0.tar.gz

libguac-client-vnc-0.7.1.tar.gz

guacamole-0.8.0.tar.gz

安裝服務端所需依賴包:

$ tar -xzf libguac-0.7.0.tar.gz

$ cd libguac-0.7.0/

$ ./configure

$ make

$ make install

$ ldconfig

$ tar -xzf guacd-0.7.0.tar.gz

$ cd guacd-0.7.0/

$ ./configure --with-init-dir=/etc/init.d

$ make

$ sudo make install

若有錯誤如:undefined rpl_malloc,則修改configura註釋掉:

$as_echo "#define malloc rpl_malloc" >>confdefs.h

$ tar -xzf libguac-client-vnc-0.7.1.tar.gz

$ cd libguac-client-vnc-0.7.1/

$ ./configure

$ make

$ sudo make install

$ sudo ldconfig

若有錯誤如:error: rfb/rfbclient.h: No such file or directory

安裝libvncserver解決

rpm -Uvh libvncserver-0.9.7-4.el6.x86_64.rpm

libvncserver-devel-0.9.7-4.el6.x86_64.rpm

安裝guacamole的web應用:

$ tar -xzf guacamole-0.8.0.tar.gz

$ cd guacamole-0.8.0/

$ mvn package

將其中的war包放入/apache-tomcat-7.0.30/webapps下將doc中的

guacamole.properties拷貝至

/apache-tomcat-7.0.30/webapps/guacamole-0.8.0/WEB-INF/classes

Guacamole.properties內容:

# Hostname and port of guacamole proxy

guacd-hostname: IP

guacd-port:     4822

# Auth provider class (authenticates user/pass combination, needed if using the provided login screen)

auth-provider: net.sourceforge.guacamole.net.basic.BasicFileAuthenticationProvider

basic-user-mapping: /guacamole/user-mapping.xml

user-mapping.xml內容

<user-mapping>

   <!-- Per-user authentication and config information -->

   <authorize username="admin" password="admin">

           <protocol>vnc</protocol>

           <param name="hostname">IP</param>

           <param name="port">5930</param>

           <param name="password"></param>

   </authorize>

</user-mapping>

啓動tomcat:/apache-tomcat-7.0.30/bin/catalina.sh run

訪問:http://IP:8080/guacamole-0.8.0

登錄:

選擇虛擬機:


提示錯誤,查看服務端日誌:

INFO: Successful connection from  to "DEFAULT".

May 30, 2013 5:30:56 PM org.slf4j.impl.JCLLoggerAdapter error

SEVERE: Server error in tunnel

net.sourceforge.guacamole.GuacamoleServerException: java.net.ConnectException: Connection refused

...

Caused by: java.net.ConnectException: Connection refused

...

錯誤排查:

執行命令:guacd

提示:error while loading shared libraries libguac.so.4

這個libguac.so.4文件存在於/usr/local/lib/下,但是卻提示找不到。解決方法:在/etc/ld.so.conf中加入/usr/local/lib這一行,保存之後,再運行:/sbin/ldconfig –v更新一下配置即可。

啓動guacd

接下來遇到新錯誤,查看日誌:

May 30, 2013 6:05:03 PM org.slf4j.impl.JCLLoggerAdapter error

SEVERE: Server error in tunnel

net.sourceforge.guacamole.GuacamoleServerException: End of stream during initial handshake.

通過查看:http://guac-dev.org/doc/gug/servlet-container-logs.html

得知client連接出錯,查看系統日誌/var/log/messages發現:

Error loading client plugin: Invalid argument:

/usr/local/lib/libguac-client-vnc.so: undefined symbol: rfbClientErr

大概意思是缺少rfbClientErr,懷疑是libvncserver版本過低,或者libguac-client的版本過高,與之不匹配。重新下載libvncserver的rpm包,地址:

http://bo.mirror.garr.it/pub/1/centos/6.4/os/x86_64/Packages/libvncserver-devel-0.9.7-4.el6.x86_64.rpm

http://bo.mirror.garr.it/pub/1/centos/6.4/os/x86_64/Packages/libvncserver-0.9.7-4.el6.x86_64.rpm

之前用的centos6.3的版本,現在用6.4的,重新安裝這兩個rpm包。之後重新安裝libguac-client-vnc客戶端:

記得清除之前安裝的:make clean

rm -f /usr/local/lib/libguac-client-vnc*

重新http啓動服務,一切OK:

最後,由於該項目是開源的,你可以根據自己的需要靈活應用與自己的項目中。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章