Postfix

Postfix & Amavis - 使用 UNIX Soket 進行通信

  • January 6, 2015

我目前使用複雜的郵件伺服器設置,使用Postfix、Dovecot、Amavis 和 Spamassassin

一切正常,但我想改進 Postfix-Amavis-Communication。目前,postfix 將發送所有localhost:10024屬於 amavis 服務的郵件。在所有檢查之後,修改後的版本被發回,localhost:10025這是一個用於接收 amavis 郵件的後綴服務。

我的想法:UNIX SOCKETS (出於安全原因;為什麼不重要)

所以我將 amavis 配置為在/run/amavis/amavis.socket.

我改變了這個:

amavis-forward:[127.0.0.1]:10024` to `amavis-forward:unix:/run/amavis/amavis.sock

但後來我得到這個錯誤:

Jan  5 13:55:23 server postfix/smtp[1447]: fatal: unknown service: /run/amavis/amavis.sock/tcp
Jan  5 13:55:24 server postfix/qmgr[1254]: warning: private/amavis-forward socket: malformed response
Jan  5 13:55:24 server postfix/qmgr[1254]: warning: transport amavis-forward failure -- see a previous warning/fatal/panic logfile record for the problem description

所以郵件狀態設置為status=deferred (unknown mail transport error)

master.cf:

...
# Amavis
amavis-forward   unix    -       -       -       -       2       smtp
   -o smtp_tls_security_level=none
   -o smtp_data_done_timeout=1200
   -o smtp_send_xforward_command=yes
   -o disable_dns_lookups=yes
   -o max_use=20
...

超過 :10024 一切正常。我該如何解決?

免責聲明:這是一半的答案,因為我可以在 postfix -> amavis 時使用套接字,但在 amavis -> postfix 時我不能使用它。請參閱此答案末尾的解釋。

要使用套接字,您應該使用 LMTP 而不是 SMTP 將電子郵件從 postfix 傳遞到 amavis。

正如上面 NickW 所說,您需要將 amavis 套接字放在 Postfix 隊列目錄中。在這個答案中,我假設後綴隊列目錄是 /var/spool/postfix/.

創建目錄來保存 amavis 套接字

mkdir /var/spool/postfix/amavis/
chmod 750 /var/spool/postfix/amavis/
chown amavis:amavis /var/spool/postfix/amavis/

在 amavis 組中添加 postfix 使用者

usermod -G amavis postfix

配置在amavisd.conf

# for socket, it should reside in /var/spool/postfix
$unix_socketname = "/var/spool/postfix/amavis/amavisd.sock";

# set permission so amavis group can access this socket
$unix_socket_mode = 0660;

# Replace $interface_policy{'SOCK'} = 'AM.PDP';

$interface_policy{'SOCK'} = 'mysock';
$policy_bank{'mysock'} = {
  protocol => 'LMTP',
  auth_required_release => 0, # don't require secret-id for release
};

後綴 main.cf

content_filter = amavis-forward:unix:amavis/amavisd.sock

後綴 master.cf

# Amavis
amavis-forward   unix    -       -       -       -       2       lmtp
   -o lmtp_data_done_timeout=1200
   -o lmtp_send_xforward_command=yes
   -o disable_dns_lookups=yes
   -o max_use=20

結果

amais postfix/smtpd[13393]: connect from localhost[127.0.0.1]
amais postfix/smtpd[13393]: 4E0B82340F: client=localhost[127.0.0.1]
amais postfix/cleanup[13359]: 4E0B82340F: message-id=<20150106070245.4E0B82340F@example.net>
amais postfix/qmgr[13352]: 4E0B82340F: from=<root@example.net>, size=344, nrcpt=1 (queue active)
amais postfix/smtpd[13363]: connect from localhost[127.0.0.1]
amais postfix/smtpd[13363]: 6081E2340B: client=localhost[127.0.0.1]
amais postfix/cleanup[13359]: 6081E2340B: message-id=<20150106070245.4E0B82340F@example.net>
amais postfix/qmgr[13352]: 6081E2340B: from=<root@example.net>, size=688, nrcpt=1 (queue active)
amais postfix/smtpd[13363]: disconnect from localhost[127.0.0.1]
amais postfix/local[13365]: 6081E2340B: to=<root@example.net>, orig_to=<koala@example.net>, relay=local, delay=0.01, delays=0.01/0/0/0.01, dsn=2.0.0, status=sent (delivered to mailbox)
amais postfix/qmgr[13352]: 6081E2340B: removed
amais amavis[13113]: (13113-03) Passed CLEAN {RelayedInbound}, mysock <root@example.net> -> <koala@example.net>, Message-ID: <20150106070245.4E0B82340F@example.net>, mail_id: MLZDzoda7siu, Hits: -, size: 344, queued_as: 6081E2340B, 90 ms
amais postfix/lmtp[13361]: 4E0B82340F: to=<koala@example.net>, relay=example.net[amavis/amavisd.sock], delay=0.11, delays=0.01/0/0.01/0.09, dsn=2.0.0, status=sent (250 2.0.0 from MTA(smtp:[127.0.0.1]:10025): 250 2.0.0 Ok: queued as 6081E2340B)
amais postfix/qmgr[13352]: 4E0B82340F: removed

對於 amavis -> postfix 傳輸,它由參數控制forward_method。除了 smtp,我不熟悉這個配置。在本頁的範例中,該參數支持的協議顯然是 pipe、smtp 和 bsmtp。此外,基於postfix 架構,postfix 只接受來自 smtpd、qmqmd 或 sendmail 的電子郵件。

引用自:https://serverfault.com/questions/656367