搭建postfix郵箱系統(筆記-1.2017-0701)

環境:centos6.5 x64

使用源碼包及RPM:postfix+Cyrus-sasl+dovecot+openwebmail+webmin

安裝前準備:

0.時間同步

yum install ntp

ntpdate ntp.api.bz

hwclock -w

1. 創建用戶:

groupadd -g 2525 postfix -s /sbin/nologin (postfix組)

useradd-g 2525 -u 2525 postfix -M -s /sbin/nologin (postfix用戶)

group -g 2526 postdrop

2. yum安裝依賴庫及相關軟件:

yum install mysql mysql-devel mysql-server mysql-lib

 yum install db*-devel

 yum groupinstall Development Tools  Development Libraries

 yum install cyrus-sasl cyrus-sasl-devel cyrus-sasl-lib cyrus-sasl-gssapi cyrus-sasl-md5 cyrus-sasl-plain



3. 解壓:

  tar  xf    postfix-3.2.2.tar.gz


4.進入解壓後的目錄,執行二進制編譯安裝:

代碼如下:

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


make && make install


5.編譯成功後,會提示需要手動設置安裝路徑,根據自己需求更改,我這裏全部保持默認 按回車鍵進行確認:

install_root: [/] (表示安裝在/根路徑下)

tempdir: [/data/postfix-3.2.2](表示臨時數據存放路徑,用戶需具有寫權限)

config_directory: [/etc/postfix](表示配置文件存放路徑)

command_directory: [/usr/sbin] (表示postfix的命令存放路徑)

daemon_directory: [/usr/libexec/postfix](表示postfix的守護程序路徑) 

data_directory: [/var/lib/postfix](表示postfix的庫數據文件存放路徑)

html_directory: [no](表示不安裝postfix的html網頁文件)

mail_owner: [postfix] (表示指定postfix用戶爲文件所有者)

mailq_path: [/usr/bin/mailq]  (表示mailq查看隊列列表命令存放路徑)

manpage_directory: [/usr/local/man](表示postfix手冊說明書存放路徑)

newaliases_path: [/usr/bin/newaliases](表示newaliases命令存放路徑,別名數據庫)

queue_directory: [/var/spool/postfix](表postfix隊列安裝路徑)

readme_directory: [no](表示README文件安裝路徑)

sendmail_path: [/usr/sbin/sendmail](表示sendmail命令的安裝路徑)

setgid_group: [postdrop](指定郵件提交組和隊列管理組命令)

shlib_directory: [no](表示不指定共享庫路徑)

meta_directory: [/etc/postfix]


結尾爲:

    Warning: you still need to edit myorigin/mydestination/mynetworks

    parameter settings in /etc/postfix/main.cf.


    See also http://www.postfix.org/STANDARD_CONFIGURATION_README.html

    for information about dialup sites or about sites inside a firewalled

    network.


    BTW: Check your /etc/aliases file and be sure to set up aliases

    that send mail for root and postmaster to a real person, then run

    /usr/bin/newaliases.


表示完成postfix安裝!



6.添加開機啓動命令:

創建文件:vim /etc/init.d/postfix

賦予權限:chown postfix.postfix /etc/init.d/postfix

添加內容:

#!/bin/bash


#


# postfix      Postfix Mail Transfer Agent


#


# chkconfig: 2345 80 30


# description: Postfix is a Mail Transport Agent, which is the program \


#              that moves mail from one machine to another.


# processname: master


# pidfile: /var/spool/postfix/pid/master.pid


# config: /etc/postfix/main.cf


# config: /etc/postfix/master.cf


# Source function library.


. /etc/rc.d/init.d/functions


# Source networking configuration.


. /etc/sysconfig/network


# Check that networking is up.


[ $NETWORKING = "no" ] && exit 3


[ -x /usr/sbin/postfix ] || exit 4


[ -d /etc/postfix ] || exit 5


[ -d /var/spool/postfix ] || exit 6


RETVAL=0


prog="postfix"


start() {


 # Start daemons.


 echo -n $"Starting postfix: "


        /usr/bin/newaliases >/dev/null 2>&1


 /usr/sbin/postfix start 2>/dev/null 1>&2 && success || failure $"$prog start"


 RETVAL=$?


 [ $RETVAL -eq 0 ] && touch /var/lock/subsys/postfix


        echo


 return $RETVAL


}


