過去記事Guacamole220120
webブラウザで画面共有が表示可能となる
本家様 http://guacamole.apache.org/
外部と内部を繋ぐサーバ(gate)があって、外部から内部のwindowsマシンとかLinuxマシンをブラウザから操作できるか確かめてみた

フラットファイルにアカウントとパスワード、そして接続先、接続方法(RDP,VNC)を予め定義して使用する方法の他に
データベースにそれら情報を格納してより便利に管理する方法もある。
ここではデータベース方式(PostgreSQL)を使ってみた.
この中継サーバはCentOS 7.9としてます
運用設定Guacamole/Setting
下拵え †
Guacamoleの構築のために必要なパッケージをあらかじめインストールしておきます
[root@gate ~]# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)
[root@gate ~]# yum -y groupinstall "Development Tools"
[root@gate ~]# yum -y install libjpeg-turbo-devel libpng-devel cairo-devel uuid-devel
これで一応サーバアプリはコンパイルはできるけど、GuacamoleでRDP対応とかのために追加のパッケージも入れます
詳細はこちらで確認できます https://guacamole.apache.org/doc/gug/installing-guacamole.html
[root@gate ~]# yum -y install epel-release
[root@gate ~]# yum -y install freerdp-devel pango-devel libssh2-devel libtelnet-devel \
libvncserver-devel libwebsockets-devel pulseaudio-libs-devel openssl-devel libvorbis-devel libwebp-devel libgcrypt-devel
*操作内容を録画したいなら「ffmpeg-devel」も必要. ただCentOSリポジトリにもepelリポジトリにもないので
「https://pkgs.org/download/ffmpeg-devel」から「CERT Forensics Tools x86_64」の「ffmpeg-devel」を入れる
[root@gate ~]# rpm -Uvh https://forensics.cert.org/cert-forensics-tools-release-el7.rpm
[root@gate ~]# yum -y --enablerepo=forensics install ffmpeg-devel
Guacamoleサーバアプリの構築 †
最新版(22.01時点)の1.4.0を取得します。ファイル名は「guacamole-server-1.4.0.tar.gz」となります。
http://guacamole.apache.org/releases/1.4.0/
[root@gate ~]# tar xf guacamole-server-1.4.0.tar.gz
[root@gate ~]# cd guacamole-server-1.4.0/
[root@gate guacamole-server-1.4.0]#
[root@c guacamole-server-1.4.0]# ./configure --with-systemd-dir=/etc/systemd/system --prefix=/opt/guacamole
:
:
------------------------------------------------
guacamole-server version 1.4.0
------------------------------------------------
Library status:
freerdp2 ............ yes
pango ............... yes
libavcodec .......... yes
libavformat.......... yes
libavutil ........... yes
libssh2 ............. yes
libssl .............. yes
libswscale .......... yes
libtelnet ........... yes
libVNCServer ........ yes
libvorbis ........... yes
libpulse ............ yes
libwebsockets ....... yes
libwebp ............. yes
wsock32 ............. no
Protocol support:
Kubernetes .... yes
RDP ........... yes
SSH ........... yes
Telnet ........ yes
VNC ........... yes
Services / tools:
guacd ...... yes
guacenc .... yes
guaclog .... yes
FreeRDP plugins: /usr/lib64/freerdp2
Init scripts: no
Systemd units: /etc/systemd/system
Type "make" to compile guacamole-server.
[root@gate guacamole-server-1.4.0]#
configureの途中で
configure: WARNING:
--------------------------------------------
This version of libvncclient lacks support
for TLS locking. VNC connections that use
TLS may experience instability as documented
in GUACAMOLE-414
が表示されるが、留意しておきます libvncserverが古いのでVNC with TLSの際に正しく機能しない場合があるみたい
っでコンパイル、インストール、起動設定
[root@gate guacamole-server-1.4.0]# make && make install
[root@gate guacamole-server-1.4.0]# echo /opt/guacamole/lib > /etc/ld.so.conf.d/guacamole.conf
[root@gate guacamole-server-1.4.0]# ldconfig
[root@gate guacamole-server-1.4.0]# ls -l /etc/systemd/system
:
-rw-r--r--. 1 root root 990 Feb 11 15:46 guacd.service
:
[root@gate guacamole-server-1.4.0]# systemctl daemon-reload
[root@gate guacamole-server-1.4.0]# systemctl enable guacd.service && systemctl start guacd.service
servlet container[jetty]の準備 †
Guacamoleはserver部分とwebコンテンツで構成されています. server部分は前段で完了済み.
Guacamoleのwebコンテンツは servlet で提供されていて、動かすには servlet containerが必要となります.
(Guacamoleのwebコンテンツはソースからは作りません. すでに提供されているwarファイルを使います. 面倒なので.)
っでそのservlet containerですが、tomcatとかでもいいのですがここでは軽量の Jetty を使います.
jettyのバージョンは http://www.eclipse.org/jetty/download.php
から 9.4 系列を使います.
version10や11でも動くとは思いますが、搭載するjavaが 1.8 系列なので9.4にしてます. java11を使うならversion10とか11なのかなと
[root@gate ~]# yum -y install java-1.8.0-openjdk-devel
[root@gate ~]# java -version
openjdk version "1.8.0_322"
OpenJDK Runtime Environment (build 1.8.0_322-b06)
OpenJDK 64-Bit Server VM (build 25.322-b06, mixed mode)
[root@gate ~]#
次にJettyを組み込みます. 場所は「/opt/jetty」を起点にします
[root@gate ~]# cd /opt/
[root@gate opt]# curl -O https://repo1.maven.org/maven2/org/eclipse/jetty/jetty-distribution/9.4.45.v20220203/jetty-distribution-9.4.45.v20220203.tar.gz
[root@gate opt]# tar xf jetty-distribution-9.4.45.v20220203.tar.gz
[root@gate opt]# ln -s jetty-distribution-9.4.45.v20220203 jetty
jettyの稼働ユーザ[jetty]を用意します. system側のユーザなので[-s]を付けてユーザを作ります. そして/opt/jettyの所有権をユーザ[jetty]に渡します
[root@gate ~]# useradd -r -s /bin/false -d /opt/jetty -M jetty
[root@gate ~]# id jetty
uid=997(jetty) gid=995(jetty) groups=995(jetty)
[root@gate ~]# chown -R jetty:jetty /opt/jetty/ <-- 「/opt/jetty/」配下のフォルダ/ファイルがjettyの所有であることが必要
jettyの起動スクリプトを作ります. サンプルが用意されていて「/opt/jetty/bin/jetty.service」これを参照に下記を作ります
そして作成したjetty起動スクリプトを有効にしておきます
[root@gate ~]# vi /etc/systemd/system/jetty.service
[Unit]
Description=Jetty Web Application Server
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
EnvironmentFile=-/etc/sysconfig/jetty
PIDFile=/opt/jetty/logs/jetty.pid
ExecStart=/opt/jetty/bin/jetty.sh start
ExecStop=/opt/jetty/bin/jetty.sh stop
ExecReload=/opt/jetty/bin/jetty.sh restart
User=jetty
Group=jetty
StandardOutput=null
[Install]
WantedBy=multi-user.target
[root@gate ~]# systemctl daemon-reload
[root@gate ~]# systemctl enable jetty
jetty起動スクリプトに記載している環境設定ファイルEnvironmentFile「/etc/sysconfig/jetty」は下記のようにします
[root@gate ~]# vi /etc/sysconfig/jetty
JETTY_HOME=/opt/jetty
JETTY_USER=jetty
JETTY_ARGS=jetty.http.port=8080
JETTY_RUN=/opt/jetty/logs
JETTY_SHELL=/bin/bash
JETTY_BASE=/opt/jetty
[root@gate ~]#
上記は port 8080 でjettyを動かすことを意味してます.「lsof -i」とかでport 8080が既に使用されていないとかの確認が必要かもしれません。
これでservlet containerの準備は完了で、次にGuacamole webコンテンツをこのjettyの載せます
webコンテンツの導入 †
作業としてはjettyの「webapps」フォルダ「/opt/jetty/webapps」に Guacamole の webコンテンツ(warファイル)を置くだけ.
https://guacamole.apache.org/releases/1.4.0/
から「guacamole-1.4.0.war」をダウンロードして「webapps」に入れる
[root@gate ~]# cp guacamole-1.4.0.war /opt/jetty/webapps/
[root@gate ~]# chown jetty. /opt/jetty/webapps/guacamole-1.4.0.war <--所有権を変更します
servlet containerのjettyの稼働を確認するため、この段階で試しに動かしてみる.
その前に firewall とかで制限を掛けているなら 8080 ポートを開けてから jetty を起動させます
[root@gate ~]# firewall-cmd --add-port=8080/tcp --zone=public --permanent
success
[root@gate ~]# firewall-cmd --reload
success
[root@gate ~]# cd /opt/jetty
[root@gate jetty]# java -jar /opt/jetty/start.jar
:
:
他のマシンから「http://gate:8080」にアクセスすると下記のような画面になる

