您的位置:首页 > 其它

基于虚拟帐号的邮件系统

2012-09-15 14:52 387 查看



1.修改主机名
# vim /etc/sysconfig/network
NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=mail.sina.com
# vim /etc/hosts
127.0.0.1 localhost.localdomain localhost
::1 localhost6.localdomain6 localhost6
2.修改临时的主机名,或者重启Linux 主机
# hostname mail.sina.com
3.配置yum工具
[root@localhost ~]# vim /etc/yum.repos.d/rhel-debuginfo.repo
[rhel-server]
name=Red Hat Enterprise Linux serverbaseurl=file:///mnt/cdrom/Server
enabled=1
gpgcheck=1
gpgkey=file:///mnt/cdrom/RPM-GPG-KEY-redhat-release
4.新建挂载点,挂载光盘
[root@localhost ~]# mkdir /mnt/cdrom
[root@localhost ~]# mount /dev/cdrom /mnt/cdrom
5.安装DNS服务器软件
[root@localhost ~]# yum install bind bind-chroot caching-nameserver -y
6.修改配置文档named.conf
[root@localhost ~]# cd /var/named/chroot/etc
[root@localhost etc]# cp -p named.caching-nameserver.conf named.conf
[root@localhost etc]# vim named.conf
listen-on port 53 { any; };
allow-query { any; };
allow-query-cache { any; };
match-clients { any; };
match-destinations { any; };
7.编辑区域声明文件,添加如下行
[root@localhost etc]# vim named.rfc1912.zones
zone "sina.com" IN {
type master;
file "sina.com.db";
allow-update { none; };
};
8.编辑区域文件
[root@localhost named]# cp -p localhost.zone sina.com.db
[root@localhost named]# vim sina.com.db
$TTL 86400
@ IN SOA ns.sina.com. root (
42 ; serial (d. adams)
3H ; refresh
15M ; retry
1W ; expiry
1D ) ; minimum
@ IN NS ns.sina.com.
ns IN A 192.168.101.250
mail IN A 192.168.101.250
POP3 IN CNAME mail
SMTP IN CNAME mail
@ IN MX 10 mail
8.检测配置文件和区域文件语法是否正确。(无提示提表示语法正确)
[root@localhost named]# named-checkconf /var/named/chroot/etc/named.conf
[root@localhost named]# named-checkzone sina.com /var/named/chroot/var/named/sina.com.db
zone sina.com/IN: loaded serial 42
OK
9.启动DNS服务器
[root@localhost named]# named-checkzone sina.com /var/named/chroot/var/named/sina.com.db
zone sina.com/IN: loaded serial 42
OK
10.在本机上测试DNS是否成功
[root@localhost named]# vim /etc/resolv.conf
nameserver 192.168.101.250
[root@localhost named]# nslookup mail.sina.com
Server: 192.168.101.250
Address: 192.168.101.250#53
Name: mail.sina.com
Address: 192.168.101.250
[root@localhost named]# nslookup
> set q=mx
> sina.com
Server: 192.168.101.250
Address: 192.168.101.250#53
sina.com mail exchanger = 10 mail.sina.com.
11.安装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@localhost ~]# 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
12.确保安装了以下开发库,如果某个组未安装可以使用yum groupinstall “组名”进行安装
yum grouplist
Development Libraries
Development Tools
Legacy Software Development
X Software Development
13.启动mysql数据库,设置为开机自启动
[root@mail ~]# service mysqld start
[root@mail ~]# chkconfig --level 2345 mysqld on
14 设置mysql数据库的用户名和密码:
[root@mail ~]# mysqladmin -u root -p password "123"
源码安装postfix
15创建postfix组和用户名
[root@mail ~]# groupadd -g 2525 postfix
[root@mail ~]# useradd -g postfix -u 2525 -s /sbin/nologin -M postfix
16.创建邮件投递帐号和组
[root@mail ~]# groupadd -g 2526 postdrop
[root@mail ~]# useradd -g postdrop -u 2526 -s /bin/false -M postdrop
17.将postfix的包拆解到/usr/local/src下
[root@mail ~]# tar -zxvf postfix-2.8.2.tar.gz -C /usr/local/src
18.切换到目录 cd /usr/local/src/postfix-2.8.2/下,发现没有configure文件,无法生成makefile文件,可以是要你那个一条命令来生成makefile文件
[root@mail ~]# 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'
19.编译生成说明文件,可执行文件,头文件,库文件
[root@mail postfix-2.8.2]# make
20 将文件放置到相应的目录
[root@mail postfix-2.8.2]# make install
按照以下的提示输入相关的路径([]号中的是缺省值,”]”后的是输入值,省略的表示采用默认值)
install_root: [/] /
tempdir: [/usr/local/src/ postfix-2.6.5] /tmp
config_directory: [/etc/postfix] /etc/postfix
daemon_directory: [/usr/libexec/postfix]
command_directory: [/usr/sbin]
queue_directory: [/var/spool/postfix]
sendmail_path: [/usr/sbin/sendmail]
newaliases_path: [/usr/bin/newaliases]
mailq_path: [/usr/bin/mailq]
mail_owner: [postfix]
setgid_group: [postdrop]
html_directory: [no] /var/www/postfix_html
manpages: [/usr/local/man]
readme_directory: [no]
21. 生成别名二进制文件,这个步骤如果忽略,会造成postfix效率极低:
[root@mail postfix-2.8.2]# newaliases
22.启动postfix
[root@mail postfix-2.8.2]# postfix start
[root@mail postfix-2.8.2]# netstat -tupln |grep 25



