Skip to content

Instantly share code, notes, and snippets.

@hamidrhashmi
Last active April 5, 2024 07:21
Show Gist options
  • Save hamidrhashmi/2ceed37348d18d027dd005e4968fed56 to your computer and use it in GitHub Desktop.
Save hamidrhashmi/2ceed37348d18d027dd005e4968fed56 to your computer and use it in GitHub Desktop.
How to Deploy MongooseIM - XMPP Server

Pre-rquisite:

I will be using Debian 12

Step 1: Install MariaDB

Add MariaDB repository

sudo apt-get install apt-transport-https curl
sudo mkdir -p /etc/apt/keyrings
sudo curl -o /etc/apt/keyrings/mariadb-keyring.pgp 'https://mariadb.org/mariadb_release_signing_key.pgp'

cat > /etc/apt/sources.list.d/mariadb.sources << EOF
# MariaDB 11.3 repository list - created 2024-04-03 09:50 UTC
# https://mariadb.org/download/
X-Repolib-Name: MariaDB
Types: deb
# deb.mariadb.org is a dynamic mirror if your preferred mirror goes offline. See https://mariadb.org/mirrorbits/ for details.
# URIs: https://deb.mariadb.org/11.3/debian
URIs: https://download.nus.edu.sg/mirror/mariadb/repo/11.3/debian
Suites: bookworm
Components: main
Signed-By: /etc/apt/keyrings/mariadb-keyring.pgp
EOF

update reporsitory

apt-get update

install MariaDB

apt-get install mariadb-server

Step 2: Configure MariaDB

vim /etc/mysql/mariadb.conf.d/50-server.cnf

set bind address to listen all ports

bind-address = 0.0.0.0

Start MariaDB

systemctl start mariadb
systemctl enable mariadb
mysql_secure_installation

Enter current password for root (enter for none): Enter

Set root password? [Y/n] Y

Remove anonymous users? [Y/n] Y

Disallow root login remotely? [Y/n] Y

Remove test database and access to it? [Y/n] Y

Reload privilege tables now? [Y/n] Y

Reference: https://cloudinfrastructureservices.co.uk/setup-mariadb-replication/

Step 3: Create Database for MongooseIM

Go to MongooseIM Github repo and download the latest MonogooseIM

wget https://github.com/esl/MongooseIM/archive/refs/tags/6.2.0.tar.gz
tar -sxvf 6.2.0.tar.gz

Go to Directtor priv/

cd MongooseIM-6.2.0/priv
mysql -h localhost -u user -p -e 'create database mongooseim'
mysql -h localhost -u user -p mongooseim < mysql.sql

This would create 40 tables. now Create DB User

mysql -u root -p 
Enter password: 
MariaDB [(none)]:) create user 'imuser'@'%' identified by 'passw0rd';
MariaDB [(none)]:) grant all on mongooseim.* to 'imuser'@'%';
MariaDB [(none)]:) flush privileges;
MariaDB [(none)]:) exit

Step 3(b): Install MySQL Server (OPTIONAL)

Download Mysql Community Server for debian 12

wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-community-server_8.3.0-1debian12_amd64.deb 
wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-community-client_8.3.0-1debian12_amd64.deb 
wget https://dev.mysql.com/get/Downloads/MySQL-8.0/libmysqlclient-dev_8.3.0-1debian12_amd64.deb 
wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-community-server-core_8.3.0-1debian12_amd64.deb 
wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-common_8.3.0-1debian12_amd64.deb 
wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-community-client-core_8.3.0-1debian12_amd64.deb 
wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-community-client-plugins_8.3.0-1debian12_amd64.deb 
wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-client_8.3.0-1debian12_amd64.deb 

Now install downloaded deb files