stop() {


  # Stop daemons.


 echo -n $"Shutting down postfix: "


 /usr/sbin/postfix stop 2>/dev/null 1>&2 && success || failure $"$prog stop"


 RETVAL=$?


 [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/postfix


 echo


 return $RETVAL


}


reload() {


 echo -n $"Reloading postfix: "


 /usr/sbin/postfix reload 2>/dev/null 1>&2 && success || failure $"$prog reload"


 RETVAL=$?


 echo


 return $RETVAL


}


abort() {


 /usr/sbin/postfix abort 2>/dev/null 1>&2 && success || failure $"$prog abort"


 return $?


}


flush() {


 /usr/sbin/postfix flush 2>/dev/null 1>&2 && success || failure $"$prog flush"


 return $?


}


check() {


 /usr/sbin/postfix check 2>/dev/null 1>&2 && success || failure $"$prog check"


 return $?


}


restart() {


 stop


 start


}


# See how we were called.


case "$1" in


  start)


 start


 ;;


  stop)


 stop


 ;;


  restart)


 stop


 start


 ;;


  reload)


 reload


 ;;


  abort)


 abort


 ;;


  flush)


 flush


 ;;


  check)


 check


 ;;


  status)


   status master


 ;;


  condrestart)


 [ -f /var/lock/subsys/postfix ] && restart || :


 ;;


  *)


 echo $"Usage: $0 {start|stop|restart|reload|abort|flush|check|status|condrestart}"


 exit 1


esac


exit $?


# END


################################################################


7.啓動報錯

service postfix start     

postfix start

提示:

[root@mail postfix]# postfix start

postfix/postfix-script: warning: not owned by postfix: /var/lib/postfix/.

postfix/postfix-script: warning: not owned by postfix: /var/lib/postfix/./master.lock

postfix/postfix-script: starting the Postfix mail system

postfix/postfix-script: fatal: mail system startup failed


報錯原因:啓動文件不是postfix所擁有,權限不夠

解決辦法:

chown postfix.postfix  -R /var/lib/postfix

chmod770/var/lib/postfix/master.lock

修改後在重新啓動

[root@mail lib]# postfix start

postfix/postfix-script: starting the Postfix mail system

[root@mail lib]# netstat -tunlp | grep 25

tcp        0      0 0.0.0.0:25                  0.0.0.0:*                   LISTEN      9755/master  


 8.設置開機自動啓動:

[root@mail /]# chkconfig --add mysqld

[root@mail /]# chkconfig --add postfix

[root@mail /]# chkconfig  mysqld on

[root@mail /]# chkconfig  postfix on




9.測試下psotfix能否正常發信

[root@mail /]# telnet localhost 25

Trying ::1...

telnet: connect to address ::1: Connection refused

Trying 127.0.0.1...

Connected to localhost.

Escape character is '^]'.

220 mail.test.com ESMTP Postfix (3.2.2)

ehol h^Hlocalhost

502 5.5.2 Error: command not recognized

ehlo localhost

250-mail.test.com

250-PIPELINING

250-SIZE 10240000

250-VRFY

250-ETRN

250-ENHANCEDSTATUSCODES

250-8BITMIME

250 DSN

mail from:[email protected]

250 2.1.0 Ok

rcpt to:[email protected]

250 2.1.5 Ok

data

354 End data with <CR><LF>.<CR><LF>

wangkejian 20170704

.

250 2.0.0 Ok: queued as 0DACD13402C2

quit

221 2.0.0 Bye


#######################################################################


10.安裝 dovecot RPM包: 

yum install dovecot

1. 配置文件路徑:

[root@mail dovecot]# ls

conf.d  dovecot.conf

[root@mail dovecot]# cd conf.d/

[root@mail conf.d]# ls

10-auth.conf      10-ssl.conf   90-acl.conf                  auth-ldap.conf.ext        auth-system.conf.ext

10-director.conf  15-lda.conf   90-plugin.conf               auth-master.conf.ext      auth-vpopmail.conf.ext

10-logging.conf   20-imap.conf  90-quota.conf                auth-passwdfile.conf.ext

10-mail.conf      20-lmtp.conf  auth-checkpassword.conf.ext  auth-sql.conf.ext

