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.

Revisions

  1. mihir-kumar-thakur revised this gist Jan 4, 2021. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions sphinx-binary-installation.md
    Original file line number Diff line number Diff line change
    @@ -33,13 +33,13 @@ searchd: /usr/local/bin/searchd
    1. First - create paths we need to store indexes, config files, logs and etc.

    ```bash
    mkdir -p /etc/sphinx /var/run/sphinx /var/log/sphinx /var/lib/sphinx/data
    sudo mkdir -p /etc/sphinx /var/run/sphinx /var/log/sphinx /var/lib/sphinx/data
    ```

    2. Change permission for system user. Change deploy with your system user and group.

    ```bash
    chown -R deploy:deploy /etc/sphinx /var/run/sphinx /var/log/sphinx /var/lib/sphinx
    sudo chown -R deploy:deploy /etc/sphinx /var/run/sphinx /var/log/sphinx /var/lib/sphinx
    ```

    chown user:group
  2. mihir-kumar-thakur revised this gist Jan 4, 2021. No changes.
  3. mihir-kumar-thakur renamed this gist Jan 4, 2021. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  4. mihir-kumar-thakur renamed this gist Jan 4, 2021. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  5. mihir-kumar-thakur created this gist Jan 4, 2021.
    101 changes: 101 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,101 @@
    # Sphinx search 3 installation with binary on Ubuntu for working with Thinking sphinx gem on ruby on rails

    ## Download sphinx with curl

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

    ## Unzip downloaded zip file

    ```bash
    sudo tar -zxvf sphinx.tar.gz
    ```

    ## Move binary to user's bin file

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

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

    ```bash
    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.

    ```bash
    mkdir -p /etc/sphinx /var/run/sphinx /var/log/sphinx /var/lib/sphinx/data
    ```

    2. Change permission for system user. Change deploy with your system user and group.

    ```bash
    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

    3. Creating Systemd service file:

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

    ```bash
    [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
    ```

    4. 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

    ```bash
    #Type Path Mode UID GID Age Argument
    d /var/run/sphinx 0755 deploy deploy - -
    ```

    5. Enable systemd service Enter this to enable system service:

    ```bash
    sudo systemctl enable sphinx
    ```

    You'l get something like:

    ```bash
    Created symlink /etc/systemd/system/sphinx.service → /lib/systemd/system/sphinx.service.
    ```

    6. Now go to rails project with thinking sphinx gem installed and run following commands.

    ```bash
    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](https://github.com/pat/thinking-sphinx) gem