apt install ./mysql-common_8.3.0-1debian12_amd64.deb 
apt install ./mysql-community-client-plugins_8.3.0-1debian12_amd64.deb 
apt install ./mysql-community-client-core_8.3.0-1debian12_amd64.deb 
apt install ./mysql-community-client_8.3.0-1debian12_amd64.deb 
apt install ./mysql-community-server-core_8.3.0-1debian12_amd64.deb 
apt install ./mysql-client_8.3.0-1debian12_amd64.deb 
apt install ./mysql-community-server_8.3.0-1debian12_amd64.deb 

Step 4: Compile MonoogseIm from Source

apt install git redis make zlib1g-dev libssl-dev unixodbc-dev gcc g++ erlang
go directory /path/to/mongooseim/tool/
./tools/configure with-mysql with-redis user=root prefix=/opt/mongooseim system=yes
make rel
cd _build/prod/rel/mongooseim

Reference: https://esl.github.io/MongooseDocs/latest/tutorials/How-to-build/

Step 5: Configure MongooseIM with Mysql

Add following modules in mongooseim.toml file

[auth]
  methods = ["rdbms"]

# methods
  [auth.rdbms]
    users_number_estimate = true

[outgoing_pools.rdbms.default]
  scope = "global"
  workers = 10
  strategy = "available_worker"

  [outgoing_pools.rdbms.default.connection]
    driver = "mysql"
    host = "localhost"
    database = "mongooseim"
    username = "imuser"
    password = "passw0rd"

[outgoing_pools.rdbms.mysql]
  scope = "global"
  workers = 10
  strategy = "available_worker"

  [outgoing_pools.rdbms.mysql.connection]
    driver = "mysql"
    host = "localhost"
    database = "mongooseim"
    username = "imuser"
    password = "passw0rd"

[modules.mod_mam]
  backend = "rdbms"

[modules.mod_muc_light]
  host = "conference.@HOST@"
  backend = "rdbms"
  equal_occupants = true
  legacy_mode = true
  rooms_per_user = 10
  blocking = false
  all_can_configure = true
  all_can_invite = true
  max_occupants = 50
  rooms_per_page = 5
  rooms_in_rosters = true

  [modules.mod_muc_light.cache_affs]
    time_to_live = 60

  [[modules.mod_muc_light.config_schema]]
    field = "roomname"
    string_value = "The Room"

  [[modules.mod_muc_light.config_schema]]
    field = "display-lines"
    integer_value = 30
    internal_key = "display_lines"

[modules.mod_roster]
  backend = "rdbms"
  versioning = true
  store_current_id = true

[modules.mod_auth_token]
  backend = "rdbms"

[modules.mod_last]
  backend = "rdbms"

[modules.mod_time]

[modules.mod_ping]
  send_pings = true
  ping_interval = 60
  timeout_action = "none"
  ping_req_timeout = 32

[modules.mod_offline]
  access_max_user_messages = "max_user_offline_messages"
  backend = "rdbms"
  store_groupchat_messages = true

[modules.mod_caps]
  cache_size = 2000
  cache_life_time = 10_000

[modules.mod_pubsub]
  access_createnode = "pubsub_createnode"
  ignore_pep_from_offline = false
  backend = "rdbms"
  last_item_cache = "mnesia"
  max_items_node = 1000
  plugins = ["flat", "pep"]

  [[modules.mod_pubsub.pep_mapping]]
    namespace = "urn:xmpp:microblog:0"
    node = "mb"

Step 6: Start MongooseIM and Debug

bin/mongooseim start
bin/mongooseimctl status

in case of error use the followingcommand for troubleshooting

bin/mongooseimctl foreground
or
bin/mongooseimctl debug

Step 7: Add User and Send your First IM

Create XMPP User

/opt/mongooseim/usr/bin/mongooseimctl account registerUser --domain imserver.hbvoice.local --username hamid --password 12345
/opt/mongooseim/usr/bin/mongooseimctl account registerUser --domain imserver.hbvoice.local --username raza --password 12345

Download pidgin for Windows or Astrachat for Android

Register user in these Apps and try sending IM messages to each other.

Enjoy ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment