免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2166 | 回复: 1
打印 上一主题 下一主题

postfix安装以及配置1 [复制链接]

论坛徽章:
8
戌狗
日期:2014-09-26 16:39:44水瓶座
日期:2014-10-10 02:06:57金牛座
日期:2014-10-11 23:04:042015亚冠之首尔
日期:2015-06-23 15:37:0015-16赛季CBA联赛之天津
日期:2016-01-22 18:58:2915-16赛季CBA联赛之佛山
日期:2016-05-31 19:18:0815-16赛季CBA联赛之同曦
日期:2016-08-10 16:26:3315-16赛季CBA联赛之辽宁
日期:2018-01-10 11:47:40
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-10-27 16:35 |只看该作者 |正序浏览
最近一段时间结合同学给我发的posftix文档,配置了下postfix邮件系统,感觉安装这个东西都是相当的麻烦,要安装好多包以及perl的模块,自己也遇见了N多问题,艰辛万苦的完成了postfix的安装和基本配置,把我相关的文档整理一下发布到博客,方便以后的参考.

安装环境:Centos4.5(32位)
软件列表以及实现功能:
1、suse10          服务器操作系统
2、Postfix        邮件服务器系统的smtp服务器,在邮件服务器系统中充当MTA角色.
3、Mysql           开源数据库,用于存储邮件系统虚拟域,虚拟帐户信息.
4、apache          用于extman对邮件系统的后台管理,extmail的web邮件收发.
5、php              extman和extmail需要使用php解析
6、cyrus-sasl        用于实现身份验证的smtp服务器
7、courier-authlib   实现带验证的pop3服务器
8、courier-imap      用于实现pop3,imap收邮件功能
9、extman            用于邮件服务器的后台管理
10、extmail          用于实现webmail
11、DBD-mysql        用于解决依赖关系,extmail将会用到
12、unix-syslog      用于解决依赖关系,extmail将会用到
13、BerkeleyDB       用于提高数据库效率
14、openssl          提供安全的邮件服务器连接
15、maildrop         用于替代postfix的mta功能,邮件投递代理,将收到的邮件转发到用户的邮箱目录(本次试验未配置此功能)
16、clamav            反病毒工具
17、SpamAssassin      反垃圾邮件过滤器
18、amavisd-new       是一个连接MTA和内容检测工具

软件包列表:
mysql-5.1.36.tar
httpd-2.2.6.tar
php-5.2.9.tar
amavisd-new-2.6.1.tar
BerkeleyDB-0.26.tar
clamav-0.95.2.tar
courier-0.63.0.tar
courier-imap-4.5.1.tar
cyrus-sasl-2.1.22.tar
db-4.5.20.tar
DBD-mysql-4.012.tar
DBI-1.609.tar
extmail-1.0.9.tar
extman-1.0.0.tar
maildrop-2.2.0.20090905.tar
Mail-SpamAssassin-3.0.5.tar
pcre-7.3.tar
phpMyAdmin-3.2.2-all-languages.tar
postfix-2.6.0.tar
postfixadmin_2.3rc7.tar
Unix-Syslog-0.100.tar
一 、安装apache,mysql,php
安装配置mysql
#cd mysql-5.1.36
#./configure --prefix=/usr/local/mysql --with-extra-charsets=all   --with-plugins=all
#make
#make install
#cp support-files/my-medium.cnf /etc/my.cnf
#cp support-files/mysql.server /etc/init.d/mysqld
#chmod +x /etc/init.d/mysqld
#cd /usr/local/mysql/
#cd bin/
#./mysql_install_db
#cd ..
#chown -R mysql:mysql ./var/
#chkconfig --add mysqld
#chkconfig --levels 35 mysqld  on
#PATH=$PATH:/usr/local/mysql/bin
#export PATH
#echo "/usr/local/mysql/lib/mysql" >> /etc/ld.so.conf
#ldconfig
#service mysqld start
# mysqladmin -u root password root
安装配置Apache
#cd httpd-2.2.6
#./configure --prefix=/usr/local/apache --enable-so --enable-rewrite --with-zlib --enable-mods-shared=most
#make
#make install
#cd /usr/local/apache/bin/
#cp apachectl /etc/init.d/httpd
#chmod +x /etc/init.d/httpd
#vi /etc/init.d/httpd(在#!/bin/sh下加入如下两行)
#chkconfig: 2345 90 90
#description:http server

#chkconfig  --add  httpd
#chkconfig --level 35 httpd on
#service httpd start
安装配置 PHP
#cd php-5.2.9
#./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-apxs2=/usr/local/apache/bin/apxs
#make
#make install

配置Apache使之支持php
#cd /usr/local/apache/conf/
#vi httpd.conf

找到AddType application/x-tar .tgz(348行) ,在下面加两行。
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

找到DirectoryIndex(206行),这表示网站的默认页也能够为index.php
DirectoryIndex index.html index.html.var index.php
#service httpd restart