エラー画面ですが、「/guacamole-1.4.0」とあればOK
確認が終わったら「Ctrl-C」でjettyを止める
データベースの準備 †
OSリポジトリでインストールできるpostgreSQLを使います.
既に別のpostgreSQLがあればそれを使っても大丈夫. 別のマシンで動ているpostgreQLでも可. 既に既設のpostgreSQLがあるならportを別にしたPostgreSQLを用意するか、その既設を使ってもいい. DBが異なるだけなので
[root@gate ~]# yum -y install postgresql-server
[root@gate ~]# postgresql-setup initdb
「/var/lib/pgsql/data/pg_hba.conf」の一部を修正してデータベースアカウントでアクセス可能にします
| --- /var/lib/pgsql/data/pg_hba.conf.orig 2022-02-12 06:42:27.764983087 +0900
+++ /var/lib/pgsql/data/pg_hba.conf 2022-02-12 06:43:46.484576158 +0900
@@ -79,7 +79,7 @@
# "local" is for Unix domain socket connections only
local all all peer
# IPv4 local connections:
-host all all 127.0.0.1/32 ident
+host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 ident
# Allow replication connections from localhost, by a user with the
|
そして起動させます
[root@gate ~]# systemctl enable postgresql && systemctl start postgresql
そしてGuacamoleが使うDB「guacamole_db」を用意します
[root@gate ~]# su - postgres
-bash-4.2$ createdb guacamole_db
-bash-4.2$ psql -l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
--------------+----------+----------+-------------+-------------+-----------------------
guacamole_db | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
(4 rows)
-bash-4.2$ exit
logout
[root@gate ~]#
データベースに必要なテーブル、コンテンツを組み込む †
作成したデータベース「guacamole_db」にスキーマオブジェクト(テーブルとか)を作ります
必要なスキーマオブジェクトは、「https://guacamole.apache.org/releases/1.4.0/
」の「guacamole-auth-jdbc-1.4.0.tar.gz」に含まれているので、これを入手して展開します
[root@gate ~]# tar xf guacamole-auth-jdbc-1.4.0.tar.gz
[root@gate ~]# cd guacamole-auth-jdbc-1.4.0
[root@gate guacamole-auth-jdbc-1.4.0]# ls -l
total 24
drwxrwxr-x. 12 1001 1001 266 Feb 12 13:22 bundled
-rw-rw-r--. 1 1001 1001 17001 Dec 29 15:46 LICENSE
drwxr-xr-x. 3 root root 63 Feb 12 13:22 mysql
-rw-rw-r--. 1 1001 1001 2695 Dec 29 15:46 NOTICE
drwxr-xr-x. 3 root root 68 Feb 12 13:22 postgresql
drwxr-xr-x. 3 root root 67 Feb 12 13:22 sqlserver
[root@gate guacamole-auth-jdbc-1.4.0]# cd postgresql/schema/
[root@gate schema]# ls -l
total 28
-rw-rw-r--. 1 1001 1001 21749 Jul 21 2021 001-create-schema.sql
-rw-rw-r--. 1 1001 1001 2699 Jul 21 2021 002-create-admin-user.sql
drwxr-xr-x. 2 1001 1001 242 Jul 21 2021 upgrade
[root@gate schema]#
この「001-create-schema.sql」にはGuacamoleに必要なスキーマオブジェクト(テーブル,インデックスとか)が明記されて、
「002-create-admin-user.sql」には作成したテーブルへのデータ(コンテンツ)が明記されている.
これらを「guacamole_db」に反映させます
[root@gate schema]# cat *.sql | su - postgres -c "psql -d guacamole_db -f -"
データベースへアクセスできるアカウントを作成 †
Guacamole から postgreSQL へ接続するためのデータベースアカウントを用意します pg_hba.confの修正でデータベースアカウントでの接続を有効にしたので
[root@gate ~]# su - postgres -c "psql -d guacamole_db"
psql (9.2.24)
Type "help" for help.
guacamole_db=# CREATE USER guacamole_user WITH PASSWORD 'some_password'; <-- ユーザ「guacamole_user」を作ってそのパスワードを「some_password」にしてます
guacamole_db=# GRANT SELECT,INSERT,UPDATE,DELETE ON ALL TABLES IN SCHEMA public TO guacamole_user; <-- ユーザ「guacamole_user」へ権限譲渡
guacamole_db=# GRANT SELECT,USAGE ON ALL SEQUENCES IN SCHEMA public TO guacamole_user; <-- ユーザ「guacamole_user」へ権限譲渡その2
guacamole_db=# \q
[root@gate ~]#
正しく作成できたかのテスト
[root@gate ~]# psql -h localhost4 -U guacamole_user -d guacamole_db
Password for user guacamole_user:
psql (9.2.24)
Type "help" for help.
guacamole_db=> \q
[root@gate ~]#
ここではpg_hba.confでipv4のみmd5としている. なので「localhost4」か「127.0.0.1」指定が必要. ipv6もmd5とすれば「localhost」でも行ける. あと別のマシンのpostgresqlを使うならpg_hba.confのさらなる設定が必要
Guacamole向けのjdbcドライバ †
Guacamole とデータベースとの接続は jdbc が使われる. なのでGuacamole側にjdbcドライバをインストールします
jdbcドライバは先ほど取得した「guacamole-auth-jdbc-1.4.0.tar.gz」に含まれている
[root@gate ~]# mkdir -p /etc/guacamole/{extensions,lib}
[root@gate ~]# cp guacamole-auth-jdbc-1.4.0/postgresql/guacamole-auth-jdbc-postgresql-1.4.0.jar /etc/guacamole/extensions/
次に postgreSQL側にも jdbcドライバも用意します
[root@gate ~]# yum install postgresql-jdbc
[root@gate ~]# cd /etc/guacamole/lib/
[root@gate lib]# ln -s /usr/share/java/postgresql-jdbc.jar .
guacamole.properties †
Guacamoleからデータベースに接続するアカウント・パスワードらを定義します
「guacamole.properties」ファイルは存在しません. 自分で作成します
[root@gate ~]# vi /etc/guacamole/guacamole.properties
postgresql-hostname: localhost4 <-- ipv4のみ許可しているので
postgresql-port: 5432
postgresql-database: guacamole_db
postgresql-username: guacamole_user
postgresql-password: some_password
[root@gate ~]#
アクセス †
以上で基本設定は完了です。
guacd(Guacamoleのサーバ)とjetty(Guacamoleのwebサービス)をsystemctlで稼働させて、
[root@gate ~]# systemctl start jetty guacd
jettyが起動できない場合は /opt/jetty 配下の所有者を確認する. すべてユーザjettyの所有者であることが必要です
その後にブラウザで「http://gate:8080/guacamole-1.4.0/」へアクセスしてみます. 下図がでたら成功.

