当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] 如何安装 Apache Guacamole 远程桌面网关

作者:精品下载站 日期:2024-12-14 12:33:35 浏览:15 分类:玩电脑

如何安装 Apache Guacamole 远程桌面网关


管理员经常使用多种类型的应用程序来连接到服务器/计算机。但您是否想知道是否有更简单的方法?为什么不使用 Apache Guacamole 作为远程桌面网关?

Apache Guacamole 支持多种连接协议,并且只需使用 Web 浏览器即可,无需其他工具或扩展。在本教程中,您将学习如何安装 Apache Guacamole 作为远程桌面网关。

继续阅读并不要过度连接到您的服务器/计算机!

先决条件

本教程将是一个实践演示。要继续操作,请确保您满足以下要求:

  • Linux 服务器 - 本教程使用最新的 Ubuntu 20.04 服务器。
  • root 或管理员用户。
  • 安装在您的服务器上的 MariaDB 数据库服务器。
  • 指向服务器 IP 地址的域名 - 本教程使用 example.io 域。

安装 Apache Guacamole 的软件包依赖项

Apache Guacamole 是一个无客户端远程桌面网关,允许您仅使用 Web 浏览器即可随时随地连接到计算机/服务器。

Apache Guacamole 是免费开源的,支持多种标准远程访问协议(例如 SSH、VNC 和 RDP),主要有两个部分:

  • 鳄梨酱服务器 - 必须从源代码手动安装
  • Guacamole Client - Java serverlet Web 应用程序,在 Apache Tomcat 下运行。该客户端是 Apache Guacamole 的前端。

在安装 Guacamole 服务器和客户端之前,您必须首先在 Linux 服务器上安装软件包依赖项。

1. 打开终端并连接到服务器。

2. 接下来,运行下面的 apt install 命令来安装用于构建 Guacamole 服务器的软件包依赖项。

sudo apt install build-essential libcairo2-dev libjpeg-turbo8-dev libpng-dev libtool-bin uuid-dev libossp-uuid-dev libavcodec-dev libavformat-dev libavutil-dev libswscale-dev freerdp2-dev libpango1.0-dev libssh2-1-dev libtelnet-dev libvncserver-dev libwebsockets-dev libpulse-dev libssl-dev libvorbis-dev libwebp-dev -y

[玩转系统] 如何安装 Apache Guacamole 远程桌面网关

3. 接下来,运行以下命令来安装 Apache Tomcat 9 软件包 (tomcat9),稍后您将使用该软件包来运行 Guacamole 客户端应用程序。

sudo apt install tomcat9 -y

[玩转系统] 如何安装 Apache Guacamole 远程桌面网关

4. 最后,运行下面的systemctl命令启动并启用tomcat9服务,然后验证tomcat9服务状态。

# Start and enable tomcat9
sudo systemctl enable --now tomcat9

# Verify tomcat9
sudo systemctl status tomcat9

下面的输出显示 tomcat9 服务状态为活动(正在运行)。

[玩转系统] 如何安装 Apache Guacamole 远程桌面网关

编译和安装鳄梨酱服务器

由于您已经安装了 Apache Guacamole 的软件包依赖项,因此是时候编译和安装 Guacamole 服务器了。唯一的方法是从源代码手动进行。

要安装鳄梨酱服务器:

1. 运行下面的wget命令,将 Guacamole 服务器 v1.4.0 的源代码 (guacamole-server-1.4.0.tar.gz) 下载到您的工作目录中。

在撰写本文时,Guacamole 服务器和客户端的 Apache Guacamole 最新版本均为 v1.4.0。

wget https://dlcdn.apache.org/guacamole/1.4.0/source/guacamole-server-1.4.0.tar.gz

2. 接下来,运行以下 tar 命令来提取 guacamole-server-1.4.0.tar.gz 文件。此命令将 Guacamole 服务器源代码提取到 guacamole-server-1.4.0 目录。

tar -xzf guacamole-server-1.4.0.tar.gz

3. 运行以下每个命令以执行以下操作:

  • 将您的工作目录 (cd) 更改为 guacamole-server-1.4.0
  • 运行 configure 脚本来设置 Guacamole 服务器。 configure 脚本是由 GNU Autotools 构建系统生成的 Bash 脚本,用于设置 Guacamole 服务器。
  • 自动将 Guacamole 服务器的 systemd 服务脚本安装 (--with-systemd-dir) 到 /etc/systemd/system/ 目录。
  • 禁用依赖项跟踪 (--disable-dependency-tracking) 以加快 Guacamole 服务器的构建时间。
