Installing Postfix

编译安装

  1. xxxx

  2. 添加postfix用户 [1]BSD

    [root@linux src]# groupadd -g 1000 postfix
    [root@linux src]# groupadd -g 1001 postdrop
    [root@linux src]# useradd postfix -u 1000 -g 1000 -d /dev/null -s /bin/false
    				
  3. 给Postfix邮箱空间配额打补丁

    [root@linux src]# patch -p0 < postfix-2.0.19.patch
    patching file postfix-2.0.19/src/global/mail_params.h
    patching file postfix-2.0.19/src/util/file_limit.c
    patching file postfix-2.0.19/src/virtual/mailbox.c
    patching file postfix-2.0.19/src/virtual/maildir.c
    patching file postfix-2.0.19/src/virtual/virtual.c
    patching file postfix-2.0.19/src/virtual/virtual.h
    				

    编译安装

    [root@linux src]# cd postfix-2.0.19
    [root@linux postfix-2.0.19]# make tidy
    [root@linux postfix-2.0.19]# make clean
    [root@linux postfix-2.0.19]# make -f Makefile.init makefiles 'CCARGS=-DUSE_SASL_AUTH -DHAS_MYSQL -I/usr/include/mysql -I/usr/include/sasl' \
    'AUXLIBS=-L/usr/lib/mysql -L/usr/lib/sasl2 -lmysqlclient -lsasl2 -lz -lm'
    [root@linux postfix-2.0.19]# make
    [root@linux postfix-2.0.19]# make install
    				

    make tidy(如果你之前编译过Postfix使用此命令)

    make upgrade(升级老版本使用此命令)

    make -f Makefile.init makefiles 'CCARGS=-DHAS_LDAP -I<ldap的include目录> -DUSE_SASL_AUTH -I/usr/local/include/sasl' 'AUXLIBS=-L<ldap的lib目录> -llber -lldap -L/usr/local/lib -lsasl2'

    !!!!!!这里切记要指定正确的SASL2的INCLUDE和LIB位置。由于现在很多linux发行版上都已经带有了sasl,如果不指定的话,很可能会使用了不同版本的头文件和库,在这种情况下,每次连接SMTP时,smtpd就会发生致命错误“Fatal: SASL per-connection server init...”而崩溃。

  4. 配置安装目录

    安装程序会提问一些问题,可以直接按回车采用默认值。

    Please specify the prefix for installed file names. Specify this ONLY
    if you are building ready-to-install packages for distribution to other
    machines.
    install_root: [/]
    
    Please specify a directory for scratch files while installing Postfix. You
    must have write permission in this directory.
    tempdir: [/root/src/postfix-2.0.19]
    
    Please specify the final destination directory for installed Postfix
    configuration files.
    config_directory: [/etc/postfix]
    
    Please specify the final destination directory for installed Postfix
    daemon programs. This directory should not be in the command search path
    of any users.
    daemon_directory: [/usr/libexec/postfix]
    
    Please specify the final destination directory for installed Postfix
    administrative commands. This directory should be in the command search
    path of adminstrative users.
    command_directory: [/usr/sbin]
    
    Please specify the final destination directory for Postfix queues.
    queue_directory: [/var/spool/postfix]
    
    Please specify the final destination pathname for the installed Postfix
    sendmail command. This is the Sendmail-compatible mail posting interface.
    sendmail_path: [/usr/sbin/sendmail]
    
    Please specify the final destination pathname for the installed Postfix
    newaliases command. This is the Sendmail-compatible command to build
    alias databases for the Postfix local delivery agent.
    newaliases_path: [/usr/bin/newaliases]
    
    Please specify the final destination pathname for the installed Postfix
    mailq command. This is the Sendmail-compatible mail queue listing command.
    mailq_path: [/usr/bin/mailq]
    
    Please specify the owner of the Postfix queue. Specify an account with
    numerical user ID and group ID values that are not used by any other
    accounts on the system.
    mail_owner: [postfix]
    
    Please specify the group for mail submission and for queue management
    commands. Specify a group name with a numerical group ID that is
    not shared with other accounts, not even with the Postfix mail_owner
    account. You can no longer specify "no" here.
    setgid_group: [postdrop]
    
    Please specify the destination directory for the Postfix on-line manual
    pages. You can no longer specify "no" here.
    manpage_directory: [/usr/local/man]
    
    Please specify the destination directory for the Postfix sample
    configuration files.
    sample_directory: [/etc/postfix]
    
    Please specify the destination directory for the Postfix README
    files. Specify "no" if you do not want to install these files.
    readme_directory: [no]
    				
  5. main.cf

    [root@linux postfix]# vi main.cf
    #======= BASE ==============
    #mail_spool_directory = /var/mail/
    myhostname = mail.example.net
    mydomain = example.net
    home_mailbox=Maildir/
    mydestination = $myhostname, $mydomain, $transport_maps
    local_recipient_maps =
    #mailbox_command= /usr/lib/courier-imap/bin/deliverquota -w 90 ~/Maildir
    #mailbox_command = /usr/local/maildrop/bin/maildrop
    #local_destination_concurrency_limit = 1
    #======= MYSQL =============
    transport_maps = mysql:/etc/postfix/mysql_transport.cf
    virtual_mailbox_base = /var/mail
    virtual_mailbox_maps = mysql:/etc/postfix/mysql_virtual.cf
    virtual_maps = mysql:/etc/postfix/mysql_aliases.cf
    #virtual_uid_maps = mysql:/etc/postfix/uids.cf
    #virtual_gid_maps = mysql:/etc/postfix/gids.cf
    virtual_uid_maps = static:1000
    virtual_gid_maps = static:1000
    #======= Quota ============
    #50MB
    virtual_mailbox_limit = 500000000
    #5MB
    message_size_limit = 50000000
    virtual_mailbox_limit_inbox = no
    virtual_mailbox_limit_maps = mysql:/etc/postfix/mysql_quota.cf
    virtual_mailbox_limit_override = yes
    virtual_maildir_extended = yes
    virtual_create_maildirsize = yes
    #====== 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
    				
  6. /etc/postfix/mysql_transport.cf

    [root@linuxas3 postfix]# cat /etc/postfix/mysql_transport.cf
    #mysql_transport.cf
    hosts = localhost
    user = postfix
    password = 6AJx9Nqv9x8hg
    dbname = postfix
    table = postfix_transport
    select_field = transport
    where_field = domain
    [root@linuxas3 postfix]#
    				
  7. /etc/postfix/mysql_virtual.cf

    [root@linuxas3 postfix]# cat /etc/postfix/mysql_virtual.cf
    #mysql_virtual.cf
    hosts = localhost
    user = postfix
    password= 6AJx9Nqv9x8hg
    dbname = postfix
    table = postfix_users
    select_field = maildir
    where_field = user
    [root@linuxas3 postfix]#
     				
  8. /etc/postfix/mysql_aliases.cf

    [root@linuxas3 postfix]# cat /etc/postfix/mysql_aliases.cf
    #mysql.aliases.cf
    hosts = localhost
    user = postfix
    password= 6AJx9Nqv9x8hg
    dbname = postfix
    table = postfix_aliases
    select_field = rcpt
    where_field = alias
    [root@linuxas3 postfix]#
     				
  9. /etc/postfix/mysql_quota.cf

    [root@linuxas3 postfix]# cat /etc/postfix/mysql_quota.cf
    #mailboxsize-mysql.cf
    hosts = localhost
    user = postfix
    password = 6AJx9Nqv9x8hg
    dbname = postfix
    table = postfix_users
    select_field = quota
    where_field = user
    [root@linuxas3 postfix]#
     				
  10. 运行,测试

    postfix start

    [root@linuxas3 src]# telnet localhost 25
    Trying 127.0.0.1...
    Connected to linuxas3.9812.net (127.0.0.1).
    Escape character is '^]'.
    220 mail.example.net ESMTP Postfix
    quit
    221 Bye
    Connection closed by foreign host.
    [root@linuxas3 src]#
     				