「ユーザ名」には「guacadmin」、「パスワード」にも「guacadmin」を入力してログインを押下します。
するとログインができて、下記画面になります

備考、メモ †
- jettyでデバックモードで調べたいなら「/opt/jetty/curt/resources/jetty-logging.properties」を作って中身は下記にして
org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog
org.eclipse.jetty.LEVEL=INFO
jetty.logs=logs
そして
[root@gate ~]# cd /opt/jetty
[root@gate jetty]# java -jar /opt/jetty/start.jar
とする.
- 80番portで運用したい場合
jettyを調整するのもいいが、firewallが動いているならポートフォワードを使う
firewall-cmd --add-forward-port=port=80:proto=tcp:toport=8080 --permanent --zone=external
firewall-cmd --remove-port=8080/tcp --zone=external --permanent
firewall-cmd --reload
これで80に届いたリクエストは8080へ渡される
apacheと組み合わせるなら「リバースプロキシ」を使用する
- コンテンツを「/」にしたい
上記のままですと 「http://gate:8080/guacamole-1.3.0」でアクセスが必要. これを「http://gate:8080/」でguacamoleに繋げるには
[root@gate ~]# /opt/jetty/webapps
[root@gate webapps]# ls -l
-rw-r--r--. 1 jetty jetty 12277201 Jun 30 08:42 guacamole-1.3.0.war
[root@gate webapps]# mv guacamole-1.3.0.war ROOT.war
[root@gate webapps]# ls -l
-rw-r--r--. 1 jetty jetty 12277201 Jun 30 08:42 ROOT.war
[root@gate webapps]#
と「guacamole-1.3.0.war」を「ROOT.war」に名称変更する.
参照先 https://www.eclipse.org/jetty/documentation/jetty-9/index.html#configuring-contexts
あるいは、「/opt/jetty/webapps」に定義がファイルを置く
[root@gate ~]# /opt/jetty/webapps
[root@gate webapps]# ls -l
-rw-r--r--. 1 jetty jetty 12277201 Jun 30 08:42 guacamole-1.3.0.war
[root@gate webapps]# vi guacamole-1.3.0.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_0.dtd">
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
<Set name="contextPath">/</Set>
<Set name="war">/opt/jetty/webapps/guacamole-1.3.0.war</Set>
</Configure>
[root@gate webapps]# chown jetty:jetty guacamole-1.3.0.xml
- apacheと連携して動かしたい
例えば「http://web.chaperone.jp/」はそのままapacheでコンテンツを提供して、「http://web.chaperone.jp/Gacamole」は
jettyに繋げたいとするなら
[root@c ~]# vi /etc/httpd/conf/httpd.conf
ServerRoot "/etc/httpd"
Listen 80
Timeout 600
Include conf.modules.d/*.conf
User apache
Group apache
<VirtualHost *:80>
ServerName web.chaperone.jp
DocumentRoot "/var/www/html"
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/w/.*$
RewriteRule ^/w/(.*)$ https://web.chaperone.jp/w/$1 [R=301,L]
</VirtualHost>
<VirtualHost *:443>
ServerName web.chaperone.jp:443
SSLProxyEngine on
ProxyPass /guacamole/ http://gate.sybyl.local/guacamole-1.3.0/
ProxyPassReverse /guacamole/ http://gate.sybyl.local/guacamole-1.3.0/
ServerAlias web.chaperone.jp
SSLCertificateFile /etc/letsencrypt/live/web.chaperone.jp-0001/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/web.chaperone.jp-0001/privkey.pem
</VirtualHost>
な感じに作る 上記はテストしてないです