前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Centos7安装Guacamole1.0.0以及自定义客户端 原

Centos7安装Guacamole1.0.0以及自定义客户端 原

作者头像
尚浩宇
发布2019-08-18 23:06:36
3.1K0
发布2019-08-18 23:06:36
举报
文章被收录于专栏:杂烩杂烩

1、概述

    Guacamole大致流程如下图所示,本文目的是快速完成安装部署,如需深入了解参阅官方文档或其他博客。

    准备两台机器,一个是代理机一个是目标机器。

2、安装依赖

    基础依赖:

  • jdk1.8+
  • tomcat8+

    系统依赖: 

代码语言:javascript
复制
yum install -y cairo-devel libjpeg-turbo-devel libpng-devel uuid-devel
yum install -y freerdp-devel pango-devel libssh2-devel libvncserver-devel pulseaudio-libs-devel openssl-devel libvorbis-devel libwebp-devel

3、部署

3.1、guacamole

    访问http://guacamole.apache.org/releases/1.0.0/下载server包,然后上传到代理机目录下,如/opt/guacamole。接着解压,cd到目录执行

代码语言:javascript
复制
./configure --with-init-dir=/etc/init.d
make && make install
ldconfig

    执行完成后,编译或下载war包,这里是war包下载地址http://mirror.bit.edu.cn/apache/guacamole/1.0.0/binary/,放入到tomcat的webapp下,然后在/opt/guacamole目录下创建三个文件:

guacamole.properties

代码语言:javascript
复制
guacd-hostname: 192.168.1.96
guacd-port:     4822

user-mapping.xml 

代码语言:javascript
复制
<user-mapping>
    <!-- 登陆账号密码 -->
    <authorize username="admin" password="1">
        <connection name="win">
            <protocol>rdp</protocol>
            <param name="hostname">192.168.4.181</param>
            <param name="port">3389</param>
            <!-- 需要链接的服务器的账号密码 -->
            <param name="username">shy</param>
            <param name="password">1</param>
            <!-- 大小自动变化 -->
            <param name="resize-method">display-update</param>
            <!-- 分辨率 -->
            <param name="dpi">100</param>
        </connection>
        <connection name="linux_cmd">
            <protocol>ssh</protocol>
            <param name="hostname">192.168.4.181</param>
            <param name="port">22</param>
            <!-- 需要链接的服务器的账号密码 -->
            <param name="username">shy</param>
            <param name="password">cmgplex!@#</param>
        </connection>
        <connection name="linux_win">
            <protocol>rdp</protocol>
            <param name="hostname">192.168.4.181</param>
            <param name="port">1</param>
            <!-- 需要链接的服务器的账号密码 -->
            <param name="username">shy</param>
            <param name="password">1</param>
        </connection>
    </authorize>
</user-mapping>

logback.xml

代码语言:javascript
复制
<configuration>
 <appender name="FILE" class="ch.qos.logback.core.FileAppender">
  <file>/opt/guacamole/guacamole.log</file>
   <encoder>
     <pattern>%msg%n</pattern>
   </encoder>
 </appender>
 <root level="info">
   <appender-ref ref="FILE" />
 </root>
</configuration>

    需要注意的是,如果guacamole.properties配置不起作用,代理会始终绑定在127.0.0.1上,导致其他服务器无法连接,这时可以手动启动加参数绑定IP即可

代码语言:javascript
复制
guacd -l 192.168.43.1

    准备完成后配置环境变量

代码语言:javascript
复制
export CATALINA_HOME=/opt/guacamole/apache-tomcat-8.5.43
export CATALINA_BASE=/opt/guacamole/apache-tomcat-8.5.43
export GUACAMOLE_HOME=/opt/guacamole

    最后启动服务

代码语言:javascript
复制
service guacd start  #启动guacamole
./startup.sh  #启动tomcat

3.2目标机器

    如果目标是windows,或者命令行linux直接配置用户名密码等即可,如果目标是linux桌面,那么需要在目标机器上安装vnc或者rdp服务,以rdp为例,部署过程如下:

代码语言:javascript
复制
i /etc/yum.repos.d/xrdp.repo

[xrdp]
name=xrdp
baseurl=http://li.nux.ro/download/nux/dextop/el7/x86_64/
enabled=1
gpgcheck=0

yum -y install xrdp tigervnc-server

#启动服务:
systemctl start xrdp.service
systemctl enable xrdp.service

    最后打开http://localhost:8080/guacamole,即可看到页面

三、自定义客户端

    有时候需要集成到自己的系统,而不是使用自带的client,Guacamole支持多种客户端API,以java为例,基于springboot流程如下:

    添加依赖

代码语言:javascript
复制
<!-- guacamole -->
		<dependency>
			<groupId>org.apache.guacamole</groupId>
			<artifactId>guacamole-common</artifactId>
			<version>1.0.0</version>
		</dependency>

    Application增加注解@ServletComponentScan,复制官方demo的servlet并稍作修改如下:

    DummyGuacamoleTunnelServlet.java

