用户工具

站点工具


doc:p:postfix_install

1、操作系统安装

这个大家应该不陌生,就不再重复。

2、配置

编辑/etc/rc.conf文件

# vi /etc/rc.conf

确保有如下内容:

sshd_enable="YES"
named_enable="YES"
sendmail_enable="NONE"

编辑/etc/resolv.conf文件

# vi /etc/resolv.conf

确保第一条nameserver记录是127.0.0.1,这样本地DNS缓存才有效,类似如下:

domain  extmail.org
nameserver      127.0.0.1
nameserver      202.96.209.133

然后重启named服务:

# /etc/rc.d/named start

3、更新ports

使用163的镜像 编辑/etc/make.conf文件

# vi /etc/make.conf

添加以下内容:

MASTER_SITE_BACKUP?=http://mirrors.163.com/FreeBSD/distfiles/${DIST_SUBDIR}/
MASTER_SITE_OVERRIDE?=${MASTER_SITE_BACKUP}

根据你的情况执行

# portsnap fetch && portsnap update

或者

# csup -gL2 /usr/share/examples/cvsup/ports-supfile -h cvsup.freebsdchina.org

4、增加存储邮件的帐号

# pw group add vmail -g 1000
# pw user add vmail -u 1000 -g 1000 -s /sbin/nologin -d /dev/null

给test用户创建路径 需要一个测试帐号test@extmail.org,需要准备该账号的路径。

# mkdir -p /home/domains/extmail.org/test/Maildir/new
# mkdir -p /home/domains/extmail.org/test/Maildir/cur
# mkdir -p /home/domains/extmail.org/test/Maildir/tmp
# chown -R vmail:vmail /home/domains/
# chmod -R 700 /home/domains/

5、MySQL的安装:

# cd /usr/ports/databases/mysql55-server/ && make install clean

编辑MySQL配置文件:

# cp /usr/local/share/mysql/my-small.cnf /usr/local/etc/my.cnf

6、MySQL添加到开机自启:

编辑/etc/rc.conf文件:

# vi /etc/rc.conf

增加如下一行:

mysql_enable=“YES”

启动MySQL

# /usr/local/etc/rc.d/mysql-server start

Courier-IMAP是一个提供POP3、IMAP服务的程序,能够很方便的配置使其支持加密协议POP3s、IMAPs。并良好的支持Maildir。

7、Courier-imap的安装

安装时选择(如果你使用OpenLDAP认证,则选择AUTH_LDAP):

TRASHQUOTA
AUTH_MYSQL

# cd /usr/ports/mail/courier-imap/ && make install clean

8、Authlib的配置

编辑/authdaemonrc文件:

# vi /usr/local/etc/authlib/authdaemonrc

内容如下:

authmodulelist="authmysql"
authmodulelistorig="authmysql"
daemons=5
authdaemonvar=/var/run/authdaemond
subsystem=mail
DEBUG_LOGIN=0
DEFAULTOPTIONS="wbnodsn=1"
LOGGEROPTS=""

增加/var/run/authdaemond的执行权限 # chmod +x /var/run/authdaemond

编辑authldaprc文件: # vi /usr/local/etc/authlib/authmysqlrc

内容如下:

MYSQL_SERVER            localhost
MYSQL_USERNAME          extmail
MYSQL_PASSWORD          extmail
MYSQL_SOCKET            /tmp/mysql.sock
MYSQL_PORT              3306
MYSQL_OPT               0
MYSQL_DATABASE          extmail
MYSQL_USER_TABLE        mailbox
MYSQL_CRYPT_PWFIELD     password
MYSQL_UID_FIELD         uidnumber
MYSQL_GID_FIELD         gidnumber
MYSQL_LOGIN_FIELD       username
MYSQL_HOME_FIELD        homedir
MYSQL_NAME_FIELD        name
MYSQL_MAILDIR_FIELD     maildir
MYSQL_QUOTA_FIELD       quota
MYSQL_SELECT_CLAUSE     SELECT username,password,"",uidnumber,gidnumber,\
                        CONCAT('/home/domains/',homedir),               \
                        CONCAT('/home/domains/',maildir),               \
                        quota,                                          \
                        name                                            \
                        FROM mailbox                                    \
                        WHERE username = '$(local_part)@$(domain)'

9、配置开机自起

配置自动启动: 编辑/etc/rc.conf文件:

# vi /etc/rc.conf

添加如下行:

courier_authdaemond_enable="YES"
courier_imap_pop3d_enable="YES"
courier_imap_imapd_enable="YES"

