这篇我们接着上一篇文章来写:(基于Red Hat Enterprise Linux Server release 5.8)
- vim /etc/named.conf
- options {
- directory "/var/named";
- forward only;
- forwarders { 172.16.9.3; };
- };
- zone "." IN {
- type hint;
- file "named.ca";
- };
- zone "test.com" IN {
- type master;
- file "test.com.zone";
- };
- zone "9.16.172.in-addr.arpa" IN {
- type master;
- file "172.16.9.zone";
- };
- vim test.com.zone
- $TTL 86400
- $ORIGIN test.com.
- @ IN SOA ns.test.com. admin.test.com. (
- 20121105
- 2H
- 10M
- 7D
- 1D )
- IN NS ns
- IN MX 10 mail
- ns IN A 172.16.9.2
- mail IN A 172.16.9.2
- www IN CNAME mail
- vim 172.16.9.zone
- $TTL 86400
- @ IN SOA ns.test.com. admin.test.com. (
- 20121105
- 2H
- 10M
- 7D
- 1D )
- IN NS ns.test.com.
- 2 IN PTR ns.test.com.
- 2 IN PTR mail.test.com.
- [root@mail named]# dig -t MX test.com
- ; <<>> DiG 9.7.0-P2-RedHat-9.7.0-6.P2.el5_7.4 <<>> -t MX test.com
- ;; global options: +cmd
- ;; connection timed out; no servers could be reached
- groupadd -g 2525 postfix
- useradd -g postfix -u 2525 -s /sbin/nologin -M postfix
- groupadd -g 2526 postdrop
- useradd -g postdrop -u 2526 -s /sbin/nologin -M postdrop
- tar xf postfix-2.9.4.tar.gz
- cd postfix-2.9.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/lib/mysql -lmysqlclient -lz -lm -L/usr/lib/sasl2 -lsasl2 -lssl -lcrypto'
- make
- make install
- install_root: [/]
- tempdir: [/root/postfix-2.9.4] /tmp/postfix
- config_directory: [/etc/postfix]
- command_directory: [/usr/sbin]
- daemon_directory: [/usr/libexec/postfix]
- data_directory: [/var/lib/postfix]
- html_directory: [no]
- mail_owner: [postfix]
- mailq_path: [/usr/bin/mailq]
- manpage_directory: [/usr/local/man]
- newaliases_path: [/usr/bin/newaliases]
- queue_directory: [/var/spool/postfix]
- readme_directory: [no]
- sendmail_path: [/usr/sbin/sendmail]
- setgid_group: [postdrop]
- vim /etc/rc.d/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
- chmod +x /etc/rc.d/init.d/postfix
- user1: hadoop
- user2: [email protected]
- newaliases
- obama@ REJECT
- postmap /etc/postfix/denyuser
- smtpd_sender_restrictions = check_sender_access hash:/etc/postfix/denyuser
- smtpd_recipient_restrictions = permit_mynetworks, reject_unauth_destination
- protocols = imap pop3
- service dovecot start
- 修改MECH=pam为 MECH=shadow
- service saslauthd start
- [root@mail ~]# testsaslauthd -u hadoop -p redhat
- 0: OK "Success."
- vim /usr/lib/sasl2/smtpd.conf
- pwcheck_method: saslauthd
- mech_list: PLAIN LOGIN
- ############################CYRUS-SASL############################
- broken_sasl_auth_clients = yes
- smtpd_recipient_restrictions=permit_mynetworks,permit_sasl_authenticated,reject_invalid_hostname,reject_non_fqdn_hostname,reject_unknown_sender_domain,reject_non_fqdn_sender,reject_non_fqdn_recipient,reject_unknown_recipient_domain,reject_unauth_pipelining,reject_unauth_destination
- smtpd_sasl_auth_enable = yes
- smtpd_sasl_local_domain = $myhostname
- smtpd_sasl_security_options = noanonymous
- cp /etc/my.cnf /root #保存主配置文件
- rpm -e mysql --nodeps
- cp /root/my.cnf /etc/my.cnf
- tar jxvf courier-authlib-0.64.0.tar.bz2
- cd courier-authlib-0.64.0
- ./configure \
- --prefix=/usr/local/courier-authlib \
- --sysconfdir=/etc \
- --without-authpam \
- --without-authshadow \
- --without-authvchkpw \
- --without-authpgsql \
- --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-mailuser=postfix \
- --with-mailgroup=postfix \
- --with-ltdl-lib=/usr/lib \
- --with-ltdl-include=/usr/include
- make && make install
- cp /etc/authdaemonrc.dist /etc/authdaemonrc
- cp /etc/authmysqlrc.dist /etc/authmysqlrc
- authmodulelist="authmysql"
- authmodulelistorig="authmysql"
- daemons=10
- MYSQL_SERVER localhost
- MYSQL_USERNAME extmail #这是为后文要用的数据库的所有者的用户名
- MYSQL_PASSWORD extmail #密码
- MYSQL_SOCKET /tmp/mysql.sock
- MYSQL_PORT 3306 #指定你的mysql监听的端口,这里使用默认的3306
- 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)
- cp courier-authlib.sysvinit /etc/rc.d/init.d/courier-authlib
- chkconfig --add courier-authlib
- chkconfig courier-authlib on
- vim /etc/ld.so.conf.d/courier-authlib.conf
- /usr/local/courier-authlib/lib/courier-authlib
- ldconfig -v
- service courier-authlib start #启动服务
- mkdir –pv /var/mailbox
- chown –R postfix /var/mailbox
- pwcheck_method: authdaemond
- mech_list:PLAIN LOGIN
- authdaemond_path:/usr/local/courier-authlib/var/spool/authdaemon/socket
- ########################Virtual Mailbox Settings########################virtual_mailbox_base = /var/mailbox
- 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
- virtualvirtual_transport = virtual
- ##########################QUOTA Settings########################
- message_size_limit = 14336000
- virtual_mailbox_limit = 20971520
- tar xf extmail-1.2.tar.gz -C /var/www/extsuite/
- tar xf extman-1.1.tar.gz -C /var/www/extsuite/
- cd /var/www/extsuite/
- mv extmail-1.2 extmail
- mv extman-1.1 extman
- cd extman/docs
- sed -i 's@TYPE=MyISAM@Engine=MyISAM@g' extmail.sql
- sed -i 's@TYPE=MyISAM@Engine=MyISAM@g' init.sql
- mysql < extmail.sql
- mysql < init.sql
- mysql> grant all on extmail.* to [email protected] identified by 'extmail';
- mysql> grant all on extmail.* to extmail@localhost identified by 'extmail';
- mysql> flush privileges;
- cp /var/www/extsuite/extmail/webmail.cf.default /var/www/extsuite/extmail/webmail.cf
- vim /var/www/extsuite/extmail/webmail.cf
- SYS_USER_LANG = zh_CN #语言选项
- SYS_MAILDIR_BASE = /var/mailbox #用户邮件的存放目录
- SYS_MYSQL_USER = extmail #连接数据库服务器所使用用户名
- SYS_MYSQL_PASS = extmail #密码
- SYS_MYSQL_SOCKET = /tmp/mysql.sock #mysql.sock的路径
- SYS_AUTHLIB_SOCKET = /usr/local/courier-authlib/var/spool/authdaemon/socket #指明authdaemo socket文件的位置
- cp /var/www/extsuite/extman/webman.cf.default /var/www/extsuite/extman/webman.cf
- vi /var/www/extsuite/extman/webman.cf
- SYS_MAILDIR_BASE = /var/mailbox #用户邮件的存放目录
- SYS_DEFAULT_UID = 2525
- SYS_DEFAULT_GID = 2525 #ID号需更改为前面创建的postfix用户和postfix组的id号
- SYS_MYSQL_USER = extmail
- SYS_MYSQL_PASS = extmail
- SYS_MYSQL_SOCKET = /tmp/mysql.sock
- SYS_CAPTCHA_ON = 0 #关闭校验功能
- mkdir -pv /tmp/extman
- chown postfix.postfix /tmp/extman
- chown -R postfix.postfix /var/www/extsuite/extman/cgi/
- cd /var/www/extsuite/extman/docs/
- mv mysql_virtual_* /etc/postfix/
- cd /etc/httpd/conf
- vim httpd.conf
- User postfix
- Group postfix #修改所属用户和组
- <VirtualHost *:80>
- ServerName mail.test.com
- DocumentRoot /var/www/extsuite/extmail/html/
- ScriptAlias /extmail/cgi /var/www/extsuite/extmail/cgi
- Alias /extmail /var/www/extsuite/extmail/html
- ScriptAlias /extman/cgi /var/www/extsuite/extman/cgi
- Alias /extman /var/www/extsuite/extman/html
- </VirtualHost>
- tar zxvf Unix-Syslog-1.1.tar.gz
- cd Unix-Syslog-1.1
- perl Makefile.PL
- make
- make install
- vi /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
- }
- ……
- vim /etc/dovecot-mysql.conf
- driver = mysql
- connect = host=/tmp/mysql.sock
- 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'