Topic: [Guide] External MySQL server using IPv6
==== Required information ====
- iRedMail version (check /etc/iredmail-release): iRedmail v0.9.7
- Linux/BSD distribution name and version: Debian 9.2 Stretch
- Store mail accounts in which backend (LDAP/MySQL/PGSQL): External MySQL
- Web server (Apache or Nginx): Nginx
- Manage mail accounts with iRedAdmin-Pro? No
- [IMPORTANT] Related original log or error message is required if you're experiencing an issue.
====
I only tested the following guide on Debian 9.2 (Stretch), but I referred to the files for other Distro's and/or BSD aswell.
Testers for other distro's are appreciated.
These issues can and (should be resolved) in my opinion as moving to IPv6 is essential in the coming years and not having to deal with these issues is important for newer iRedmail users.
If you're trying to setup a mailserver using iRedmail using the following guide in order to use a remote mysql database be aware that iRedmail does not natively support this.
Guide: https://docs.iredmail.org/install.iredm … erver.html
I've posted a topic earlier this week regarding SOGo not fully working, this wasn't only related to SOGo but everything else aswel. The SOGo issue has been resolved as a bugfix and should work for everybody else now accordingly to ZhangHuangbin.
For demonstration purposes only let's say we used this command to install iRedmail:
USE_EXISTING_MYSQL='YES' \
MYSQL_SERVER_ADDRESS='fd01:2345:6789:1::1' \ # Your external MySQL server's IP
MYSQL_SERVER_PORT='3306' \
MYSQL_ROOT_USER='admin_iredmail' \
MYSQL_ROOT_PASSWD='admin_password' \
MYSQL_GRANT_HOST='fd01:2345:6789:1::99' \ # Your iRedmail server's IP
bash iRedMail.sh
Keep in mind the remote MySQL server should allow the user 'admin_iredmail' (in this case) all privileges as written in the guide and has been allowed by the grant host ip.
The Grant Host should also be statically assigned so it'll never change.
After you've installed iRedmail nothing will work as nothing supports IPv6 addresses using mysql, and encoding it as IPv6 (Adding brackets around them eg. [fd01:2345:6789:1::1]) does not work for everything (Works for SOGo) meaning you'll need to create a local host entry for the ipv6 mysql address in your /etc/hosts file.
Here's how it would look in this example:
# Default entries
127.0.1.1 server.domain.tld server localhost
::1 server.domain.tld server localhost ip6-localhost ip6-loopbackff02::1 ip6-allnodes
ff02::2 ip6-allrouters# Add this entry
fd01:2345:6789:1::1 mysql
You can change 'mysql' to whatever you like, but this name will be used everywhere to refer to the ipv6 address.
Confige Postfix to work:
# Running the following line of code will replace the first line of every file in the /etc/postfix/mysql folder.
# It will replace it to "hosts = mysql"
# Relace 'mysql' to the name in your /etc/hosts file.# For all Linux distro's and OpenBSD:
sed -i "1s/.*/hosts = mysql/" /etc/postfix/mysql/*# For FreeBSD:
sed -i "1s/.*/hosts = mysql/" /usr/local/etc/postfix/mysql/*# Save the file and restart postfix
systemctl restart postfix
Dovecot should work out of the box using ipv6 addresses so no problems here, if you do struggle try the following:
Confige dovecot to work:
# Edit the following file using your favorite editor (Nano in my case)
# For all Linux distro's and OpenBSD:
nano /etc/dovecot/dovecot-mysql.conf# For FreeBSD
nano /usr/local/etc/dovecot/dovecot-mysql.conf# Find the line starting with CONNECT
# Change 'host=fd01:2345:6789:1::1' (this example) to your hostname (Specified in /etc/hosts).
# In thise case it would be:
'host=mysql'# Save the file and restart dovecot
systemctl restart dovecot
Configure iRedAPD to work:
# Edit the following file using your favorite editor (Nano in my case)
nano /opt/iredapd/settings.py# Find the following lines starting with:
# vmail_db_server =
# amavisd_db_server =
# iredapd_db_server =
# Update all 3 entries to your mysql hostname configured in /etc/hosts
# This example:
vmail_db_sever = "mysql"
amavisd_db_server = "mysql"
iredapd_db_server = "mysql"# Save the file and restart iredapd
systemctl restart iredapd
Configure Amavisd/Amavis-new to work:
# Edit the following file using your favorite editor (Nano in my case)
# For RHEL/CentOS:
nano /etc/amavisd/amavisd.conf# For Debian/Ubuntu:
nano /etc/amavis/conf.d/50-user# For FreeBSD:
nano /usr/local/etc/amavisd.conf# For OpenBSD:
nano /etc/amavisd.conf# Change the 'host=fd01:2345:6789:1::1' (this case) to 'host=mysql' where mysql is the hostname you entered in /etc/hosts
# for the line starting with @storage_sql_dsn so it looks like:
@storage_sql_dsn = (['DBI:mysql:database=amavisd;host=mysql;port=3306', 'LEAVE THIS', 'LEAVE THIS!']);# Keep in mind not to change the original value to 'LEAVE THIS' like the example as these are the
# predefined database credentials for amavisd.# Save the configuration and restart amavisd/amavis-new
systemctl amavisd restart
I do not use iRedadmin (Standard or pro) or Roundcube (Only SOGo and command line administering using custom tools) so I did not require a fix for those.
Post future problems down in this post and I'll be sure to help you out.
Kind Regards.
Wraptor
----
Spider Email Archiver: On-Premises, lightweight email archiving software developed by iRedMail team. Supports Amazon S3 compatible storage and custom branding.