23.查看postfix是否支持mysql
[root@mail postfix-2.8.2]# postconf -m



24.查看支持的验证
[root@mail postfix-2.8.2]# postconf -a
cyrus
dovecot
25.如果想使用service postfix start ,需要将将rpm包中的postfix程序拆解出来,放置到/etc/init.d/下。
mkdir ~/abc
[root@mail abc]# rpm2cpio /mnt/cdrom/Server/postfix-2.3.3-2.1.el5_2.i386.rpm |cpio -id
26.切换到 /root/abc/etc/rc.d/init.d 下将postfix 文件拷贝到 /etc/init.d/下,直接就可以使用。使用service postfix start |stop命令



27.将postfix加入chkconfig管理组,并设置为开机自启动
chkconfig --add postfix
chkconfig postfix on
28.使用postfix发送邮件,看是否能够工作
新建本地账号user1 ,user2 ,使用telnet 127.0.0.1 25 ,user1向user2 发信



29.切换到user2 ,接收邮件
user 2能接收到信件



30.进入目录/etc/postfix/下,配置main.cf文件
[root@mail postfix]# vim main.cf
myhostname = mail.sina.com
mydomain = sina.com
myorigin = $myhostname
inet_interfaces = all
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
mynetworks = 192.168.101.0/24, 127.0.0.0/8
31 重启postfix访问
[root@mail postfix]# service postfix restart
Shutting down postfix: [ OK ]
Starting postfix: [ OK ]
32.再次使用telnet 192.168.101.250 25 来进行发信,结果能够发信成功



33. 为postfix开启基于cyrus-sasl的认证功能(修改为mynetworks = 127.0.0.0/8)
编辑/etc/postfix/main.cf 添加如下几行语句
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
smtpd_banner = Welcome to our $myhostname ESMTP,Warning: Version not Available!
smtpd_sender_restrictions = permit_sasl_authenticated,reject
34.重启postfix服务
[root@mail postfix]# service postfix restart
Shutting down postfix: [ OK ]
Starting postfix: [ OK ]
35.编辑 /usr/lib/sasl2/smtpd.conf
vim /usr/lib/sasl2/smtpd.conf
pwcheck_method: saslauthd
mech_list: PLAIN LOGIN
启动 sasl服务,开机启动
[root@mail sasl2]# service saslauthd restart
[root@mail sasl2]# chkconfig saslauthd on
36.再次登录邮件服务器,发现多处两行验证参数,说明支持身份验证



