配置Postfix支持Mysql虚拟用户
1、 建立虚拟用户数据库
a、 挂载postfix2.iso
cd /tmp/postfix
tar -zxvf extman-0.2.5.tar.gz -C /usr/src
cd /usr/src/extman-0.2.5/docs
mysql -u root -p < extmail.sql
mysql -u root -p < init.sql
vim /etc/postfix/main.cf
21 #mydestination = $mydomain, $myhostname
virtual_mailbox_base = /mailbox
virtual_alias_maps = mysql:/etc/postfix/mysql_virtual_alias_maps.cf
virtual_mailbox_maps = mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf
virtual_mailbox_domains = mysql:/etc/postfix/mysql_virtual_domains_maps.cf
virtual_uid_maps = static:1000
virtual_gid_maps = static:1000
cp mysql_virtual_* /etc/postfix
tar -jxvf /tmp/postfix/courier-authlib-0.60.2.tar.bz2 -C /usr/src
cd /usr/src/courier-authlib-0.60.2
./configure --prefix=/usr/local/courier-authlib --without-stdheaderdir --with-authmysql --with-redhat --with-mysql-libs=/usr/local/mysql/lib/mysql --with-mysql-includes=/usr/local/mysql/include/mysql
make
make install
make install-configure
echo "/usr/local/courier-authlib/lib/courier-authlib" >> /etc/ld.so.conf
ldconfig
cd /usr/local/courier-authlib/etc/authlib
cp authdaemonrc authdaemonrc.bak
vim authdaemonrc
27 authmodulelist="authmysql"
34 authmodulelistorig="authmysql"
chmod -R 755 /usr/local/courier-authlib/var/spool/authdaemon
cp authmysqlrc authmysqlrc.bak
vim authmysqlrc
26 MYSQL_SERVER localhost //mysql数据库服务器位置
27 MYSQL_USERNAME extmail //管理员帐号
28 MYSQL_PASSWORD extmail //密码
49 MYSQL_SOCKET /tmp/mysql.sock
68 MYSQL_DATABASE extmail //虚拟用户数据库
83 MYSQL_USER_TABLE mailbox //从mailbox表获取邮件账户信息
92 MYSQL_CRYPT_PWFIELD password //从password获取密码
113 MYSQL_UID_FIELD uidnumber //从uidnumber字段映射本地uid
119 MYSQL_GID_FIELD gidnumber //从gidnumber字段映射本地gid
128 MYSQL_LOGIN_FIELD username
133 MYSQL_HOME_FIELD concat('/mailbox/',homedir)
139 MYSQL_NAME_FIELD name
150 MYSQL_MAILDIR_FIELD concat('/mailbox/',maildir)
cp /usr/src/courier-authlib-0.60.2/courier-authlib.sysvinit /etc/init.d/courier-authlib
chmod 755 /etc/init.d/courier-authlib
chkconfig courier-authlib on
service courier-authlib start
vim /usr/lib/sasl2/smtpd.conf
pwcheck_method:authdaemond
authdaemond_path: /usr/local/courier-authlib/var/spool/authdaemon/socket
vim /etc/dovecot.conf
208#mail_location = maildir:~/Maildir (将此行#注释,改为下行)
mail_location = maildir:/mailbox/%d/%n/Maildir
auth default {
mechanisms = plain
829 passdb sql {
856 args = /etc/dovecot-mysql.conf
}
928 userdb sql {
934 args = /etc/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'
mkdir -p /mailbox/extmail.org/postmaster/Maildir
chown -R postfix:postfix /mailbox
pkill dovecot
dovecot
/usr/local/courier-authlib/sbin/authtest -s login [email protected] extmail
部署ExtMail邮件
tar -zxvf Unix-Syslog-1.1.tar.gz -C /usr/src
tar -zxvf DBI-1.607.tar.gz -C /usr/src
tar -zxvf DBD-mysql-4.011.tar.gz -C /usr/src
tar -zxvf extmail-1.0.5.tar.gz -C /usr/local/apache2/htdocs
cd /usr/src/Unix-Syslog-1.1
perl Makefile.PL
make
make install
cd ../DBI-1.607
perl Makefile.PL
make
make install
cd ../DBD-mysql-4.011
perl Makefile.PL --libs="-L/usr/local/mysql/lib/mysql -lmysqlclient -lz" --cflags=-I/usr/local/mysql/include/mysql
make
make install
cd /usr/local/apache2/htdocs
mv extmail-1.0.5/ extmail
cd extmail
chown -R postfix:postfix cgi
cp webmail.cf.default webmail.cf
vim webmail.cf
2 SYS_CONFIG = /usr/local/apache2/htdocs/extmail/
5 SYS_LANGDIR = /usr/local/apache2/htdocs/extmail/lang
8 SYS_TEMPLDIR = /usr/local/apache2/htdocs/extmail/html
112 SYS_MAILDIR_BASE = /mailbox
124 SYS_MYSQL_USER = extmail
125 SYS_MYSQL_PASS = extmail
126 SYS_MYSQL_DB = extmail
127 SYS_MYSQL_HOST = localhost
128 SYS_MYSQL_SOCKET = /tmp/mysql.sock
vim /usr/local/apache2/conf/httpd.conf
66 User postfix
67 Group postfix
390 Include conf/extra/httpd-vhosts.conf
vim /usr/local/apache2/conf/extra/httpd-vhosts.conf
NameVirtualHost 192.168.0.1
<VirtualHost 192.168.0.1>
DocumentRoot "/usr/local/apache2/htdocs/extmail/html"
ServerName mail.extmail.org
ScriptAlias /extmail/cgi/ /usr/local/apache2/htdocs/extmail/cgi/
Alias /extmail /usr/local/apache2/htdocs/extmail/html/
</VirtualHost>
service httpd restart
部署Extman
cd /media
tar -zxvf GD-2.41.tar.gz -C /usr/src
tar –zxvf File-Tail-0.99.3.tar.gz -C /usr/src/
tar -zxvf extman-0.2.5.tar.gz -C /usr/local/apache2/htdocs/
cd /usr/src/GD-2.41
perl Makefile.PL
make && make install
cd ../File-Tail-0.99.3
perl Makefile.PL
make && make install
rpm -ivh rrdtool-1.2.23-3.el5.i386.rpm
rpm -ivh rrdtool-perl-1.2.23-3.el5.i386.rpm
cd /usr/local/apache2/htdocs
mv extman-0.2.5 extman
chown -R postfix:postfix /usr/local/apache2/htdocs/extman/cgi
mkdir /tmp/extman
chown -R postfix:postfix /tmp/extman
vim /usr/local/apache2/htdocs/extman/webman.cf
2 SYS_CONFIG = /usr/local/apache2/htdocs/extman/
5 SYS_LANGDIR = /usr/local/apache2/htdocs/extman/lang
8 SYS_TEMPLDIR = /usr/local/apache2/htdocs/extman/html
12 SYS_MAILDIR_BASE = /mailbox
127 SYS_MYSQL_USER = webman
128 SYS_MYSQL_PASS = webman
129 SYS_MYSQL_DB = extmail
130 SYS_MYSQL_HOST = localhost
131 SYS_MYSQL_SOCKET = /tmp/mysql.sock
vim /usr/local/apache2/conf/extra/httpd-vhosts.conf
<VirtualHost 192.168.0.1>
DocumentRoot "/usr/local/apache2/htdocs/extmail/html"
ServerName mail.extmai.org
ScriptAlias /extmail/cgi/ /usr/local/apache2/htdocs/extmail/cgi/
Alias /extmail /usr/local/apache2/htdocs/extmail/html/
ScriptAlias /extman/cgi/ /usr/local/apache2/htdocs/extman/cgi/ //新加入以下两行
Alias /extman /usr/local/apache2/htdocs/extman/html/
</VirtualHost>
mkdir /usr/local/mailgraph_ext
cd /usr/local/apache2/htdocs/extman/addon/mailgraph_ext/
cp mailgraph_ext.pl qmonitor.pl /usr/local/mailgraph_ext/
ln -sf /usr/local/apache2/htdocs/extman/addon/mailgraph_ext/mailgraph-init /usr/sbin/
ln -sf /usr/local/apache2/htdocs/extman/addon/mailgraph_ext/qmonitor-init /usr/sbin/
mailgraph-init start
qmonitor-init start
echo "/usr/sbin/mailgraph-init start" >> /etc/rc.local
echo "/usr/sbin/qmonitor-init start" >> /etc/rc.local
部署MailScanner
cd /tmp/postfix
tar -zxvf MailScanner-4.75.11-1.rpm.tar.gz -C /usr/src/
cd /usr/src/MailScanner-4.75.11-1
./install.sh
vim /etc/MailScanner/MailScanner.conf
115 Run As User = postfix
120 Run As Group = postfix
149 Incoming Queue Dir = /var/spool/postfix/hold
153 Outgoing Queue Dir = /var/spool/postfix/incoming
180 MTA = postfix
2083 Required SpamAssassin Score = 7
2089 High SpamAssassin Score = 10
2286 Spam Actions = deliver header "X-Spam-Status: Yes"
2347 High Scoring Spam Actions = delete forward [email protected]
vim /etc/postfix/main.cf
header_checks = regexp:/etc/postfix/header_checks //加入一行
vim /etc/postfix/header_checks
/^Received:/ HOLD //最后加入
chown -R postfix:postfix /var/spool/MailScanner/incoming/
chown -R postfix:postfix /var/spool/MailScanner/quarantine/
/etc/init.d/MailScanner start
chkconfig --level 35 MailScanner on
配置SpamAssassin/反垃圾功能。
yum install -y perl-Archive-Tar* perl-IO-Socket-INET6* perl-IO-Socket-SSL* perl-Digest-SHA1* perl-IO-Zlib* perl-Net-DNS* perl-Socket6* perl-Net-SSLeay* perl-Digest-HMAC*
rpm -ivh /tmp/postfix/spamassassin-3.1.7-4.el5.i386.rpm
/etc/init.d/spamassassin start
chkconfig spamassassin on
本文出自 “Linux网络安全” 博客,转载请与作者联系!