一、系统环境
1、Extmail架构
2、拓朴图
系 统 |
域 名 |
服务器 |
客户端 |
RedHat 5.4 |
mail.postfix.org |
172.16.1.254 |
172.16.1.10 |
所软件包:
postfix-2.8.6.tar.gz
extman-1.1.tar.gz
extmail-1.2.tar.gz
courier-authlib-0.63.0.tar.bz2
Unix-Syslog-1.1.tar.gz
Time-HiRes-1.9725.tar.gz
File-Tail-0.99.3.tar.gz
rrdtool-1.4.7.tar.gz
二、基本配置
1、配置IP
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
BOOTPROTO=static
IPADDR=172.16.1.254
NETMASK=255.255.255.0
:wq
[root@localhost ~]# service network restart
2、配置DNS文件
[root@mail ~]# vim /etc/resolv.conf
nameserver 172.16.1.254
3、配置hosts文件
[root@mail ~]# vim /etc/hosts
127.0.0.1 localhost.localdomain localhost
172.16.1.254 mail.postfix.org
4、配置主机名:mail.postfix.org
[root@localhost ~]# vim /etc/sysconfig/network
HOSTNAME=mail.postfix.org
:wq 保存
[root@localhost ~]# hostname mail.postfix.org
断开终端,再次连接,这样就需要重新启动系统:ctrl+d
[root@mail ~]# hostname
mail.postfix.org
5、SELinux关闭、LINUX关闭防火墙
SELinux关闭
1 永久方法 – 需要重启服务器
修改/etc/selinux/config文件中设置SELINUX=disabled ,然后重启服务器。
2 临时方法 – 设置系统参数
使用命令setenforce 0
LINUX关闭防火墙
1 重启后永久性生效:
开启:chkconfig iptables on
关闭:chkconfig iptables off
2 即时生效,重启后失效:
开启:service iptables start
关闭:service iptables stop
三、配置YUM(略)
参考方案:http://yanghuawu.blog.51cto.com/2638960/886129
挂载光盘:本次挂载目录:/mnt
[root@mail ~]# mount -i /dev/cdrom /mnt
四、安装bind(DNS)
[root@mail ~]# yum install bind bind-chroot caching-nameserver
[root@mail ~]# cd /var/named/chroot/etc/
[root@mail etc]# ll
total 32
-rw-r--r-- 1 root root 405 Dec 18 09:17 localtime
-rw-r----- 1 root named 1230 Jul 30 2009 named.caching-nameserver.conf
-rw-r----- 1 root named 955 Jul 30 2009 named.rfc1912.zones
-rw-r----- 1 root named 113 Dec 18 14:30 rndc.key
[root@mail etc]# cp -p named.caching-nameserver.conf named.conf
[root@mail etc]# cp named.conf named.confbak #备份
[root@mail etc]# vim named.conf
修改:
行数
15 listen-on port 53 { any; };
27 allow-query { any; };
28 allow-query-cache { any; };
37 match-clients { any; };
38 match-destinations { any; };
:wq
[root@mail etc]# cd named.rfc1912.zones named.rfc1912.zonesbak #备份
[root@mail etc]# vim named.rfc1912.zones
复制修改以下内容:
21 zone "localhost" IN {
22 type master;
23 file "localhost.zone";
24 allow-update { none; };
25 };
修改如下:
27 zone "postfix.org" IN {
28 type master;
29 file "postfix.org.zone";
30 allow-update { none; };
31 };
:wq
[root@mail etc]# cd ../var/named/
[root@mail named]# pwd
/var/named/chroot/var/named
[root@mail named]# cp -p localhost.zone postfix.org.zone
[root@mail named]# cp postfix.org.zone postfix.org.zonebak #备份
[root@mail named]# vim postfix.org.zone
$TTL 86400
@ IN SOA ns.postfix.org. root (
42 ; serial (d. adams)
3H ; refresh
15M ; retry
1W ; expiry
1D ) ; minimum
IN NS ns.postfix.org.
ns IN A 172.16.1.254
mail IN A 172.16.1.254
pop3 IN CNAME mail
smtp IN CNAME mail
@ IN MX 10 mail
:wq
[root@mail named]# service named restart
[root@mail named]# chkconfig named on
[root@mail named]# rndc reload
server reload successful
[root@mail named]# dig -t mx postfix.org
; <<>> DiG 9.3.6-P1-RedHat-9.3.6-4.P1.el5 <<>> -t mx postfix.org
;; global options: printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 663
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 2
;; QUESTION SECTION:
;postfix.org. IN MX
;; ANSWER SECTION:
postfix.org. 86400 IN MX 10 mail.postfix.org.
;; AUTHORITY SECTION:
postfix.org. 86400 IN NS ns.postfix.org.
;; ADDITIONAL SECTION:
mail.postfix.org. 86400 IN A 172.16.1.254
ns.postfix.org. 86400 IN A 172.16.1.254
;; Query time: 5 msec
;; SERVER: 172.16.1.254#53(172.16.1.254)
;; WHEN: Thu Dec 27 09:24:26 2012
;; MSG SIZE rcvd: 99
五、关闭sendmail,并不随机启动或者卸载
[root@mail named]# service sendmail status
sendmail (pid 2754) is running...
[root@mail named]# service sendmail stop
[root@mail named]# chkconfig sendmail off
六、安装所需依赖rpm包
yum install -y 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 db* cyrus*
七、检查以上开发所有用到的RPM包组是否启动安装
[root@mail named]# yum grouplist
Development Libraries 开发言库
Development Tools 开发工具
Legacy Software Development 传统软件开发
X Software Development 图形开发组
方法安装:
[root@mail named]# yum groupinstall "FTP Server"
八、启动mysql数据库,并给mysql的root用户设置密码
[root@mail named]# service mysqld start
[root@mail named]# chkconfig mysqld on
[root@mail named]# mysqladmin -u root password 'redhat' #为mysql的用户设置密码:redhat
或也可以以下操作:
---------------------------------授权本地用户
[root@mail named]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.0.77 Source distribution
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> set password for root@'localhost'=password('redhat');
Query OK, 0 rows affected (0.00 sec)
mysql> set password for root@'127.0.0.1'=password('redhat');
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
---------------------------------------------授权远程用户
mysql> grant all privileges on *.* to root@'%' identified by 'redhat';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> \q
九、安装postfix
1、创建postfix的执行用户postfix和属组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
[root@mail ~]# useradd -g postdrop -u 2526 -s /bin/false -M postdrop
2、编译、安装postfix
[root@mail ~]# tar -zxvf postfix-2.8.6.tar.gz -C /usr/local/src/
[root@mail ~]# cd /usr/local/src/
[root@mail src]# cd postfix-2.8.6/
[root@mail postfix-2.8.6]# 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' 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.6]# make
[root@mail postfix-2.8.6]# make install
如下配置:
install_root: [/]
tempdir: [/usr/local/src/postfix-2.8.6] /tmp
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]
3、生成别名二进制文件,这个步骤如果忽略,会造成postfix效率极低
newaliases_path: [/usr/bin/newaliases]
[root@mail postfix-2.8.6]# newaliases
[root@mail postfix-2.8.6]# postfix start #启动postfix
[root@mail postfix-2.8.6]# netstat -anp |grep :25或# netstat -tupln |less
tcp 0 0 0.0.0.0:25 0.0.0.0:* LISTEN 13280/master
[root@mail postfix-2.8.6]# postconf -m #模块 mysql
btree
cidr
environ
hash
internal
mysql
nis
proxy
regexp
static
tcp
texthash
unix
实现用service 服务名 start 启动服务!
源代码没有控制同步,可借助于rpm包的控制同步
[root@mail postfix-2.8.6]# mkdir /tmp/abc
[root@mail postfix-2.8.6]# cd /tmp/abc/
[root@mail abc]# cp /mnt/Server/postfix-2.3.3-2.1.el5_2.i386.rpm ./
[root@mail abc]# ll
total 3656
-r--r--r-- 1 root root 3734257 Dec 18 17:31 postfix-2.3.3-2.1.el5_2.i386.rpm
[root@mail abc]# rpm2cpio postfix-2.3.3-2.1.el5_2.i386.rpm |cpio -id
16333 blocks
[root@mail abc]# ll
total 3680
drwxr-xr-x 5 root root 4096 Dec 18 17:32 etc
-r--r--r-- 1 root root 3734257 Dec 18 17:31 postfix-2.3.3-2.1.el5_2.i386.rpm
drwxr-xr-x 7 root root 4096 Dec 18 17:32 usr
drwxr-xr-x 3 root root 4096 Dec 18 17:32 var
[root@mail abc]# cd etc/
[root@mail etc]# ll
total 24
drwxr-xr-x 2 root root 4096 Dec 18 17:32 pam.d
drwxr-xr-x 2 root root 4096 Dec 18 17:32 postfix
drwxr-xr-x 3 root root 4096 Dec 18 17:32 rc.d
[root@mail etc]# cd rc.d/
[root@mail rc.d]# ll
total 8
drwxr-xr-x 2 root root 4096 Dec 18 17:32 init.d
[root@mail rc.d]# cd init.d/
[root@mail init.d]# ll
total 8
-rwxr-xr-x 1 root root 2404 Dec 18 17:32 postfix
[root@mail init.d]# cp postfix /etc/init.d/
[root@mail init.d]# vim /etc/init.d/postfix #查看代码,不用编辑(略)
[root@mail init.d]# service postfix stop
[root@mail init.d]# netstat -tupln |grep 25
tcp 0 0 172.16.1.253:53 0.0.0.0:* LISTEN 3486/named
udp 0 0 172.16.1.253:53 0.0.0.0:* 3486/named
[root@mail init.d]# service postfix start
[root@mail init.d]# netstat -tupln |grep 25
tcp 0 0 172.16.1.253:53 0.0.0.0:* LISTEN 3486/named
tcp 0 0 0.0.0.0:25 0.0.0.0:* LISTEN 13429/master
udp 0 0 172.16.1.253:53 0.0.0.0:* 3486/named
[root@mail init.d]# chkconfig postfix on 或# chkconfig --add postfix #相同
[root@mail init.d]# chkconfig --list |grep postfix
postfix 0:off 1:off 2:on 3:on 4:on 5:on 6:off
4、创建账号
[root@mail init.d]# useradd user1
5、发邮件测试
[root@mail init.d]# telnet 127.0.0.1 25
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
220 mail.postfix.org ESMTP Postfix
HELO mail.postfix.org
250 mail.postfix.org
mail from:root@localhost
250 2.1.0 Ok
rcpt to:user1@localhost
250 2.1.5 Ok
data
354 End data with <CR><LF>.<CR><LF>
11111111111111111111111111111
.
250 2.0.0 Ok: queued as 48ABCE72F3
quit
221 2.0.0 Bye
Connection closed by foreign host.
6、查看邮件日志
[root@mail ~]# tail -f /var/log/maillog 或# tail /var/log/maillog
邮件发送成功!
本文转自 yhw85 51CTO博客,原文链接:http://blog.51cto.com/yanghuawu/1103287,如需转载请自行联系原作者