安装Courier authentication library
37.拆解Courier authentication library
[root@mail ~]# tar -jxvf courier-authlib-0.63.1.20111230.tar.bz2 -C /usr/local/src/
[root@mail ~]# cd /usr/local/src/courier-authlib-0.63.1.20111230/
38 检测预编译环境
[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
39.编译安装
[root@mail courier-authlib-0.63.1.20111230]# make
[root@mail courier-authlib-0.63.1.20111230]# make install
40.更改权限
[root@mail ~]# chmod 755 /usr/local/courier-authlib/var/spool/authdaemon
41.拷贝样例文件
[root@mail ~]# cp /etc/authdaemonrc.dist /etc/authdaemonrc
[root@mail ~]# cp /etc/authmysqlrc.dist /etc/authmysqlrc
42. 修改/etc/authdaemonrc 文件 ,设置调用的模块
authmodulelist="authmysql"
authmodulelistorig="authmysql"
daemons=10
43.修改/etc/authmysqlrc
其中2525,2525 为postfix 用户的UID和GID。
MYSQL_SERVER localhost mysql数据库的位置在本机
MYSQL_PORT 3306 (指定你的mysql监听的端口,这里使用默认的3306)
MYSQL_USERNAME extmail (这时为后文要用的数据库的所有者的用户名)
MYSQL_PASSWORD extmail (密码)
MYSQL_SOCKET /var/lib/mysql/mysql.sock
MYSQL_DATABASE extmail mysql数据库中的数据库
MYSQL_USER_TABLE mailbox extmail 中的表格
MYSQL_CRYPT_PWFIELD password 密码要进行加密
MYSQL_UID_FIELD '2525' UID 列的值为2525
MYSQL_GID_FIELD '2525' GID 列的值为2525
MYSQL_LOGIN_FIELD username LOGIN列的值为username
MYSQL_HOME_FIELD concat('/var/mailbox/',homedir) HOME列的值为…
MYSQL_NAME_FIELD name NAME列的值为name
MYSQL_MAILDIR_FIELD concat('/var/mailbox/',maildir) MAILDIR列的值邮箱位置
44.复制控制脚本
cp /usr/local/src/courier-authlib-0.63.1.20111230/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]# chkconfig --add courier-authlib
[root@mail courier-authlib-0.63.1.20111230]# chkconfig courier-authlib on
[root@mail courier-authlib-0.63.1.20111230]# service courier-authlib restart
45.加载库文件
编辑新文件courier-authlib.conf
# vim /etc/ld.so.conf.d/courier-authlib.conf
插入以下内容
/usr/local/courier-authlib/lib/courier-authlib
重新读取库文件
[root@mail courier-authlib]# ldconfig
46.查看是否加载上courier-authlib 的库文件
[root@mail courier-authlib]# ldconfig -v |grep courier
/usr/local/courier-authlib/lib/courier-authlib:
libcourierauthsasl.so -> libcourierauthsasl.so.0
libcourierauthcommon.so -> libcourierauthcommon.so.0
libcourierauthsaslclient.so -> libcourierauthsaslclient.so.0
libcourierauth.so -> libcourierauth.so.0
47. 新建虚拟用户邮箱所在的目录,并将其权限赋予postfix用户:
#mkdir -pv /var/mailbox
# chown -R postfix /var/mailbox
48. 接下来重新配置SMTP 认证,编辑 /usr/local/lib/sasl2/smtpd.conf ,确保其为以下内容:
pwcheck_method: authdaemond
log_level: 3
mech_list:PLAIN LOGIN
authdaemond_path:/usr/local/courier-authlib/var/spool/authdaemon/socket
49.重启courier-authlib 和saslauthd服务
[root@mail sasl2]# service courier-authlib restart
[root@mail sasl2]# service saslauthd restart
50. 让postfix支持虚拟域和虚拟用户
编辑/etc/postfix/main.cf,添加如下内容,重启postfix 服务
########################Virtual Mailbox Settings########################
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
virtual_transport = virtual
maildrop_destination_recipient_limit = 1
maildrop_destination_concurrency_limit = 1
##########################QUOTA Settings########################
message_size_limit = 14336000
virtual_mailbox_limit = 20971520
virtual_create_maildirsize = yes
virtual_mailbox_extended = yes
virtual_mailbox_limit_maps = mysql:/etc/postfix/mysql_virtual_mailbox_limit_maps.cf
virtual_mailbox_limit_override = yes
virtual_maildir_limit_message = Sorry, the user's maildir has overdrawn his diskspace quota, please Tidy your mailbox and try again later.
virtual_overquota_bounce = yes
52. 使用extman源码目录下docs目录中的extmail.sql和init.sql建立数据库:
[root@mail ~]# tar -zxvf extman-1.1.tar.gz
cd extman-1.1/docs
[root@mail docs]# mysql -u root -p <extmail.sql
[root@mail docs]# mysql -u root -p <init.sql
将docs目录下的以mysql_virtual开头的文件复制到/etc/postfix 目录下
[root@mail docs]# cp mysql_virtual_* /etc/postfix/
53. 授予用户extmail访问extmail数据库的权限
连接上mysql数据库
[root@mail docs]# mysql -u root -p
mysql> GRANT all privileges on extmail.* TO extmail@localhost IDENTIFIED BY 'extmail';
mysql> GRANT all privileges on extmail.* TO extmail@127.0.0.1 IDENTIFIED BY 'extmail';
54.刷新权限,使设置生效
mysql> FLUSH PRIVILEGES;
55. 配置dovecot
vi /etc/dovecot.conf
211 mail_location =maildir:/var/mailbox/%d/%n/Maildir
passdb sql {
args = /etc/dovecot-mysql.conf
}
userdb sql {
args = /etc/dovecot-mysql.conf
}
56. 创建 /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'



