Instructions for setting up Ejabberd with J2J / ICQ transport (with correct encoding) on Ubuntu Server
Hello.
Today we will be setting up our own jabber server for example.org on Ubuntu Server Edition.
On this server there will be transport to ICQ and jabber. Logs will be written to the example.org/logs directory. Logs can be conveniently viewed from a mobile device (fancyindex + htpasswd + fail2ban).
It is understood that at least on Linux you already know. It is also worth noting: the instruction is a guiding light, gives a general direction and does not urge to fulfill it 100% as it is written in it. Also, it does not cover 100% of the settings, you need to be able to configure the web server and work with mysql.
Further for an example I will use Clodo.ru as a hoster. Naturally, various pieces of instructions can be used on any other distribution / hoster.
Stage 1. Preparation of a server environment.
We register with the hoster, create a scale-server with ubuntu lucid 10.04 LTS 32-bit, 512MB of memory, 5GB SAS.
After obtaining root access and other details, we go to the server.
We wait until dpkg updates the system to the current state:
Replace /etc/apt/sources.list with: Create a file /etc/apt/apt.conf.d/03test with the contents: Add the Spectrum key (our future Jabber transport): We replace hostname for convenience: We edit the files in the output, replacing the lines with the example.org we need, and then we change hostname: Configure sudo for our user: At the end of the file, enter:
We configure access by key (google how it is done, keywords ssh-agent, ssh-keygen -t rsa, ssh-copy-id) for the user user created by default.
We try to log in as user, and also check the operation of sudo su. After that, edit / etc / ssh / sshd_config.
Required options: After that, we restart SSH (here, be careful, we have denied access by password, as well as root. We can fix the jambs here through VNC in the case of Clodo, or through KVM, in general, using physical access to the server console ): Russify a system with UTF-8 support: Edit the file /var/lib/locales/supported.d/locale.gen and the file / etc / environment Generate locales:
At this point, you can go to the server by specifying UTF-8 in the SSH client. Russian language will appear.
We add to /etc/rc.local: this will save money on the server (relevant for clodo). Install the necessary packages: During installation, the system will ask for the root password from MySQL, how the mail server will function (select the Internet Site, domain name example.org). In the zone for example.org we indicate: We configure aliases by editing the / etc / aliases file: Generate aliases for postfix: Send a test letter: We look at the logs /var/log/mail.info, as well as the presence of the letter in the mailbox myemail@gmail.com. If everything is ok, let's go further! Configure reboot notifications by email.
As user user, do the following:
Write the line:
Attention, if you specify the +% modifier in date, put a percent before the percentage, for example: $ (date + \% m. \% D), or `date + \% m. \% D` otherwise the crown will be coveted with incomprehensible errors.
Stage 2. Setting up our Jabber.
Download the ejabberd distribution. Installation is simple. We select the language, carefully read the entire license agreement, select “y” in response to the question: “Do you accept the terms of the license agreement? [y / n]: ”, select the installation directory (leave the default /opt/ejabberd-2.1.6), example.org domain name, admin admin user name, administrator password. We refuse cluster settings: Ejabberd will be installed. Server management occurs from the /opt/ejabberd-2.1.6/bin directory. For more details, see the ejabberd documentation. Now we are interested in /opt/ejabberd-2.1.6/conf/ejabberd.cfg, edit it by adding the necessary lines: to the section {modules ,: to the section {listen ,:
We make sure that the /opt/ejabberd-2.1.6/www directory is created and has permissions of 0755.
Now we need to compile the mod_log_chat module and install it: Now run and test ejabberd, write a message to someone, and look at the logs. Everything should work. Stop ejabberd. Add to /etc/rc.local before exit 0:
Stage 3. We configure transport on ICQ.
We will use pyicq-t.
Adding user jabber: Download the pyicqt with pyicqt.googlecode.com in homework to jabber and extract transport. Edit config.xml, set everything as in the config above, server 127.0.0.1, port 8888, secret token - password, encoding cp1251, login.icq.com, 5190, language ru - the config speaks for itself. append to /etc/rc.local before exit 0:
The mysql commands create the user j2j with the password pass and the database j2j. Editing spectrum.cfg: Pay attention to log_areas, it is better to leave the field empty, otherwise there will be a lot of garbage in the / var / log / spectrum log. Add to /etc/rc.local before exit 0:
Lets say apache2 is set up in /home/user/www/example.org to work with example.org.
Create a symlink:
lrwxrwxrwx 1 root root 24-03-03-04 13:24 chat -> /opt/ejabberd-2.1.6/www/
Create /opt/ejabberd-2.1.6/www/.htaccess with the contents: Generate file / opt / ejabberd-2.1.6 / www / .htpasswd can, for example, be this: www.htaccesstools.com/htpasswd-generator fail2ban will protect us from password guessing. Do not forget to add the necessary services to startup: That's all. After a reboot, if everything was done correctly, the server will work. For use, I recommend the PSI + client with options for automatic user authorization and automatic user nicknames. This is a hidden option, added to options / contactlist:
For Android, I recommend Xabber.
To test and configure while reading the instructions, you need to look and use:
ejabberd
logs : /opt/ejabberd-2.1.6/logs These logs will tell you why the server did not start, what generally happens, where the problem is in the syntax, etc.
Logs Spectrum: / var / log / spectrum
Similarly for problems, the Spectrum will
flood the Ejabberctl log : /opt/ejabberd-2.1.6/bin/ejabberdctl
Used to create, delete, set a user password. Ultra-useful utility, until they figured out the roster, automatic user authorization and automatic nicknames.
Documentation sites:
ejabberd.im
spectrum.im
code.google.com/p/pyicqt
google.com
In contact with you, write about typos and errors in the Habrahta or comments, I will correct.
Today we will be setting up our own jabber server for example.org on Ubuntu Server Edition.
On this server there will be transport to ICQ and jabber. Logs will be written to the example.org/logs directory. Logs can be conveniently viewed from a mobile device (fancyindex + htpasswd + fail2ban).
It is understood that at least on Linux you already know. It is also worth noting: the instruction is a guiding light, gives a general direction and does not urge to fulfill it 100% as it is written in it. Also, it does not cover 100% of the settings, you need to be able to configure the web server and work with mysql.
Further for an example I will use Clodo.ru as a hoster. Naturally, various pieces of instructions can be used on any other distribution / hoster.
Stage 1. Preparation of a server environment.
We register with the hoster, create a scale-server with ubuntu lucid 10.04 LTS 32-bit, 512MB of memory, 5GB SAS.
After obtaining root access and other details, we go to the server.
We wait until dpkg updates the system to the current state:
ps uxa | egrep '(firstrun|local|apt|dpkg)'
Replace /etc/apt/sources.list with: Create a file /etc/apt/apt.conf.d/03test with the contents: Add the Spectrum key (our future Jabber transport): We replace hostname for convenience: We edit the files in the output, replacing the lines with the example.org we need, and then we change hostname: Configure sudo for our user: At the end of the file, enter:
deb ru.archive.ubuntu.com/ubuntu lucid main restricted
deb ru.archive.ubuntu.com/ubuntu lucid-updates main restricted
deb ru.archive.ubuntu.com/ubuntu lucid universe
deb ru.archive.ubuntu.com/ubuntu lucid-updates universe
deb ru.archive.ubuntu.com/ubuntu lucid multiverse
deb ru.archive.ubuntu.com/ubuntu lucid-updates multiverse
deb ru.archive.ubuntu.com/ubuntu lucid-backports main restricted universe multiverse
deb archive.canonical.com/ubuntu lucid partner
deb security.ubuntu.com/ubuntu lucid-security main restricted
deb security.ubuntu.com/ubuntu lucid-security universe
deb security.ubuntu.com/ubuntu lucid-security multiverse
deb packages.spectrum.im lucid spectrum
APT::Install-Recommends "false";
APT::Install-Suggests "false";
sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 47A944AF1905866A
fgrep -r $(uname -n) /etc
hostname example.org
visudo
user ALL=(ALL) ALL
We configure access by key (google how it is done, keywords ssh-agent, ssh-keygen -t rsa, ssh-copy-id) for the user user created by default.
We try to log in as user, and also check the operation of sudo su. After that, edit / etc / ssh / sshd_config.
Required options: After that, we restart SSH (here, be careful, we have denied access by password, as well as root. We can fix the jambs here through VNC in the case of Clodo, or through KVM, in general, using physical access to the server console ): Russify a system with UTF-8 support: Edit the file /var/lib/locales/supported.d/locale.gen and the file / etc / environment Generate locales:
PermitRootLogin no
PasswordAuthentication no
RSAAuthentication yes
PubkeyAuthentication yes
service ssh restart
ru_RU.UTF-8 UTF-8
en_US.UTF-8 UTF-8
LANGUAGE=ru_RU.UTF-8
LANG=ru_RU.UTF-8
dpkg-reconfigure locales
At this point, you can go to the server by specifying UTF-8 in the SSH client. Russian language will appear.
We add to /etc/rc.local: this will save money on the server (relevant for clodo). Install the necessary packages: During installation, the system will ask for the root password from MySQL, how the mail server will function (select the Internet Site, domain name example.org). In the zone for example.org we indicate: We configure aliases by editing the / etc / aliases file: Generate aliases for postfix: Send a test letter: We look at the logs /var/log/mail.info, as well as the presence of the letter in the mailbox myemail@gmail.com. If everything is ok, let's go further! Configure reboot notifications by email.
sysctl -w vm.swappiness=100
su -c 'echo 0 > /sys/devices/system/xenmgm/xenmgm0/memmin_bytes'
su -c 'echo 60000000 > /sys/devices/system/xenmgm/xenmgm0/reserve_free_bytes'
apt-get install libpurple0-minimal htop strace apache2 mysql-server spectrum python python-twisted python-imaging postfix iptables fail2ban mailutils mpack subversion
example.org. A 1.2.3.4 (ваш IP-адрес)
example.org MX 10 example.org.
_xmpp-server._tcp.example.org. SRV 0 0 5269 example.org.
_xmpp-client._tcp.example.org. SRV 0 0 5222 example.org.
_jabber._tcp.example.org. SRV 0 0 5269 example.org.
example.org. TXT "v=spf1 a mx ~all"
* CNAME @
root: myemail@gmail.com
user:: myemail@gmail.com
newaliases
mail -s test user [нажимаем enter]
CC: [нажимаем enter]
[нажимаем ctrl+d]
As user user, do the following:
crontab -e
Write the line:
@reboot echo "server rebooted at `date`" | mail -s "Server `uname -n` Rebooted!" user@example.org
Attention, if you specify the +% modifier in date, put a percent before the percentage, for example: $ (date + \% m. \% D), or `date + \% m. \% D` otherwise the crown will be coveted with incomprehensible errors.
Stage 2. Setting up our Jabber.
Download the ejabberd distribution. Installation is simple. We select the language, carefully read the entire license agreement, select “y” in response to the question: “Do you accept the terms of the license agreement? [y / n]: ”, select the installation directory (leave the default /opt/ejabberd-2.1.6), example.org domain name, admin admin user name, administrator password. We refuse cluster settings: Ejabberd will be installed. Server management occurs from the /opt/ejabberd-2.1.6/bin directory. For more details, see the ejabberd documentation. Now we are interested in /opt/ejabberd-2.1.6/conf/ejabberd.cfg, edit it by adding the necessary lines: to the section {modules ,: to the section {listen ,:
cd /usr/src
wget www.process-one.net/downloads/ejabberd/2.1.6/ejabberd-2.1.6-linux-x86-installer.bin.gz
gunzip ejabberd-2.1.6-linux-x86-installer.bin.gz
chmod +x ejabberd-2.1.6-linux-x86-installer.bin
./ejabberd-2.1.6-linux-x86-installer.bin
Кластер [y/N]: N
----------------------------------------------------------------------------
Программа готова к установке ejabberd на ваш компьютер.
Вы хотите продолжить? [Y/n]: Y
{mod_log_chat, [{path, "/opt/ejabberd-2.1.6/www"}, {format, html}]},
{8888, ejabberd_service, [
{access, all},
{shaper_rule, fast},
{ip, {127, 0, 0, 1}},
{hosts, ["icq.example.org”, "sms.example.org"],
[{password, "iearhg98a3hg89h3498gha9"}]
}
]},
{8883, ejabberd_service, [
{access, all},
{shaper_rule, fast},
{ip, {127, 0, 0, 1}},
{hosts, ["j2j.example.org"],
[{password, "ojer0jg0a9jg09j0gjreg0"}]
}
]},
We make sure that the /opt/ejabberd-2.1.6/www directory is created and has permissions of 0755.
Now we need to compile the mod_log_chat module and install it: Now run and test ejabberd, write a message to someone, and look at the logs. Everything should work. Stop ejabberd. Add to /etc/rc.local before exit 0:
cd /usr/src
svn co svn.process-one.net/ejabberd-modules
cp ejabberd-modules/mod_log_chat/trunk/src/mod_log_chat.erl /opt/ejabberd-2.1.6/
cd /opt/ejabberd-2.1.6
bin/erlc -I includes/ejabberd/include mod_log_chat.erl
mv mod_log_chat.beam lib/ejabberd-2.1.6/ebin/
rm mod_log_chat.erl
cd /opt/ejabberd-2.1.6/bin
./start
./stop
sleep 10
su -c '/opt/ejabberd-2.1.6/bin/start'
Stage 3. We configure transport on ICQ.
We will use pyicq-t.
Adding user jabber: Download the pyicqt with pyicqt.googlecode.com in homework to jabber and extract transport. Edit config.xml, set everything as in the config above, server 127.0.0.1, port 8888, secret token - password, encoding cp1251, login.icq.com, 5190, language ru - the config speaks for itself. append to /etc/rc.local before exit 0:
useradd -m -s /bin/bash jabber
passwd jabber
su jabber
cd
wget pyicqt.googlecode.com/files/pyicqt-0.8.1.5.tar.gz
tar zvxf pyicqt-0.8.1.5.tar.gz
mv pyicqt-0.8.1.5 pyicqt
cd pyicqt
cp config_example.xml config.xml
su -c 'python /home/jabber/pyicqt/PyICQt.py > /home/jabber/pyicqt/log 2>&1 &' - jabber
Step 4. Configure j2j transport:
cd /etc/spectrum/
wget spectrum.im/attachments/download/14/mysql_schema.sql
The mysql commands create the user j2j with the password pass and the database j2j. Editing spectrum.cfg: Pay attention to log_areas, it is better to leave the field empty, otherwise there will be a lot of garbage in the / var / log / spectrum log. Add to /etc/rc.local before exit 0:
mysql -u j2j -p'pass' j2j < mysql_schema.sql
mv spectrum.cfg.example spectrum.cfg
jid=j2j.example.org
password=как_выше
port=8883
filetransfer_cache=/var/lib/spectrum/filetransfer_cache
name=j2j
language=en
enable_public_registration=1
[logging]
log_file=/var/log/spectrum/$jid.log
log_areas=
[database]
type=mysql
host=localhost
user=j2j
password=pass
database=j2j
prefix=j2j_
/etc/init.d/spectrum start
Step 5. Set up viewing logs:
Lets say apache2 is set up in /home/user/www/example.org to work with example.org.
Create a symlink:
lrwxrwxrwx 1 root root 24-03-03-04 13:24 chat -> /opt/ejabberd-2.1.6/www/
Create /opt/ejabberd-2.1.6/www/.htaccess with the contents: Generate file / opt / ejabberd-2.1.6 / www / .htpasswd can, for example, be this: www.htaccesstools.com/htpasswd-generator fail2ban will protect us from password guessing. Do not forget to add the necessary services to startup: That's all. After a reboot, if everything was done correctly, the server will work. For use, I recommend the PSI + client with options for automatic user authorization and automatic user nicknames. This is a hidden option, added to options / contactlist:
Options +Indexes
IndexOptions FancyIndexing
IndexOptions +SuppressSize
IndexOrderDefault Descending Date
AuthType Basic
AuthName "wat"
AuthUserFile /opt/ejabberd-2.1.6/www/.htpasswd
Require valid-user
update-rc.d SERVICENAME defaults
bool options.contactlist.resolve-nicks-on-contact-add true
For Android, I recommend Xabber.
To test and configure while reading the instructions, you need to look and use:
ejabberd
logs : /opt/ejabberd-2.1.6/logs These logs will tell you why the server did not start, what generally happens, where the problem is in the syntax, etc.
Logs Spectrum: / var / log / spectrum
Similarly for problems, the Spectrum will
flood the Ejabberctl log : /opt/ejabberd-2.1.6/bin/ejabberdctl
Used to create, delete, set a user password. Ultra-useful utility, until they figured out the roster, automatic user authorization and automatic nicknames.
Documentation sites:
ejabberd.im
spectrum.im
code.google.com/p/pyicqt
google.com
In contact with you, write about typos and errors in the Habrahta or comments, I will correct.