试验需求:
试验说明:(需要软件的可以Q395061796)
服务器担任dns、mail Server的角色,ip为192.168.100.123。
客户机进行测试
软件需求:
搭建基于虚拟账号的邮件服务器_第1张图片
一、修改机器名称、搭建DNS 并且安装所需软件
[root@zhangc ~]# vim /etc/sysconfig/network【修改主机名】
3 HOSTNAME=mail.yeah.net
[root@zhangc ~]# vim /etc/hosts【恢复默认值】
3 127.0.0.1 localhost.localdomain localhost
[root@zhangc ~]# vim /etc/resolv.conf【设置DNS服务器地址】
2 nameserver 192.168.100.123
[root@zhangc ~]# vim /etc/yum.repos.d/rhel-debuginfo.repo【编辑YUM仓库】
[root@zhangc ~]# yum repolist
[root@zhangc etc]# vim named.conf
[root@zhangc etc]# vim named.rfc1912.zones【增加相应的作用域】
27 zone "yeah.net" IN {
28 type master;
29 file "yeah.net.zone";
30 allow-update { none; };
31 };
[root@zhangc etc]# cd ../var/named/
[root@zhangc named]# vim yeah.net.zone【增添并编辑区域文件】
搭建基于虚拟账号的邮件服务器_第2张图片
[root@zhangc named]# service named start
[root@zhangc named]# chkconfig named on
[root@zhangc named]# service sendmail stop
[root@zhangc named]# chkconfig sendmail off
安装以下服务;
[root@mail Server]# yum 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
[root@mail Server]# service mysqld start【启动mysqld】
[root@mail Server]# chkconfig mysqld on
[root@mail Server]# mysql
mysql> SET PASSWORD FOR root@'localhost'=PASSWORD('redhat');
mysql> SET PASSWORD FOR root@'127.0.0.1'=PASSWORD('redhat');
mysql> FLUSH PRIVILEGES;
mysql> GRANT ALL PRIVILEGES ON *.* TO root@'%' IDENTIFIED BY 'redhat';
mysql> FLUSH PRIVILEGES;
mysql> \q
[root@mail Server]# service saslauthd start【启动saslauthd】
[root@mail Server]# chkconfig saslauthd on
二、安装配置POSTFIX
[root@mail ~]# groupadd -g 2525 postfix【创建组】
[root@mail ~]# useradd -g postfix -u 2525 -s /sbin/nologin -M postfix
[root@mail ~]# groupadd -g 2526 postdrop【将postdrop的组号设置为2526】
[root@mail ~]# useradd -g postdrop -u 2526 -s /bin/false -M postdrop
[root@mail postfix-2.8.2]# tar zxvf postfix-2.8.2.tar.gz -C /usr/local/src/【拆解源文件】
[root@mail postfix-2.8.2]# cd /usr/local/src/postfix-2.8.2/
[root@mail postfix-2.8.2]# 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'【预编译环境检测】
[root@mail postfix-2.8.2]# make【编译】
[root@mail postfix-2.8.2]# make install【安装】
install_root: [/] /
tempdir: [/usr/local/src/postfix-2.8.2] /tmp
以下的都使用默认目录文件夹
[root@mail postfix-2.8.2]# newaliases
[root@mail postfix-2.8.2]# postfix start
[root@mail postfix-2.8.2]# postconf -a
查看是否启动了cyrus
[root@mail ~]# mkdir /tmp/abc【创建目录】
[root@mail ~]# cd /tmp/abc/
[root@mail abc]# cp /mnt/cdrom/Server/postfix-2.3.3-2.1.el5_2.i386.rpm ./【拷贝postfix到当前目录】
[root@mail abc]# rpm2cpio postfix-2.3.3-2.1.el5_2.i386.rpm |cpio –id【安装】
[root@mail abc]# cd etc/rc.d/init.d/
[root@mail init.d]# cp postfix /etc/init.d/
[root@mail init.d]# vim /etc/postfix/main.cf【编辑postfix的主配置文档】
75 myhostname = mail.yeah.net
83 mydomain = yeah.net
99 myorigin = $mydomain
113 inet_interfaces = all
161 mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
260 mynetworks = 127.0.0.0/8
三、加入安全认证功能
[root@mail sasl2]# vim /etc/postfix/main.cf【编辑postfix的主配置文档】
653 ############################CYRUS-SASL############################
654 broken_sasl_auth_clients = yes
655 smtpd_recipient_restrictions=permit_mynetworks,permit_sasl_authenticated,reject_invalid_hostname,reject_non_fq dn_hostname,reject_unknown_sender_domain,reject_non_fqdn_sender,reject_non_fqdn_recipient,reject_unknown_recip ient_domain,reject_unauth_pipelining,reject_unauth_destination
656 smtpd_sasl_auth_enable = yes
657 smtpd_sasl_local_domain = $myhostname
658 smtpd_sasl_security_options = noanonymous
659 smtpd_banner = Welcome to our $myhostname ESMTP,Warning: Version not Available!
:wq
[root@mail sasl2]# cd /usr/lib/sasl2/
[root@mail sasl2]# cp -p Sendmail.conf smtpd.conf【拷贝并编辑smtpd.conf,添加下面语句】
2 mech_list: PLAIN LOGIN
进行测试:
[root@mail sasl2]# telnet mail.yeah.net 25
ehlo mail.yeah.net
250-AUTH PLAIN LOGIN
250-AUTH=PLAIN LOGIN
四、安装Courier anthentication library
[root@mail ~]# tar jxvf courier-authlib-0.63.1.20111230.tar.bz2【拆解】
[root@mail ~]# cd courier-authlib-0.63.1.20111230
[root@mail courier-authlib-0.63.1.20111230]# ./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【预编译环境检测】
[root@mail courier-authlib-0.63.1.20111230]# make【编译】
[root@mail courier-authlib-0.63.1.20111230]# make install【安装】
[root@mail courier-authlib-0.63.1.20111230]# chmod 755 /usr/local/courier-authlib/var/spool/authdaemon【修改权限】
[root@mail spool]# cp /etc/authdaemonrc.dist /etc/authdaemonrc
[root@mail spool]# cp /etc/authmysqlrc.dist /etc/authmysqlrc
[root@mail spool]# vim /etc/authdaemonrc
27 authmodulelist="authmysql"
34 authmodulelistorig="authmysql"
53 daemons=10
:wq
[root@mail spool]# vim /etc/authmysqlrc
83 MYSQL_USER_TABLE mailbox
92 MYSQL_CRYPT_PWFIELD password
26 MYSQL_SERVER localhost
27 MYSQL_USERNAME extmail
28 MYSQL_PASSWORD extmail
49 MYSQL_SOCKET /var/lib/mysql/mysql.sock
68 MYSQL_DATABASE extmail
83 MYSQL_USER_TABLE mailbox
92 MYSQL_CRYPT_PWFIELD password
113 MYSQL_UID_FIELD 2525
119 MYSQL_GID_FIELD 2525
128 MYSQL_LOGIN_FIELD username
133 MYSQL_HOME_FIELD concat('/var/mailbox/',homedir)
139 MYSQL_NAME_FIELD name
150 MYSQL_MAILDIR_FIELD concat('/var/mailbox/',maildir)
[root@mail ~]# cd courier-authlib-0.63.1.20111230
[root@mail courier-authlib-0.63.1.20111230]# cp courier-authlib.sysvinit /etc/init.d/courier-authlib
[root@mail courier-authlib-0.63.1.20111230]# chmod 755 /etc/init.d/courier-authlib
[root@mail courier-authlib-0.63.1.20111230]# service courier-authlib start
[root@mail courier-authlib-0.63.1.20111230]# chkconfig --add courier-authlib
[root@mail courier-authlib-0.63.1.20111230]# chkconfig --level 2345 courier-authlib on
指明库文件的路径
[root@mail courier-authlib-0.63.1.20111230]# echo "/usr/local/courier-authlib/lib/courier-authlib" >> /etc/ld.so.conf.d/courier-authlib.conf
[root@mail courier-authlib-0.63.1.20111230]# ldconfig –v
[root@mail courier-authlib-0.63.1.20111230]# service courier-authlib restart
新建虚拟用户邮箱所在的目录,并将其权限赋予postfix用户
[root@mail courier-authlib-0.63.1.20111230]# mkdir -pv /var/mailbox
[root@mail courier-authlib-0.63.1.20111230]# chown -R postfix /var/mailbox
[root@mail ~]# cd /usr/lib/sasl2/
[root@mail sasl2]# vim smtpd.conf
确保有以下4行
1 pwcheck_method:saslauthd
1 pwcheck_method:saslauthd
2 mech_list: PLAIN LOGIN
3 log_level: 3
4 authdaemond_path:/usr/local/courier-authlib/var/spool/authdaemon/socket
五、让postfix支持虚拟域和虚拟用户
[root@mail sasl2]# vim /etc/postfix/main.cf
661 ########################Virtual Mailbox Settings########################
662 virtual_mailbox_base = /var/mailbox
663 virtual_mailbox_maps = mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf
664 virtual_mailbox_domains = mysql:/etc/postfix/mysql_virtual_domains_maps.cf
665 virtual_alias_domains =
666 virtual_alias_maps = mysql:/etc/postfix/mysql_virtual_alias_maps.cf
667 virtual_uid_maps = static:2525
668 virtual_gid_maps = static:2525
669 virtual_transport = virtual
670 maildrop_destination_recipient_limit = 1
671 maildrop_destination_concurrency_limit = 1
672 ##########################QUOTA Settings########################
673 message_size_limit = 14336000
674 virtual_mailbox_limit = 20971520
675 virtual_create_maildirsize = yes
676 virtual_mailbox_extended = yes
677 virtual_mailbox_limit_maps =
678
679 mysql:/etc/postfix/mysql_virtual_mailbox_limit_maps.cf
680 virtual_mailbox_limit_override = yes
681 virtual_maildir_limit_message = Sorry, the user's maildir has overdrawn his
682
683 diskspace quota, please Tidy your mailbox and try again later.
684 virtual_overquota_bounce = yes
使用extman源码目录下docs目录中的extmail.sql和init.sql建立数据库
[root@mail ~]# tar zxvf extman-1.1.tar.gz
[root@mail ~]# cd extman-1.1/docs/
进行测试
搭建基于虚拟账号的邮件服务器_第3张图片
[root@mail docs]# cp mysql_virtual_* /etc/postfix/
3.授予用户extmail访问extmail数据库的权限
[root@mail postfix]# mysql -u root -p
Enter password:
mysql> GRANT all privileges on extmail.* TO extmail@localhost IDENTIFIED BY 'extmail';
mysql> GRANT all privileges on extmail.* TO [email protected] IDENTIFIED BY 'extmail';
mysql> FLUSH PRIVILEGES;
mysql> \q
搭建基于虚拟账号的邮件服务器_第4张图片
[root@mail postfix]# service postfix restart
六、dovecot的安装
编辑/etc/dovecot.conf
[root@mail ~]# vim /etc/dovecot.conf
211 mail_location = maildir:/var/mailbox/%d/%n/Maildir
795 #passdb pam {
828 #}
869 passdb sql {
871 args = /etc/dovecot-mysql.conf
872 }
896 #userdb passwd {
903 #}
930 userdb sql {
932 args = /etc/dovecot-mysql.conf
933 }
[root@mail ~]# vim /etc/postfix/main.cf
414 home_mailbox = Mailbox
[root@mail ~]# vim /etc/dovecot-mysql.conf
1 driver = mysql
2 connect = host=localhost dbname=extmail user=extmail password=extmail
3 default_pass_scheme = CRYPT
4 password_query = SELECT username AS user,password AS password FROM mailbox WHERE username = '%u'
5 user_query = SELECT maildir, uidnumber AS uid, gidnumber AS gid FROM mailbox WHERE username = '%u'
[root@mail ~]# service dovecot restart
Stopping Dovecot Imap: [ OK ]
Starting Dovecot Imap: [ OK ]
七、安装extmail-1.2
[root@mail ~]# tar zxvf extmail-1.2.tar.gz
[root@mail ~]# mkdir -pv /var/www/extsuite
[root@mail ~]# mv extmail-1.2 /var/www/extsuite/extmail
[root@mail ~]# cp /var/www/extsuite/extmail/webmail.cf.default /var/www/extsuite/extmail/webmail.cf
[root@mail ~]# vim /var/www/extsuite/extmail/webmail.cf
77 SYS_USER_LANG = zh_CN
127 SYS_MAILDIR_BASE = /var/mailbox
139 SYS_MYSQL_USER = extmail
140 SYS_MYSQL_PASS = extmail
197 SYS_AUTHLIB_SOCKET = /usr/local/courier-authlib/var/spool/authdaemon/socket
[root@mail ~]# service httpd start
Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name,using mail.yeah.net for ServerName
[ OK ]
[root@mail ~]# chkconfig httpd on
[root@mail ~]# vim /etc/httpd/conf/httpd.conf
231 User postfix
232 Group postfix
992
993 ServerName mail.yeah.net
994 DocumentRoot /var/www/extsuite/extmail/html/
995 ScriptAlias /extmail/cgi /var/www/extsuite/extmail/cgi
996 Alias /extmail /var/www/extsuite/extmail/html
997
[root@mail extmail]# chown -R postfix.postfix /var/www/extsuite/extmail/cgi/
[root@mail extmail]# service httpd restart
八、安装extman
[root@mail ~]# mv extman-1.1 /var/www/extsuite/extman
[root@mail extman]# cp /var/www/extsuite/extman/webman.cf.default /var/www/extsuite/extman/webman.cf
[root@mail extman]# vim /var/www/extsuite/extman/webman.cf
12 SYS_MAILDIR_BASE = /var/mailbox
21 SYS_CAPTCHA_ON = 0
:wq
[root@mail extman]# chown -R postfix.postfix /var/www/extsuite/extman/cgi/
[root@mail extman]# vim /etc/httpd/conf/httpd.conf
加入997 、998行
992
993 ServerName mail.yeah.net
994 DocumentRoot /var/www/extsuite/extmail/html/
995 ScriptAlias /extmail/cgi /var/www/extsuite/extmail/cgi
996 Alias /extmail /var/www/extsuite/extmail/html
997 ScriptAlias /extman/cgi /var/www/extsuite/extman/cgi
998 Alias /extman /var/www/extsuite/extman/html
999
[root@mail extman]# mkdir -pv /tmp/extman
[root@mail extman]# chown postfix.postfix /tmp/extman
九、安装补丁文件
[root@mail ~]# tar zxvf Unix-Syslog-1.1.tar.gz
[root@mail ~]# cd Unix-Syslog-1.1
[root@mail Unix-Syslog-1.1]# perl Makefile.PL【编译】
[root@mail Unix-Syslog-1.1]# make install【安装】
[root@mail Unix-Syslog-1.1]# service httpd restart
十、访问服务器进行测试:
http://192.168.100.123/
初始管理员账号: [email protected]
初始管理员密码:extmail*123*
点击登录邮箱——》登陆邮箱管理——》输入管理员账号和密码进行登陆
截图:
搭建基于虚拟账号的邮件服务器_第5张图片
退出管理员界面进行注册测试
搭建基于虚拟账号的邮件服务器_第6张图片
搭建基于虚拟账号的邮件服务器_第7张图片
搭建基于虚拟账号的邮件服务器_第8张图片
注册成功能够正常登陆