57.编辑/etc/postfix/main.cf
home_mailbox = Maildir/
58 重启dovecot 和postfix 服务
[root@mail ~]# service dovecot restart
Stopping Dovecot Imap: [FAILED]
Starting Dovecot Imap: [ OK ]
[root@mail ~]# service postfix restart
Shutting down postfix: [ OK ]
Starting postfix: [ OK ]
59.设置dovecot开机启动
[root@mail ~]# chkconfig dovecot on
安装Extmail-1.2 (先安装httpd)
60.先创建存放extmail的位置
[root@mail ~]# mkdir -pv /var/www/extsuite
61.拆解extmail包
[root@mail ~]# tar -zxvf extmail-1.2.tar.gz
62将该文件移动到/var/www/extsuite/extmail
[root@mail ~]# mv extmail-1.2 /var/www/extsuite/extmail
63将extman也放置到http根目录下
[root@mail ~]# mv extman-1.1 /var/www/extsuite/extman
64.切换到/var/www/extsuite/extmail/下
[root@mail ~]# cd /var/www/extsuite/extmail/
65创建配置文件webmail.cf
[root@mail extmail]# cp webmail.cf.default webmail.cf
66. 修改主配置文件webmail.cf
#vi /var/www/extsuite/extmail/webmail.cf
部分修改选项的说明:
SYS_MESSAGE_SIZE_LIMIT = 5242880
用户可以发送的最大邮件
SYS_USER_LANG = en_US
语言选项,可改作:
SYS_USER_LANG = zh_CN
SYS_MAILDIR_BASE = /home/domains
此处即为您在前文所设置的用户邮件的存放目录,可改作:
SYS_MAILDIR_BASE = /var/mailbox
SYS_MYSQL_USER = db_user
SYS_MYSQL_PASS = db_pass
以上两句句用来设置连接数据库服务器所使用用户名、密码和邮件服务器用到的数据库,这里修改为:
SYS_MYSQL_USER = extmail
SYS_MYSQL_PASS = extmail
SYS_MYSQL_HOST = localhost
指明数据库服务器主机名,这里默认即可
SYS_MYSQL_TABLE = mailbox
SYS_MYSQL_ATTR_USERNAME = username
SYS_MYSQL_ATTR_DOMAIN = domain
SYS_MYSQL_ATTR_PASSWD = password
以上用来指定验正用户登录里所用到的表,以及用户名、域名和用户密码分别对应的表中列的名称;这里默认即可
SYS_AUTHLIB_SOCKET = /var/spool/authdaemon/socket
此句用来指明authdaemo socket文件的位置,这里修改为:
SYS_AUTHLIB_SOCKET = /usr/local/courier-authlib/var/spool/authdaemon/socket
67.编辑http的配置文件
添加虚拟主机
<VirtualHost 192.168.101.250:80>
ServerName mail.sina.com
DocumentRoot /var/www/extsuite/extmail/html/
ScriptAlias /extmail/cgi /var/www/extsuite/extmail/cgi
Alias /extmail /var/www/extsuite/extmail/html
</VirtualHost>
修改appache的运营身份
User postfix
Group postfix
68修改 cgi执行文件属主为apache运行身份用户:
# chown -R postfix.postfix /var/www/extsuite/extmail/cgi/
依赖关系的解决
69. extmail将会用到perl的Unix::syslogd功能
[root@mail ~]# tar -zxvf Unix-Syslog-1.1.tar.gz
cd Unix-Syslog-0.100
[root@mail Unix-Syslog-1.1]# perl Makefile.PL
70 编译并安装
[root@mail Unix-Syslog-1.1]# make
[root@mail Unix-Syslog-1.1]# make install
71.进入/var/www/extsuite/extman内
cp /var/www/extsuite/extman/webman.cf.default /var/www/extsuite/extman/webman.cf
vim webman.cf
SYS_MAILDIR_BASE = /home/domains
此处即为您在前文所设置的用户邮件的存放目录,可改作:
SYS_MAILDIR_BASE = /var/mailbox
修改
SYS_CAPTCHA_ON = 1