# change working directory
cd guacamole-server-1.4.0/

# configure Guacamole server installation and verify system requirements
./configure --with-systemd-dir=/etc/systemd/system/ --disable-dependency-tracking

运行命令后,您将看到如下屏幕截图所示的输出。

请注意,Guacamole 服务器安装的所有库均已安装。您可以看到 Guacamole 支持多种协议,例如 Kubernetes(通过 WebSocket)、RDP、SSH 和 VNC。

[玩转系统] 如何安装 Apache Guacamole 远程桌面网关

4. 现在,运行下面的 make 命令来执行以下操作:

  • 这些命令在 Linux 服务器上编译鳄梨酱服务器 (make)。
  • 将鳄梨酱服务器的二进制文件 (make install) 安装到 /usr/local/bin/usr/local/sbin 目录。
  • /usr/local/lib 目录中安装鳄梨酱服务器的库。
# Compiling the source code
make

# Installing Guacamole server
make install

[玩转系统] 如何安装 Apache Guacamole 远程桌面网关

5. 运行以下命令来更新系统库的符号链接 (ldconfig),并重新加载 systemd 管理器 (daemon-reload)。

这些命令没有输出,但请确保您的 Linux 服务器加载所有新的 Guacamole 服务器库并应用 Guacamole 服务器的新 systemd 服务 (guacd)。

# Update symbolic links of the system libraries
sudo ldconfig
# Reload the systemd manager, and apply the new systemd service(guacd)
sudo systemctl daemon-reload

6. 最后,运行下面的 systemctl 命令来启动并启用鳄梨酱服务器服务 (guacd) 并验证 guacd 服务正在运行。

# Start and enable guacd
sudo systemctl enable --now guacd

# Verify guacd
sudo systemctl status guacd

您将在下面的输出中看到鳄梨酱服务器服务 guacd 处于活动状态(正在运行)。

[玩转系统] 如何安装 Apache Guacamole 远程桌面网关

创建鳄梨酱配置和目录

现在您已经安装了 Guacamole 服务器,是时候创建一个配置目录 (/etc/guacamole/) 以使 Apache Guacamole 正常工作。

/etc/guacamole/ 目录将存储 guacamole.propertiesguacd.conf 文件作为 Apache Guacamole 的主要配置。

1. 运行下面的 echo 命令,将环境变量 GUACAMOLE_HOME 定义到 Apache Tomcat 配置 (/etc/default/tomcat9)。

此命令确保 tomcat9 服务加载 Guacamole 配置目录 (/etc/guacamole)

echo GUACAMOLE_HOME=/etc/guacamole >> /etc/default/tomcat9

2. 现在,运行以下命令在以下其他目录中创建鳄梨酱服务器配置目录 (/etc/guacamole):

  • extensions 目录存储鳄梨酱扩展程序。
  • lib 目录存储 Guacamole 服务器所需的库。
mkdir -p /etc/guacamole/{extensions,lib}

3. 最后,运行以下命令创建 Apache Guacamole 配置文件 (guacamole.propertiesguacd.conf):

  • guacamole.properties 文件是 Apache Guacamole 的主要配置。
  • guacd.conf 文件是 Guacamole 服务器的配置。
touch /etc/guacamole/{guacamole.properties,guacd.conf}

设置 MariaDB 数据库

至此,您已经完成了 Apache Guacamole 的基本配置。但是,您仍然需要设置 Apache Guacamole 的身份验证方法。本教程使用 MariaDB 数据库进行 Apache Guacamole 身份验证。

要为 Apache Guacamole 设置 MariaDB 数据库:

1. 首先,运行以下 mysql 命令以默认 root 用户身份登录 MariaDB shell。出现提示时,输入 MariaDB 服务器的root 密码。

mysql -u root -p

您可以从下面的提示 (MariaDB [(none)]>) 看出您处于 MariaDB shell 中。

[玩转系统] 如何安装 Apache Guacamole 远程桌面网关

2. 接下来,运行以下 MySQL 查询来创建新数据库 guacamole_db 并退出 MariaDB shell。

CREATE DATABASE guacamole_db;
exit

[玩转系统] 如何安装 Apache Guacamole 远程桌面网关

3. 运行下面的 wget 命令来下载 Guacamole 数据库身份验证扩展程序。