测试
#vi /usr/local/apache/htdocs/index.php
编辑apache/htdocs目录下的index.php
添加如下代码
Phpinfo();
?>
在浏览器输入http://192.168.10.199,确定apache是否以支持php.
二 、 安装和配置cyrus-sasl(用于实现身份验证的smtp服务器)
1. 安装cyrus-sasl
(1)首先先要卸载系统已经安装cyrus-sasl
#rpm -q cyrus-sasl
#rpm -e cyrus-sasl  --nodeps
    (2)编译安装cyrus-sasl2.1.22
#tar zxvf cyrus-sasl-2.1.22.tar.gz
#cd cyrus-sasl-2.1.22
#./configure --prefix=/usr/local/sasl2 \
--disable-gssapi --disable-anon --disable-digest \
--enable-plain --enable-login \
--enable-sql --with-mysql=/usr/local/mysql/ \
--with-mysql-includes=/usr/local/mysql/include/mysql/ \
--with-mysql-libs=/usr/local/mysql/lib/mysql/ \
--with-authdaemond=/usr/local/courier-authlib/var/spool/authdaemon/socket
/*  一定要加上--enable-login因为SASL2默认不支持login这种验证方式,而OUTLOOK是通过login来进行SMTP验证得)  */
        #make  (这里可能会编译错误,解决的方法: cp mac/libdes/public/des.h /root/tools/Postfix/cyrus-sasl-2.1.22/,
说明: mac/libdes/public/des.h 这个路径是cyrus-sasl源码包文件夹下面的mac路径
/root/tools/Postfix/cyrus-sasl-2.1.22/  这个路径是源码包的路径)
        #make install

2. 配置sasl
(1) 创建运行时需要的目录并调试启动
#mkdir -pv /var/state/saslauthd
在/var/目录下建一个目录给saslauthd进程存放临时数据.假如没有这些目录,运行saslauthd时,会提示出错.

(2) 接着为确保CYRUS-SASL2函数库知道怎样验证所收来的SASL认证请求,必须创建一个SASL的配置文档。配置文档名为smtpd.conf位于/usr/local/sasl2/lib/sasl2这个目录,在该文档中您定义您希望使用的认证数据库方法,以下这个例子使用saslauthd来验证认证请求.
#vi /usr/local/sasl2/lib/sasl2/smtpd.conf
添加以下内容
pwcheck_method: saslauthd
mech_list: PLAIN LOGIN

(3)启动并测试
#/usr/local/sasl2/sbin/saslauthd -a shadow pam
#/usr/local/sasl2/sbin/testsaslauthd  -u root -p root   //用户密码
例如:# /usr/local/sasl2/sbin/testsaslauthd -u root -p 123456
0: OK "Success."
假如出现以上信息,就说明saslauthd正常运行了。
(testsaslauthd程式默认是没有编译的,您需要在源码目录树的saslauthd子目录中运行 make testsaslauthd命令生成.)

(4)添加连接库 postfix编译安装会用到,否则报错.
#echo "/usr/local/sasl2/lib" >> /etc/ld.so.conf
#echo "/usr/local/sasl2/lib/sasl2" >> /etc/ld.so.conf
#ldconfig -v

(5)添加库连接到/usr/lib 因为postfix会到/usr/lib目录下去找SASL2库,而我们是把程式安装在/usr/local/sasl2中,所以我们要在/usr/lib目录下做一个链接:
#ln -s /usr/local/sasl2/lib/sasl2   /usr/lib/sasl2

(6)设置为开机启动
#echo “/usr/local/sasl2/sbin/saslauthd -a shadow pam” >>/etc/rc.local
三、安装配置courier-authlib (实现带验证的pop3服务器)
1、安装courier-authlib
#tar -jxvf courier-authlib-0.62.4.tar.bz2
#cd courier-authlib-0.62.4
#./configure --prefix=/usr/local/courier-authlib\
--without-authpam\
--without-authdap\
--without-authshadow\
--without-vchkpw\
--with-authmysql\
--with-mysql-libs=/usr/local/mysql/lib/mysql\ --with-mysql-includes=/usr/local/mysql/include/mysql
#make
#make install
2、配置courier-authlib
(1)#cd /usr/local/courier-authlib/
#chmod 755 var/spool/authdaemon/

(2) #cd etc/authlib/
#cp authdaemonrc.dist  authdaemonrc
#cp authmysqlrc.dist   authmysqlrc

(3) #vi authdaemonrc
修改etc/authlib/authdaemonrc 文件为:
authmodulelist="authmysql"
authmodulelistorig="authmysql"
  daemons=10

(4)#vi authmysqlrc
修改etc/authlib/authmysqlrc 为以下内容
  MYSQL_SERVER      localhost
  MYSQL_PORT        3306   //指定你的mysql监听的端口,这里使用默认的3306
