免费注册 查看新帖 |

Chinaunix

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

[Mail] Freebsd postfix with SASL2 mysql courier-imap完全ports安装 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2005-05-09 18:06 |只看该作者 |倒序浏览
Freebsd postfix with SASL2 mysql courier-imap完全ports安装
作者:柯贵中    QQ:93606088   E-mail:chaohu@tom.com

版权所有:华柯天下(www.chinake.com)。如有转载,请注明来源,本文形成于2005年4月30日。
本文硬件环境为:CII800+256M+intel815E+40G+intel 10/100 pro+ADSL上网。
软件环境为:Windows xp sp2+Vmware 5.0+secureCRT4.1+leapftp+freebsd 4.10
2005年5月6日,本系统在freebsd 5.3下测试通过。
本系统最大的优点是简单,而且支持加密认证和安全连接。认证部分使用courier认证,是同一个进程,效率更高。配置文件更少。
————————————————————————————————————————
1、基本系统准备
1.1准备网络环境,使虚拟机也能上网
首先安装下载4.10-RELEASE-i386-disc1.iso,然后安装Vmware5.0,安装好后会产生两个网络连结,我们禁用它(用不上),在ADSL连结上右击——属性——共享——共享到本地连结——确定。在本地连结上右击——internet 协议(tcp/ip)——使用下面的DNS服务器地址,将ADSL拨号所获取的DNS地址(如:202.102.192.68)填入——确定。
1.2创建freebsd虚拟机
启动Vmware——new virtual machine——下一步——typical——下一步——other——freebsd——下一步——(修改保存虚拟机的路径,要求空间不得少于4G)下一步(use bridged networking)——下一步disk size(分配最大空间)为10G——完成。
单击edit virtual machine setting 调节虚拟机内存为128M,调整CD-ROM——USE ISO image,浏览到我们下载的4.10-RELEASE-i386-disc1.iso后OK。注意虚拟机和windows xp间的切换键为 Ctrl+Alt。
1.3安装freebsd系统
启动虚拟机进入freebsd安装界面。
1.3.1 Skip kernel configuration and continue with installation
1.3.2 standard,进入硬盘管理,直接按a、q。
1.3.3 引导程序选standard,进入分区管理,直接按a、q。
1.3.4 选择安装包,我选择Minimal,也可以选择All,使用上下键+空格选择,左右键在OK和cancel之间选择,然后回车,大约5分钟。
注意:没有说明的直接回车确定。如果是实际机器安装,请自行确定好网络环境。
由于ports安装下载程序为单线程,太慢,所以准备在win下将所需要的软件用google找到下载回来,通过ftp上传到freebsd,并且使用sshd管理freebsd,所以需要增加一个wheel组用户帐号。
1.3.5 User confirmation requested
Would you like to configure any Ethernet or slip/ppp network devices?(yes)
选择lnc lance/pcnet (isolan/novell ne2100/ne32-vl)Ethernet,
do you want to try ipv6 configuration of the interface ?(no)
do you want to try dhcp configuration of the interface?(no)
1.3.6主机和网络配置,能不能上网关键在这里
host: mail
domain:chinake.com
ipv4 gateway:192.168.0.1
name server:202.102.192.68
ipv4 address:192.168.0.66
netmask:255.255.255.0.
would you like to bring the lnc0 interface up right now?(yes)
do you want this machine to function as a network gateway?(no)
1.3.7开启ftp服务,便于以后上传文件,如果你的网络快,也可不开启。
do you want to configure inetd and the network services that it provides?(yes)
将ftp前的#号给删了,然后敲Esc一次,回车两次。
Do you want to have anonymous ftp access to this machine?(no)
Do you want to configure this machine as an NFS server?(no)
Do you want to configure this machine as an NFS client?(no)
Do you want to select a default security profile for this host?(no)
Would you like to customize your system console setting?(no)
Would you like to set this machine’s time zone now?(no)
Would you like to enable Linux binary compatibility?(yes)
Does this system have a non-usb mouse attaché to it?(yes)
选择2 enable test and run the mouse daemon,然后exit
1.3.8 增加软件包,这里只需要增加更新ports树程序
the freebsd package collection is a collection of thousands of ready-to-run applications, from text editors to games to web servers and more. would you browse the collection now?(yes). 如果想以后配置,可以运行/stand/sysinstall.
选择All——用空格键选择cvsup-16.1h和portupgrade-20040325_1,ok——install.
1.3.9增加系统用户,并使它具有wheel组权限。
Would you like to add any initial user accounts to the system?(yes)
User add a new user to the system
Login id:chaohu
Uid:1001
Group: wheel
Password:chaohu
Ok——exit
1.3.10 修改root用户密码
Now you must set the system manager’s password
This is the password you’ll use to log in as “root”.
输入两次密码,注意输入时是看不见的。
选择no——exit install——yes,重启电脑。FREEBSD 基本系统安装成功。
————————————————————————————————————————
2、WEB服务器系统软件安装
2.1建立sshd连接
安装secureCRT,启动后新建连结。
Name :mail.chinake.com
Hostname:192.168.0.66
Username:chaohu
Password:chaohu
$su
password:
mail#
注:#表示是root身份,$表示普通用户身份。
以下如无特别说明,所有命令都是以root用户身份运行。
2.2 更新ports树。
cd /usr/share/examples/cvsup; cvsup -g -L 2 -h ftp.freebsdchina.org ports-supfile
大约十几分钟,取决于网络的快慢。
mkdir /usr/ports/distfiles
chmod 777 /usr/ports/distfiles
更改这个目录为所有用户可写,使用leapftp软件,ftp://192.168.0.66,用户名和密码:chaohu,登入,并切换到该目录,上传所需要软件,主要是比较大的软件包,如mysql等。
2.3 安装openssl
cd /usr/ports/security/openssl; make install clean
2.4 安装mysql数据库,建议安装3.23或4.0版。
cd /usr/ports/databases/mysql323-server/;
make BUILD_OPTIMIZED=yes WITH_OPENSSL=yes install clean
ee /etc/rc.conf;加入:mysql_enable="YES"
2.5 安装apache
cd /usr/ports/www/apache13-modssl;make install clean
支持https连接,web服务路径为:/usr/local/www/data/。也可以选择apache2。
ee /etc/rc.conf;加入:apache_enable="YES"
2.6 安装php4
cd /usr/ports/lang/php4;make install clean
cp /usr/local/etc/php.ini.dist /usr/local/etc/php.ini
ee /usr/local/etc/apache/httpd.conf
在最后加入:
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

