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
    
    [ root@server/~ ]# mkdir /var/spool/virtual
    [ root@server/~ ]# chown 1000:1000 /var/spool/virtual
    				
  3. 編譯安裝

    [ root@server/~ ]# wget ftp://ftp.matrix.com.br/pub/postfix/official/postfix-2.1.0.tar.gz 
    [ root@server/~ ]# tar xvjf postfix-2.1.0.tar.gz; cd postfix-2.1.0/
    [ root@server/~ ]# make tidy
    [ root@server/~ ]# make -f Makefile.init makefiles 'CCARGS=-DHAS_PGSQL -I/usr/local/pgsql/include' 'AUXLIBS=-L/usr/local/pgsql/lib -lpq'
    (Altere o caminho dos headers e das libs conforme a sua instala??o do postgre)
    [ root@server/~ ]# make
    [ root@server/~ ]# make install	
    				
  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
    virtual_uid_maps = static:1000
    virtual_gid_maps = static:1000
    virtual_mailbox_base = /var/spool/virtual
    virtual_mailbox_domains = pgsql:/etc/postfix/pgsql_virtual_domains_maps.cf
    virtual_mailbox_maps = pgsql:/etc/postfix/pgsql_virtual_mailbox_maps.cf
    virtual_alias_maps = pgsql:/etc/postfix/pgsql_virtual_alias_maps.cf
    virtual_mailbox_limit = 51200000
    virtual_transport = virtual
    
    				
  6. /etc/postfix/pgsql_virtual_domains_maps.cf

    user = postfix
    password = postfix
    dbname = postfix
    table = domain
    select_field = domain
    where_field = domain
    additional_conditions = and active = true
    				
  7. /etc/postfix/pgsql_virtual_mailbox_maps.cf

    user = postfix
    password = postfix
    dbname = postfix
    table = mailbox
    select_field = maildir
    where_field = username
    additional_conditions = and active = true
     				
  8. /etc/postfix/pgsql_virtual_alias_maps.cf

    user = postfix
    password = postfix
    dbname = postfix
    table = alias
    select_field = goto
    where_field = address
    additional_conditions = and active = true
     				
  9. 運行,測試

    postfix start

    [ root@server/~ ]# postfix stop; postfix start 
    
    [root@server~/]# telnet localhost 25 
    Trying 127.0.0.1...
    Connected to localhost.
    Escape character is '^]'.
    220 server.domain.com.br ESMTP Postfix (2.1.0)
    MAIL FROM: teste@dominio.com.br
    250 Ok
    RCPT TO: teste@dominio.com.br
    250 Ok
    DATA
    354 End data with <CR><LF>.<CR><LF>
    teste
    .
    250 Ok: queued as 7B41F4665A
    quit
    221 Bye
    Connection closed by foreign host.
    [root@server~/]# cd /var/spool/virtual;ls -la
    drwxr-xr-x    3    vuser   vgroup    4096 Abr 26 11:18 .
    drwxr-xr-x   11    root    root      4096 Abr 26 10:44 ..
    drwx------    5    vuser   vgroup    4096 Abr 26 11:18 teste@dominio.com.br
    [root@server~/]#
     				

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