您需要手动安装数据库扩展并导入数据库架构才能为 Apache Guacamole 设置数据库身份验证。

wget https://dlcdn.apache.org/guacamole/1.4.0/binary/guacamole-auth-jdbc-1.4.0.tar.gz

4. 现在运行以下命令来提取文件 guacamole-auth-jdbc-1.4.0.tar.gz,为您提供目录 guacamole-auth-jdbc-1.4.0代码>.

# Extract guacamole-auth-jdbc-1.4.0.tar.gz
tar -xf guacamole-auth-jdbc-1.4.0.tar.gz

# Change the working directory
cd guacamole-auth-jdbc-1.4.0/mysql/

5. 运行下面的 cat 命令,将 Apache Guacamole MariaDB 数据库架构 (schema/*.sql) 导入到 guacamole_db 数据库。

MariaDB 数据库模式用于多种 RDBMS,例如 MariaDB/MySQL、PostgreSQL 和 SQL Server。

# Check if the Apache Guacamole MariaDB database schema exists
ls
# Import the database schema (schema/*.sql) to theguacamole_dbdatabase
cat schema/*.sql | mysql -u root -p guacamole_db

出现提示时输入 MariaDB 的 root 用户密码,如下所示。

[玩转系统] 如何安装 Apache Guacamole 远程桌面网关

6. 现在,重新运行下面的 mysql 命令来登录 MariaDB shell。您将为 Apache Guacamole 设置一个新的 MariaDB 用户。

mysql -u root -p

[玩转系统] 如何安装 Apache Guacamole 远程桌面网关

7. 最后,运行下面的 MariaDB 查询来为 guacamole_db 数据库创建一个数据库用户。

# Create a new usercalled guacamole_user. 
# Make sure to change the password with a strong password.
CREATE USER 'guacamole_user'@'localhost' IDENTIFIED BY 'StrongPassword';
# Allow the userguacamole_userto access theguacamole_db database.
GRANT SELECT,INSERT,UPDATE,DELETE ON guacamole_db.* TO 'guacamole_user'@'localhost';
# Reload privileges from the privilege tables
FLUSH PRIVILEGES;
# Exit from MariaDB shell.
exit

[玩转系统] 如何安装 Apache Guacamole 远程桌面网关

安装数据库身份验证扩展和 MySQL/J 库

您现在已经为 Apache Guacamole 创建了 MariaDB 数据库和用户。接下来,您将安装 Guacamole 数据库身份验证扩展和数据库驱动程序的 MySQL/J 连接器。

Guacamole 数据库身份验证扩展允许您使用数据库身份验证设置 Apache Guacamole,例如 MySQL/MariaDB 和 PostgreSQL。 MySQL/J连接器库用于连接MySQL/MariaDB数据库。

1. 运行以下命令将工作目录更改为guacamole-auth-jdbc-1.4.0/mysql/,并列出工作目录中的文件。

# change working directory
cd guacamole-auth-jdbc-1.4.0/mysql/

# check list files
ls -lah

如下所示,您将看到鳄梨酱数据库身份验证扩展 (guacamole-auth-jdbc-mysql-1.4.0.jar)。

[玩转系统] 如何安装 Apache Guacamole 远程桌面网关

2. 接下来,运行下面的 cp 命令将 Guacamole 数据库身份验证扩展 (guacamole-auth-jdbc-mysql-1.4.0.jar) 安装到 /etc/guacamole/extensions/ 目录。

此命令安装并启用 Apache Guacamole 的 MariaDB/MySQL 扩展。

cp guacamole-auth-jdbc-mysql-1.4.0.jar /etc/guacamole/extensions/guacamole-auth-jdbc-mysql.jar

[玩转系统] 如何安装 Apache Guacamole 远程桌面网关

3. 运行下面的 wget 命令下载适用于 Java 的 MySQL/J 连接器(库)(mysql-connector-java_8.0.28-1ubuntu20.04_all.deb)。

Guacamole 数据库身份验证扩展将使用此 Java 库连接到 MariaDB 数据库服务器。

wget https://cdn.mysql.com//Downloads/Connector-J/mysql-connector-java_8.0.28-1ubuntu20.04_all.deb

4. 现在,运行下面的 dpkg 命令,将 MySQL/J 连接器 (mysql-connector-java_8.0.28-1ubuntu20.04_all.deb) 手动安装到您的 Ubuntu 系统。

此命令将 MySQL/J 库安装到 /usr/share/java 目录。

dpkg -i mysql-connector-java_8.0.28-1ubuntu20.04_all.deb

5. 最后,运行以下命令将 MySQL/J 连接器库复制到 /etc/guacamole/lib/ 目录。此命令允许 Apache Guacamole 使用 MySQL/J 库连接到 MariaDB 数据库。

# copy the MySQL/J connector
cp /usr/share/java/mysql-connector-java-8.0.28.jar /etc/guacamole/lib/mysql-connector.jar

[玩转系统] 如何安装 Apache Guacamole 远程桌面网关

使用 MariaDB 数据库配置 Apache Guacamole

您现在已经安装了 Guacamole 数据库身份验证扩展和 MySQL/J 连接器。但除非您应用数据库身份验证,否则它们不会做太多事情。

您将通过鳄梨酱配置 (guacamole.properties) 应用鳄梨酱数据库身份验证。您还可以使用 guacd.conf 配置来设置 guacd 绑定 IP 地址和端口。

1. 使用您喜欢的编辑器编辑/etc/guacamole/guacamole.properties文件并填充以下配置。

请务必输入正确的 MariaDB 用户、密码和数据库名称。 Apache Guacamole 将使用此配置连接到 MariaDB 数据库。

mysql-hostname: localhost
mysql-port: 3306
mysql-database: guacamole_db
mysql-username: guacamole_user
mysql-password: StrongPassword

2. 接下来,编辑 /etc/guacamole/guacd.conf 文件并填充以下配置。

此配置在绑定地址 0.0.0.0 或服务器上具有默认 TCP 端口 4822 的任何 IP 地址上运行 guacd 服务。

[server]
bind_host = 0.0.0.0
bind_port = 4822

最后,运行下面的 systemctl 命令来重新加载 guacdtomcat9 服务并应用新的更改。

# restart guacd
sudo systemctl restart guacd

# restart tomcat9
sudo systemctl restart tomcat9

安装鳄梨酱客户端 Web 应用程序

至此,您已经完成了带有 MariaDB 数据库身份验证扩展的鳄梨酱服务器安装。现在,您将安装 Guacamole 客户端,它是 Apache Guacamole 软件堆栈的前端。

本教程使用来自官方鳄梨酱下载页面的预构建鳄梨酱客户端包 (guacamole.war)。

运行下面的 wget 命令下载 Guacamole Web 应用程序 v1.4.0 的完整包 (guacamole-1.4.0.war)。

截至撰写本文时,Guacamole Web 应用程序的最新版本是 v1.4.0。

wget <https://dlcdn.apache.org/guacamole/1.4.0/binary/guacamole-1.4.0.war>

[玩转系统] 如何安装 Apache Guacamole 远程桌面网关

现在,运行下面的每个命令,将文件 guacamole-1.4.0.war 移动并安装到 /var/lib/tomcat9/webapps 目录。此操作使鳄梨酱客户端可以通过路径 URL (/guacamole/) 进行访问。

# Rename guacamole-1.4.0.war to guacamole.war
mv guacamole-1.4.0.war guacamole.war

# Copy guacamole.war
cp guacamole.war /var/lib/tomcat9/webapps

# Verify guacamole.war
ls /var/lib/tomcat9/webapps

[玩转系统] 如何安装 Apache Guacamole 远程桌面网关

将 Apache 设置为鳄梨酱客户端的反向代理

在服务器上安装 Guacamole 客户端后,您需要使用 Apache 虚拟主机配置来安装和配置 Apache Web 服务器。您将启用 Apache Web 服务器作为 Guacamole 客户端的反向代理。

1. 按照 certbot 文档为您的域名生成免费的 LetsEncrypt SSL 证书。 SSL 证书将保护并加密您与 Guacamole 客户端 Web 应用程序的连接。

2. 接下来,运行下面的 apt 命令来安装 Apache 网络服务器。

sudo apt install apache2 -y

[玩转系统] 如何安装 Apache Guacamole 远程桌面网关

3. 安装后,运行下面的a2enmod命令以启用 Apache 反向代理的模块。

sudo a2enmod proxy proxy_wstunnel proxy_http ssl rewrite

[玩转系统] 如何安装 Apache Guacamole 远程桌面网关

4. 现在,创建一个新的虚拟主机配置文件 (/etc/apache2/sites-available/guacamole.conf) 并填充以下配置。

example.io 域名更改为您的域名,并将 SSL 证书路径 (/etc/letsencrypt/live/example.io/) 更改为您的 SSL 路径。

此 Apache 虚拟主机配置为 Guacamole 客户端 Web 应用程序启用反向代理。客户端 Web 应用程序在 Apache Tomcat 的端口 8080 下运行,URL 路径为 /guacamole

<VirtualHost *:80>
    ServerName example.io
    ServerAlias www.example.io

    Redirect permanent / https://example.io/
</VirtualHost>

<VirtualHost *:443>
    ServerName example.io
    ServerAlias www.example.io

    <If "%{HTTP_HOST} == 'www.example.io'">
    Redirect permanent / https://example.io/
    </If>

    ErrorLog /var/log/apache2/example.io-error.log
    CustomLog /var/log/apache2/example.io-access.log combined

    SSLEngine On
    SSLCertificateFile /etc/letsencrypt/live/example.io/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/example.io/privkey.pem

    <Location /guacamole/>
        Order allow,deny
        Allow from all
        ProxyPass http://127.0.0.1:8080/guacamole/ flushpackets=on
        ProxyPassReverse http://127.0.0.1:8080/guacamole/
    </Location>

    <Location /guacamole/websocket-tunnel>
        Order allow,deny
        Allow from all
        ProxyPass ws://127.0.0.1:8080/guacamole/websocket-tunnel
        ProxyPassReverse ws://127.0.0.1:8080/guacamole/websocket-tunnel
    </Location>

</VirtualHost>

5. 运行以下每个命令以激活 guacamole.conf 虚拟主机配置并验证 Apache 配置。 # 激活 guacamole.conf a2ensite guacamole.conf # 验证 apache2 配置 apachectl configtest

# activate guacamole.conf
a2ensite guacamole.conf

# verify apache2 configuration
apachectl configtest

如果您的配置没有错误,您将看到语法正常消息输出,如下所示。

[玩转系统] 如何安装 Apache Guacamole 远程桌面网关

6. 接下来,编辑 Tomcat 配置 (/etc/tomcat9/server.xml) 并在 部分中填充以下配置。

此配置允许 Tomcat 中的应用程序查看客户端的真实 IP 地址。您需要此配置,因为主应用程序 Guacamole 客户端位于 Apache 反向代理后面。

<Valve className="org.apache.catalina.valves.RemoteIpValve"
            internalProxies="127.0.0.1"
            remoteIpHeader="x-forwarded-for"
            remoteIpProxiesHeader="x-forwarded-by"
            protocolHeader="x-forwarded-proto" />

[玩转系统] 如何安装 Apache Guacamole 远程桌面网关

7. 最后,运行下面的 systemctl 命令来重新启动 apache2tomcat9 服务并应用新的更改。

# Restart apache2
sudo systemctl restart apache2

# Restart tomcat9
sudo systemctl restart tomcat9

验证 Apache 鳄梨酱

您现在已经完成了使用 Apache2 反向代理的 Apache Guacamole 安装。但你怎么知道安装是否有效呢?您将通过从 Web 浏览器访问 Apache Guacamole 来验证安装。

打开网络浏览器并输入 Apache Guacamole 安装的域名,后跟 URL 路径/guacamole(即 https://example.io/guacamole)。如果所有配置均正确,您将看到 Apache Guacamole Web 应用程序的登录页面,如下所示。

输入默认用户guacadmin和密码guacadmin,然后点击登录按钮。

[玩转系统] 如何安装 Apache Guacamole 远程桌面网关

登录后,您将看到 Apache Guacamole 管理仪表板的空白页面,如下所示。

[玩转系统] 如何安装 Apache Guacamole 远程桌面网关

接下来,点击右上角的用户 (guacadmin),然后选择设置以访问用户帐户设置。

[玩转系统] 如何安装 Apache Guacamole 远程桌面网关

如下所示,您可以更改 guacadmin 用户的默认密码、创建新用户、创建新的远程桌面连接以及设置 Apache Guacamole 本身。

[玩转系统] 如何安装 Apache Guacamole 远程桌面网关

结论

在本教程中,您学习了如何安装 Apache Guacamole 作为具有 MariaDB 数据库身份验证和 Apache 反向代理的远程桌面网关。至此,您已经拥有了一个功能齐全的远程桌面网关。

现在,为什么不探索与 CAS 身份验证和 Apache Guacamole 基本管理的集成呢?查看官方 Guacamole 文档,了解有关 Apache Guacamole 的更多信息。

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