2.7 安装phpmyadmin
由于phpmyadmin默认安装路径为:/usr/local/www/phpMyAdmin
而我们的web服务路径是:/usr/local/www/data/
所以我们要更改其默认的安装。
cd /usr/ports/databases/phpmyadmin;
ee Makefile
将www/全部更改为www/data/。
make install clean
ee /usr/local/www/data/phpMyAdmin/config.inc.php;
将第一个config,改为http
$cfg['PmaAbsoluteUri'] = 'http://192.168.0.66/phpMyAdmin/';
$cfg['Servers'][$i]['auth_type']     = 'http';    // Authentication method (config, http or cookie based)?
2.8 安装perl5.8
cd /usr/ports/lang/perl5.8/;make install clean
完成后根据提示执行:
/usr/local/bin/use.perl port
2.9 安装expect
cd /usr/ports/lang/expect
make install clean
2.10 安装postfixadmin
同phpmyadmin一样,其默认安装目录为:/usr/local/www/postfixadmin/,
所以我也想把它安装到/usr/local/www/data/postfixadmin/下,修改makefile,将所有www/,都改为www/data/,注意有很多处。
cd /usr/ports/mail/postfixadmin;ee Makefile;make install clean
导入数据库:
cd /usr/local/www/data/postfixadmin/
mysql –u root < DATABASE_MYSQL.TXT
修改config.ini.php文件,ee config.ini.php
$CONF['default_language'] = 'cn';
$CONF['domain_path'] = 'YES';
$CONF['domain_in_mailbox'] = 'NO';
这样产生的用户邮件目录形式如:/usr/local/virtual/chinake.com/chaohu
建立邮件存储目录:
mkdir /usr/local/virtual;
chown www:www /usr/local/virtual;
chmod 771 /usr/local/virtual