MYSQL_USERNAME     extmail    //这是为后文要用的数据库的所有者的用户名 MYSQL_PASSWORD     extmail    //这是为后文要用的数据库的所有者的密码
MYSQL_SOCKET      /tmp/mysql.sock   //mysql的接口文件
MYSQL_DATABASE     extmail           //用于验证的数据库
MYSQL_USER_TABLE   mailbox           //用于验证的数据库表
MYSQL_CRYPT_PWFIELD   password
MYSQL_UID_FIELD '501'                //501为postfix用户uid
MYSQL_GID_FIELD '501'                //501为postfix组gid
MYSQL_LOGIN_FIELD     username
MYSQL_HOME_FIELD      concat('/var/mailbox/',homedir)
MYSQL_NAME_FIELD      name
MYSQL_MAILDIR_FIELD   concat('/var/mailbox/',maildir)
3、设置开机自启动
#cp /root/tools/postfix/courier-authlib-0.62.4/courier-authlib.sysvinit /etc/init.d/courier-authlib
#chmod 755 /etc/init.d/courier-authlib
#chkconfig --add  courier-authlib
#chkconfig --level 35 courier-authlib on
#service courier-authlib start
#netstat -an |grep 110
unix  2      [ ACC ]     STREAM     LISTENING     11090  /var/state/saslauthd/mux
unix  2      [ ]         DGRAM                    11089

四、安装配置Postfix
邮件服务器系统的smtp服务器,在邮件服务器系统中充当MTA角色
1 安装Postfix
(1)   创建相关的用户和组否则make install得时候会报错
#groupadd postfix -g 501
#groupadd postdrop
#useradd postfix  -u 501 -g postfix  -G postdrop

(2)   解压安装
#tar -zxvf postfix-2.6.0.tar.gz
#cd postfix-2.6.0
#make -f Makefile makefiles 'CCARGS=-DHAS_MYSQL -I/usr/local/mysql/include/mysql -DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I/usr/local/sasl2/include/sasl' 'AUXLIBS=-L/usr/local/mysql/lib/mysql -lmysqlclient -lz -lm –L /usr/local/sasl2/lib -lsasl2'
注意: -lmysqlclient -lz –lm这三个开头是L的小写,不是i的大写
#make
#make install

install_root: [/]
tempdir: [/srv/postfix-2.6.0] /tmp
config_directory: [/etc/postfix]
command_directory: [/usr/sbin]  /usr/local/postfix/sbin
daemon_directory: [/usr/libexec/postfix] /usr/local/postfix/libexec
data_directory: [/var/lib/postfix]
html_directory: [no]
mail_owner: [postfix]
mailq_path: [/usr/bin/mailq]
manpage_directory: [/usr/local/man]  /usr/local/postfix/man
newaliases_path: [/usr/bin/newaliases]
queue_directory: [/var/spool/postfix]
readme_directory: [no]

2. 配置potfix
(1)生成别名二进制文件,这个步骤如果忽略,会造成postfix效率极低:
#newaliases

(2)编辑主配置文件设置一些基本参数
#vi /etc/postfix/main.cf

修改以下几项为您需要的配置
myhostname = postfix.lixin.org
myorigin = lixin.org
mydomain = lixin.org
mydestination = $myhostname,localhost.$mydomain,localhost, $mydomain
mynetworks = 10.10.0.0/22, 127.0.0.0/8
inet_interfaces = all
local_recipient_maps  =       //去掉前面的注释

上述配置中,需要特别注意的是mydomain和myhostname,这2个项的值不要设置成一样,否则postfix将不能正确启动,虚拟邮箱不可用.
myorigin参数用来指明发件人所在的域名;
       mydestination参数指定postfix接收邮件时收件人的域名,即您的postfix系统
       要接收到哪个域名的邮件
myhostname 参数指定运行postfix邮件系统的主机的主机名,默认情况下,其
值被设定为本地机器名;
mydomain参数指定您的域名,默认情况下,postfix将myhostname的第一部分删
除而作为mydomain的值;  
mynetworks 参数指定你所在的网络的网络地址,postfix系统根据其值来区别用户是远程的还是本地的,如果是本地网络用户则允许其访问;
inet_interfaces 参数指定postfix系统监听的网络接口;
注意: 在postfix的配置文件中,参数行和注释行是不能处在同一行中的;

(3)  为postfix开启基于cyrus-sasl的认证功能
使用以下命令验正postfix是否支持cyrus风格的sasl认证,如果您的输出为以下结果,则是支持的:
#/usr/local/postfix/sbin/postconf  -a
cyrus
dovecot    //出现这些就表示支持

查看是否已经加入了mysql支持
# /usr/local/postfix/sbin/postconf –m
   btree
cidr
environ
hash
mysql
nis
proxy
regexp
static
unix         //出现这些表示已经加入到mysql

#vi /etc/postfix/main.cf
在最后添加以下内容:
############################CYRUS-SASL############################
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_sasl_application_name = smtpd
smtpd_banner = Welcome to our $myhostname ESMTP,Warning: Version not Available!

让postfix重新加载配置文件
#/usr/local/postfix/sbin/postfix  reload




本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u2/75613/showart_2080005.html

论坛徽章:
0
2 [报告]
发表于 2012-08-08 00:09 |只看该作者
学习一下。。。
  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP