Skip to content

Example Solr Setup (Ubuntu)

Angel Sanadinov edited this page May 9, 2017 · 3 revisions

Setup: Elasticsearch | Redis | Solr

These are example steps for setting up a Solr instance on Ubuntu. They will create a user solr, download version 6.3.0, install it under /opt/solr and add config under /opt/solr/<org>.

<org> should be replaced with some identifier (your organization, user, etc).

Create user

useradd -d /home/solr -m solr

Download

cd /tmp
wget http://apache.belnet.be/lucene/solr/6.3.0/solr-6.3.0.tgz
tar -xvf solr-6.3.0.zip
sudo mkdir /opt/solr
sudo cp -R /tmp/solr-6.3.0/* /opt/solr
sudo mkdir -p /opt/solr/<org>/node1/solr
sudo cp /opt/solr/server/solr/*.* /opt/solr/<org>/node1/solr/

Configure

# ... add service script ...
sudo touch /opt/solr/<org>/com-<org>-solr.sh

# ... start service ...
sudo service com-<org>-solr start

# ... create default shard ...
sudo su - solr -c "/opt/solr/bin/solr create -c "default" -shards 1"

# ... add security config ...
# add/edit in /opt/solr/security.json

# ... put file on Solr ...
sudo /opt/solr/server/scripts/cloud-scripts/zkcli.sh -zkhost localhost:9983 -cmd putfile /security.json /opt/solr/security.json

# ... add new user and remote default ...
curl --user solr:SolrRocks http://localhost:8983/solr/admin/authentication -H "Content-type:application/json" -d "{\"set-user\":{\"<some user>\":\"<some password>\"}}"
curl --user solr:SolrRocks http://localhost:8983/solr/admin/authorization -H "Content-type:application/json" -d "{\"set-user-role\": {\"<some user>\":\"admin\"}}"
curl --user solr:SolrRocks http://localhost:8983/solr/admin/authentication -H "Content-type:application/json" -d  "{\"delete-user\": \"solr\"}"
curl --user <some user>:<some password> http://localhost:8983/solr/admin/authorization -H "Content-type:application/json" -d "{\"set-user-role\": {\"solr\":null}}"

sudo chown -R solr:solr /opt/solr
sudo chmod 700 /opt/solr/<org>/com-<org>-solr.sh
sudo ln -s /opt/solr/<org>/com-<org>-solr.sh /etc/init.d/com-<org>-solr
sudo update-rc.d com-<org>-solr defaults 97 03

Tested with

  • Ubuntu 16.04
  • Solr 6.3.0

security.json

{
  "authentication":{
    "class":"solr.BasicAuthPlugin",
    "credentials":{
      "solr":"IV0EHq1OnNrj6gvRCwvFwTrZ1+z1oBbnQdiVC3otuq0= Ndd7LKvVBAaZIF0QAVi1ekCfAJXr1GGfLtRUXhgrF8c="
    }
  },
  "authorization":{
    "class":"solr.RuleBasedAuthorizationPlugin",
    "user-role":{"solr":"admin"},
    "permissions":[
      {"name":"security-edit", "role":"admin"},
      {"name":"security-read", "role":"admin"},
      {"name":"schema-edit", "role":"admin"},
      {"name":"schema-read", "role":"admin"},
      {"name":"config-read", "role":"admin"},
      {"name":"config-edit", "role":"admin"},
      {"name":"collection-admin-read", "role":"admin"},
      {"name":"collection-admin-edit", "role":"admin"},
      {"name":"update", "role":"admin"},
      {"name":"read", "role":"query"}
    ]
  }
}

Service script

Replace <org> with your organization name (or something else)

#! /bin/sh
### BEGIN INIT INFO
# Provides: com-<org>-solr
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 3 4 5
# Default-Stop: 0 1 2 6
# Short-Description: solr
# Description: This file starts and stops a single (node1) SolrCloud instance
### END INIT INFO

case "$1" in
    start)
        su solr -c "/opt/solr/bin/solr start -cloud -s /opt/solr/<org>/node1/solr"
        ;;
    stop)
        su solr -c "/opt/solr/bin/solr stop -all"
        ;;
    restart)
        su solr -c "/opt/solr/bin/solr stop -all"
        su solr -c "/opt/solr/bin/solr start -cloud -s /opt/solr/<org>/node1/solr"
        ;;
    status)
        1
        ;;
    *)
        echo "Usage: com-<org>-solr.sh {start|stop|restart}" >&2
        exit 3
        ;;
esac

Clone this wiki locally