postfixWietse VenemaIBMGPL协议之下开发的MTA(邮件传输代理)软件。postfixWietse Venema想要为使用最广泛的sendmail提供替代品的一个尝试。在nternet世界中,大部分的电子邮件都是通过sendmail来投递的,大约有100万用户使用sendmail,每天投递上亿封邮件。这真是一个让人吃惊的数字。Postfix试图更快、更容易管理、更安全,同时还与sendmail保持足够的兼容性。

一、预安装环境

1.软件包准备

Unix-Syslog-1.1.tar.gz

extmail-1.2.tar.gz

extman-1.1.tar.gz

postfix-2.8.2.tar.gz

courier-authlib-0.63.1.20111230.tar.bz2

将软件包上传到服务器,可以上传到管理员家目录(略)

2.系统环境

Linux 5.4 2.6.18-164.el5

想要实现源码安装,必须先要配置好编译环境。使用yum grouplist |less进行查看。

Development Tools --开发工具

Legacy Software Development  -- 传统软件开发工具

Development Libraries –开发工具库

    如果需要图形。那么以下安装包是需要的。

    Kde环境需要安装:

    Kde software development

    Gnome环境需要安装:

    Gnome software development

    X software development

[root@server ~]# yum groupinstall "Development Libraries"

[root@server ~]# yum groupinstall "Development Tools"

 

3.修改相关文件

卸载sendmail

[root@phoenix ~]# rpm -e sendmail --nodeps

[root@phoenix ~]# vim /etc/resolv.conf  

修改网卡

[root@phoenix ~]# vim /etc/sysconfig/network 

修改主机名称

[root@phoenix ~]# hostname mail.phoenix.com

[root@phoenix ~]# export hostname

[root@phoenix ~]# init 6

[root@mail ~]# hostname

mail.phoenix.com

4.安装DNS

安装DNS

[root@phoenix /]# yum install bind bind-chroot caching-nameserver -y

修改相关文件

[root@phoenix ~]# cd /var/named/chroot/etc/

[root@phoenix etc]# ll

total 16

-rw-r--r-- 1 root root   405 Feb  8 02:08 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 Feb  8 02:43 rndc.key

[root@phoenix etc]# cp -p named.caching-nameserver.conf named.conf

[root@phoenix etc]# vim named.conf

 

[root@phoenix etc]# vim named.rfc1912.zones 

 

[root@phoenix etc]# pwd

/var/named/chroot/etc

[root@phoenix etc]# cd ../var/named

[root@phoenix named]# pwd

/var/named/chroot/var/named

[root@phoenix named]# ll

total 36

drwxrwx--- 2 named named 4096 Aug 26  2004 data

-rw-r----- 1 root  named  198 Jul 30  2009 localdomain.zone

-rw-r----- 1 root  named  195 Jul 30  2009 localhost.zone

-rw-r----- 1 root  named  427 Jul 30  2009 named.broadcast

-rw-r----- 1 root  named 1892 Jul 30  2009 named.ca

-rw-r----- 1 root  named  424 Jul 30  2009 named.ip6.local

-rw-r----- 1 root  named  426 Jul 30  2009 named.local

-rw-r----- 1 root  named  427 Jul 30  2009 named.zero

drwxrwx--- 2 named named 4096 Jul 27  2004 slaves

[root@phoenix named]# cp -p localhost.zone phoenix.com.db

[root@phoenix named]# cp -p named.local 10.168.192.db

[root@phoenix named]# vim phoenix.com.db 

 

[root@phoenix named]# vim 10.168.192.db 

 

 

测试DNS是否正常启动

[root@phoenix named]# rndc reload

server reload successful

[root@phoenix named]# service named restart

Stopping named:                                            [  OK  ]

Starting named:                                            [  OK  ]

[root@phoenix named]#

[root@mail ~]# chkconfig named on

[root@mail ~]# chkconfig --list |grep named

named           0:off  1:off  2:on   3:on   4:on   5:on   6:off

 

 

5.开启mysql

开启mysql

[root@mail ~]# service mysqld start

Starting MySQL:                                            [  OK  ]

[root@mail ~]# chkconfig mysqld on

[root@mail ~]# chkconfig --list |grep mysqld

mysqld             0:off  1:off  2:on   3:on   4:on   5:on   6:off

[root@mail ~]#

[root@mail ~]# 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> show databases;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| mysql              |

| test               |

+--------------------+

3 rows in set (0.00 sec)

 

mysql> \q

Bye

[root@mail ~]#

但是这样并不安全,需要修改密码

[root@mail ~]# mysqladmin -u root -p password 'redhat'

Enter password:

[root@mail ~]#

可以发现直接登录失败

[root@mail ~]# mysql

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

[root@mail ~]#

添加远程管理等

[root@mail ~]# mysql -u root -p

Enter password:

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 14

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.01 sec)

 

mysql> \q

Bye

[root@mail ~]# 

 

二、安装postfix

1.创建有关用户

[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

[root@mail ~]#

2.拆包

[root@mail ~]# ll

total 6972

-rw------- 1 root root    1291 Feb  8 02:05 anaconda-ks.cfg

-rw-r--r-- 1 root root 2268626 Feb  8 02:37 courier-authlib-0.63.1.20111230.tar.bz2

-rw-r--r-- 1 root root  541279 Feb  8 02:37 extmail-1.2.tar.gz

-rw-r--r-- 1 root root  586234 Feb  8 02:37 extman-1.1.tar.gz

-rw-r--r-- 1 root root   35236 Feb  8 02:04 install.log

-rw-r--r-- 1 root root    3995 Feb  8 02:02 install.log.syslog

-rw-r--r-- 1 root root 3644570 Feb  8 02:37 postfix-2.8.2.tar.gz

-rw-r--r-- 1 root root   13738 Feb  8 02:37 Unix-Syslog-1.1.tar.gz

[root@mail ~]# tar -zxvf postfix-2.8.2.tar.gz -C /usr/src

3.配置

[root@mail ~]# cd /usr/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'

4.编译安装

[root@mail postfix-2.8.2]# make

[root@mail postfix-2.8.2]# make install 

5.查看支持的模块

[root@mail postfix-2.8.2]# postconf -m

btree

cidr

environ

hash

internal

mysql

nis

proxy

regexp

static

tcp

texthash

unix

[root@mail postfix-2.8.2]#

6.修改相关配置文件

[root@mail postfix-2.8.2]# cd /etc/postfix/

[root@mail postfix]# cp -p main.cf main.cf.bak //可以进行备份,防止将文件修改错误后无法进行恢复

[root@mail postfix]# vim main.cf

 

 

相关参数说明:

myorigin参数用来指明发件人所在的域名;

mydestination参数指定postfix接收邮件时收件人的域名,即您的postfix系统要接收到哪个域名的邮件;

myhostname 参数指定运行postfix邮件系统的主机的主机名,默认情况下,其值被设定为本地机器名;

mydomain参数指定您的域名,默认情况下,postfixmyhostname的第一部分删除而作为mydomain的值;

mynetworks 参数指定你所在的网络的网络地址,postfix系统根据其值来区别用户是远程的还是本地的,如果是本地网络用户则允许其访问;

inet_interfaces 参数指定postfix系统监听的网络接口;

注意:

1、在postfix的配置文件中,参数行和注释行是不能处在同一行中的;

2任何一个参数的值都不需要加引号,否则,引号将会被当作参数值的一部分来使用;

3每修改参数及其值后执行 postfix reload 即可令其生效;但若修改了inet_interfaces,则需重新启动postfix

4如果一个参数的值有多个,可以将它们放在不同的行中,只需要在其后的每个行前多置一个空格即可;postfix会把第一个字符为空格或tab的文本行视为上一行的延续;

 

7.为了使用方便使用脚本

[root@mail postfix]# mkdir ~/abc

[root@mail postfix]# cd ~/abc

[root@mail abc]# cp /mnt/cdrom/Server/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 //拆解文件

[root@mail abc]# cd etc/rc.d/init.d/

[root@mail init.d]# ll

total 4

-rwxr-xr-x 1 root root 2404 Feb  8 04:24 postfix

[root@mail init.d]# cp postfix /etc/init.d

[root@mail init.d]# ll /etc/init.d/postfix

-rwxr-xr-x 1 root root 2404 Feb  8 04:26 /etc/init.d/postfix

[root@mail init.d]# vim /etc/init.d/postfix //如果您需要修改本配置脚本,可以进行修改,但是建议保持为默认

 

 重启服务

[root@mail init.d]# service postfix start

Starting postfix:                                          [  OK  ]

[root@mail init.d]# chkconfig --add postfix

[root@mail init.d]# chkconfig postfix on

[root@mail init.d]# chkconfig --list |grep postfix

postfix            0:off  1:off  2:on   3:on   4:on   5:on   6:off

[root@mail init.d]# 

 

8.小问题

[root@mail ~]# ll /etc/aliases*

-rw-r--r-- 1 root root  1512 Apr 26  2005 /etc/aliases

-rw-r--r-- 1 root root 12288 Feb  8 04:27 /etc/aliases.db //如果您发现并没有此文件,那么您应该执行 newaliases ,手工进行创建该文件

9.测试

 

三、为postfix开启基于cyrus-sasl的认证功能

1.查看

[root@mail ~]# postconf -a

cyrus

dovecot

[root@mail ~]# 

 

2.修改相关文件

root@mail ~]# vim /etc/postfix/main.cf  

 

