postfix
邮件服务器详细配置文档
配置postfix邮件服务器首先要检查本机是否已安装sendmail邮件服务器,如果安装了sendmail服务,请将sendmail服务停止或卸载sendmail服务。
可以使用下面两种方法:
1. service sendmail stop:关闭sendmail服务,也要将开机启动服务关闭,否则重启机器时会发生冲突。
chkconfig –level sendmail 345 off:关闭sendmail开机启动项
2. yum remove sendmail
可以通过yum 删除sendmail服务
修改主机名 注意:主机名要和你配置的邮件域名相同,否则邮件会出问题
修改主机名方法:
hostname
#查看本机名
hostname mail.lgh.com 临时修改,重启后失效
vim /etc/sysconfig/network
#修改网卡配置
HOSTNAME=mail.lgh.com
#修改主机名,需要重启后起作用
echo "mail.lgh.com" > /proc/sys/kernel/hostname 这种方法是最好的办法,修改后不用重启就生效。
因为做实验测试邮件服务器,所要最好要把
DNS服务安装上,这样测试比较容易理解,在真实生产环境,DNS一般不需要自己配置。
我们使用
REHL5.4光盘进行一些软件包的安装,首先要先挂载光盘。
mount /dev/cdrom /mnt/cdrom
//我光盘挂载的位置
/mnt/cdrom
安装一些软件包我们使用
yum来进行安装,所以要先配置yum仓库。使用yum安装的好处是可以解决安装软件依赖关系问题。
首先要配置
yum仓库:
cd /etc/yum.repos.repo 进入安装目录
将此目录下的
rhel-debuginfo.repo 文件另存为一个文件名
cp rhel-debuginfo.repo service.repo
复制完成后:
vim service.repo 修改yum仓库配置文件内容如下:
[rhel]
name=rhel
baseurl=file:///mnt/cdrom/Server
//指定仓库的位置,光盘挂载的位置。
enabled=1
//是否启用
yum仓库,值为1表示启用,值为0表示禁用。
gpgcheck=0
//是否进行机校验,值为
1表示校验,值为0表示不校验。
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
保存后退出
DNS
服务配置:
#yum install bind*
//通过YUM 安装DNS服务
# rpm -qa |grep bind*
//安装完成后使用RPM检查所安装的软件包,至少要有以下4个软件包:
bind-devel-9.3.6-4.P1.el5
bind-9.3.6-4.P1.el5
bind-chroot-9.3.6-4.P1.el5
bind-utils-9.3.6-4.P1.el5
软件包安装完成后,我们首先要从模板中拷贝DNS主配置文件及数据库配置文件:
cp /usr/share/doc/bind-9.3.6/sample/etc/named.conf /var/named/chroot/etc/ DNS主配置文件
cp/usr/share/doc/bind-9.3.6/sample/var/named/localhost.zone /var/named/chroot/var/named/lgh.com.zone 数据库配置文件,注意空格位置
DNS
主配置文件:/var/named/chrot/etc/named.conf
vim /var/named/chroot/etc/named.conf :编辑DNS服务主配置文件
options {
directory "var/named";
};
zone "lgh.com"{
type master;
file "lgh.com.zone";
};
zone "jeason.com" {
type master;
file "jeason.com.zone";
};
DNS
服务数据库配置文件:/var/named/chroot/var/named/lgh.com.zone
$TTL
86400
@
IN SOA @ root (
42 ; serial (d. adams)
3H ; refresh
15M ; retry
1W ; expiry
1D ) ; minimum
IN NS mail.lgh.com.
mail
IN A 192.168.1.3
lgh.com.
IN MX 10 mail.lgh.com.
DNS
服务数据库配置文件:/var/named/chroot/var/named/jeason.com.zone
$TTL
86400
@
IN SOA @ root (
42 ; serial (d. adams)
3H ; refresh
15M ; retry
1W ; expiry
1D ) ; minimum
IN NS mail.jeason.com.
mail
IN A 192.168.1.4
jeason.com.
IN MX 10 mail.jeason.com.
DNS配置成功后进行测试:
# host mail.lgh.com
mail.lgh.com has address 192.168.1.3
到此
DNS配置完成。注意:实现不同域之间的邮件转发。
安装邮件传输代理及postfix
软件包:
rpm -ivh system-switch-mail*.rpm:安装邮件传输入代理,图形界面切换工具。
rpm -ivh postfix-2.3.3-2.1.el5_2.i386.rpm:安装postfix软件包
![](http://www.blueideal.net/pic/002.bmp)
service postfix start:启动postfix
chkconfig --level 345 postfix on:开启postfix开机启动
配置postfix
服务的基本配置vim /etc/postfix/main.cf
vim /etc/postfix/main.cf:配置postfix服务的配置文件修改如下行,后面标注的行号仅方便查找,不确定所标示的行号完全相同。
myhostname = mail.lgh.com
//69行 指定运行Postfix邮件系统的主机名
mydomain = lgh.com
//77行 指定运行 Postfix邮件系统主机的域名
![](http://www.blueideal.net/pic/003.bmp)
myorigin = lgh.com
//93行 指定发件人所在的域名
![](http://www.blueideal.net/pic/004.bmp)
inet_interfaces = all
//107行
指定Postfix 系统所监听的网络接口。
#inet_interfaces = localhost
//110 注释掉本行
![](http://www.blueideal.net/pic/005.bmp)
mydestination = $ myhostname, $mydomain //155行 指定Postfix 的接收邮件的收件人域名
![](http://www.blueideal.net/pic/006.bmp)
mynetworks = 192.168.1.0/24, 127.0.0.0/8
//255行
![](http://www.blueideal.net/pic/007.bmp)
relay_domains = lgh.com
//287行
邮件转发哪些网域
![](http://www.blueideal.net/pic/008.bmp)
SMTP
认证包安装
# rpm -ivh cyrus-sasl-2.1.22-5.el5.i386.rpm
![](http://www.blueideal.net/pic/009.bmp)
[root@mail Server]# saslauthd -v
//查看验证密码方式
![](http://www.blueideal.net/pic/010.bmp)
vim /etc/sysconfig/saslauthd:编缉验证配置文件
MECH=shadow
设置为shadow验证方法
![](http://www.blueideal.net/pic/011.bmp)
/etc/init.d/saslauthd start: 启动saslauthd服务
chkconfig --level 345 saslauthd on
开启开机自动启动saslauthd服务
![](http://www.blueideal.net/pic/012.bmp)
在/etc/postfix/main.cf
配置文件最后加入下述几行:
smtpd_sasl_auth_enable = yes
smtpd_sasl_local_domain = ''
//注意单引号
smtpd_recipient_restrictions = permit_mynetworks,permit_sasl_authenticated,reject_unauth_destination
broken_sasl_auth_clients = yes
smtpd_client_restrictions = permit_sasl_authenticated
smtpd_sasl_security_options = noanonymous
![](http://www.blueideal.net/pic/013.bmp)
测试saslauthd进程的验证功能
testsaslauthd -u liuguohui -p '123456'
0: OK "Success."
![](http://www.blueideal.net/pic/014.bmp)
postfix reload 重新加载服务
service postfix restart 重启postfix服务
测试postfix是否启用了smtp认证:
telnet mail.lgh.com 25
ehlo mail.lgh.com.
测试成功会显示如图:
![](http://www.blueideal.net/pic/015.bmp)
quit 退出即可
service postfix restart:重新启动postfix服务
POP
和IMPAD
邮件服务的实现:
安装POP
服务所需要的软件包
rpm -ivh perl-DBI-1.52-2.el5.i386.rpm
rpm -ivh mysql-5.077-3.el5.i386.rpm
![](http://www.blueideal.net/pic/016.bmp)
rpm -ivh dovecot-1.0.7-7.el5.i386.rpm
![](http://www.blueideal.net/pic/017.bmp)
修改/etc/dovecot.conf配置文件
将以下行开启,去掉注释
protocols = pop3 pop3s
//20
protocol pop3{
//35
listen= *:10100
//36
}
//38
![](http://www.blueideal.net/pic/018.bmp)
service dovecot start
//启动服务
chkconfig --level 345 dovecot on
//设置开机自动启动dovecot服务
chkconfig --list dovecot
//查看开机启动项
安装IMPAD
服务所需要的软件包
rpm -ivh cyrus-imapd-perl-2.3.7-7.el5.i386.rpm
rpm -ivh cyrus-imapd-utils-2.3.7-7.el5.i386.rpm
rpm -ivh db4-utils-4.3.29-10.el5.i386.rpm
rpm -ivh lm_sensors-2.10.7-4.el5.i386.rpm
rpm -ivh cyrus-imapd-2.3.7-7.el5.i386.rpm
rpm -ivh cyrus-imapd-devel2.3.7-7.el5.i386.rpm
![](http://www.blueideal.net/pic/019.bmp)
vim /etc/postfix/main.cf 编辑此文件
mailbox_transport = lmtp:unxi:/var/lib/imap/socket/lmtp
//整合postfix与cyrus-impad服务,需要开启
![](http://www.blueideal.net/pic/020.bmp)
postfix reload
重新加载服务
service cyrus-imapd start 启动cyrus-imapd服务
![](http://www.blueideal.net/pic/021.bmp)
chkconfig --level 345 cyrus-imapd on
chkconfig -list cyrus-imapd
设置邮箱管理员密码及创建邮件帐户:
id cyrus
passwd cyrus
cyradm -u cyrus localhost
IMAP password:vfast
//邮箱管理员密码
localhost.localdomain> cm user.liuguohui 创建邮箱帐号
localhost.localdomain>cm user.liuguohui.send //给用户创建邮箱文件夹
localhost.localdomain>cm user.liuguohui.trash
localhost.localdomain>cm user.liuguohui.drafts
![](http://www.blueideal.net/pic/022.bmp)
quit退出
WEB
方式收发邮件
安装WEB
收发所需要的软件包:
php-mbstring-5.1.6-23.2.el5_3.i386.rpm
squirrelmail-1.4.8-5.el5_3.7.noarch.rpm
![](http://www.blueideal.net/pic/023.bmp)
/usr/share/squirrelmail/config/conf.pl
配置WEB
/usr/share/squirrelmail/config/conf.pl
D---->cyrus 回车两次
2 ---->1(Domain) jeason.com
3 ---->2(SMTP)
r返回上一级
4 ---->5(Usernames in Lowercase) ---->y
r
10 ---->1 ---->zh_CN
2 ---->gb2312
r
S 保存
q 退出
![](http://www.blueideal.net/pic/024.bmp)
![](http://www.blueideal.net/pic/025.bmp)
![](http://www.blueideal.net/pic/026.bmp)
![](http://www.blueideal.net/pic/027.bmp)
![](http://www.blueideal.net/pic/028.bmp)
![](http://www.blueideal.net/pic/029.bmp)
![](http://www.blueideal.net/pic/030.bmp)
![](http://www.blueideal.net/pic/031.bmp)
![](http://www.blueideal.net/pic/032.bmp)
![](http://www.blueideal.net/pic/033.bmp)
![](http://www.blueideal.net/pic/034.bmp)
![](http://www.blueideal.net/pic/035.bmp)
![](http://www.blueideal.net/pic/036.bmp)
![](http://www.blueideal.net/pic/037.bmp)
![](http://www.blueideal.net/pic/038.bmp)
![](http://www.blueideal.net/pic/039.bmp)
![](http://www.blueideal.net/pic/040.bmp)
![](http://www.blueideal.net/pic/041.bmp)
![](http://www.blueideal.net/pic/042.bmp)
![](http://www.blueideal.net/pic/043.bmp)
Apache 服务配置:
安装apache 服务软件包:
Apache
配置文件
vim /etc/httpd/conf/httpd.conf 在配置文件加入下面一行。
ServerName mail.lgh.com:80
![](http://www.blueideal.net/pic/044.bmp)
开启
Apache服务:
service httpd restart
chkconfig --level 345 httpd on
通过WEB
测试:http://mail.lgh.com/webmail
测试截图:
![](http://www.blueideal.net/pic/045.bmp)
自己给自己发送邮件测试:
![](http://www.blueideal.net/pic/046.bmp)
![](http://www.blueideal.net/pic/047.bmp)
![](http://www.blueideal.net/pic/048.bmp)
测试成功,至此。本实验结束。
注: 如果要设置多域间邮件收、发,设置relay domains .具体步骤在此不详细介绍。
转载于:https://blog.51cto.com/miclesvic/475041