Senario
Here is the script how to create SolrCloud environment in local dev setup: a collection with numShards=2&replicationFactor=3 on 3 separate (local) nodes.
vms_solr_init creates folders: example/cloud/node{1,2,3}/solr, copy solr.xml and zoo.cfg to these folders, starts the server and creates the collection using admin collection apis.
Other scripts which start/stop are easier to implement.
The implementation
Here is the script how to create SolrCloud environment in local dev setup: a collection with numShards=2&replicationFactor=3 on 3 separate (local) nodes.
vms_solr_init creates folders: example/cloud/node{1,2,3}/solr, copy solr.xml and zoo.cfg to these folders, starts the server and creates the collection using admin collection apis.
Other scripts which start/stop are easier to implement.
The implementation
function solr_init()
{
cd $SOLR_HOME
mkdir -p $SOLR_NODE1_REL_HOME
mkdir -p $SOLR_NODE2_REL_HOME
mkdir -p $SOLR_NODE3_REL_HOME
cp $SOLR_HOME/server/solr/solr.xml $SOLR_HOME/server/solr/zoo.cfg $SOLR_NODE1_REL_HOME
cp $SOLR_HOME/server/solr/solr.xml $SOLR_HOME/server/solr/zoo.cfg $SOLR_NODE2_REL_HOME
cp $SOLR_HOME/server/solr/solr.xml $SOLR_HOME/server/solr/zoo.cfg $SOLR_NODE3_REL_HOME
solr_start
data_solr_create
}
function solr_start() {
if [[ `solr_pid` ]]
then
echo "solr is already running...";
else
echo "Starting solr-cloud... $SOLR_NODE1_PORT, $SOLR_NODE2_PORT, $SOLR_NODE3_PORT";
$SOLR_HOME/bin/solr start -cloud -Dsolr.ltr.enabled=true -s "$SOLR_NODE1_REL_HOME" -p $SOLR_NODE1_PORT -h $SOLR_HOSTNAME;
$SOLR_HOME/bin/solr start -cloud -Dsolr.ltr.enabled=true -s "$SOLR_NODE2_REL_HOME" -p $SOLR_NODE2_PORT -z $SOLR_ZKHOST -h $SOLR_HOSTNAME;
$SOLR_HOME/bin/solr start -cloud -Dsolr.ltr.enabled=true -s "$SOLR_NODE3_REL_HOME" -p $SOLR_NODE3_PORT -z $SOLR_ZKHOST -h $SOLR_HOSTNAME;
fi
}
function solr_stop() {
echo "Stopping solr-cloud...";
$SOLR_HOME/bin/solr stop -all;
}
function solr_restart() {
echo "Restarting solr-cloud...";
solr_stop && solr_start
}
function solr_pid() {
pgrep -f "solr-6.4.0/server";
}
function data_solr_create() {
# Go to the solr config directory
currdir=`pwd`;
cd "$WS/resource/solr";
# Retrieve list of collections
collections_list=`curl -s -v -X GET -H 'Content-type:application/json' "$SOLR_NODE1_PORT/admin/collections?action=LIST&wt=json" | jq '.collections | join(" ")' `;
# Create/update schema
mv solrconfig solrconfig.old.`datetimestamp`;
unzip -d solrconfig solr-core-config.zip;
# create myCollection
cp myCollection_solrconfig.xml solrconfig/conf/solrconfig.xml;
cp myCollection_schema.xml solrconfig/conf/schema.xml;
$SOLR_HOME/server/scripts/cloud-scripts/zkcli.sh -zkhost "$SOLR_ZKHOST" -cmd upconfig -confname myCollection -confdir "solrconfig/conf/";
if grep -q "myCollection" <<< $collections_list; then
curl -s -v -X GET "$SOLR_NODE1_ENDPOINT/admin/collections?action=RELOAD&name=myCollection";
echo "Updated myCollection";
else
curl -s -v -X GET "$SOLR_NODE1_ENDPOINT/admin/collections?action=CREATE&name=myCollection
&numShards=2&collection.configName=myCollection&replicationFactor=3&maxShardsPerNode=2";
echo "Created myCollection";
fi
rm -rf solrconfig;
cd $currdir;
}