【教學】Instalation HOWTO for postfix with MySQL / complete virtual user



贊助商連結


repsol
2002-05-27, 11:27 AM
Instalation HOWTO for postfix with MySQL / complete virtual user
system.

Disclaimer:

This HOWTO is based on the assumption that you have a good deal of
knowledge of postfix and MySQL.

Furthermore you need to read MYSQL.README (comes with the postfix
distribution), and basicly everything else there is to read.
This is a step by step HOWTO of how to setup a the virtual part of postfix.

Postfix install:

Unpack postfix. Do (inside the postfix directory):

1: make -f Makefile.init makefiles \
'CCARGS=-DHAS_MYSQL -I/some/where/include/mysql' \
'AUXLIBS=/some/where/lib/mysql/libmysqlclient.a -lm'

2: make && make install

3: cp the virtual bin from the virtual directory into the postfix
source directory. ie: cp src/virtual/virtual /usr/libexec/postfix

Replace the '/some/where/' with your system's path.

Now setup postfix as you usually would, but almost all the mapping is
done with mysql.

main.cf:

transport_maps = mysql:/etc/postfix/transport.cf
virtual_maps = mysql:/etc/postfix/virtual_remote_aliases.cf
virtual_mailbox_base = /data/mail
virtual_uid_maps = mysql:/etc/postfix/virtual_ids.cf
virtual_gid_maps = mysql:/etc/postfix/virtual_ids.cf
virtual_mailbox_maps = mysql:/etc/postfix/virtual_aliases.cf

Also remember that relay_domains needs to contain $transport_maps to
lookup local virtual domains. alias_maps does not affect the virtual
agent.

Mysql Setup:

Make a mysql user for postfix.

I pt. have 5 tables in my system for postfix:

mysql> show tables;
+------------------------+
| Tables in mail_hosting |
+------------------------+
| transport |
| virtual_aliases |
| virtual_ids |
| virtual_remote_aliases |
| virtual_users |
+------------------------+

transport:

mysql> desc transport;
+-----------+-----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+-----------+------+-----+---------+-------+
| domain | char(100) | YES | | NULL | |
| transport | char(100) | YES | | NULL | |
+-----------+-----------+------+-----+---------+-------+

This is needed so that postfix knows it is a virtual domain.

Example:

mysql> select * from transport;
+----------------+-----------+
| domain | transport |
+----------------+-----------+
| somedomain.dom | virtual: |
+----------------+-----------+

virtual_aliases:

mysql> desc virtual_aliases;
+------------------+-----------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------------+-----------+------+-----+---------+----------------+
| email_alias | char(100) | YES | | NULL | |
| local_mbox | char(100) | YES | | NULL | |
+------------------+-----------+------+-----+---------+----------------+

This table is used to determine where the email's that are virtual is
going.

Example:

mysql> select * from virtual_aliases;
+---------------------------+---------------------+
| email_alias | local_mbox |
+---------------------------+---------------------+
| [email protected] | somedomain.com/user |
| [email protected] | somedomain.com/user |
+---------------------------+---------------------+

These two are both going to the same mailbox, so the postmaster could be
called an alias (or the user could be an alias, whatever). The path to
local_mbox is relative to virtual_mailbox_base.

virtual_ids:

mysql> desc virtual_ids;
+-------------+-----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------+-----------+------+-----+---------+-------+
| email_alias | char(100) | YES | | NULL | |
| id | int(3) | YES | | NULL | |
+-------------+-----------+------+-----+---------+-------+

This table is used to assign uid+gid to the mailbox per user. since my
system only needs one id i simply point both virtual_uid_maps and
virtual_gid_maps to the same id.

Example:

mysql> select * from virtual_ids;
+---------------------------+------+
| email_alias | id |
+---------------------------+------+
| [email protected] | 756 |
| [email protected] | 756 |
+---------------------------+------+

virtual_remote_aliases:

mysql> desc virtual_remote_aliases;
+-------------+-----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------+-----------+------+-----+---------+-------+
| email_alias | char(100) | YES | | NULL | |
| remote_addr | char(100) | YES | | NULL | |
+-------------+-----------+------+-----+---------+-------+

... is used to forward mail to other domains.

Example:


mysql> select * from virtual_remote_aliases;
+---------------------+-------------------------------+
| email_alias | remote_addr |
+---------------------+-------------------------------+
| [email protected] | [email protected] |
+---------------------+-------------------------------+

virtual_users:

Well, thats that.

Now, after doing this you want to monitor your logs, the permissions on
the mailbox's, etc etc to see if everything works ok. if not, send me a
mail and I'll probably make a FAQ sometime soon.

Daniel V. Pedersen
[email protected]
pgp key: http://www.kummefryser.dk/daniel-gpg.key