# Guacamole 学习
## 编译与安装
官方文档
[Installing Guacamole natively — Apache Guacamole Manual v1.5.2](https://guacamole.apache.org/doc/gug/installing-guacamole.html)
### guacamole-server
```bash
# 前面需要安装一系列依赖库 使用arch搜索很容易解决 比如 libvncserver
> pacman -Ss libvncserver
extra/libvncserver 0.9.14-2 [installed]
Cross-platform C libraries that allow you to easily implement VNC server or
client functionality
# 如果还是找不到 那么使用 yay 查找 比如 libtelnet
> yay -Ss libtelnet
aur/libtelnet 0.23-1 (+7 0.00) (Installed)
Simple RFC-complient TELNET implementation as a C library.
> git clone git://github.com/apache/guacamole-server.git
> cd guacamole-server/
> autoreconf -fi
> ./configure --prefix=/usr/local/apps/guacamole-server/
------------------------------------------------
guacamole-server version 1.5.2
------------------------------------------------
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/lib/freerdp2
Init scripts: no
Systemd units: no
Type "make" to compile guacamole-server.
> make -j20
> sudo make install
```
### guacamole-client
安装配置一下java 环境 maven环境 tomcat环境 (tomcat 10 会报错 所以使用tomcat8 )
mvn 配置一下 proxy 否则`下载node(client 项目前端会用到)` 的时候会出现问题
```bash
> mvn package
# 省略很多
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary for guacamole-client 1.5.2:
[INFO]
[INFO] guacamole-client ................................... SUCCESS [ 7.942 s]
[INFO] guacamole-common ................................... SUCCESS [ 4.113 s]
[INFO] guacamole-ext ...................................... SUCCESS [ 7.908 s]
[INFO] guacamole-common-js ................................ SUCCESS [ 3.418 s]
[INFO] guacamole .......................................... SUCCESS [01:13 min]
[INFO] extensions ......................................... SUCCESS [ 0.161 s]
[INFO] guacamole-auth-ban ................................. SUCCESS [ 2.878 s]
[INFO] guacamole-auth-duo ................................. SUCCESS [ 6.666 s]
[INFO] guacamole-auth-header .............................. SUCCESS [ 1.655 s]
[INFO] guacamole-auth-jdbc ................................ SUCCESS [ 0.143 s]
[INFO] guacamole-auth-jdbc-base ........................... SUCCESS [ 5.022 s]
[INFO] guacamole-auth-jdbc-mysql .......................... SUCCESS [ 2.075 s]
[INFO] guacamole-auth-jdbc-postgresql ..................... SUCCESS [ 1.970 s]
[INFO] guacamole-auth-jdbc-sqlserver ...................... SUCCESS [ 1.996 s]
[INFO] guacamole-auth-jdbc-dist ........................... SUCCESS [ 1.943 s]
[INFO] guacamole-auth-json ................................ SUCCESS [ 4.320 s]
[INFO] guacamole-auth-ldap ................................ SUCCESS [ 10.833 s]
[INFO] guacamole-auth-quickconnect ........................ SUCCESS [ 3.722 s]
[INFO] guacamole-auth-sso ................................. SUCCESS [ 0.131 s]
[INFO] guacamole-auth-sso-base ............................ SUCCESS [ 1.678 s]
[INFO] guacamole-auth-sso-cas ............................. SUCCESS [ 14.957 s]
[INFO] guacamole-auth-sso-openid .......................... SUCCESS [ 2.555 s]
[INFO] guacamole-auth-sso-saml ............................ SUCCESS [ 6.638 s]
[INFO] guacamole-auth-sso-ssl ............................. SUCCESS [ 6.135 s]
[INFO] guacamole-auth-sso-dist ............................ SUCCESS [ 3.566 s]
[INFO] guacamole-auth-totp ................................ SUCCESS [ 5.739 s]
[INFO] guacamole-history-recording-storage ................ SUCCESS [ 1.077 s]
[INFO] guacamole-vault .................................... SUCCESS [ 0.125 s]
[INFO] guacamole-vault-base ............................... SUCCESS [ 3.050 s]
[INFO] guacamole-vault-ksm ................................ SUCCESS [ 6.229 s]
[INFO] guacamole-vault-dist ............................... SUCCESS [ 1.922 s]
[INFO] guacamole-display-statistics ....................... SUCCESS [ 0.438 s]
[INFO] guacamole-example .................................. SUCCESS [ 13.830 s]
[INFO] guacamole-playback-example ......................... SUCCESS [ 4.402 s]
> ls -alh guacamole-client/guacamole/target
guacamole-1.5.2.war # 其他省略
# cp guacamole-1.5.2.war tomcat文件夹/webapps
> cp guacamole-1.5.2.war /usr/local/apps/tomcat8/webapps/
> /usr/local/apps/tomcat8/bin/startup.sh
```
## 配置
### 无数据库
```bash
> cat /etc/zsh/zshrc | grep guac
export PATH=/usr/local/apps/guacamole-server/bin:$PATH
export GUACAMOLE_HOME=/etc/guacamole
# 因为 guacamole-server 的安装路径是 /usr/local/apps/guacamole-server/
# 所以 生成的lib 库中的内容 系统是不知道的 需要配置 ldconfig
> ls /usr/local/apps/guacamole-server/lib/*.so
/usr/local/apps/guacamole-server/lib/libguac-client-kubernetes.so
/usr/local/apps/guacamole-server/lib/libguac-client-rdp.so
/usr/local/apps/guacamole-server/lib/libguac-client-ssh.so
/usr/local/apps/guacamole-server/lib/libguac-client-telnet.so
/usr/local/apps/guacamole-server/lib/libguac-client-vnc.so
/usr/local/apps/guacamole-server/lib/libguac.so
/usr/local/apps/guacamole-server/lib/libguac-terminal.so
> vim /etc/ld.so.conf.d/guacamole.conf
/usr/local/apps/guacamole-server/lib
> ldconfig
> guacd start
> sudo mkdir /etc/guacamole
> sudo vim /etc/guacamole/user-mapping.xml
<user-mapping>
<!-- Per-user authentication and config information -->
<authorize username="bob" password="1">
<protocol>vnc</protocol>
<param name="hostname">localhost</param>
<param name="port">5901</param>
<param name="password">VNCPASS</param>
</authorize>
</user-mapping>
> sudo vim /etc/guacamole/guacamole.properties
# Hostname and port of guacamole proxy
guacd-hostname: 127.0.0.1
guacd-port: 4822
user-mapping: /etc/guacamole/user-mapping.xml
auth-provider: net.sourceforge.guacamole.net.basic.BasicFileAuthenticationProvider
basic-user-mapping: /etc/guacamole/user-mapping.xml
> sudo vim /etc/guacamole/guacd.conf
[daemon]
pid_file = /var/run/guacd.pid
log_level = info
[server]
bind_host = 0.0.0.0
bind_port = 4822
```
### 有数据库mysql
```bash
# 下载解压jdbc
# GUACAMOLE_HOME 是 之前设置过的 /etc/guacamole 官方默认配置
> mkdir $GUACAMOLE_HOME/extensions/
> cd $GUACAMOLE_HOME/extensions/
> wget https://mirrors.bfsu.edu.cn/apache/guacamole/1.5.2/binary/guacamole-auth-jdbc-1.5.2.tar.gz
> tar xvf guacamole-auth-jdbc-1.5.2.tar.gz
> wget https://repo1.maven.org/maven2/com/mysql/mysql-connector-j/8.0.32/mysql-connector-j-8.0.32.jar
# cd 解压地址/mysql
> mv guacamole-auth-jdbc-mysql-1.5.2.jar $GUACAMOLE_HOME/extensions/
> mv schema $GUACAMOLE_HOME/extensions/
> ls
guacamole-auth-jdbc-mysql-1.5.2.jar mysql-connector-j-8.0.32.jar schema
# 数据库配置
# docker 启动一个mysql 这里有个坑 如果需要创建用户的话 需要指定 CREATE USER 'guacamole'@'%' 必须使用这个
> mysql -u root -h 127.0.0.1 -p
# ...
# 新建数据库, guacamole_db为数据库名
mysql> CREATE DATABASE guacamole_db;
# 新建用户, user/password为用户名/密码
mysql> CREATE USER 'guacamole'@'%' IDENTIFIED BY '112233';
# 给用户授权, guacamole_db数据库的全部权限
mysql> GRANT ALL PRIVILEGES ON guacamole_db.* TO 'guacamole'@'%';
mysql> FLUSH PRIVILEGES;
# 初始化数据库
mysql> system ls
001-create-schema.sql 002-create-admin-user.sql upgrade
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| guacamole_db |
| information_schema |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)
mysql> use guacamole_db;
# 或者直接 利用管道可以实现 直接在shell中操作 两个都可行
# cat schema/*.sql | mysql -u root -p guacamole_db -h 127.0.0.1
mysql> source 001-create-schema.sql
mysql> source 002-create-admin-user.sql
Query OK, 1 row affected (0.01 sec) # 省略大部分
> sudo vim /etc/guacamole/guacamole.properties
guacd-hostname: 127.0.0.1
guacd-port: 4822
mysql-hostname: 127.0.0.1
mysql-port: 3306
mysql-database: guacamole_db
mysql-username: guacamole
mysql-password: 112233
# 重启tomcat 和 guacd
pkill guacd
guacd
shutdown.sh
startup.sh
```
### vnc 支持声音
```bash
> vim /etc/pulse/default.pa
# 添加或者解开注释
load-module module-native-protocol-tcp auth-ip-acl=192.168.31.0/24 auth-anonymous=1
> systemctl --user restart pulseaudio.service
> systemctl --user status pulseaudio.service
● pulseaudio.service - Sound Service
Loaded: loaded (/usr/lib/systemd/user/pulseaudio.service; disabled; preset: enabled)
Active: active (running) since Wed 2023-06-28 17:03:32 CST; 59s ago
TriggeredBy: ● pulseaudio.socket
Main PID: 1205966 (pulseaudio)
Tasks: 7 (limit: 38487)
Memory: 3.7M
CPU: 48ms
CGroup: /user.slice/user-1000.slice/user@1000.service/session.slice/pulseaudio.service
├─1205966 /usr/bin/pulseaudio --daemonize=no --log-target=journal
└─1205979 /usr/lib/pulse/gsettings-helper
Jun 28 17:03:31 homearchlinux systemd[568]: Starting Sound Service...
Jun 28 17:03:32 homearchlinux pulseaudio[1205966]: stat('/etc/pulse/default.pa.d'): No such file or directo>
Jun 28 17:03:32 homearchlinux systemd[568]: Started Sound Service.
> netstat -lnp | grep 4713
tcp 0 0 0.0.0.0:4713 0.0.0.0:* LISTEN 1205966/pulseaudio
tcp6 0 0 :::4713 :::* LISTEN 1205966/pulseaudio
# 还需要在网页设置中开启 如下图
# audio server name需要设置 为 需要展示声音的地址 应该是通过4713 端口交换的声音数据
```
![image-20230628172041753](./guacamole学习.assets/image-20230628172041753.png)
```
set PULSE_SERVER=tcp:192.168.31.163:8001
D:\software\pulseaudio-1.1\bin\pulseaudio.exe --start -vvvv
```
### session recording 功能
# pulseaudio
## 声音在其他设备播放
```bash
# 音量控制
> pacman -Sy pavucontrol
# 开启声音传输 监听8001 端口 如果有人连接上来 那么 就 将声音发送给client
# 使用telnet 可以观察到接收了声音数据
# 服务端(192.168.31.163) 安装 pulseaudio 和 pavucontrol 执行以下内容
pacmd load-module module-null-sink sink_name=playback-sink
pacmd update-sink-proplist playback-sink device.description="playback-sink"
pacmd update-source-proplist playback-sink.monitor device.description="playback-sink.monitor"
pacmd load-module module-simple-protocol-tcp rate=48000 format=s16le channels=2 source=playback-sink.monitor record=true port=8001
> netstat -lnp | grep 8001 # 可以看到
tcp 0 0 0.0.0.0:8001 0.0.0.0:* LISTEN 1864600/pulseaudio
tcp6 0 0 :::8001 :::* LISTEN 1864600/pulseaudio
# 客户端 使用windows 的telnet
> telnet 192.168.31.163 8001 # 可以看到一堆乱码
```
server端打开pavucontrol 可以看到 guacamole audio是 guacamole 客户端创建的
但是 下边的simple client 是windows telnet 去tcp连接看到的 telnet窗口会有一大堆乱码 就是 接收到的音频数据
![image-20230629104547684](./guacamole学习.assets/image-20230629104547684.png)
Guacamole 学习