summaryrefslogtreecommitdiff
path: root/content/ejabberd.md
blob: 0080dba418821d2ec50a32725159ef6f43176214 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
---
title: "ejabberd"
date: 2022-03-29
icon: 'ejabberd.png'
tags: ['service']
short_desc: "A chat server based on XMPP."
---

[Ejabberd](https://ejabberd.im) is a server for the XMPP protocol
written in Erlang. It\'s easier to configure and setup than
[Prosody](/prosody) due to having most of its modules built-in and
pre-configured by default.

## Prerequisites

### Subdomains

Ejabberd presumes that you have already created all the **required and
optional subdomains** for its operation prior to running it.

Depending on the usecase, you may need any or all of the following
domains for XMPP functionality:

-   **example.org** - Your XMPP hostname
-   **conference.example.org** - For Multi User Chats (MUCs)
-   **upload.example.org** - For file upload support
-   **proxy.example.org** - For SOCKS5 proxy support
-   **pubsub.example.org** - For publish-subscribe support

This guide will assume **all these subdomains** have been created.

## Installation

Ejabberd is available in the Debian repositories:

```sh
apt install ejabberd
```

## Configuration

The ejabberd server is configured in `/etc/ejabberd/ejabberd.yml`.
Changes are only applied by restarting the ejabberd daemon in systemd:

```sh
systemctl restart ejabberd
```

### Hostnames

The **XMPP hostname** is specified in the `hosts` section of
`ejabberd.yml`:

```yml
hosts:
  - example.org
```

### Certificates

Unlike [Prosody,](https://prosody.im) ejabberd doesn\'t come equipped
with a script that can automatically copy over the relevant certificates
to a directory where the ejabberd user can read them.

One way of organizing certificates for ejabberd is to have them stored
in `/etc/ejabberd/certs`, with each domain having a separate directory
for both the fullchain cert and private key.

Using certbot, this process can be easily automated with these commands:

```sh
$DOMAIN=subdomain.example.org
certbot --nginx -d $DOMAIN certonly; mkdir -p /etc/ejabberd/certs/$DOMAIN
cp /etc/letsencrypt/live/$DOMAIN/fullchain.pem /etc/ejabberd/certs/$DOMAIN
cp /etc/letsencrypt/live/$DOMAIN/privkey.pem /etc/ejabberd/certs/$DOMAIN
```

This should be ran with your XMPP hostname **(example.org)** and
repeated for all your desired subdomains.

Make sure all the certificates are readable by the `ejabberd` user:
```sh
chown -R ejabberd:ejabberd /etc/ejabberd/certs
```

To enable the use of all these certificates in ejabberd, the following
configuration is necessary:

```yml
certfiles:
  - "/etc/ejabberd/certs/*/*.pem"
```

### Admin User

The **admin user** can be specified in `ejabberd.yml` under the `acl`
section:

```yml
acl:
  admin:
    user: admin
```

This would make **admin@example.org** the user with administrator
privileges.

### Message Archives

The ejabberd server supports keeping archives of messages through its
`mod_mam` module. This can be enabled by uncommenting the following
lines:

```yml
mod_mam:
  assume_mam_usage: true
  default: always
```

## Database

### Why use a database?

In the `mod_mam` section of the ejabberd config file, the following
message is in comments:

```yml
mod_mam:
  ## Mnesia is limited to 2GB, better to use an SQL backend
  ## For small servers SQLite is a good fit and is very easy
  ## to configure. Uncomment this when you have SQL configured:
  ## db_type: sql
```

As these comments imply, an **SQL backend** is strongly recommended if
you wish to use your ejabberd server for anything more than just
testing. Ejabberd supports **MySQL, SQLite** and **PostgreSQL.**

While all of those are suitable choices, the best database system to use
is PostgreSQL. It\'s the same database backend used by
[PeerTube](/peertube) and [Matrix](/matrix), making it the most
convenient option if you\'re already running those too.

### Installing PostgreSQL

PostgreSQL is available in the Debian repositories:

```sh
apt install postgresql
```

Start the PostgreSQL daemon to begin using it:

```sh
systemctl start postgresql
```

### Creating the Database

To create the database, first create a PostgreSQL user for ejabberd:

```sh
su -c "createuser --pwprompt ejabberd" postgres
```

Then, create the database and make `ejabberd` its owner:

```sh
su -c "psql -c 'CREATE DATABASE ejabberd OWNER ejabberd;'" postgres
```

### Importing Database Scheme

Ejabberd doesn\'t create the database scheme by default; It has to be
imported into the database before use.

```sh
su -c "curl -s https://raw.githubusercontent.com/processone/ejabberd/master/sql/pg.sql | psql ejabberd" postgres
```

### Configuring ejabberd to use PostgreSQL

Finally, add the following configuration to `ejabberd.yml`:

```yml
sql_type: pgsql
sql_server: "localhost"
sql_database: "ejabberd"
sql_username: "ejabberd"
sql_password: "psql_password"
```

Once you\'ve ensured your database name, username and password are all
correct, enable SQL storage for `mod_mam`:

```yml
mod_mam:
  ## (Other parameters)
  db_type: sql
```

## Using ejabberd

### Registering the Admin User

To begin using ejabberd, firstly start the ejabberd daemon:

```sh
systemctl restart ejabberd
```

Then, using `ejabberdctl` as the ejabberd user, register the admin user
which is set in `ejabberd.yml`:

```sh
su -c "ejabberdctl register admin example.org password" ejabberd
```

This will create the user **admin@example.org.**

### Using the Web Interface

By default, ejabberd has a web interface accessible from
**http://example.org:5280/admin**. When accessing this interface, you
will be prompted for the admin credentials:

{{< img src="/pix/ejabberd-login.jpg" >}}

After signing in with the admin credentials, you will be able to manage
your ejabberd server from this web interface:

{{< img src="/pix/ejabberd-admin.jpg" >}}

## TURN & STUN for Calls

Ejabberd supports the **TURN** and **STUN** protocols to allow internet
users behind NATs to perform voice and video calls with other XMPP
users.

Firstly, setup a TURN and STUN server with [Coturn,](/coturn) using
an **authentication secret.**

Then, edit `mod_stun_disco` to contain the appropriate information for
your turnserver:

```yml
  mod_stun_disco:
    secret: "your_auth_secret"
    services:
      -
        host: turn.example.org
        type: stun
      -
        host: turn.example.org
        type: turn
```

And with that, you\'ve successfully setup your ejabberd XMPP server!

------------------------------------------------------------------------

*Written by [Denshi.](https://denshi.org) Donate Monero
[here](https://denshi.org/donate.html)
[\[QR\]](https://denshi.org/images/monero.jpg)*