10-master.conf    20-pop3.conf  auth-deny.conf.ext           auth-static.conf.ext


2.文件主配置更改如下:

1.在etc/dovecot/dovecot.conf中設置:

protocols = imap pop3 允許認證的協議類型

listen = *, ::允許所有監聽的端口

login_trusted_networks = 6.6.6.6/8   允許該網段認證

2.在/etc/dovecot/conf.d/10-mail.conf中設置:

mail_location = mbox:~/mail:INBOX=/var/mail/%u  設置郵箱目錄


3.在/etc/dovecot/conf.d/10-auth.conf中設置:

disable_plaintext_auth = no 使用明文認證 


 4.設置新建用戶後,自動創建郵箱目錄;如下

 mkdir -p /etc/skel/mail/.imap/INBOX  

#在用戶模板文件中添加這些目錄文件,以後只要是創建用戶系統會自動在用戶的家目錄下創建這些文件


#######################################################################


11.sasl認證設置


1.使用系統用戶認證

vim /etc/sysconfig/saslauthd

修改 MECH=pam 參數爲 MECH=shadow   #更改認證方式


2.添加smtpd.conf文件,讓postfix使用sasl認證

編輯vim /usr/lib64/sasl2/smtpd.conf

添加以下參數:

log_level: 3

pwcheck_method: saslauthd

mech_list: PLAIN LOGIN

賦予文件權限:

chown postfix  /usr/lib64/sasl2/smtpd.conf



12.安裝webmin源碼包:


源碼包下載地址:http://prdownloads.sourceforge.net/webadmin/webmin-1.850.tar.gz

install:

tar xf webmin-1.850.tar.gz

cd  webmin-1.850

./setup.sh

設置過程中其他保持默認,只修改自己定義的端口號即可


##############################################################


13.安裝openwebmail


文檔地址:http://openwebmail.org/openwebmail/download/centos/el6/00.readme.txt


1)下載openwebmail repo文件,並用yum安裝openwebmail軟件包

#cd /etc/yum.repos.d

#wget -q http://openwebmail.org/openwebmail/download/redhat/rpm/release/openwebmail.repo

#yum install openwebmail


2)   配置

編輯文件:

vim   /var/www/cgi-bin/openwebmail/etc/openwebmail.conf

把 default_language    en                            語言英文

改爲 default_language    zh_cn.gb2312       語言中文


vim    /var/www/cgi-bin/openwebmail/etc/defaults/dbm.conf 

把最後三項改爲:

        

            dbm_ext                 .db

            dbmopen_ext             .db

            dbmopen_haslock         yes

 保存退出後,執行初始化命令

    root#    /var/www/cgi-bin/openwebmail/openwebmail-tool.pl --init

3)web登入地址:

http://6.6.6.6/cgi-bin/openwebmail/openwebmail.pl



4) 公用通訊錄設置:

   設置一個通訊錄管理員  address

    useradd address #創建管理員

chown address.address    /var/www/cgi-bin/openwebmail/etc/addressbooks

yum install perl* #安裝網頁支持模塊


4)禁用網絡磁盤:

編輯:vim /var/www/cgi-bin/openwebmail/etc/defaults/openwebmail.conf

找到這個選項改爲no:

enable_webdisk            no #不允許用戶使用網絡磁盤


主要配置文件:

/var/www/cgi-bin/openwebmail/etc/defaults/openwebmail.conf   #功能設置

/var/www/cgi-bin/openwebmail/etc/openwebmail.conf #參數設置


14.說明

安裝了webmin後,發現在web訪問過程中,他會自動修改postfix的主配置文件內的內容

避免問題(老版本沒有這個問題):

1. 設置好策略,以及一些其他配置後,進行備份

2. 新建一個web管理賬戶,主要給 用戶和組管理 和 postfix設置中的郵件別名即可,因爲

安裝webmail本身就只需要這兩個功能就可以了

        3.webmail主界面:

wKiom1mJegbS0TyGAAFL6FQLy2E755.png-wh_50


        4. postfixweb主管理界面

wKioL1mJegfgDXpFAACZapl6yTM985.png-wh_50

wKiom1mJegjBf37OAAIUWTEvGTc795.png-wh_50



         5. 郵箱用戶管理登入界面:

wKioL1mJegjxmjIkAAEmkR8BVtQ752.png-wh_50


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