2010-12-24

ubuntu 10.4 的 postfix + mysql + postfixadmin 安裝記錄

sudo apt-get install mysql-client mysql-server 
sudo apt-get install phpmyadmin apache2 libapache2-mod-php5 php5 php5-mysql
sudo apt-get install postfix postfix-mysql postfix-doc courier-authdaemon courier-authlib-mysql courier-pop courier-pop-ssl courier-imap courier-imap-ssl postfix-tls libsasl2-2 libsasl2-modules libsasl2-modules-sql sasl2-bin libpam-mysql openssl 
#開始建 postfix to mysql的連結
sudo vim /etc/postfix/mysql_virtual_alias_maps.cf
#################################
user = mysql_username
password = mysql_pass
hosts = 127.0.0.1
dbname = mysql_dbname
table = alias
select_field = goto
where_field = address
#################################

sudo vim /etc/postfix/mysql_virtual_domains_maps.cf
#################################
user = mysql_username
password = mysql_pass
hosts = 127.0.0.1
dbname = mysql_dbname
table = domain
select_field = domain
where_field = domain
#additional_conditions = and backupmx = '0' and active = '1'
#################################

sudo vim /etc/postfix/mysql_virtual_mailbox_maps.cf
#################################
user = mysql_username
password = mysql_pass
hosts = 127.0.0.1
dbname = mysql_dbname
table = mailbox
select_field = maildir
where_field = username
#additional_conditions = and active = '1'
#################################

sudo vim /etc/postfix/mysql_virtual_mailbox_limit_maps.cf
#################################
user = mysql_username
password = mysql_pass
hosts = 127.0.0.1
dbname = mysql_dbname
table = mailbox
select_field = quota
where_field = username
#additional_conditions = and active = '1'
#################################

sudo vim /etc/postfix/mysql_relay_domains_maps.cf
#################################
user = mysql_username
password = mysql_pass
hosts = 127.0.0.1
dbname = mysql_dbname
table = domain
select_field = domain
where_field = domain
additional_conditions = and backupmx = '1'
#################################

sudo chgrp postfix /etc/postfix/mysql_*.cf
sudo chmod 640 /etc/postfix/mysql_*.cf

#在 main.conf 中加入建立連結的選 項

sudo vim /etc/postfix/main.cf

#################################
# Virtual Mailbox Domain Settings

virtual_alias_maps = mysql:/etc/postfix/mysql_virtual_alias_maps.cf
virtual_mailbox_domains = mysql:/etc/postfix/mysql_virtual_domains_maps.cf
virtual_mailbox_maps = mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf
virtual_mailbox_limit = 51200000
virtual_minimum_uid = 5000
virtual_uid_maps = static:5000
virtual_gid_maps = static:5000
virtual_mailbox_base = /home/vmail
virtual_transport = virtual

# Additional for quota support

virtual_create_maildirsize = yes
virtual_mailbox_extended = yes
virtual_mailbox_limit_maps = mysql:/etc/postfix/mysql_virtual_mailbox_limit_maps.cf
virtual_mailbox_limit_override = yes
virtual_maildir_limit_message = Sorry, the your maildir has overdrawn your diskspace quota, please free up some of spaces of your mailbox try again.
virtual_overquota_bounce = yes
#################################


sudo groupadd -g 5000 vmail
sudo useradd -m -g vmail -u 5000 -d /home/vmail -s /bin/bash vmail

### 改nameserver


sudo vim /var/spool/postfix/etc/resolv.conf
#設定
nameserver 168.95.1.1
nameserver 8.8.8.8
##沒設定寄出的信會就出現Host or domain name not found. Name service error ,nameserver 可指定自家的不一定要用168.95.1.1

### smtp登入的使用者驗證
vi /etc/courier/authdaemonrc
## Change to mysql mode
authmodulelist="authmysql"

## 顯示 login 的 log 來 debug
DEBUG_LOGIN=2

sudo vim /etc/courier/authmysqlrc
#################################
MYSQL_SERVER 127.0.0.1
MYSQL_USERNAME mysql_username
MYSQL_PASSWORD mysql_pass
MYSQL_DATABASE mysql_dbname
MYSQL_USER_TABLE mailbox
MYSQL_LOGIN_FIELD username
MYSQL_NAME_FIELD name
MYSQL_CRYPT_PWFIELD password
#MYSQL_CLEAR_PWFIELD     password
MYSQL_MAILDIR_FIELD maildir
MYSQL_QUOTA_FIELD concat(quota,'S')
MYSQL_HOME_FIELD        '/home/vmail'
MYSQL_UID_FIELD '5000'
MYSQL_GID_FIELD '5000'
#################################


/etc/postfix/sasl/smtpd.conf
不用這個
#################################
pwcheck_method: auxprop
auxprop_plugin: sql
mech_list: plain login cram-md5 digest-md5
sql_engine: mysql
sql_hostnames: 127.0.0.1
sql_user: mysql_username
sql_passwd: mysql_pass
sql_database: mysql_dbname
sql_select: select password from mailbox where username='%u@%r' and active = 1
#################################
改這個
##########################
pwcheck_method: saslauthd
mech_list: plain login
allow_plaintext: true
auxprop_plugin: mysql
sql_hostnames: 127.0.0.1
sql_user: mysql_username
sql_passwd: mysql_pass
sql_database: mysql_dbname
sql_select: select password from mailbox where username='%u@%r' and active = 1
##########################

sudo vim /etc/pam.d/smtp
##########################
auth    required   pam_mysql.so user=mysql_username passwd=mysql_pass host=127.0.0.1 db=mysql_dbname table=mailbox usercolumn=username passwdcolumn=password crypt=1
account sufficient pam_mysql.so user=mysql_username passwd=mysql_pass host=127.0.0.1 db=mysql_dbname table=mailbox usercolumn=username passwdcolumn=password crypt=1
##########################

### 加入 smtp 的驗証
sudo vim /etc/postfix/main.cf

##########################
smtpd_recipient_restrictions = reject_unauth_pipelining, permit_mynetworks, permit_sasl_authenticated, reject_non_fqdn_recipient, reject_unknown_recipient_domain reject_unauth_destination, permit
# modify the existing smtpd_sender_restrictions
smtpd_sender_restrictions = permit_sasl_authenticated, permit_mynetworks, reject_non_fqdn_sender, reject_unknown_sender_domain, reject_unauth_pipelining, permit
# then add these
smtpd_sasl_auth_enable = yes
broken_sasl_auth_clients = yes
smtpd_sasl_security_options = noanonymous
smtpd_sasl_local_domain =
##########################
###  建立 key

sudo openssl req -new -outform PEM -out /etc/postfix/smtpd.cert -newkey rsa:2048 -nodes -keyout /etc/postfix/smtpd.key -keyform PEM -days 3650 -x509sudo chmod 640 /etc/postfix/smtpd.key

### 啟用 saslauthd
sudo adduser postfix sasl
sudo mkdir -p /var/spool/postfix/var/run/saslauthd
### 編輯 /etc/default/saslauthd 
sudo vim /etc/default/saslauthd
######只改
START=yes
OPTIONS="-c -m /var/spool/postfix/var/run/saslauthd -r"
############
sudo /etc/init.d/saslauthd restart
 參考來源:http://www.debiantutorials.com/installing-postfix-with-mysql-backend-and-sasl-for-smtp-authentication/

沒有留言: