postfix的配置和安裝(上)

    我們現在要安裝一個postfix,要求其支持web mail,並安裝web mail實現郵箱的註冊、郵件的發送接收。

一、安裝配置DNS

    參考:DNS的快速配置和安裝

 

未完待續:

 

二、安裝postfix前的準備工作

1.關閉sendmail

service sendmail stop 

chkconfig sendmail off

2.安裝編譯環境(工具)

安裝以下開發所用到的rpm包組:

Development Libraries

Development Tools

Legacy Software Development

X Software Development

yum -y groupinstall "Development Libraries" "Development Tools" "Legacy Software  Development" "X Software Development"

3.安裝所需的rpm

包括:httpd, php, php-mysql, mysql, mysql-server, mysql-devel, openssl-devel, dovecot,  perl-DBD-MySQL, tcl, tcl-devel, libart_lgpl, libart_lgpl-devel, libtool-ltdl, libtool-ltdl-devel,  expect

yum -y install httpd php php-mysql mysql mysql-server mysql-devel openssl-devel dovecot  perl-DBD-MySQL tcl tcl-devel libart_lgpl libart_lgpl-devel libtool-ltdl libtool-ltdl-devel  expect

4.啓動mysql數據庫

service mysqld start

chkconfig mysqld on

5.啓動saslauthd服務

service saslauthd start

chkconfig saslauthd on

準備工作完成

三、安裝配置postfix

1.下載並解壓postfix (可以在官網www.postfix.org下載)

tar xf postfix-2.6.5.tar.gz 

2.添加用戶和組

groupadd -g 2525 postfix

groupadd -g 2526 postdrop

useradd -g postfix -u 2525 -s /sbin/nologin -M postfix

useradd -g postdrop -u 2526 -s /sbin/nologin -M postdrop

2.編譯安裝

cd postfix-2.6.5

make makefiles 'CCARGS=-DHAS_MYSQL -I/usr/include/mysql -DUSE_SASL_AUTH  -DUSE_CYRUS_SASL -I/usr/include/sasl  -DUSE_TLS ' 'AUXLIBS=-L/usr/lib/mysql  -lmysqlclient -lz -lm -L/usr/lib/sasl2 -lsasl2   -lssl -lcrypto'

make

make install

3.生成別名二進制文件,這個步驟如果忽略,會造成postfix效率極低:

Newaliases

4.編輯配置文件main.cf

cd /etc/postfix

cp main.cf main.cf.bak        備份main.cf

vim main.cf   

修改以下幾項爲您需要的配置

myhostname = mail.zsl.com

myorigin = zsl.com

mydomain = zsl.com

inet_interfaces = all

mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain

mynetworks = 192.168.19.0/24, 127.0.0.0/8

5.啓動postfix

postfix start

6.拷貝一個已經寫好的 postfix 到 /etc/init.d/postfix並啓動postfix

chomd +x /etc/init.d/postfix

chkconfig --add postfix

chkconfig postfix on

OKPostfix安裝完成了。

四、爲postfix開啓基於cyrus-sasl的認證功能

1.驗證postfix是否支持cyrus風格的sasl認證,如果您的輸出爲以下結果,則是支持的:

/usr/local/postfix/sbin/postconf  -a

cyrus

dovecot

2.編輯配置文件main.cf

vim /etc/postfix/main.cf

添加以下內容:

############################CYRUS-SASL############################

broken_sasl_auth_clients = yes

smtpd_recipient_restrictions=permit_mynetworks,permit_sasl_authenticated,reject_invalid_h ostname,reject_non_fqdn_hostname,reject_unknown_sender_domain,reject_non_fqdn_sende r,reject_non_fqdn_recipient,reject_unknown_recipient_domain,reject_unauth_pipelining,reje ct_unauth_destination

smtpd_sasl_auth_enable = yes

smtpd_sasl_local_domain = $myhostname

smtpd_sasl_security_options = noanonymous

smtpd_sasl_application_name = smtpd

smtpd_banner = Welcome to our $myhostname ESMTP,Warning: Version not Available!

3.編輯/usr/lib/sasl2/smtpd.conf

vim /usr/lib/sasl2/smtpd.conf

添加如下內容:

pwcheck_method: saslauthd

mech_list: PLAIN LOGIN

4.postfix重新加載配置文件

/usr/sbin/postfix/sbin/postfix reload

OK!現在postfix可以使用cyrus-sasl認證了。

五、安裝Courier authentication library

1.下載並解壓courier-authlib-0.62.4.tar.bz2

tar jxvf courier-authlib-0.62.4.tar.bz2

2.編譯安裝

cd courier-authlib-0.62.4

./configure --prefix=/usr/local/courier-authlib --sysconfdir=/etc --with-authmysql  --with-mysql-libs=/usr/lib/mysql --with-mysql-includes=/usr/include/mysql --with-redhat  --with-authmysqlrc=/etc/authmysqlrc --with-authdaemonrc=/etc/authdaemonrc  --with-ltdl-lib=/usr/lib --with-ltdl-include=/usr/include