[root@mail ~]# cd /usr/lib/sasl2/

[root@mail sasl2]# vim smtpd.conf 

 

3.重启服务

[root@mail ~]# service saslauthd start

Starting saslauthd:                                        [  OK  ]

[root@mail ~]# chkconfig saslauthd on

[root@mail ~]# chkconfig --list |grep saslauthd

saslauthd         0:off  1:off  2:on   3:on   4:on   5:on   6:off

[root@mail ~]# service postfix restart

Shutting down postfix:                                     [  OK  ]

Starting postfix:                                          [  OK  ]

[root@mail ~]#

4.再次查看

[root@mail ~]# postfix reload  //postfix重新加载配置文件

查看

 

四、安装Courier authentication library

1.拆包

[root@mail ~]# ll

total 6980

drwxr-xr-x 5 root root    4096 Feb  8 04:24 abc

-rw------- 1 root root    1291 Feb  8 02:05 anaconda-ks.cfg

-rw-r--r-- 1 root root 2268626 Feb  8 02:37 courier-authlib-0.63.1.20111230.tar.bz2

-rw-r--r-- 1 root root  541279 Feb  8 02:37 extmail-1.2.tar.gz

-rw-r--r-- 1 root root  586234 Feb  8 02:37 extman-1.1.tar.gz

-rw-r--r-- 1 root root   35236 Feb  8 02:04 install.log

-rw-r--r-- 1 root root    3995 Feb  8 02:02 install.log.syslog

-rw------- 1 root root     488 Feb  8 04:31 mbox

-rw-r--r-- 1 root root 3644570 Feb  8 02:37 postfix-2.8.2.tar.gz

-rw-r--r-- 1 root root   13738 Feb  8 02:37 Unix-Syslog-1.1.tar.gz

[root@mail ~]# tar -jxvf courier-authlib-0.63.1.20111230.tar.bz2 -C /usr/src

 

2.配置

[root@mail ~]# cd /usr/src/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

 

3.编译安装

[root@mail courier-authlib-0.63.1.20111230]# make

[root@mail courier-authlib-0.63.1.20111230]# make install

 

4.修改有关文件

[root@mail courier-authlib-0.63.1.20111230]# cd ~

[root@mail ~]#

[root@mail ~]# chmod 755 /usr/local/courier-authlib/var/spool/authdaemon

[root@mail ~]# cp /etc/authdaemonrc.dist  /etc/authdaemonrc

[root@mail ~]# cp /etc/authmysqlrc.dist  /etc/authmysqlrc

[root@mail ~]#

[root@mail ~]# vim /etc/authdaemonrc

 

[root@mail ~]# vim /etc/authmysqlrc

 

[root@mail ~]# cp /usr/src/courier-authlib-0.63.1.20111230/courier-authlib.sysvinit /etc/init.d/courier-authlib

[root@mail ~]# chmod 755 /etc/init.d/courier-authlib

重启服务

[root@mail ~]# chkconfig --add courier-authlib

[root@mail ~]# chkconfig --level 2345 courier-authlib on

 

[root@mail ~]# cd /usr/local/courier-authlib/lib

[root@mail lib]# ldconfig -v |grep courier

[root@mail lib]# echo "/usr/local/courier-authlib/lib/courier-authlib" >> /etc/ld.so.conf.d/courier-authlib.conf

[root@mail lib]#

[root@mail lib]# service courier-authlib start

Starting Courier authentication services: authdaemond

[root@mail lib]#

[root@mail lib]# ldconfig -v |grep courier

/usr/local/courier-authlib/lib/courier-authlib:

    libcourierauth.so -> libcourierauth.so.0

    libcourierauthcommon.so -> libcourierauthcommon.so.0

    libcourierauthsasl.so -> libcourierauthsasl.so.0

    libcourierauthsaslclient.so -> libcourierauthsaslclient.so.0

[root@mail lib]#

新建虚拟用户邮箱所在的目录,并将其权限赋予postfix用户:

[root@mail ~]# mkdir -pv /var/mailbox

mkdir: created directory `/var/mailbox'

[root@mail ~]# chown -R postfix /var/mailbox/

接下来重新配置SMTP 认证,编辑 /usr/local/lib/sasl2/smtpd.conf ,确保其为以下内容:

[root@mail ~]# vim /usr/lib/sasl2/smtpd.conf 

 

五、让postfix支持虚拟域和虚拟用户

1.编辑文件

[root@mail ~]# vim /etc/postfix/main.cf

 

 

2.拆包

使用extman源码目录下docs目录中的extmail.sqlinit.sql建立数据库:

[root@mail ~]# ll

total 6980

drwxr-xr-x 5 root root    4096 Feb  8 04:24 abc

-rw------- 1 root root    1291 Feb  8 02:05 anaconda-ks.cfg

-rw-r--r-- 1 root root 2268626 Feb  8 02:37 courier-authlib-0.63.1.20111230.tar.bz2

-rw-r--r-- 1 root root  541279 Feb  8 02:37 extmail-1.2.tar.gz

-rw-r--r-- 1 root root  586234 Feb  8 02:37 extman-1.1.tar.gz

-rw-r--r-- 1 root root   35236 Feb  8 02:04 install.log

-rw-r--r-- 1 root root    3995 Feb  8 02:02 install.log.syslog

-rw------- 1 root root     488 Feb  8 04:31 mbox

-rw-r--r-- 1 root root 3644570 Feb  8 02:37 postfix-2.8.2.tar.gz

-rw-r--r-- 1 root root   13738 Feb  8 02:37 Unix-Syslog-1.1.tar.gz

[root@mail ~]# tar -zxvf extman-1.1.tar.gz

[root@mail ~]# cd extman-1.1

[root@mail extman-1.1]# cd  docs/

[root@mail docs]# mysql -u root -p <extmail.sql

Enter password:

[root@mail docs]# mysql -u root -p <init.sql

Enter password:

[root@mail docs]#

 

[root@mail docs]# mysql -u root -p

Enter password:

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 19

Server version: 5.0.77 Source distribution

 

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

 

mysql> show databases;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| extmail            |

| mysql              |

| test               |

+--------------------+

4 rows in set (0.00 sec)

 

mysql> \q

Bye

[root@mail docs]#

 

[root@mail docs]# cp mysql*  /etc/postfix/

 

[root@mail docs]# service  postfix  restart

Shutting down postfix:                                     [  OK  ]

Starting postfix:                                          [  OK  ]

 3.授权

 

 

    声明:未完,由于文章格式的问题,本篇被迫分为上、下两篇,如果您对本文章感兴趣,您可以继续浏览本篇文章下篇,给您造成的不便,笔者表示抱歉!