Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Trunking configuration #54

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
194 changes: 194 additions & 0 deletions trunking/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
# Trunked configuration

Running `./start.sh` will perform some cleanup then start the containers in a federated configuration.
When running, the system looks like this:

```
+---------------------------------------------+
| 172.50.0.10 172.50.0.20 |
| +--------+ +--------+ |
(XMPP-C2S) 5221 -| | | | | |- 5222 (XMPP-C2S)
(XMPP-S2S) 5261 -|------| XMPP 1 +============+ XMPP 2 |-------|- 5262 (XMPP-S2S)
(HTTP-Admin) 9091 -| | | | | |- 9092 (HTTP-Admin)
(BOSH) 7071/7441 -| +----+---+ +----+---+ |- 7072/7442 (BOSH)
| | | |
| | | |
| +---+--+ +--+---+ |
| | | | | |
(Database) 5431 -|-------| DB 1 | | DB 2 |-------|- 5432 (Database)
| | | | | |
| +------+ +------+ |
| 172.50.0.11 172.50.0.21 |
| |
+----------------172.50.0.0/24----------------+
```

Openfire is configured with the following hostnames/XMPP domain names:

* `xmpp1.localhost.example`
* `xmpp2.localhost.example`

XMPP 1 has the following users:

* `user1` `password`
* `user2` `password`

XMPP 1 hosts the following MUC rooms:

* `muc1`
* `muc2`

XMPP 2 has the following users:

* `user3` `password`
* `user4` `password`

XMPP 2 hosts the following MUC rooms:

* `muc3`
* `muc4`

## Network

The Docker compose file defines a custom bridge network with a single subnet of `172.50.0.0/24`

### Removing a node from the network

To remove a node from the network run the following command:

`docker network disconnect NETWORK-NAME CONTAINER-NAME`

For example:

`docker network disconnect openfire-testing_openfire-federated-net openfire-testing_xmpp1_1`

### Adding a node to the network

To add a node to the network fun the following command:

`docker network connect NETWORK-NAME CONTAINER-NAME`

For example:

`docker network connect openfire-testing_openfire-federated-net openfire-testing_xmpp1_1`

## How it's built

To recreate the known good state for the system we first create base Openfire and Postgres containers.
We then perform the manual setup and any other configuration that we require, such as adding users and MUC rooms.
Once the setup is complete we dump the database from the container to the Docker host and copy the Openfire config
files from the container to the Docker host. These are then used with Docker volumes for creating the same state in
subsequent Openfire and Postgres containers.

### Adding a new node

Configure a docker-compose file to stand up:

1. a base Openfire container (named `xmpp3`)
1. a base Postgres Docker container (named `db3`)

We will use these containers to configure our third node before exporting the DB and Openfire configuration.
Be sure to set the correct IP addresses and increment the host port numbers so they don't clash with existing exposed ports.
The convention I have followed is to increment the IP addresses by 10 and the port numbers by 1:

For `xmpp1`

* Openfire IP: `172.50.0.10`
* DB IP: `172.50.0.11`
* XMPP port: `5221`
* Admin port: `9091`

For `xmpp2`

* Openfire IP: `172.50.0.20`
* DB IP: `172.50.0.21`
* XMPP port: `5222`
* Admin port: `9092`

Example docker-compose file for our third node:

```
db3:
image: library/postgres:9.6.24-alpine
environment:
- "POSTGRES_DB=openfire"
- "POSTGRES_USER=openfire"
- "POSTGRES_PASSWORD=hunter2"
networks:
openfire-federated-net:
ipv4_address: 172.50.0.31

xmpp3:
image: openfire:latest
ports:
- "5223:5222"
- "9093:9090"
depends_on:
- "db3"
networks:
openfire-federated-net:
ipv4_address: 172.50.0.30

networks:
openfire-federated-net:
driver: bridge
ipam:
driver: default
config:
- subnet: 172.50.0.0/24
```

Run this with the `start.sh`. Once running navigate to `http://localhost:9093` and manually configure the Openfire server.
The database hostname should be the name of the DB node in the compose file (so `db3` in this case).
You should also get the database name, username, and password, from the compose file.

Create any configuration you require (e.g. adding users).

Create directories for the exported DB and config:

```
mkdir -p ./sql/3
mkdir -p ./xmpp/3
```

Export the database:

`docker exec -t openfire-testing_db3_1 pg_dump -U openfire openfire > ./sql/3/openfire.sql`

Export the Openfire configuration:

`docker cp openfire-testing_xmpp3_1:/var/lib/openfire/conf ./xmpp/3/`

Add the new node to the main `docker-compose-federated.yml` including the volume definitions to pull in your exported base
configuration data:

```
...

db3:
image: library/postgres:9.6.24-alpine
environment:
- "POSTGRES_DB=openfire"
- "POSTGRES_USER=openfire"
- "POSTGRES_PASSWORD=hunter2"
volumes:
- ./sql/3:/docker-entrypoint-initdb.d
networks:
openfire-federated-net:
ipv4_address: 172.50.0.31

xmpp3:
image: openfire:latest
ports:
- "5223:5222"
- "9093:9090"
depends_on:
- "db3"
volumes:
- ./_data/xmpp/3/conf:/var/lib/openfire/conf
networks:
openfire-federated-net:
ipv4_address: 172.50.0.30
...

```
139 changes: 139 additions & 0 deletions trunking/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
version: '3.7'