make

make install

3.修改文件權限

chmod 755 /usr/local/courier-authlib/var/spool/authdaemon

4.修改配置文件/etc/authdaemonrc cp/etc/authmysqlrc

cp /etc/authdaemonrc.dist  /etc/authdaemonrc

cp /etc/authmysqlrc.dist  /etc/authmysqlrc

修改/etc/authdaemonrc 文件

authmodulelist="authmysql"

authmodulelistorig="authmysql"

daemons=10

編輯/etc/authmysqlrc 爲以下內容,其中25252525 postfix 用戶的UIDGID

MYSQL_SERVER 

MYSQL_PORT 3306             (指定你的mysql監聽的端口,這裏使用默認的3306)

MYSQL_USERNAME  extmail   (這時爲後文要用的數據庫的所有者的用戶名)

MYSQL_PASSWORD extmail     (密碼)

MYSQL_SOCKET  /var/lib/mysql/mysql.sock

MYSQL_DATABASE  extmail

MYSQL_USER_TABLE  mailbox

MYSQL_CRYPT_PWFIELD  password

MYSQL_UID_FIELD  '2525'

MYSQL_GID_FIELD  '2525'

MYSQL_LOGIN_FIELD  username

MYSQL_HOME_FIELD  concat('/var/mailbox/',homedir)

MYSQL_NAME_FIELD  name

MYSQL_MAILDIR_FIELD  concat('/var/mailbox/',maildir)

5.配置/etc/init.d中加入courier-authlib並開機啓動

cp courier-authlib.sysvinit /etc/init.d/courier-authlib

chmod 755 /etc/init.d/courier-authlib

chkconfig --add courier-authlib

chkconfig courier-authlib on

6.編輯默認庫文件路徑,並重新引導

vim /etc/ld.so.conf.d/courier-authlib.conf

寫入

/usr/local/courier-authlib/lib/courier-authlib

ldconfig -v

7.啓動服務

service courier-authlib start

8.新建虛擬用戶郵箱所在的目錄,並將其權限賦予postfix用戶:

mkdir pv /var/mailbox

chown R postfix /var/mailbox

9.接下來重新配置SMTP 認證,編輯 /usr/lib/sasl2/smtpd.conf ,確保其爲以下內容:

pwcheck_method: authdaemond

log_level: 3

mech_list:PLAIN LOGIN

authdaemond_path:/usr/local/courier-authlib/var/spool/authdaemon/socket

六、讓postfix支持虛擬域和虛擬用戶

1.編輯/etc/postfix/main.cf,添加如下內容:

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

virtual_mailbox_base = /var/mailbox

virtual_mailbox_maps = mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf

virtual_mailbox_domains = mysql:/etc/postfix/mysql_virtual_domains_maps.cf

virtual_alias_domains =

virtual_alias_maps = mysql:/etc/postfix/mysql_virtual_alias_maps.cf

virtual_uid_maps = static:2525

virtual_gid_maps = static:2525

virtual_transport = virtual

maildrop_destination_recipient_limit = 1

maildrop_destination_concurrency_limit = 1

##########################QUOTA Settings########################

message_size_limit = 14336000

virtual_mailbox_limit = 20971520

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 user's maildir has overdrawn his diskspace quota,  please Tidy your mailbox and try again later.

virtual_overquota_bounce = yes

2.使用extman源碼目錄下docs目錄中的extmail.sqlinit.sql建立數據庫:

tar zxvf  extman-1.1.tar.gz

cd extman-1.1/docs

mysql -u root -p <extmail.sql

mysql -u root -p <init.sql

cp mysql*  /etc/postfix/

3.授予用戶extmail訪問extmail數據庫的權限

mysql> GRANT all privileges on extmail.* TO extmail@localhost IDENTIFIED BY  'extmail';

mysql> GRANT all privileges on extmail.* TO [email protected] IDENTIFIED BY  'extmail';

FLUSH PRIVILEGES;

說明:啓用虛擬域以後,需要取消中心域,即註釋掉myhostname, mydestination, mydomain, myorigin幾個指令;當然,你也可以把mydestionation的值改爲你自己需要的。

未完待續……

七、配置dovecot

1.編輯配置文件dovecot.conf

vim /etc/dovecot.conf

mail_location = maildir:/var/mailbox/%d/%n/Maildir

auth default {

    mechanisms = plain

    passdb sql {

        args = /etc/dovecot-mysql.conf

    }

    userdb sql {

        args = /etc/dovecot-mysql.conf

    }

2.編輯dovecot-mysql.conf

vim /etc/dovecot-mysql.conf                 

driver = mysql

connect = host=localhost dbname=extmail user=extmail password=extmail

default_pass_scheme = CRYPT

password_query = SELECT username AS user,password AS password FROM mailbox  WHERE username = '%u'                            

user_query = SELECT maildir, uidnumber AS uid, gidnumber AS gid FROM mailbox  WHERE username = '%u'

3.啓動dovecot服務:

service dovecot start

chkconfig dovecot on

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章