CentOS搭建邮件服务器
时间:2014-10-07 16:59 来源:linux.it.net.cn 作者:it
虽然没有webmail但是前面的步骤有图介绍,后面webmail可以自己安装即可。
SMTP服务器的构建 ( Postfix )
POP / IMAP 服务器的构建( Dovecot )
-----------------------------分割线-----------------------------------
系统自带的sendmail会和postfix冲突
第一步卸载sendmail,yum remove sendmail
第二步:安装postfix ,dovecot,cyrus-sasl,直接yum安装
yum -y install devecot
yum -y install postfix
yum -y install cyrus-sasl
三、修改postfix的配置文件
[root@ser ~]# vim /etc/postfix/main.cf
myhostname = mail.eimam.com
mydomain = eimam.com
myorigin = eimam.com
inet_interfaces =all
mynetworks = 192.168.1.0/240
relay_domains = yjw.com, $mydomain
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain, mail.$mydomain, www.$mydomain, ftp.$mydomain
重启 postfix 服务
[root@ser ~]# service postfix restart
Shutting down postfix: [ OK ]
Starting postfix: [ OK ]
[root@ser ~]# chkconfig postfix on
[root@ser ~]# chkconfig dovecot on
修改dovecot的配置文件
vim /etc/dovecot.conf
protocols = imap imaps pop3 pop3s(在后面启动dovecot时,说端口已经被使用,lsof -i tcp:端口,是pop3s占用了,如果出现这样的情况,把这里的pop3s去掉。)
listen = *
在iptables 里开放25,110,143端口
[root@ser ~]# vim /etc/sysconfig/iptables
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 110 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 25 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 143 -j ACCEPT
重启iptables
[root@ser ~]# service iptables restart
Flushing firewall rules: [ OK ]
Setting chains to policy ACCEPT: filter [ OK ]
Unloading iptables modules: [ OK
Applying iptables firewall rules: [ OK ]
Loading additional iptables modules: ip_conntrack_netbios_n[ OK ]ntrack_ftp
[root@ser ~]# chkconfig saslauthd on
修改 /etc/sysconfig/saslauthd
[root@ser ~]# vim /etc/sysconfig/saslauthd
# Directory in which to place saslauthd's listening socket, pid file, and so
# on. This directory must already exist.
SOCKETDIR=/var/run/saslauthd
# Mechanism to use when checking passwords. Run "saslauthd -v" to get a list
# of which mechanism your installation was compiled with the ablity to use.
MECH=shadow
# Additional flags to pass to saslauthd on the command line. See saslauthd(8)
# for the list of accepted flags.
FLAGS=
修改 /usr/lib/sasl2/smtpd.conf
[root@ser ~]# vim /usr/lib64/sasl2/smtpd.conf
pwcheck_method: saslauthd
测试 saslauthd
[root@ser ~]# service saslauthd restart
[root@ser ~]# testsaslautd -u yjw -p '020304'
0: OK "Success."
在postfix 的配置文件中,添加以下内容,使其支持SMTP认证
[root@ser ~]# vim /etc/postfix/main.cf
message_size_limit = 1073741824 # 邮件的大小为10M
default_process_limit = 50
default_destination_concurrency_limit = 20
smtpd_sasl_auth_enable = yes
smtpd_sasl_local_domain = $myhostname
smtpd_sasl_application_name = smtpd
broken_sasl_auth_clients = yes
smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated,reject_unauth_destination
smtpd_client_restrictions = permit_sasl_authenticated
smtpd_sasl_security_options = noanonymous
测试 25端口
[root@ser ~]# telnet mail.yjw.com 25
Trying 192.168.1.2...
Connected to mail.yjw.com (192.168.1.2).
Escape character is '^]'.
220 mail.yjw.com ESMTP Postfix
EHLO 163.com
250-mail.yjw.com
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-AUTH LOGIN PLAIN
250-AUTH=LOGIN PLAIN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
quit
221 2.0.0 Bye
Connection closed by foreign host.
[root@ser ~]#
现在可以测试一下给root发一封邮件,echo "this is a test mail !"|mail -s mailname root
输入mail查看是否成功。也可给给QQ邮箱发,将root修改成QQ邮箱地址就可以了。
四、安装openwebmail
[root@ser ~]# vim /etc/yum.repos.d/openwebmail.repo
[openwebmail]
## Thomas Chung
## 2008.05.29
name=Openwebmail for Fedora or Enterprise Linux
baseurl=http://openwebmail.org/openwebmail/download/redhat/rpm/release/
enabled=1
gpgcheck=1
gpgkey=http://openwebmail.org/openwebmail/download/redhat/rpm/release/RPM-GPG-KEY-openwebmail
#metadata_expire=0
若这样安装不成功,先安装 perl-Text-Iconv-1.4-1.2.el4.rf.i386.rpm
下载地址:http://rpm.pbone.net/index.php3?stat=26&dist=42&size=19383&name=perl-Text-Iconv-1.4-1.2.el4.rf.i386.rpm
[root@ser ~]# yum -y install openwebmail
[root@ser ~]# cd /var/www/cgi-bin/openwebmail/
[root@ser openwebmail]# ./openwebmail-tool.pl --init #出现Y/N时 ,按N.
修改openwebmail 的一些配置文件
[root@ser etc]# vim dbm.conf
dbm_ext .db
dbmopen_ext .db
dbmopen_haslock no
[root@ser etc]]# cd defaults/
[root@ser defaults]# vim dbm.conf
dbm_ext .db
dbmopen_ext .db
dbmopen_haslock yes
smtpserver 192.168.1.2
[root@ser defaults]# vim openwebmail.conf
domainnames yjw.com
smtpserver 192.168.1.2
authpop3_server 192.168.1.2
再次初始化openwebmail
[root@ser defaults]# cd http://www.cnblogs.com/openwebmail-tool.pl --init
出现Y/N 时,按Y。
把Postfix+Dovecot+Openwebmail 三者个格式统一下就行了
1.postfix 配置 main.cf
mail_spool_directory = /var/spool/mail
2.Dovecot 配置 Dovecot.conf
mail_location = mbox:~/mail:INBOX=/var/spool/mail/%u
3.Openwebmail.conf
mailspooldir /var/spool/mail
修改apache配置
[root@ser ~]# vim /etc/httpd/conf/httpd.conf
ServerAdmin
root@yjw.com
ServerName mail.yjw.com:80
AddHandler cgi-script .cgi .pl
五、登陆openwebmail
在IE 中输入 mail.yjw.com/cgi-bin/openwebmail/openwebmail.pl, 这个地址是不是很长,那么我们来点短点的
在 httpd的 配置文件中添加 下面 内容:
ScriptAlias /mail /var/www/cgi-bin/openwebmail/openwebmail.pl
这样在IE 中直接输入
mail.yjw.com/mail
如果出现了下面的问题
Couldn't create File /var/log/openwebmail.log! (Permission denied)
在网上找到解决办法了:如下方面 运行:
touch /var/log/openwebmail.log
chcon -u system_u /var/log/openwebmail.log
chcon -t httpd_sys_script_rw_t /var/log/openwebmail.log
chcon -t httpd_unconfined_script_exec_t /var/www/cgi-bin/openwebmail/openwebmail*
然后刷新了一下 OK ,很漂亮的界面出现了。
(责任编辑:IT)
虽然没有webmail但是前面的步骤有图介绍,后面webmail可以自己安装即可。
SMTP服务器的构建 ( Postfix )
POP / IMAP 服务器的构建( Dovecot )
-----------------------------分割线-----------------------------------
系统自带的sendmail会和postfix冲突 第一步卸载sendmail,yum remove sendmail 第二步:安装postfix ,dovecot,cyrus-sasl,直接yum安装 yum -y install devecot yum -y install postfix yum -y install cyrus-sasl 三、修改postfix的配置文件 [root@ser ~]# vim /etc/postfix/main.cf myhostname = mail.eimam.com mydomain = eimam.com myorigin = eimam.com inet_interfaces =all mynetworks = 192.168.1.0/240 relay_domains = yjw.com, $mydomain mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain, mail.$mydomain, www.$mydomain, ftp.$mydomain 重启 postfix 服务 [root@ser ~]# service postfix restart Shutting down postfix: [ OK ] Starting postfix: [ OK ] [root@ser ~]# chkconfig postfix on [root@ser ~]# chkconfig dovecot on 修改dovecot的配置文件 vim /etc/dovecot.conf protocols = imap imaps pop3 pop3s(在后面启动dovecot时,说端口已经被使用,lsof -i tcp:端口,是pop3s占用了,如果出现这样的情况,把这里的pop3s去掉。) listen = * 在iptables 里开放25,110,143端口 [root@ser ~]# vim /etc/sysconfig/iptables -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 110 -j ACCEPT -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 25 -j ACCEPT -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 143 -j ACCEPT 重启iptables [root@ser ~]# service iptables restart Flushing firewall rules: [ OK ] Setting chains to policy ACCEPT: filter [ OK ] Unloading iptables modules: [ OK Applying iptables firewall rules: [ OK ] Loading additional iptables modules: ip_conntrack_netbios_n[ OK ]ntrack_ftp [root@ser ~]# chkconfig saslauthd on 修改 /etc/sysconfig/saslauthd [root@ser ~]# vim /etc/sysconfig/saslauthd # Directory in which to place saslauthd's listening socket, pid file, and so # on. This directory must already exist. SOCKETDIR=/var/run/saslauthd # Mechanism to use when checking passwords. Run "saslauthd -v" to get a list # of which mechanism your installation was compiled with the ablity to use. MECH=shadow # Additional flags to pass to saslauthd on the command line. See saslauthd(8) # for the list of accepted flags. FLAGS= 修改 /usr/lib/sasl2/smtpd.conf [root@ser ~]# vim /usr/lib64/sasl2/smtpd.conf pwcheck_method: saslauthd 测试 saslauthd [root@ser ~]# service saslauthd restart [root@ser ~]# testsaslautd -u yjw -p '020304' 0: OK "Success." 在postfix 的配置文件中,添加以下内容,使其支持SMTP认证 [root@ser ~]# vim /etc/postfix/main.cf message_size_limit = 1073741824 # 邮件的大小为10M default_process_limit = 50 default_destination_concurrency_limit = 20 smtpd_sasl_auth_enable = yes smtpd_sasl_local_domain = $myhostname smtpd_sasl_application_name = smtpd broken_sasl_auth_clients = yes smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated,reject_unauth_destination smtpd_client_restrictions = permit_sasl_authenticated smtpd_sasl_security_options = noanonymous 测试 25端口 [root@ser ~]# telnet mail.yjw.com 25 Trying 192.168.1.2... Connected to mail.yjw.com (192.168.1.2). Escape character is '^]'. 220 mail.yjw.com ESMTP Postfix EHLO 163.com 250-mail.yjw.com 250-PIPELINING 250-SIZE 10240000 250-VRFY 250-ETRN 250-AUTH LOGIN PLAIN 250-AUTH=LOGIN PLAIN 250-ENHANCEDSTATUSCODES 250-8BITMIME 250 DSN quit 221 2.0.0 Bye Connection closed by foreign host. [root@ser ~]# 现在可以测试一下给root发一封邮件,echo "this is a test mail !"|mail -s mailname root 输入mail查看是否成功。也可给给QQ邮箱发,将root修改成QQ邮箱地址就可以了。 四、安装openwebmail [root@ser ~]# vim /etc/yum.repos.d/openwebmail.repo [openwebmail] ## Thomas Chung ## 2008.05.29 name=Openwebmail for Fedora or Enterprise Linux baseurl=http://openwebmail.org/openwebmail/download/redhat/rpm/release/ enabled=1 gpgcheck=1 gpgkey=http://openwebmail.org/openwebmail/download/redhat/rpm/release/RPM-GPG-KEY-openwebmail #metadata_expire=0 若这样安装不成功,先安装 perl-Text-Iconv-1.4-1.2.el4.rf.i386.rpm 下载地址:http://rpm.pbone.net/index.php3?stat=26&dist=42&size=19383&name=perl-Text-Iconv-1.4-1.2.el4.rf.i386.rpm [root@ser ~]# yum -y install openwebmail [root@ser ~]# cd /var/www/cgi-bin/openwebmail/ [root@ser openwebmail]# ./openwebmail-tool.pl --init #出现Y/N时 ,按N. 修改openwebmail 的一些配置文件 [root@ser etc]# vim dbm.conf dbm_ext .db dbmopen_ext .db dbmopen_haslock no [root@ser etc]]# cd defaults/ [root@ser defaults]# vim dbm.conf dbm_ext .db dbmopen_ext .db dbmopen_haslock yes smtpserver 192.168.1.2 [root@ser defaults]# vim openwebmail.conf domainnames yjw.com smtpserver 192.168.1.2 authpop3_server 192.168.1.2 再次初始化openwebmail [root@ser defaults]# cd http://www.cnblogs.com/openwebmail-tool.pl --init 出现Y/N 时,按Y。 把Postfix+Dovecot+Openwebmail 三者个格式统一下就行了 1.postfix 配置 main.cf mail_spool_directory = /var/spool/mail 2.Dovecot 配置 Dovecot.conf mail_location = mbox:~/mail:INBOX=/var/spool/mail/%u 3.Openwebmail.conf mailspooldir /var/spool/mail 修改apache配置 [root@ser ~]# vim /etc/httpd/conf/httpd.conf ServerAdmin root@yjw.com ServerName mail.yjw.com:80 AddHandler cgi-script .cgi .pl 五、登陆openwebmail 在IE 中输入 mail.yjw.com/cgi-bin/openwebmail/openwebmail.pl, 这个地址是不是很长,那么我们来点短点的 在 httpd的 配置文件中添加 下面 内容: ScriptAlias /mail /var/www/cgi-bin/openwebmail/openwebmail.pl 这样在IE 中直接输入 mail.yjw.com/mail 如果出现了下面的问题 Couldn't create File /var/log/openwebmail.log! (Permission denied) 在网上找到解决办法了:如下方面 运行: touch /var/log/openwebmail.log chcon -u system_u /var/log/openwebmail.log chcon -t httpd_sys_script_rw_t /var/log/openwebmail.log chcon -t httpd_unconfined_script_exec_t /var/www/cgi-bin/openwebmail/openwebmail* 然后刷新了一下 OK ,很漂亮的界面出现了。 (责任编辑:IT) |