SYS_CAPTCHA_ON = 0
71.修改cgi目录的属主:
# chown -R postfix.postfix /var/www/extsuite/extman/cgi/
72. 在apache的主配置文件中Extmail的虚拟主机部分,添加如下两行:
ScriptAlias /extman/cgi /var/www/extsuite/extman/cgi
Alias /extman /var/www/extsuite/extman/html
即:
<VirtualHost 192.168.101.250:80>
ServerName mail.sina.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>
73.
创建其运行时所需的临时目录,并修改其相应的权限:
#mkdir -pv /tmp/extman
#chown postfix.postfix /tmp/extman



选择管理即可登入extman进行后台管理了。默认管理帐号为:root@extmail.org 密码为:extmail*123*



添加域sina.cm






保存修改后再次进入修改该域,勾选允许自由注册



注册邮箱












同样新建账户test2
test1 向test2 发送邮件



监控邮件服务器的日志
tail -F /var/log/maillog



提示说sina.com在mydestination和 virtual_mailbox_domains 中冲突
修改postfix的配置文件main.cf
禁用mydestination 行



并禁用该项
#smtpd_sender_restrictions = permit_sasl_authenticated,reject
重启postfix服务器
[root@mail ~]# service postfix restart
Shutting down postfix: [ OK ]
Starting postfix: [ OK ]
再次发送邮件



发送成功



test2账户登录,接收邮件



一个邮件服务器可以负责几个区域,新建区域163.com



注册163.com域邮箱






test3 @163.com向test1@sina.com发送邮件



test1 用户登录来接收邮件





内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息