summaryrefslogtreecommitdiff
path: root/ejabberd.html
blob: 910db7b08ff59c148f7069ec34a729a09c29b35e (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
<!DOCTYPE html>
<html lang=en>
    <head>
        <title>ejabberd (an XMPP Server) &ndash; LandChad.net</title>
        <meta charset="utf-8"/>
        <link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
        <link rel='stylesheet' type='text/css' href='style.css'>
        <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel='alternate' type='application/rss+xml' title='Land Chad RSS' href='/rss.xml'>
    </head>
<body>
    <header><h1>ejabberd (an XMPP Server)</h1></header>
    <nav></nav>
    <main>

        <img class=titleimg src="pix/xmpp.svg" alt="XMPP logo and icon">

	<p>
	<a href="https://ejabberd.im">Ejabberd</a> is a server for the XMPP protocol written in Erlang.
	It's easier to configure and setup than <a href="xmpp.html">Prosody</a> due to having most of its modules built-in and pre-configured by default.
	</p>

        <h2>Prerequisites</h2>
	<h3>Subdomains</h3>
        <p>
	Ejabberd presumes that you have already created all the <strong>required and optional subdomains</strong> for its operation prior to running it.
	</p>

	<p>Depending on the usecase, you may need any or all of the following domains for XMPP functionality:<p>
	<ul>
		<li><strong>example.org</strong> - Your XMPP hostname</li>
		<li><strong>conference.example.org</strong> - For Multi User Chats (MUCs)</li>
		<li><strong>upload.example.org</strong> - For file upload support</li>
		<li><strong>proxy.example.org</strong> - For SOCKS5 proxy support</li>
		<li><strong>pubsub.example.org</strong> - For publish-subscribe support</li>
	</ul>

	<p>This guide will assume <strong>all these subdomains</strong> have been created.</p>

	<h2>Installation</h2>
	<p>Ejabberd is available in the Debian repositories:</p>
	<pre><code>apt install ejabberd</code></pre>

	<h2>Configuration</h2>
	<p>The ejabberd server is configured in <code>/etc/ejabberd/ejabberd.yml</code>. Changes are only applied by restarting the ejabberd daemon in systemd:</p>
	<pre><code>systemctl restart ejabberd</code></pre>

	<h3>Hostnames</h3>
	<p>The <strong>XMPP hostname</strong> is specified in the <code>hosts</code> section of <code>ejabberd.yml</code>:</p>

	<pre><code>hosts:
  - <strong>example.org</strong></code></pre>

	<h3>Certificates</h3>
	<p>Unlike <a href="https://prosody.im">Prosody,</a> 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.</p>

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

	<p>Using certbot, this process can be easily automated with this one-liner:</p>
	<pre><code>$DOMAIN=<strong>subdomain.example.org</strong>
certbot --nginx -d $DOMAIN certonly; mkdir /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</code></pre>

	<p>This should be ran with your XMPP hostname <strong>(example.org)</strong> and repeated for all your desired subdomains.</p>

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

	<pre><code>certfiles:
  - "/etc/ejabberd/certs/*/*.pem"</code></pre>

	<h3>Admin User</h3>

	<p>The <strong>admin user</strong> can be specified in <code>ejabberd.yml</code> under the <code>acl</code> section:</p>

	<pre><code>acl:
  admin:
    user: <strong>admin</strong></code></pre>

	<p>This would make <strong>admin@example.org</strong> the user with administrator privileges.</p>

	<h3>Message Archives</h3>

	<p>The ejabberd server supports keeping archives of messages through its <code>mod_mam</code> module. This can be enabled by uncommenting the following lines:</p>

	<pre><code>mod_mam:
  assume_mam_usage: true
  default: always</code></pre>

	<h2>Database</h2>
	<h3>Why use a database?</h3>
	<p>In the <code>mod_mam</code> section of the ejabberd config file, the following message is in comments:</p>

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

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

	<p>While all of those are suitable choices, the best database system to use is PostgreSQL. It's the same database backend used by <a href="peertube.html">PeerTube</a> and <a href="matrix.html">Matrix,</a> making it the most convenient option if you're already running those too.</p>

	<h3>Installing PostgreSQL</h3>

	<p>PostgreSQL is available in the Debian repositories:</p>
	<pre><code>apt install postgresql</code></pre>

	<p>Start the PostgreSQL daemon to begin using it:</p>
	<pre><code>systemctl start postgresql</code></pre>

	<h3>Creating the Database</h3>
	<p>To create the database, first create a PostgreSQL user for ejabberd:</p>

	<pre><code>su -c "createuser --pwprompt ejabberd" postgres</code></pre>

	<p>Then, create the database and make <code>ejabberd</code> its owner:</p>

	<pre><code>su -c "psql -c 'CREATE DATABASE ejabberd OWNER ejabberd;'" postgres</code></pre>

	<h3>Importing Database Scheme</h3>

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

	<pre><code>su -c "curl -s https://raw.githubusercontent.com/processone/ejabberd/master/sql/pg.sql | psql ejabberd" postgres</code></pre>

	<h3>Configuring ejabberd to use PostgreSQL</h3>
	<p>Finally, add the following configuration to <code>ejabberd.yml</code>:</p>

	<pre><code>sql_type: pgsql
sql_server: "localhost"
sql_database: <strong>"ejabberd"</strong>
sql_username: <strong>"ejabberd"</strong>
sql_password: <strong>"psql_password"</strong></code></pre>

	<p>Once you've ensured your database name, username and password are all correct, enable SQL storage for <code>mod_mam</code>:</p>

	<pre><code>mod_mam:
  ## (Other parameters)
  db_type: <strong>sql</strong></code></pre>

	<h2>Using ejabberd</h2>
	<h3>Registering the Admin User</h3>
	<p>To begin using ejabberd, firstly start the ejabberd daemon:</p>

	<pre><code>systemctl restart ejabberd</code></pre>

	<p>Then, using <code>ejabberdctl</code> as the ejabberd user, register the admin user which is set in <code>ejabberd.yml</code>:</p>

	<pre><code>su -c "ejabberdctl register <strong>admin example.org password</strong>" ejabberd</code></pre>

	<p>This will create the user <strong>admin@example.org.</strong></p>

	<h3>Using the Web Interface</h3>

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

	<img src="pix/ejabberd-login.jpg" height="260px">

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

	<img src="pix/ejabberd-admin.jpg" height="300px">

	<h2>TURN & STUN for Calls</h2>

	<p>Ejabberd supports the <strong>TURN</strong> and <strong>STUN</strong> protocols to allow internet users behind NATs to perform voice and video calls with other XMPP users.</p>

	<p>Firstly, setup a TURN and STUN server with <a href="coturn.html">Coturn,</a> using an <strong>authentication secret.</strong></p>

	<p>Then, edit <code>mod_stun_disco</code> to contain the appropriate information for your turnserver:</p>

	<pre><code>  mod_stun_disco:
    secret: <strong>"your_auth_secret"</strong>
    services:
      -
	host: <strong>turn.example.org</strong>
        type: stun
      -
	host: <strong>turn.example.org</strong>
	type: turn</code></pre>

<p>And with that, you've successfully setup your ejabberd XMPP server!</p>

 <hr>
        <p><em>Written by <a href="https://denshi.org">Denshi.</a> Donate Monero <a href="https://denshi.org/donate.html">here</a> <a href="https://denshi.org/images/monero.jpg">[QR]</a></em></p>

    </main>
	<footer><a href="https://landchad.net">LandChad.net</a></br>Because Everyone should be an Internet LandChad.</br><a href="index.html"><li><img src="pix/chad.gif" alt="chad"></li></a><a href="rss.xml"><li><img src="pix/rss.svg" alt="RSS"></li></a><a href="pix/btc.png"><li><img src="pix/btc.svg" alt="BTC"></li></a><a href="pix/xmr.png"><li><img src="pix/xmr.svg" alt="XMR"></li></a><a href="https://github.com/lukesmithxyz/landchad"><li><img src="pix/git.svg" alt="Github"></li></a></footer>
</body>
</html>