第一, 首先必須安裝 apacache mysql php
CentOS 直接使用 yum 安裝
yum -y install httpd httpd-devel mysql php-mysql mysql-server mysql-devel mysql-test mysql-connector-odbc64 php pam-devel perl-ExtUtils-CBuilder perl-ExtUtils-MakeMaker
第二,安裝Postfix郵件
tar zxvf postfix-2.10.0.tar.gz
cd postfix-2.10.0
groupadd -g 1200 postdrop
groupadd -g 25 postfix
useradd -u 25 -g 25 -G postdrop -s /sbin/nologin -M postfix
make -f Makefile.init makefiles 'CCARGS=-DHAS_MYSQL -I/usr/include/mysql' 'AUXLIBS=-L/usr/lib64/mysql -lmysqlclient -lz -lm'
make install
其間需要配置,我們按照預設方式既可,一直按按回車,既為預設模式安裝
輸出以下資訊:
----------------------------------------------------------------------------------------------------------------------------
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.
-----------------------------------------------------------------------------------------------------------------------------
這裡先關閉系統自帶的sendmail
chkconfig --level 2345 sendmail off
啟用別名功能
newaliases
使用postconf 可檢視支援
postconf -m |grep mysql 檢視是否支援mysql
第三,下面配置postfix
vim /etc/postfix/main.cf
修改 myhostname 為郵件域名
myhostname = mail.11111.com 改成自己的主機名
myorigin = $mydomain
inet_interfaces = all
mynetworks = 127.0.0.0/8
home_mailbox = Maildir/
啟動 postfix
postfix start
---------------------------------------------------------------------
postfix/postfix-script: starting the Postfix mail system
----------------------------------------------------------------------
第四,安裝配置 dovecot
1. 新建 dovecot 使用者
useradd -M -s /sbin/nologin dovecot
編譯安裝 dovecot
tar zxvf dovecot-1.1.4.tar.gz
cd dovecot-1.1.4
./configure --sysconfdir=/etc/ --with-mysql
make -j 2 && make install
2. 配置 dovecot
cp /etc/dovecot-example.conf /etc/dovecot.conf
vim /etc/dovecot.conf
protocols = imap imaps pop3 pop3s
disable_plaintext_auth = no
ssl_disable = yes
mail_location = maildir:~/opt/mailbox/%d/%n/Maildir
3. 啟動dovecot (-c指定配置檔案)
/usr/local/sbin/dovecot -c /etc/dovecot.conf
ps aux|grep dovecot
lsof -i:110
lsof -i:143
第五,新增mysql 虛擬使用者支援
tar zxvf extman-1.1.tar.gz
cd extman-1.1/docs/
1.匯入資料庫
mysql -uroot -p < extmail.sql
mysql -uroot -p < init.sql
2. 拷貝mysql認證配置檔案到 postfix 目錄
cp mysql_virtual_* /etc/postfix/
3. 建虛擬使用者vuser
groupadd -g 1000 vuser
useradd -u 1000 -g 1000 -s /sbin/nologin -M vuser
mkdir /opt/mailbox
chown -R vuser:vuser /opt/mailbox
4. 修改main.cf 配置檔案,增加以下內容支援mysql 認證查詢
vim /etc/postfix/main.cf
# extmail config here
virtual_mailbox_base = /opt/mailbox
virtual_uid_maps = static:1000
virtual_gid_maps = static:1000
virtual_transport = virtual
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_maps = mysql:/etc/postfix/mysql_virtual_limit_maps.cf
第六,搭建extmail
1. 安裝依賴包.
tar zxvf Unix-Syslog-1.1.tar.gz
cd Unix-Syslog-1.1
perl Makefile.PL && make && make install
cd ..
tar zxvf DBI-1.616.tar.gz
cd DBI-1.616
perl Makefile.PL && make && make install
cd ..
tar zxvf DBD-mysql-4.020.tar.gz
cd DBD-mysql-4.020
perl Makefile.PL && make && make install
cd ..
2. 安裝 extmail
tar zxvf extmail-1.2.tar.gz
cp -r extmail-1.2 /opt/htdocs/extmail
cd /opt/htdocs/extmail/
chown -R postfix:postfix cgi/
cp webmail.cf.default webmail.cf
vim webmail.cf
SYS_CONFIG = /opt/htdocs/extmail/
SYS_LANGDIR = /opt/htdocs/extmail/lang
SYS_TEMPLDIR = /opt/htdocs/extmail/html
SYS_MAILDIR_BASE = /opt/mailbox
SYS_MYSQL_USER = extmail
SYS_MYSQL_PASS = extmail
SYS_MYSQL_DB = extmail
SYS_MYSQL_HOST = localhost
SYS_MYSQL_SOCKET = /var/lib/mysql/mysql.sock
SYS_G_ABOOK_FILE_PATH = /opt/htdcos/extmail/globabook.cf
3. 配置httpd 虛擬主機
vim /etc/httpd/conf/httpd.conf
User vuser
Group vuser
<VirtualHost *:80>
ServerAdmin admin@moxian.com
DocumentRoot /var/www/html/extmail/html
ServerName mail.moxian.com
ErrorLog logs/error.log
CustomLog logs/access.log common
ScriptAlias /extmail/cgi/ "/var/www/html/extmail/cgi/"
Alias /extmail "/var/www/html/extmail/html/"
</VirtualHost>
第七,搭建extman
1. 安裝依賴包.
yum install gd-devel -y
tar zxvf GD-2.46.tar.gz
cd GD-2.46
perl Makefile.PL && make && make install
cd ..
tar zxvf File-Tail-0.99.3.tar.gz
cd File-Tail-0.99.3
perl Makefile.PL && make && make install
cd ..
2. 安裝圖形日誌依賴包rrdtool,rrdtool-perl (centos 6.0以上的可用 yum 安裝 yum -y install rrdtool rrdtool-perl )
centos預設yum源中沒有這兩個包,所以需要手動新增yum源來安裝這兩個包
vim /etc/yum.repos.d/CentOS-Base.repo
---------------------------------------------------------------
[dag]
name=Dag RPM Repository for Red Hat Enterprise Linux
baseurl=http://apt.sw.be/redhat/el$releasever/en/$basearch/dag
gpgcheck=1
gpgkey=http://dag.wieers.com/rpm/packages/RPM-GPG-KEY.dag.txt
enabled=1
-------------------------------------------------------------------
yum install rrdtool rrdtool-perl -y
3. 安裝extman
tar zxvf extman-1.1.tar.gz
cp -r extman-1.1 /opt/htdocs/extman
cd /opt/htdocs/extman/
chown -R postfix:postfix cgi/
mkdir /tmp/extman
chown -R postfix:postfix /tmp/extman/
chmod -R 777 /tmp/extman/
4. 修改extman配置引數, 讓其支援MYSQL 查詢
cp webman.cf.default webman.cf
vim webman.cf
SYS_CONFIG = /opt/htdocs/extman/
SYS_LANGDIR = /opt/htdocs/extman/lang
SYS_TEMPLDIR = /opt/htdocs/extman/html
SYS_MAILDIR_BASE = /opt/mailbox
SYS_SESS_DIR = /tmp/extman/
SYS_DEFAULT_UID = 1000
SYS_DEFAULT_GID = 1000
SYS_MYSQL_USER = webman
SYS_MYSQL_PASS = webman
SYS_MYSQL_DB = extmail
SYS_MYSQL_HOST = localhost
SYS_MYSQL_SOCKET = /var/lib/mysql/mysql.sock
5. 修改虛擬主機配置檔案,使其支援extman
在上面虛擬機器中新增
<VirtualHost *:80>
.......
ScriptAlias /extman/cgi "/opt/htdocs/extman/cgi/"
Alias /extman "/opt/htdocs/extman/html/"</VirtualHost>
6. 啟動extman 中自帶的圖形化支援指令碼
/opt/htdocs/extman/daemon/cmdserver -d
cp -a /opt/htdocs/extman/addon/mailgraph_ext/ /usr/local/
/opt/htdocs/extman/addon/mailgraph_ext/mailgraph-init start
/opt/htdocs/extman/addon/mailgraph_ext/qmonitor.pl &
第八,虛擬使用者發信認證
1. 安裝courier-authlib認證軟體包
tar jxvf courier-authlib-0.62.4.tar.bz2
cd courier-authlib-0.62.4
./configure --prefix=/usr/local/courier-authlib --without-stdheaderdir --with-authmysql --with-mysql-libs=/usr/lib64/mysql/ --with-mysql-includes=/usr/include/mysql/
make -j 8 && make install && make install-configure
2. 把courier-authlib連結庫新增進系統預設支援庫
vim /etc/ld.so.conf.d/courier-authlib.conf
/usr/local/courier-authlib/lib/courier-authlib
3. 編輯authdaemonrc,使其支援mysql認證
cd /usr/local/courier-authlib/etc/authlib/
vim authdaemonrc
authmodulelist="authmysql"
authmodulelistorig="authmysql"
chmod -R 755 /usr/local/courier-authlib/var/spool/authdaemon/
4. 編輯authmysqlrc設定和mysql的連線引數.
cd /usr/local/courier-authlib/etc/authlib/
vim authmysqlrc
MYSQL_SERVER localhost
MYSQL_USERNAME extmail
MYSQL_PASSWORD extmail
MYSQL_SOCKET /var/lib/mysql/mysql.sock
MYSQL_PORT 3306
MYSQL_DATABASE extmail
MYSQL_USER_TABLE mailbox
MYSQL_CRYPT_PWFIELD password
MYSQL_UID_FIELD 1000
MYSQL_GID_FIELD 1000
MYSQL_LOGIN_FIELD username
MYSQL_HOME_FIELD concat('/opt/mailbox/',homedir)
MYSQL_NAME_FIELD name
MYSQL_MAILDIR_FIELD concat('/opt/mailbox/',maildir)
5. 將指令碼檔案新增進預設環境變數中,並新增開機啟動程式
cp /opt/software/courier-authlib-0.62.4/courier-authlib.sysvinit /usr/local/bin/courier-authlib
chmod 755 /usr/local/bin/courier-authlib
courier-authlib start
6. 新建smtpd.conf檔案,使postfix支援認證。
vim /usr/lib64/sasl2/smtpd.conf
----------------------------------------------------------------------------
pwcheck_method: authdaemond
mech_list:PLAIN LOGIN
authdaemond_path:/usr/local/courier-authlib/var/spool/authdaemon/socket
-----------------------------------------------------------------------------
cp -a /usr/local/courier-authlib/sbin/authtest /usr/local/sbin/
第九,虛擬使用者收信認證
1. 編輯dovecot.conf 檔案 開啟mysql認證,關閉預設pam認證
vim /etc/dovecot.conf
--------------------------------------------------------------------------------------------------
protocols = imap imaps pop3 pop3s <---預設沒有開啟pop3,需要手動新增
disable_plaintext_auth = no <------允許plain認證
ssl_disable = yes<------禁用ssl加密
mail_location = maildir:~/opt/mailbox/%d/%n/Maildir
mechanisms = plain
#passdb pam {<--預設是開啟的,需要註釋掉
#}
passdb sql {
args = /etc/dovecot-mysql.conf
}
userdb sql {
args = /etc/dovecot-mysql.conf
}
---------------------------------------------------------------------------------------------------
2. 建立dovecot-mysql.conf,設定和mysql連線及查詢引數
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
pkill dovecot
dovecot -c /etc/dovecot.conf
第十,虛擬使用者SASL身份認證
1. 重新編譯 postfix
postfix stop
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 -j 8
2. 升級postfix (升級)
make upgrade
重新啟動 postfix
postfix start
postconf -a 檢視是否支援 cyrus
3. 修改main.cf配置檔案,配置sasl認證引數
vim /etc/postfix/main.cf
在最後面增加 sasl認證
#sasl認證
smtpd_sasl_auth_enable = yes
broken_sasl_auth_clients = yes
smtpd_sasl_security_options = noanonymous
smtpd_recipient_restrictions =
permit_mynetworks,
permit_sasl_authenticated,
reject_non_fqdn_hostname,
reject_unknown_sender_domain,
reject_non_fqdn_sender,
reject_non_fqdn_recipient,
reject_unauth_destination,
reject_unauth_pipelining,
reject_invalid_hostname
smtpd_sender_login_maps =
mysql:/etc/postfix/mysql_virtual_sender_maps.cf,
mysql:/etc/postfix/mysql_virtual_alias_maps.cf
郵件過濾 dkim-milter
--------------------------------------------------------------------------------------------------
rpm -ivh http://download4.fedora.redhat.com/pub/epel/5/`uname -i`/dkim-milter-2.8.3-8.el5.`uname -i`.rpm --nodeps
wget -O dkim-milter.tar.gz http://sourceforge.net/projects/dkim-milter/files/latest/download?source=files
tar zxvf dkim-milter.tar.gz
cd dkim-milter-*
mkdir -p /etc/dkim-milter/keys/
cp ./dkim-filter/dkim-genkey.sh /etc/dkim-milter/keys/
cd /etc/dkim-milter/keys/
chmod +x ./dkim-genkey.sh
chown dkim-milter /etc/dkim-milter
chmod 700 /etc/dkim-milter
chgrp postfix /var/run/dkim-milter
chmod 770 /var/run/dkim-milter
./dkim-genkey.sh -r -d `hostname -f`
chown dkim-milter /etc/dkim-milter/keys/default.private
mv /etc/dkim-milter/keys/default.private /etc/dkim-milter/keys/default.key.pem
#會生成default.txt 和 default.private
#根據default.txt 裡面的內容,將DNS的TXT記錄新增好
#default.private已安置好,並改名為default.key.pem,可以使用了
#下面的命令,大家根據實際微調
echo "*@moxianmail.com:moxianmail.com:/etc/dkim-milter/keys/default.key.pem" >> /etc/mail/dkim-milter/keys/keylist
echo 'AutoRestart yes' >> /etc/mail/dkim-milter/dkim-filter.conf
echo 'AutoRestartRate 10/1h' >> /etc/mail/dkim-milter/dkim-filter.conf
echo 'Domain kn007.net' >> /etc/mail/dkim-milter/dkim-filter.conf
echo 'SubDomains yes' >> /etc/mail/dkim-milter/dkim-filter.conf
echo 'Selector default' >> /etc/mail/dkim-milter/dkim-filter.conf
echo 'KeyFile /etc/dkim-milter/keys/default.key.pem' >> /etc/mail/dkim-milter/dkim-filter.conf
echo 'Background yes' >> /etc/mail/dkim-milter/dkim-filter.conf
echo 'Socket inet:8891' >> /etc/mail/dkim-milter/dkim-filter.conf
echo 'Userid dkim-milter' >> /etc/mail/dkim-milter/dkim-filter.conf
echo 'smtpd_milters = inet:8891' >> /etc/postfix/main.cf
echo 'non_smtpd_milters = inet:8891' >> /etc/postfix/main.cf
echo 'milter_protocol = 2' >> /etc/postfix/main.cf
echo 'milter_default_action = accept' >> /etc/postfix/main.cf
chkconfig --level 345 dkim-milter on
service dkim-milter start
service postfix restart
cat /var/log/maillog
錯誤 1
Can't locate CPAN.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .).
BEGIN failed--compilation aborted.
yum -y install perl-CPAN
然後
perl -MCPAN -eshell
出現 cpan[1]>
輸入
install CGI
錯誤 2
warning: dict_nis_init: NIS domain name not set - NIS lookups disabled
postfix/smtpd[7256]: connect from unknown[113.116.237.125]
postfix/smtpd[7256]: warning: xsasl_cyrus_server_get_mechanism_list: no applicable SASL mechanisms
postfix/smtpd[7256]: fatal: no SASL authentication mechanisms
postfix/master[7247]: warning: process /usr/libexec/postfix/smtpd pid 7256 exit status 1
postfix/master[7247]: warning: /usr/libexec/postfix/smtpd: bad command startup -- throttling
ln -s /usr/local/lib/sasl2 /usr/lib/sasl2
yum -y install cyrus-sasl-plain cyrus-sasl-sql
=====================================================================================
常用命令維護:
查詢郵件佇列:postqueue -p
清除所有郵件佇列:postsuper -d ALL