services:

domain1-db:
image: library/postgres:14.5-alpine
ports:
- "5431:5432"
environment:
- "POSTGRES_DB=openfire"
- "POSTGRES_USER=openfire"
- "POSTGRES_PASSWORD=hunter2"
volumes:
- ./sql/1:/docker-entrypoint-initdb.d
networks:
openfire-trunking-net:
ipv4_address: 172.50.0.101

domain2-db:
image: library/postgres:14.5-alpine
ports:
- "5432:5432"
environment:
- "POSTGRES_DB=openfire"
- "POSTGRES_USER=openfire"
- "POSTGRES_PASSWORD=hunter2"
volumes:
- ./sql/2:/docker-entrypoint-initdb.d
networks:
openfire-trunking-net:
ipv4_address: 172.50.0.151

domain3-db:
image: library/postgres:14.5-alpine
ports:
- "5433:5432"
environment:
- "POSTGRES_DB=openfire"
- "POSTGRES_USER=openfire"
- "POSTGRES_PASSWORD=hunter2"
volumes:
- ./sql/3:/docker-entrypoint-initdb.d
networks:
openfire-trunking-net:
ipv4_address: 172.50.0.201

xmpp1:
image: "openfire:${OPENFIRE_TAG}"
ports:
- "5221:5222"
- "5261:5269"
- "7071:7070"
- "7441:7443"
- "9091:9090"
depends_on:
- "domain1-db"
volumes:
- ./_data/xmpp/1/conf:/var/lib/openfire/conf
- ./_data/plugins:/opt/plugins
- ../_common/wait-for-it.sh:/wait-for-it.sh
command: ["/wait-for-it.sh", "-s", "domain1-db:5432", "--", "/sbin/entrypoint.sh"]
networks:
openfire-trunking-net:
ipv4_address: 172.50.0.100
extra_hosts:
- "xmpp1.localhost.example:172.50.0.100"
- "conference.xmpp1.localhost.example:172.50.0.100"
- "xmpp2.localhost.example:172.50.0.150"
- "conference.xmpp2.localhost.example:172.50.0.150"
- "xmpp3.localhost.example:172.50.0.200"
- "conference.xmpp3.localhost.example:172.50.0.200"

xmpp2:
image: "openfire:${OPENFIRE_TAG}"
ports:
- "5222:5222"
- "5262:5269"
- "7072:7070"
- "7442:7443"
- "9092:9090"
depends_on:
- "domain2-db"
volumes:
- ./_data/xmpp/2/conf:/var/lib/openfire/conf
- ./_data/plugins:/opt/plugins
- ../_common/wait-for-it.sh:/wait-for-it.sh
command: ["/wait-for-it.sh", "-s", "domain2-db:5432", "--", "/sbin/entrypoint.sh"]
networks:
openfire-trunking-net:
ipv4_address: 172.50.0.150
extra_hosts:
- "xmpp1.localhost.example:172.50.0.100"
- "conference.xmpp1.localhost.example:172.50.0.100"
- "xmpp2.localhost.example:172.50.0.150"
- "conference.xmpp2.localhost.example:172.50.0.150"
- "xmpp3.localhost.example:172.50.0.200"
- "conference.xmpp3.localhost.example:172.50.0.200"

xmpp3:
image: "openfire:${OPENFIRE_TAG}"
ports:
- "5223:5222"
- "5263:5269"
- "7073:7070"
- "7443:7443"
- "9093:9090"
depends_on:
- "domain3-db"
volumes:
- ./_data/xmpp/3/conf:/var/lib/openfire/conf
- ./_data/plugins:/opt/plugins
- ../_common/wait-for-it.sh:/wait-for-it.sh
command: ["/wait-for-it.sh", "-s", "domain3-db:5432", "--", "/sbin/entrypoint.sh"]
networks:
openfire-trunking-net:
ipv4_address: 172.50.0.200
extra_hosts:
- "xmpp1.localhost.example:172.50.0.100"
- "conference.xmpp1.localhost.example:172.50.0.100"
- "xmpp2.localhost.example:172.50.0.150"
- "conference.xmpp2.localhost.example:172.50.0.150"
- "xmpp3.localhost.example:172.50.0.200"
- "conference.xmpp3.localhost.example:172.50.0.200"

dozzle:
image: amir20/dozzle:latest
volumes:
- /var/run/docker.sock:/var/run/docker.sock
ports:
- 9999:8080

networks:
openfire-trunking-net:
driver: bridge
ipam:
driver: default
config:
- subnet: 172.50.0.0/24

Binary file added trunking/plugins/heapdump.jar
Binary file not shown.
Binary file added trunking/plugins/jsxc.jar
Binary file not shown.
Loading