/
/
Installing and configuring Rspamd in ispmanager 6

Installing and configuring Rspamd in ispmanager 6

Rspamd is a modern alternative to SpamAssassin: it offers higher performance, consumes less RAM, supports DKIM, SPF, DMARC, and ARC checks, and includes built-in modules for handling blacklists (RBL), whitelists, and Bayesian learning.

Preparation

Before installing and configuring Rspamd, remove SpamAssassin.

First, create a backup of the SpamAssassin and Exim configuration files:

cp -ar /etc/spamassassin /root/backup/spamassassin_backup
cp -ar /etc/exim4 /root/backup/exim4_backup
cp -ar /etc/mail/spamassassin /root/backup/spamassassin_backup
cp -ar /etc/exim /root/backup/exim4_backup

Stop the SpamAssassin service and disable its autostart:

systemctl stop spamassassin spamd
systemctl disable spamassassin spamd

Disable SpamAssassin in the control panel under Software configuration - Mail server.

Installing and configuring Rspamd

Before installation, add the Rspamd repository:

curl -fsSL https://rspamd.com/apt-stable/gpg.key | \
sudo gpg --dearmor -o /usr/share/keyrings/rspamd.gpg

echo "deb [signed-by=/usr/share/keyrings/rspamd.gpg] https://rspamd.com/apt-stable/ $(lsb_release -cs) main" | \
sudo tee /etc/apt/sources.list.d/rspamd.list
curl -sSL https://rspamd.com/rpm-stable/<centos-release>/rspamd.repo | \
sudo tee /etc/yum.repos.d/rspamd.repo

Replace <centos-release> with the value corresponding to your OS:

  • centos-7 - for CentOS 7
  • centos-8 - for AlmaLinux 8, CloudLinux 8, RockyLinux 8
  • centos-9 - for AlmaLinux 9, CloudLinux 9
  • centos-10 - for AlmaLinux 10, CloudLinux 10

Rspamd requires Redis to function; install Redis and Rspamd using the following commands:

apt install rspamd redis-server -y
dnf install rspamd redis

Create files for local Rspamd overrides:

cd /etc/rspamd/local.d/
touch worker-normal.inc worker-proxy.inc redis.conf classifier-bayes.conf

Add the following line to the worker-normal.inc file:

bind_socket = "127.0.0.1:11333";

Add the following lines to the worker-proxy.inc file:

bind_socket = "127.0.0.1:11332";
milter = yes;
timeout = 120s;
upstream "local" {
  default = yes;
  self_scan = yes;
}

Add the following line to the redis.conf file:

servers = "127.0.0.1";

Add the following lines to the classifier-bayes.conf file:

backend = "redis";
servers = "127.0.0.1";
autolearn = true;

Enable autostart and start Rspamd and the Redis server:

systemctl enable --now rspamd redis-server 

Verify that Rspamd is listening on port 11333:

ss -tlnp | grep 11333

Configuring Exim

For Exim, modify the parameters responsible for integration with SpamAssassin.

First, ensure that the line SA_ENABLE = yes is present in the Exim configuration file:

cat /etc/exim4/exim4.conf.template | grep "SA_ENABLE = yes"
cat /etc/exim/exim.conf | grep "SA_ENABLE = yes"

Update the value of the spamd_address parameter:

sed -i "s/spamd_address = 127.0.0.1 783/spamd_address = 127.0.0.1 11333 variant=rspamd/g" /etc/exim4/exim4.conf.template
sed -i "s/spamd_address = 127.0.0.1 783/spamd_address = 127.0.0.1 11333 variant=rspamd/g" /etc/exim/exim.conf

In the configuration file, replace the entire SA_ENABLE block—which follows immediately after the VIRUS_SCAN block—with the following configuration:

.ifdef SA_ENABLE
        warn
            !authenticated = *
            hosts = !+relay_from_hosts
            spam       = nobody:true/defer_ok
            add_header = X-Spam-Score: $spam_score ($spam_bar)
            add_header = X-Spam-Report: $spam_report
            set acl_m4 = $spam_score_int

        deny
            condition  = ${if and{{!eq{$acl_m4}{}}{>{$acl_m4}{SA_SCORE_REJECT}}}{yes}{no}}
            message    = Content analysis detected spam (from $sender_address to $recipients). Contact SA_ABUSE_ADDR.
.endif

Check the configuration syntax for correctness:

exim4 -C /etc/exim4/exim4.conf.template -bV
exim -C /etc/exim/exim.conf -bV

If any syntax errors are reported, check the configuration file for errors and fix them. Once the check shows no errors, restart the Exim service:

systemctl restart exim4
systemctl restart exim

Bayesian learning

Rspamd supports Bayesian learning: it allows Rspamd to learn from actual emails—both spam and legitimate messages ("ham")—which improves and accelerates spam filtering.

Before starting the learning process, it is highly recommended to collect a sufficient number of various email samples in at least one of your mailboxes.

To train the system using spam messages, use the following command:

rspamc learn_spam /var/www/<username>/data/email/<mail_domain>/<mailbox_name>/.maildir/.Junk/cur/

To train the system using legitimate (ham) messages, use the following command:

rspamc learn_spam /var/www/<username>/data/email/<mail_domain>/<mailbox_name>/.maildir/cur/

To verify that data has been written to Redis, run the following command:

redis-cli keys 'RS*' | head -20

To view current training statistics, use the following command:

rspamc stat | grep -A5 -i bayes