代码语言:javascript
复制
/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;

import org.apache.guacamole.GuacamoleException;
import org.apache.guacamole.net.GuacamoleTunnel;
import org.apache.guacamole.net.InetGuacamoleSocket;
import org.apache.guacamole.net.SimpleGuacamoleTunnel;
import org.apache.guacamole.protocol.ConfiguredGuacamoleSocket;
import org.apache.guacamole.protocol.GuacamoleConfiguration;
import org.apache.guacamole.servlet.GuacamoleHTTPTunnelServlet;
import org.springframework.beans.factory.annotation.Value;

/**
 * Simple tunnel example with hard-coded configuration parameters.
 */
@WebServlet(urlPatterns = "/tunnel")
public class DummyGuacamoleTunnelServlet extends GuacamoleHTTPTunnelServlet {
	@Value("${guacamole.guacd.host}")
	private String guacdHost;
	@Value("${guacamole.guacd.port}")
	private Integer guacdPort;
	@Value("${guacamole.target.protocol}")
	private String targetProtocol;
	@Value("${guacamole.target.host}")
	private String targetHost;
	@Value("${guacamole.target.port}")
	private String targetPort;
	@Value("${guacamole.target.username}")
	private String targetUsername;
	@Value("${guacamole.target.password}")
	private String targetPassword;

	private static final long serialVersionUID = 1126569778799758654L;

	@Override
	protected GuacamoleTunnel doConnect(HttpServletRequest request) throws GuacamoleException {
		GuacamoleConfiguration config = new GuacamoleConfiguration();
		config.setProtocol(this.targetProtocol);
		config.setParameter("hostname", this.targetHost);
		config.setParameter("port", this.targetPort);
		config.setParameter("username", this.targetUsername);
		config.setParameter("password", this.targetPassword);
		return new SimpleGuacamoleTunnel(
				new ConfiguredGuacamoleSocket(new InetGuacamoleSocket(this.guacdHost, this.guacdPort), config));

	}

}

    application.properties增加如下配置

代码语言:javascript
复制
guacamole.guacd.host=xxxx
guacamole.guacd.port=4822
guacamole.target.protocol=rdp
guacamole.target.host=192.168.1.1
guacamole.target.port=3389
guacamole.target.username=ad
guacamole.target.password=1

    最后增加页面,页面很简单注意引用js即可

代码语言:javascript
复制
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!--
    Licensed to the Apache Software Foundation (ASF) under one
    or more contributor license agreements.  See the NOTICE file
    distributed with this work for additional information
    regarding copyright ownership.  The ASF licenses this file
    to you under the Apache License, Version 2.0 (the
    "License"); you may not use this file except in compliance
    with the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing,
    software distributed under the License is distributed on an
    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    KIND, either express or implied.  See the License for the
    specific language governing permissions and limitations
    under the License.
-->
<html>

    <head>
        <link rel="stylesheet" type="text/css" href="/media/css/guacamole.css"/>
        <!-- Guacamole JavaScript API -->
        <script type="text/javascript" src="/media/js/all.min.js"></script>
        <link rel="shortcut icon" href="/media/image/favicon.ico" />
    </head>

    <body>

        <!-- Display -->
        <div id="display"></div>
        <!-- Init -->
        <script type="text/javascript"> /* <![CDATA[ */

            // Get display div from document
            var display = document.getElementById("display");

            // Instantiate client, using an HTTP tunnel for communications.
            var guac = new Guacamole.Client(
                new Guacamole.HTTPTunnel("/tunnel")
            );

            // Add client to display div
            display.appendChild(guac.getDisplay().getElement());
            
            // Error handler
            guac.onerror = function(error) {
                alert(error);
            };

            // Connect
            guac.connect();

            // Disconnect on close
            window.onunload = function() {
                guac.disconnect();
            }

            // Mouse
            var mouse = new Guacamole.Mouse(guac.getDisplay().getElement());

            mouse.onmousedown = 
            mouse.onmouseup   =
            mouse.onmousemove = function(mouseState) {
                guac.sendMouseState(mouseState);
            };

            // Keyboard
            var keyboard = new Guacamole.Keyboard(document);

            keyboard.onkeydown = function (keysym) {
                guac.sendKeyEvent(1, keysym);
            };

            keyboard.onkeyup = function (keysym) {
                guac.sendKeyEvent(0, keysym);
            };

        /* ]]> */ </script>

    </body>

</html>

    js可以在官方demo里找到。

    这里展示的是比较简单的自定义客户端,根据自身业务可以做到更强大的功能。

(adsbygoogle = window.adsbygoogle || []).push({});

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 1、概述
    • 2、安装依赖
    • 3、部署
      • 3.1、guacamole
        • 3.2目标机器
        • 三、自定义客户端
        领券
        问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档