Skip to content

Instantly share code, notes, and snippets.

@mihir-kumar-thakur
Last active June 1, 2021 15:33
Show Gist options
  • Save mihir-kumar-thakur/8a75da2f50894b8d93aff7a42212467a to your computer and use it in GitHub Desktop.
Save mihir-kumar-thakur/8a75da2f50894b8d93aff7a42212467a to your computer and use it in GitHub Desktop.
Sphinx search 3 installation with binary on Ubuntu for working with Thinking sphinx gem on ruby on rails

Sphinx search 3 installation with binary on Ubuntu for working with Thinking sphinx gem on ruby on rails

Download sphinx with curl

curl http://sphinxsearch.com/files/sphinx-3.3.1-b72d67b-linux-amd64.tar.gz -o sphinx.tar.gz

Unzip downloaded zip file

sudo tar -zxvf sphinx.tar.gz

Move binary to user's bin file

sudo mv sphinx-3.3.1/bin/* /usr/local/bin/.

Test that searchd - SphinxSearch daemon binary now exists in your system

whereis searchd

This command will output following

searchd: /usr/local/bin/searchd

Configurations

  1. First - create paths we need to store indexes, config files, logs and etc.
sudo mkdir -p /etc/sphinx /var/run/sphinx /var/log/sphinx /var/lib/sphinx/data
  1. Change permission for system user. Change deploy with your system user and group.
sudo chown -R deploy:deploy /etc/sphinx /var/run/sphinx /var/log/sphinx /var/lib/sphinx

chown user:group https://linuxize.com/post/linux-chown-command

  1. Creating Systemd service file:

Create this file /lib/systemd/system/sphinx.service and put following code

[Unit]
Description=Sphinx Search - Fast standalone full-text SQL search engine
After=network.target

[Service]
ExecStart=/usr/local/bin/searchd --config /etc/sphinx/sphinx.conf
ExecStop=/usr/local/bin/searchd --stop
KillMode=process
Restart=on-failure
PIDFile=/var/run/sphinx/sphinx.pid
User=sphinx
Group=sphinx

[Install]
WantedBy=multi-user.target
Alias=sphinx.service
  1. File, indicating our OS to restore /var/run/sphinx folder with write permissions for sphinx user:

Create this file - /usr/lib/tmpfiles.d/sphinx.conf and put following code

#Type Path           Mode   UID      GID    Age Argument
d /var/run/sphinx    0755   deploy  deploy   -   -
  1. Enable systemd service Enter this to enable system service:
sudo systemctl enable sphinx

You'l get something like:

Created symlink /etc/systemd/system/sphinx.service → /lib/systemd/system/sphinx.service.
  1. Now go to rails project with thinking sphinx gem installed and run following commands.
bundle exec rake ts:clear
bundle exec rake ts:configure
bundle exec rake ts:start
bundle exec rake ts:index

Now sphinx should be running with thinking sphinx gem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment