📜 ⬆️ ⬇️

Installing the lightweight Jabber Prosody server (v0.9 and v0.10beta)

This article is about how to set up a jabber Prosody server for home, perhaps corporate, use. I had the task to raise a personal jabber server on my domain, while preserving history (perhaps synchronization with the client XEP-0136 ), with supporting communication with other jabber servers, and conferences. In general, everything is standard and nothing special, but when raising the server I ran into two problems that I plan to tell today.

Prosody is a lightweight jabber server written in lua, supporting many XEPP (XMPP Extension Protocol) standards, all supported standards can be viewed on this page . To the question "why lua" creator prosody Matthew Wild says that this is a very simple language that has a fast interpreter, which is the reason for such an unusual choice.

In this article I will install prosody on Debian 7.

First we need to add the required repository to source.list:
$ echo deb http://packages.prosody.im/debian $(lsb_release -sc) main | sudo tee -a /etc/apt/sources.list 

After you need to apply the key:
 $ wget https://prosody.im/files/prosody-debian-packages.key -O- | sudo apt-key add - 

You need to update the repository:
 $ sudo apt-get update 

Next will be 2 versions for installing Prosody v0.9 and v0.10
')

Install Prosody 0.9


Installing version 0.9, currently stable:
 $ sudo apt-get install prosody 

We set up prosody on the files, for this you need to tweak the settings that are in the file "/etc/prosody/prosody.cfg.lua", I will immediately give the whole config, with comments:
 admins = { "user@example.com" } --   modules_enabled = { -- Generally required "roster"; -- Allow users to have a roster. Recommended ;) "saslauth"; -- Authentication for clients and servers. Recommended if you want to log in. "tls"; -- Add support for secure TLS on c2s/s2s connections "dialback"; -- s2s dialback support "disco"; -- Service discovery "posix"; -- POSIX functionality, sends server to background, enables syslog, etc. -- Not essential, but recommended "private"; -- Private XML storage (for room bookmarks, etc.) "vcard"; -- Allow users to set vCards -- These are commented by default as they have a performance impact --"privacy"; -- Support privacy lists --"compression"; -- Stream compression (requires the lua-zlib package installed) -- Nice to have "version"; -- Replies to server version requests "uptime"; -- Report how long server has been running "time"; -- Let others know the time here on this server "ping"; -- Replies to XMPP pings with pongs "pep"; -- Enables users to publish their mood, activity, playing music and more "register"; -- Allow users to register on this server using a client and change passwords -- Admin interfaces "admin_adhoc"; -- Allows administration via an XMPP client that supports ad-hoc commands "admin_telnet"; -- Opens telnet console interface on localhost port 5582 } modules_disabled = { } allow_registration = false --       ssl = { --  ssl ,    key = "/etc/prosody/certs/localhost.key"; certificate = "/etc/prosody/certs/localhost.crt"; } c2s_require_encryption = true --  -  s2s_secure_auth = false pidfile = "/var/run/prosody/prosody.pid" authentication = "internal_hashed" --   (    ) storage = "internal" --     log = { info = "/var/log/prosody/prosody.log"; error = "/var/log/prosody/prosody.err"; "*syslog"; } VirtualHost "example.com" --     jabber  ssl = { --       key = "/etc/prosody/certs/example.com.key"; certificate = "/etc/prosody/certs/example.com.crt"; } 

example.com needs to be replaced with your domain everywhere, after which you need to generate the keys:
 $ sudo prosodyctl cert generate example.com $ sudo cp /usr/lib/prosody/example.com* /etc/prosody/certs/ 

Register a new user and restart prosody:
 $ sudo prosodyctl register user example.com password $ sudo prosodyctl restart 

Now you can log in to the server, but you can only communicate inside your prosody server, if you want to configure s2s (server-server communication) you need to write a couple of entries in srv dns:
_xmpp-client._tcp.example.com. 18000 IN SRV 0 5 5222 xmpp.example.com.
_xmpp-server._tcp.example.com. 18000 IN SRV 0 5 5269 xmpp.example.com.
jabber._tcp.example.com. 18000 IN SRV 0 5 5269 xmpp.example.com.

As soon as the data is applied, the s2s connection should work and you can connect to conferences on jabber.ru or add to the contact list and communicate with people who use any jabber servers supporting s2s.

Everything works well, but it remains to configure the message history, it is not supported by prosody by default, for this you need to install a module from prosody-modules called “mod_message_logging”.
There are two options for how to install modules in prosody:
1) You need to copy the lua file with the contents of the module code to the / usr / lib / modules directory and add it to the config in the modules_enabled section:
 modules_enabled = { ... "message_logging"; ... } 

2) Clone the prosody-modules in any directory, give it read permissions for the prosody user and add to the config this:
 plugin_paths = { "/usr/lib/prosody/modules", "/path/to/prosody-modules" } ... modules_enabled = { ... "message_logging"; ... } 

Restart the server:
 $ prosodyctl restart 

And we admire the history of messages in / var / lib / prosody / message_logging /. As you can see, the entire history of messages for 1 day is written to one file on the server for each authorized user, that is, /var/lib/prosody/message_logs/example.com/2013-12-20/user.msglog contains logs for this user. for the whole day with all his contacts.
This implementation seemed to me very uncomfortable, in the prosody conference they said that there was no normal implementation of the message history and I changed mod_message_logging a little and it turned out that mod_message_loggind_diff_files also slightly fixed the problems of the past module and the following directory / file structure appeared - along the path / var / lib / prosody / message_logs /example.com/2013-12-20/user directories with all files with message history, all file names are the jid of the contact or conference, for example "prosody% 40conference.prosody.im.msglog".

You can also connect as standard mod_message_logging.

At this point, you can finish setting up the prosody server, but some will want to connect the module with support for HEP-0136 (synchronization of logs to the client), this module is called mod_mam, but the developers say that this module works very slowly with files, and even someone will want to switch on the database, but prosody 0.9 has a problem with that.
The current implementation of the module for storing data in sql when running prosody in the absence of a connection to the database throws out a critical error and prosody does not start. This problem is badly built in debian and centos, since their boot systems do not allow waiting for the database to be fully initialized to run the desired application, but in the sql2 module, which is available at 0.10, this problem is fixed, so we can install prosody 0.10 + mod_mam.

Install Prosody 0.10


Installing version 0.10, currently beta:
 $ sudo apt-get install prosody-0.10 

Then we repeat everything as with version 0.9 with minor changes.
1) Change the data storage location from internal to sql2
 storage = "sql2" 

2) Add a setting to link to the base. Before the necessary line, delete the "-" and change the data on your own to access the desired database
 --sql = { driver = "SQLite3", database = "prosody.sqlite" } -- Default. 'database' is the filename. --sql = { driver = "MySQL", database = "prosody", username = "prosody", password = "secret", host = "localhost" } --sql = { driver = "PostgreSQL", database = "prosody", username = "prosody", password = "", host = "localhost" } 

3) Install the lua driver to communicate with the desired database, for example, for sqlite
 $ sudo apt-get install lua-dbi-sqlite3 

The module for logging to the database is in prosody-modules called “mod_mam”, although unlike the module that writes message history to a file, this module stores only private messages. If you need a posting history from conferences, you will need to install mod_message_logging or mod_message_loggind_diff_files. There is also a module that stores the messages of the mod_mam_muc conferences, but it only stores messages from your local conferences raised on your server (if such a module can be useful).
There are two options for how to install modules in prosody:
1) You need to copy the lua file with the contents of the module code to the / usr / lib / modules directory and add it to the config in the modules_enabled section:
 modules_enabled = { ... "mam"; ... } 

2) Clone the prosody-modules in any directory, give it read permissions for the prosody user and add to the config this:
 plugin_paths = { "/usr/lib/prosody/modules", "/path/to/prosody-modules" } ... modules_enabled = { ... "mam"; ... } 

Restart the server:
 $ prosodyctl restart 

After prosody reboot, you will be configured with message and conference history in files and personal message history in the database with synchronization to the client.

I hope I helped someone, if there is an opportunity, I will answer your questions in the comments or in the LAN.

Source: https://habr.com/ru/post/207032/


All Articles