3、邮件系统安装
3.1 安装courier-imap
cd /usr/ports/mail/courier-imap
make install clean
选择添加:[auth_mysql],如果没有做,可以make config,进行重新选择。
然后编辑:ee /etc/rc.conf;增加courier_authdaemond_enable="YES"自启动,并启动:
/usr/local/etc/rc.d/courier_authdaemond.sh start。此时会在/var/run/authdaemond/下产生socket。
chmod o+x /var/run/authdaemond;给sasl可执行权限。
3.2 安装SASL2
cd /usr/ports/security/cyrus-sasl2;make install WITH_AUTHDAEMON=yes clean;
或者使用:make -DWITH_AUTHDAEMOND install clean
ee /usr/local/lib/sasl2/smtpd.conf ;
pwcheck_method: authdaemond
log_level: 3
mech_list: PLAIN LOGIN
authdaemond_path:/var/run/authdaemond/socket
至此,认证部分基本完成。
3.3 安装POSTFIX
3.3.1 cd /usr/ports/mail/postfix
安装时选中[sasl2]+[tls]+[db42]+[mysql]+[vda]+[test]。
make install clean
在安装快结束时会提示两个问题,分别是加入用户组和修改mailer.conf。全部回答为y。
echo ‘postfix: root’ >;>; /etc/aliases
/usr/local/bin/newaliases
chown postfix:postfix /etc/opiekeys
3.3.2 替换并停止sendmail
ee /etc/rc.conf;修改sendmail_enable=’NONE’
建立启动链接:
cd /usr/local/etc/rc.d/;ln –s /usr/local/sbin/postfix postfix.sh
创建/etc/periodic.conf
ee /etc/periodic.conf
daily_clean_hoststat_enable="NO"
daily_status_mail_rejects_enable="NO"
daily_status_include_submit_mailq="NO"
daily_submit_queuerun="NO"
3.3.3配置postfix
因为我想使用和apache一样的用户来读取邮件目录,因为apache用户为www,id:80,所以要注意/usr/local/etc/postfix/main.cf中的用户id。
ee /usr/local/etc/postfix/main.cf
在最后添加:
#======= BASE ==============
myhostname = mail.chinake.com
mydomain = chinake.com
home_mailbox = Maildir/
mydestination = $myhostname
local_recipient_maps =
#======= MYSQL =============
virtual_gid_maps = static:80
virtual_mailbox_base = /usr/local/virtual
virtual_uid_maps = static:80
virtual_minimum_uid = 80
virtual_alias_maps = mysql:/usr/local/etc/postfix/mysql_virtual_alias_maps.cf
virtual_mailbox_domains = mysql:/usr/local/etc/postfix/mysql_virtual_domains_maps.cf
virtual_mailbox_maps = mysql:/usr/local/etc/postfix/mysql_virtual_mailbox_maps.cf
#======= Quota ============
message_size_limit = 5242880
virtual_mailbox_limit_inbox = no
virtual_mailbox_limit_override = yes
virtual_maildir_extended = yes
virtual_create_maildirsize = yes
virtual_mailbox_limit_maps = mysql:/usr/local/etc/postfix/mysql_virtual_mailbox_limit_maps.cf
virtual_mailbox_limit = 52428800
#======== SASL ================
smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous
broken_sasl_auth_clients = yes
smtpd_recipient_restrictions = permit_sasl_authenticated permit_auth_destination reject
#smtpd_sasl_local_domain = $mydomain
smtpd_client_restrictions = permit_sasl_authenticated

几个配置文件:
cd /usr/local/etc/postfix/;
1、ee mysql_virtual_alias_maps.cf
user = postfix
password = postfix
hosts = localhost
dbname = postfix
table = alias
select_field = goto
where_field = address

2、ee mysql_virtual_domains_maps.cf
user = postfix
password = postfix
hosts = localhost
dbname = postfix
table = domain
select_field = description
where_field = domain
#additional_conditions = and backupmx = '0' and active = '1'
3、ee mysql_virtual_mailbox_maps.cf
user = postfix
password = postfix
hosts = localhost
dbname = postfix
table = mailbox
select_field = maildir
where_field = username
#additional_conditions = and active = '1'
4、ee mysql_virtual_mailbox_limit_maps.cf
user = postfix
password = postfix
hosts = localhost
dbname = postfix
table = mailbox
select_field = quota
where_field = username
#additional_conditions = and active = '1'

这里我使用80用户,即WWW(HTTP)并修改:

3.4、配置courier-imap认证
ee /usr/local/etc/authlib/authmysqlrc
DEFAULT_DOMAIN                                chinake.com
MYSQL_CRYPT_PWFIELD                        password
MYSQL_DATABASE                                postfix
MYSQL_GID_FIELD                                '80'
MYSQL_HOME_FIELD                        '/usr/local/virtual'
MYSQL_LOGIN_FIELD                        username
MYSQL_MAILDIR_FIELD                        maildir
MYSQL_NAME_FIELD                        name
MYSQL_OPT                                        0
MYSQL_PASSWORD                                postfix
#MYSQL_PORT                                        0
#MYSQL_QUOTA_FIELD                        quota
MYSQL_SERVER                                localhost
MYSQL_UID_FIELD                                '80'
MYSQL_USERNAME                                postfix
MYSQL_USER_TABLE                        mailbox

这里用户也修改为80,注意中间不是空格,是TAB键,在Unix系统中,很多都是用TAB键的。也请特别注意其中的引号。
ee /usr/local/etc/authlib/authdaemonrc
authmodulelist="authmysql authpam authuserdb"
authmodulelistorig="authmysql authpam authuserdb"
version="authdaemond.mysql"
4、安装webmail
在默认的配置上添加[AUTH_MYSQL]
cd /usr/ports/mail/sqwebmail/;make install clean
ee /etc/rc.conf;添加:sqwebmaild_enable=”YES”
ee /etc/crontab
#minute hour    mday    month   wday    who     command
0      *       *       *       *       bin    /usr/local/share/sqwebmail/ cleancache.pl
好了,邮件服务器建设好了。
5、虚拟域名、管理员、用户的管理。
http://192.168.0.66/postfixadmin/admin/
注意先建域,后管理员,然后添加用户,再到/usr/local/virtual下看看,用户目录有没有建立,如果没有,请查看 /var/log/下的maillog和messages。仔细检查配置文件。
6、收发邮件
可以使用outlook或http://192.168.0.66/cgi-bin/sqwebmail/sqwebmail
注意虚拟域,使用邮件地址登入。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP