Skip to content

Instantly share code, notes, and snippets.

@nazarii-piontko
Last active April 25, 2021 12:22
Show Gist options
  • Save nazarii-piontko/9823ec9a11d6d1dfd8a0cf57c75e1c76 to your computer and use it in GitHub Desktop.
Save nazarii-piontko/9823ec9a11d6d1dfd8a0cf57c75e1c76 to your computer and use it in GitHub Desktop.
Bash script that install Sphinxsearch 3.0.3 on Ubuntu system
#!/bin/bash
# Sphinxsearch 3.0.3 install script for Ubuntu.
# It downloads sphinxsearch 3.0.3 and installs as daemon with dummy configuration.
# http://sphinxsearch.com
set -e
# Package manager update and recommended packages installation
apt-get update -y
apt-get install -y wget mysql-client libmysqlclient-dev cron
# Sphinx 3.0.3 installation
wget -O sphinx.tar.gz http://sphinxsearch.com/files/sphinx-3.0.3-facc3fb-linux-amd64-glibc2.12.tar.gz
tar -zxf sphinx.tar.gz && rm sphinx.tar.gz
chmod +x sphinx-3.0.3/bin/*
mv sphinx-3.0.3/bin/* /usr/bin
rm -rf sphinx-3.0.3
# Create user account for sphinx daemon
useradd -r -s /bin/false sphinx
# Create directories
mkdir /etc/sphinx
mkdir -p /var/sphinx/data && chown sphinx:sphinx -R /var/sphinx
mkdir -p /var/log/sphinx && chown sphinx:sphinx /var/log/sphinx
# Make default configuration file
cat > /etc/sphinx/sphinx.conf << EOF
source src
{
type = csvpipe
csvpipe_command = cat /var/sphinx/sample.csv
csvpipe_field_string= title
csvpipe_field_string= content
}
index test
{
source = src
path = /var/sphinx/data/test
}
indexer
{
mem_limit = 128M
}
searchd
{
listen = 9312
listen = 9306:mysql41
log = /var/log/sphinx/searchd.log
query_log = /var/log/sphinx/query.log
read_timeout = 5
max_children = 30
pid_file = /var/sphinx/searchd.pid
seamless_rotate = 1
preopen_indexes = 1
unlink_old = 1
binlog_path = /var/sphinx/
}
EOF
# Make test index
cat > /var/sphinx/sample.csv << EOF
"2499832633136058001","Lorem Ipsum","Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi et libero neque. Mauris magna neque, hendrerit eget elit vel, lobortis elementum nibh. In porttitor pretium lectus, tincidunt posuere ante varius rutrum."
"2499832633136058002","Lorem Ipsum","Mauris commodo, felis eu tempus feugiat, nisl eros iaculis justo, eu efficitur eros ligula blandit urna."
"2499832633136058003","Lorem Ipsum","Praesent sed mauris id tellus hendrerit posuere. Curabitur id vehicula quam, et lobortis orci. Vestibulum vitae felis sollicitudin, tempor nibh in, mattis lorem."
EOF
chown sphinx:sphinx /var/sphinx/sample.csv
# Register sphinx at systemd
cat > /etc/systemd/system/sphinx.service << EOF
[Unit]
Description=Sphinxsearch 3.0.3
[Service]
Type=forking
User=sphinx
Group=sphinx
PIDFile=/var/sphinx/searchd.pid
ExecStart=/usr/bin/searchd --config /etc/sphinx/sphinx.conf
[Install]
WantedBy=multi-user.target
EOF
systemctl enable sphinx.service
# Run indexer. searchd woun't start on empty data directory
sudo -u sphinx indexer --config /etc/sphinx/sphinx.conf --all
sudo -u sphinx indextool --config /etc/sphinx/sphinx.conf --check test
# Start sphinx
systemctl start sphinx
systemctl status sphinx
@nazarii-piontko
Copy link
Author

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