卸载Postfix [2]

Notes

[1]

BSD 平台请使用下面命令:

# pw groupadd postfix -g 2003
# pw groupadd postdrop -g 2004
# pw useradd postfix -u 2003 -g 2003 -d /dev/null -s /nologin
				
[2]

复制下面命令粘贴到CLI上即可。

postfix stop
rm -rf /usr/libexec/postfix/bounce
rm -rf /usr/libexec/postfix/cleanup
rm -rf /usr/libexec/postfix/error
rm -rf /usr/libexec/postfix/flush
rm -rf /usr/libexec/postfix/lmtp
rm -rf /usr/libexec/postfix/local
rm -rf /usr/libexec/postfix/master
rm -rf /usr/libexec/postfix/nqmgr
rm -rf /usr/libexec/postfix/pickup
rm -rf /usr/libexec/postfix/pipe
rm -rf /usr/libexec/postfix/proxymap
rm -rf /usr/libexec/postfix/qmgr
rm -rf /usr/libexec/postfix/qmqpd
rm -rf /usr/libexec/postfix/showq
rm -rf /usr/libexec/postfix/smtp
rm -rf /usr/libexec/postfix/smtpd
rm -rf /usr/libexec/postfix/spawn
rm -rf /usr/libexec/postfix/trivial-rewrite
rm -rf /usr/libexec/postfix/virtual
rm -rf /usr/sbin/postalias
rm -rf /usr/sbin/postcat
rm -rf /usr/sbin/postconf
rm -rf /usr/sbin/postfix
rm -rf /usr/sbin/postkick
rm -rf /usr/sbin/postlock
rm -rf /usr/sbin/postlog
rm -rf /usr/sbin/postmap
rm -rf /usr/sbin/postsuper
rm -rf /usr/sbin/postdrop
rm -rf /usr/sbin/postqueue
rm -rf /usr/sbin/sendmail
rm -rf /usr/bin/newaliases
rm -rf /usr/bin/mailq
rm -rf /etc/postfix/LICENSE
rm -rf /etc/postfix/access
rm -rf /etc/postfix/aliases
rm -rf /etc/postfix/canonical
rm -rf /etc/postfix/main.cf
rm -rf /etc/postfix/main.cf.default
rm -rf /etc/postfix/master.cf
rm -rf /etc/postfix/pcre_table
rm -rf /etc/postfix/postfix-files
rm -rf /etc/postfix/regexp_table
rm -rf /etc/postfix/relocated
rm -rf /etc/postfix/transport
rm -rf /etc/postfix/virtual
rm -rf /etc/postfix/postfix-script
rm -rf /etc/postfix/post-install
rm -rf /usr/local/man/man1/mailq.1
rm -rf /usr/local/man/man1/newaliases.1
rm -rf /usr/local/man/man1/postalias.1
rm -rf /usr/local/man/man1/postcat.1
rm -rf /usr/local/man/man1/postconf.1
rm -rf /usr/local/man/man1/postdrop.1
rm -rf /usr/local/man/man1/postfix.1
rm -rf /usr/local/man/man1/postkick.1
rm -rf /usr/local/man/man1/postlock.1
rm -rf /usr/local/man/man1/postlog.1
rm -rf /usr/local/man/man1/postmap.1
rm -rf /usr/local/man/man1/postqueue.1
rm -rf /usr/local/man/man1/postsuper.1
rm -rf /usr/local/man/man1/sendmail.1
rm -rf /usr/local/man/man5/access.5
rm -rf /usr/local/man/man5/aliases.5
rm -rf /usr/local/man/man5/canonical.5
rm -rf /usr/local/man/man5/pcre_table.5
rm -rf /usr/local/man/man5/regexp_table.5
rm -rf /usr/local/man/man5/relocated.5
rm -rf /usr/local/man/man5/transport.5
rm -rf /usr/local/man/man5/virtual.5
rm -rf /usr/local/man/man8/bounce.8
rm -rf /usr/local/man/man8/cleanup.8
rm -rf /usr/local/man/man8/defer.8
rm -rf /usr/local/man/man8/error.8
rm -rf /usr/local/man/man8/flush.8
rm -rf /usr/local/man/man8/lmtp.8
rm -rf /usr/local/man/man8/local.8
rm -rf /usr/local/man/man8/master.8
rm -rf /usr/local/man/man8/nqmgr.8
rm -rf /usr/local/man/man8/pickup.8
rm -rf /usr/local/man/man8/pipe.8
rm -rf /usr/local/man/man8/proxymap.8
rm -rf /usr/local/man/man8/qmgr.8
rm -rf /usr/local/man/man8/qmqpd.8
rm -rf /usr/local/man/man8/showq.8
rm -rf /usr/local/man/man8/smtp.8
rm -rf /usr/local/man/man8/smtpd.8
rm -rf /usr/local/man/man8/spawn.8
rm -rf /usr/local/man/man8/trivial-rewrite.8
rm -rf /usr/local/man/man8/virtual.8
rm -rf /etc/postfix/sample-aliases.cf
rm -rf /etc/postfix/sample-auth.cf
rm -rf /etc/postfix/sample-canonical.cf
rm -rf /etc/postfix/sample-compatibility.cf
rm -rf /etc/postfix/sample-debug.cf
rm -rf /etc/postfix/sample-filter.cf
rm -rf /etc/postfix/sample-flush.cf
rm -rf /etc/postfix/sample-ldap.cf
rm -rf /etc/postfix/sample-lmtp.cf
rm -rf /etc/postfix/sample-local.cf
rm -rf /etc/postfix/sample-mime.cf
rm -rf /etc/postfix/sample-misc.cf
rm -rf /etc/postfix/sample-pcre-access.cf
rm -rf /etc/postfix/sample-pcre-body.cf
rm -rf /etc/postfix/sample-pcre-header.cf
rm -rf /etc/postfix/sample-qmqpd.cf
rm -rf /etc/postfix/sample-rate.cf
rm -rf /etc/postfix/sample-regexp-access.cf
rm -rf /etc/postfix/sample-regexp-body.cf
rm -rf /etc/postfix/sample-regexp-header.cf
rm -rf /etc/postfix/sample-relocated.cf
rm -rf /etc/postfix/sample-resource.cf
rm -rf /etc/postfix/sample-rewrite.cf
rm -rf /etc/postfix/sample-smtp.cf
rm -rf /etc/postfix/sample-smtpd.cf
rm -rf /etc/postfix/sample-transport.cf
rm -rf /etc/postfix/sample-virtual.cf
rm -rf /etc/postfix
rm -rf /usr/libexec/postfix
rm -rf /var/spool/postfix