Thursday, July 26, 2018

Milter opendkim error connecting to filter connection refused by localhost


VM Ubuntu server 16.04 lts, Postfix, Opendkim, Clamav, Mysql, Roundcube, Apache2, SSL Lets Encrypt ( tanpa Dovecot )

Masalah ini diketahui saat menjalankan perintah,
# service postfix status
Kemudian masalah ini terlihat dengan keterangan sbb:
warning : connect to Milter service inet:localhost:12301: Connection refused
...yang menyebabkan masalah ini adalah Milter (Opendkim), saat di cek service-nya running, normal
# service opendkim status
namun saat di cek dengan, maka kelihatan Opendkim is not listening on port 12301
# netstat -tulnp | grep opendkim
# ' No result'
Solusinya :
  1. Cek konfigurasi opendkim, perbaiki bila ada kesalahan konfigurasi,
  2. # cat /etc/opendkim.conf
    Restart opendkim dan cek statusnya.
  3. Jika masih bermasalah, maka lakukan ini, gunakan editor yang biasa anda gunakan,
  4. # nano /etc/systemd/system/multi-user.target.wants/opendkim.service
# If you are using OpenDKIM with SQL datasets it might be necessary to start OpenDKIM after the database servers.
# For example, if using both MariaDB and PostgreSQL, change "After=" in the "[Unit]" section to:
# After=network.target nss-lookup.target syslog.target mariadb.service postgresql.service

[Unit]
Description=DomainKeys Identified Mail (DKIM) Milter
Documentation=man:opendkim(8) man:opendkim.conf(5) man:opendkim-genkey(8) man:opendkim-genzone(8) man:opendkim-testadsp(8) ma$
After=network.target nss-lookup.target

[Service]
Type=forking
EnvironmentFile=-/etc/default/opendkim
PIDFile=/var/run/opendkim/opendkim.pid
PermissionsStartOnly=true
User=opendkim
Group=opendkim
ExecStartPre=-/bin/mkdir -p /var/run/opendkim
ExecStartPre=-/bin/chown opendkim.opendkim /var/run/opendkim
#ExecStart=/usr/sbin/opendkim -x /etc/opendkim.conf -u opendkim -P /var/run/opendkim/opendkim.pid -p $SOCKET $DAEMON_OPTS
ExecStart=/usr/sbin/opendkim -x /etc/opendkim.conf -u opendkim -P /var/run/opendkim/opendkim.pid -p inet:12301@localhost
TimeoutStartSec=10
ExecReload=/bin/kill -USR1 $MAINPID

[Install]
WantedBy=multi-user.target
Dan edit di line ini, add inet:port@localhost sehingga menjadi,
#ExecStart=/usr/sbin/opendkim -x /etc/opendkim.conf -u opendkim -P /var/run/opendkim/opendkim.pid -p $SOCKET $DAEMON_OPTS
ExecStart=/usr/sbin/opendkim -x /etc/opendkim.conf -u opendkim -P /var/run/opendkim/opendkim.pid -p inet:12301@localhost
Save dan reload opendkim, cek ulang dengan netstat,
Warning: opendkim.service changed on disk. Run 'systemctl daemon-reload' to reload units.
root@smtp-ubuntu:/etc# systemctl daemon-reload
root@smtp-ubuntu:/etc# service opendkim restart
root@smtp-ubuntu:/etc# netstat -tulnp | grep opendkim
tcp        0      0 127.0.0.1:12301         0.0.0.0:*               LISTEN      9754/opendkim

Done. Problem solved.