diff --git a/README.md b/README.md index 6477abad..1033e5d1 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ Functionality changes and additions enable postfix filters, lengthen bantime and findtime * Add fail2ban jails for both above mentioned geoipblocking filters * Add fail2ban filters for web scanners and badbots -* Add solr full text searching to dovecot +* Add xapian full text searching to dovecot * Add rkhunter and chkrootkit * Configure domain names for which only www will be hosted. Edit /etc/miabwwwdomains.conf to configure. * Add some munin plugins diff --git a/conf/cron/miab_dovecot b/conf/cron/miab_dovecot index 869ca377..7144b8f0 100644 --- a/conf/cron/miab_dovecot +++ b/conf/cron/miab_dovecot @@ -1,2 +1,3 @@ #!/bin/bash /usr/bin/doveadm fts rescan -A > /dev/null 2>&1 +/usr/bin/doveadm fts optimize -A > /dev/null 2>&1 diff --git a/conf/cron/miab_solr b/conf/cron/miab_solr deleted file mode 100644 index 7dafd5cc..00000000 --- a/conf/cron/miab_solr +++ /dev/null @@ -1,2 +0,0 @@ -1 */1 * * * root /usr/bin/curl -s http://127.0.0.1:8983/solr/update?commit=true >/dev/null 2>&1 -30 3 * * * root /usr/bin/curl -s http://127.0.0.1:8983/solr/update?optimize=true >/dev/null 2>&1 diff --git a/conf/solr/solr-config-7.7.0.xml b/conf/solr/solr-config-7.7.0.xml deleted file mode 100644 index 3661874d..00000000 --- a/conf/solr/solr-config-7.7.0.xml +++ /dev/null @@ -1,289 +0,0 @@ - - - - - - - 7.7.0 - - - - - - - - - - - - - - - - ${solr.data.dir:} - - - - - - - ${solr.ulog.dir:} - ${solr.ulog.numVersionBuckets:65536} - - - - - ${solr.autoCommit.maxTime:15000} - false - - - - - ${solr.autoSoftCommit.maxTime:-1} - - - - - - - - - - - - - - - - - - - - - - - - true - - - 20 - - - 200 - - - false - - - - - - - - - - - - - - - explicit - 10 - - - - - - _text_ - - - - - - diff --git a/conf/solr/solr-jetty.xml b/conf/solr/solr-jetty.xml deleted file mode 100644 index 27de9994..00000000 --- a/conf/solr/solr-jetty.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - /solr - /usr/share/solr/web - - - - solr.solr.home - /usr/share/solr - - - - - diff --git a/conf/solr/solr-schema-7.7.0.xml b/conf/solr/solr-schema-7.7.0.xml deleted file mode 100644 index 601a290c..00000000 --- a/conf/solr/solr-schema-7.7.0.xml +++ /dev/null @@ -1,48 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - id - diff --git a/conf/solr/solr.service b/conf/solr/solr.service deleted file mode 100644 index ba336584..00000000 --- a/conf/solr/solr.service +++ /dev/null @@ -1,20 +0,0 @@ -[Unit] -Description=Apache SOLR -After=network.target - -[Service] -Type=forking -User=solr -Environment=SOLR_INCLUDE=/etc/default/solr.in.sh -ExecStart=/usr/local/lib/solr/bin/solr start -ExecStop=/usr/local/lib/solr/bin/solr stop -Restart=on-failure -#ReadWritePaths=/var/lib/solr/ -#ReadWritePaths=/var/lib/solr/data/ -LimitNOFILE=65000 -LimitNPROC=65000 -TimeoutSec=180s -PrivateTmp=true - -[Install] -WantedBy=multi-user.target diff --git a/lib/howto_build_xapian.txt b/lib/howto_build_xapian.txt new file mode 100644 index 00000000..85a8dd92 --- /dev/null +++ b/lib/howto_build_xapian.txt @@ -0,0 +1,15 @@ +# Install required packages +apt-get build-dep dovecot-core +apt-get install dovecot-dev libxapian-dev git libxapian30 libicu-dev + +# Clone the project +git clone https://github.com/grosjo/fts-xapian +cd fts-xapian + +# Compile (don't install) +autoreconf -vi +./configure --with-dovecot=/usr/lib/dovecot +make + +# install library found under src/.libs +cp src/.libs/lib21_fts_xapian_plugin.so /usr/lib/dovecot/modules \ No newline at end of file diff --git a/lib/lib21_fts_xapian_plugin.so b/lib/lib21_fts_xapian_plugin.so new file mode 100755 index 00000000..65087e65 Binary files /dev/null and b/lib/lib21_fts_xapian_plugin.so differ diff --git a/management/status_checks.py b/management/status_checks.py index 73283249..e73b0d17 100755 --- a/management/status_checks.py +++ b/management/status_checks.py @@ -40,7 +40,6 @@ def get_services(): { "name": "Mail Filters (Sieve/dovecot)", "port": 4190, "public": True, }, { "name": "HTTP Web (nginx)", "port": 80, "public": True, }, { "name": "HTTPS Web (nginx)", "port": 443, "public": True, }, - { "name": "Solr Full Text Search", "port": 8983, "public": False, }, ] def run_checks(rounded_values, env, output, pool): diff --git a/setup/dovecot-fts-xapian.sh b/setup/dovecot-fts-xapian.sh new file mode 100644 index 00000000..655ab886 --- /dev/null +++ b/setup/dovecot-fts-xapian.sh @@ -0,0 +1,86 @@ +#!/bin/bash +# +# IMAP search with xapian +# -------------------------------- +# +# By default dovecot uses its own Squat search index that has awful performance +# on large mailboxes and is obsolete. Dovecot 2.1+ has support for using Lucene +# internally but this didn't make it into the Ubuntu packages. Solr uses too +# much memory. Same goes for elasticsearch. fts xapian might be a good match +# for mail-in-a-box. See https://github.com/grosjo/fts-xapian + +source setup/functions.sh # load our functions +source /etc/mailinabox.conf # load global vars + +# Install packages and basic configuation +# --------------------------------------- + +echo "Installing fts-xapian..." + +apt_install libxapian30 + +# Update the dovecot plugin configuration +# +# Break-imap-search makes search work the way users expect, rather than the way +# the IMAP specification expects. +tools/editconf.py /etc/dovecot/conf.d/10-mail.conf \ + mail_plugins="fts fts_xapian" \ + mail_home="/home/user-data/mail/homes/%d/%n" + +# Install cronjobs to keep FTS up to date. +hide_output install -m 755 conf/cron/miab_dovecot /etc/cron.daily/ + +# Install files +if [ ! -f /usr/lib/dovecot/decode2text.sh ]; then + cp -f /usr/share/doc/dovecot-core/examples/decode2text.sh /usr/lib/dovecot +fi + +cp -f lib/lib21_fts_xapian_plugin.so /usr/lib/dovecot/modules/ + +# Create configuration file +cat > /etc/dovecot/conf.d/90-plugin-fts.conf << EOF; +plugin { + plugin = fts fts_xapian + + fts = xapian + fts_xapian = partial=3 full=20 verbose=0 + + fts_autoindex = yes + fts_enforced = yes + + fts_autoindex_exclude = \Trash + fts_autoindex_exclude2 = \Junk + fts_autoindex_exclude3 = \Spam + + fts_decoder = decode2text +} + +service indexer-worker { + vsz_limit = 2G +} + +service decode2text { + executable = script /usr/lib/dovecot/decode2text.sh + user = dovecot + unix_listener decode2text { + mode = 0666 + } +} +EOF + +restart_service dovecot + +# Kickoff building the index + +# Per doveadm-fts manpage: Scan what mails exist in the full text search index +# and compare those to what actually exist in mailboxes. +# This removes mails from the index that have already been expunged and makes +# sure that the next doveadm index will index all the missing mails (if any). +doveadm fts rescan -A + +# Adds unindexed files to the fts database +# * `-q`: Queues the indexing to be run by indexer process. (will background the indexing) +# * `-A`: All users +# * `'*'`: All folders +doveadm index -q -A '*' + diff --git a/setup/solr.sh b/setup/solr.sh deleted file mode 100644 index caab1bef..00000000 --- a/setup/solr.sh +++ /dev/null @@ -1,166 +0,0 @@ -#!/bin/bash -# -# IMAP search with lucene via solr -# -------------------------------- -# -# By default dovecot uses its own Squat search index that has awful performance -# on large mailboxes. Dovecot 2.1+ has support for using Lucene internally but -# this didn't make it into the Ubuntu packages, so we use Solr instead to run -# Lucene for us. -# -# Solr runs as a Jetty process. The dovecot solr plugin talks to solr via its -# HTTP interface, searching indexed mail and returning results back to dovecot. -# -# Based on https://forum.iredmail.org/topic17251-dovecot-fts-full-text-search-using-apache-solr-on-ubuntu-1804-lts.html -# https://doc.dovecot.org/configuration_manual/fts/solr/ and https://solr.apache.org/guide/8_8/installing-solr.html -# -# solr-jetty package is removed from Ubuntu 21.04 onward. This installation -# therefore depends on manual installation of solr instead of an ubuntu package - -source setup/functions.sh # load our functions -source /etc/mailinabox.conf # load global vars - -# Install packages and basic configuation -# --------------------------------------- - -echo "Installing Solr..." - -apt_install dovecot-solr default-jre-headless - -VERSION=8.8.2 -HASH=7c3e2ed31a4412e7dac48d68c3abd52f75684577 - -needs_update=0 - -if [ ! -f /usr/local/lib/solr/bin/solr ]; then - # not installed yet - needs_update=1 -elif [[ "$VERSION" != `/usr/local/lib/solr/bin/solr version` ]]; then - # checks if the version is what we want - needs_update=1 -fi - -if [ $needs_update == 1 ]; then - # install SOLR - wget_verify \ - "https://www.apache.org/dyn/closer.lua?action=download&filename=lucene/solr/$VERSION/solr-$VERSION.tgz" \ - $HASH \ - /tmp/solr-$VERSION.tgz - - tar xzf /tmp/solr-$VERSION.tgz -C /tmp solr-$VERSION/bin/install_solr_service.sh --strip-components=2 - # install to usr/local, force update, do not start service on installation complete - bash /tmp/install_solr_service.sh /tmp/solr-$VERSION.tgz -i /usr/local/lib -f -n - - rm -f /tmp/solr-$VERSION.tgz - rm -f /tmp/install_solr_service.sh - - # stop and remove the init.d script - rm -f /etc/init.d/solr - update-rc.d solr remove -fi - -# Add security -tools/editconf.py /etc/default/solr.in.sh \ - SOLR_IP_WHITELIST='"127.0.0.1, [::1]"' - -# Change log dir -if [ ! -d "/var/log/solr" ]; then - mkdir /var/log/solr -fi - -chown solr:solr /var/log/solr - -tools/editconf.py /etc/default/solr.in.sh \ - SOLR_LOGS_DIR="/var/log/solr" - -# Install systemd service -cp -f conf/solr/solr.service /lib/systemd/system/solr.service -# hide_output systemctl link -f /lib/systemd/system/solr.service - -# Reload systemctl to pickup the above changes -hide_output systemctl daemon-reload - -# Make sure service is enabled -hide_output systemctl enable solr.service - -# Update the dovecot plugin configuration -# -# Break-imap-search makes search work the way users expect, rather than the way -# the IMAP specification expects. -# https://wiki.dovecot.org/Plugins/FTS/Solr -# "break-imap-search : Use Solr also for indexing TEXT and BODY searches. -# This makes your server non-IMAP-compliant." -tools/editconf.py /etc/dovecot/conf.d/10-mail.conf \ - mail_plugins="fts fts_solr" - -cat > /etc/dovecot/conf.d/90-plugin-fts.conf << EOF; -plugin { - fts = solr - fts_autoindex = yes - fts_solr = url=http://127.0.0.1:8983/solr/dovecot/ -} -EOF - -# Install cronjobs to keep FTS up to date. -hide_output install -m 755 conf/cron/miab_dovecot /etc/cron.daily/ -hide_output install -m 644 conf/cron/miab_solr /etc/cron.d/ - -# Initialize solr dovecot instance -if [ ! -d "/var/solr/data/dovecot" ]; then - # Starting solr might take a while - echo "Starting solr..." - hide_output systemctl restart solr.service - - sudo -u solr /usr/local/lib/solr/bin/solr create -c dovecot - rm -f /var/solr/data/dovecot/conf/schema.xml - rm -f /var/solr/data/dovecot/conf/managed-schema - rm -f /var/solr/data/dovecot/conf/solrconfig.xml - cp -f conf/solr/solr-config-7.7.0.xml /var/solr/data/dovecot/conf/solrconfig.xml - cp -f conf/solr/solr-schema-7.7.0.xml /var/solr/data/dovecot/conf/schema.xml - chown -R solr:solr /var/solr/data/dovecot/conf/* -fi - -# Create new rsyslog config for solr -cat > /etc/rsyslog.d/10-solr.conf < /etc/logrotate.d/solr-systemd <