这3行的作用分别是在开机时:启动authdaemond,启动pop3d,启动imapd。

也可以使用命令行来控制这些进程的启动或者停止:

/usr/local/etc/rc.d/courier-authdaemond start/stop
/usr/local/etc/rc.d/courier-imap-pop3d start/stop
/usr/local/etc/rc.d/courier-imap-imapd start/stop

10、安装postfix

安装时选择(如果你使用MySQL验证,可以选择MYSQL):

PCRE
SASL2
TLS
MYSQL
VDA
TEST

# cd /usr/ports/mail/postfix/ && make install clean

11、配置postfix

编辑/etc/rc.conf文件:

# vi /etc/rc.conf

增加如下一行:

postfix_enable="YES" 

编辑/etc/aliases文件:

# vi /etc/aliases

确保有如下一行

postfix: root 

替换掉系统带的sendmail程序

# mv /usr/sbin/sendmail /usr/sbin/sendmail.bak
# cp /usr/local/sbin/sendmail /usr/sbin/sendmail

编辑/etc/periodic.conf文件:加入如下内容,禁掉sendmail的自动维护。

daily_clean_hoststat_enable="NO"
daily_status_mail_rejects_enable="NO"
daily_status_include_submit_mailq="NO"
daily_submit_queuerun="NO"

执行如下命令

# /usr/local/sbin/postalias /etc/aliases
# chown postfix:postfix /etc/opiekeys
# /usr/local/sbin/postconf -n > /usr/local/etc/postfix/main2.cf
# mv /usr/local/etc/postfix/main2.cf /usr/local/etc/postfix/main.cf
# vi /usr/local/etc/postfix/main.cf

增加如下内容:

# hostname
mydomain = extmail.org
myhostname = mail.extmail.org
myorigin = $mydomain
virtual_mailbox_base = /home/domains
virtual_uid_maps=static:1000
virtual_gid_maps=static:1000

12、SMTP认证设置

编辑/usr/local/lib/sasl2/smtpd.conf文件:

# vi /usr/local/lib/sasl2/smtpd.conf

增加以下内容:

pwcheck_method:authdaemond
log_level:3
mech_list:PLAIN LOGIN
authdaemond_path:/var/run/authdaemond/socket

对postfix做如下配置使支持smtp认证

# SMTP AUTH config here
smtpd_sasl_auth_enable = yes
broken_sasl_auth_clients = yes
smtpd_sasl_local_domain = $myhostname

13、postfix反垃圾设置

此处的反垃圾邮件只是在MTA级的一些预防垃圾邮件的设置,可根据实际情况以及自己的需要进行调整。

# vi /usr/local/etc/postfix/main.cf

增加以下内容:

smtpd_helo_required = yes
smtpd_delay_reject = yes
disable_vrfy_command = yes

smtpd_client_restrictions =
        check_client_access hash:/usr/local/etc/postfix/client_access

smtpd_helo_restrictions=
        reject_invalid_hostname,check_helo_access hash:/usr/local/etc/postfix/helo_access

# SMTP sender login matching config
smtpd_sender_restrictions =
        reject_non_fqdn_sender,
        reject_unknown_sender_domain,
        check_sender_access hash:/usr/local/etc/postfix/sender_access

#smtpd related config
smtpd_recipient_restrictions=
        permit_mynetworks,
        permit_sasl_authenticated,
        reject_non_fqdn_hostname,
        reject_non_fqdn_sender,
        reject_non_fqdn_recipient,
        reject_unauth_destination,
        reject_unauth_pipelining,
        reject_invalid_hostname

smtpd_data_restrictions = reject_unauth_pipelining
header_checks = regexp:/usr/local/etc/postfix/head_checks
body_checks = regexp:/usr/local/etc/postfix/body_checks

生成虚拟域数据库

# rehash
# touch /usr/local/etc/postfix/head_checks
# touch /usr/local/etc/postfix/body_checks
# touch /usr/local/etc/postfix/client_access
# touch /usr/local/etc/postfix/sender_access
# touch /usr/local/etc/postfix/helo_access
# postmap /usr/local/etc/postfix/head_checks
# postmap /usr/local/etc/postfix/body_checks
# postmap /usr/local/etc/postfix/client_access
# postmap /usr/local/etc/postfix/sender_access
# postmap /usr/local/etc/postfix/helo_access

/data/vhosts/wiki-data/pages/doc/p/postfix_install.txt · 最后更改: 2012/11/16 23:05 由 wf.ab