注意:本文档配置的为root用户集群操作脚本,如果要配置其他用户请修改相关配置。

SolrCloud启动脚本(start-solr-cloud)

  1. sudo su
  2. cd /bin
  3. vi start-solr-cloud

脚本内容如下:

  1. #!/bin/bash
  2. SOLR_HOME=/home/vagrant/datas/solrcloud/solr-7.7.2
  3. # 启动SolrCloud
  4. echo "start SolrCloud-------------------------------------------------"
  5. for i in bigdata-node1 bigdata-node2 bigdata-node3
  6. do
  7. ssh $i "source /etc/profile;${SOLR_HOME}/bin/solr start -cloud -force"
  8. done
  9. sleep 3s
  10. echo "start done..."
  11. # 检查SolrCloud状态
  12. echo "SolrCloud status------------------------------------------------"
  13. for i in bigdata-node1 bigdata-node2 bigdata-node3
  14. do
  15. echo ------------------- $i --------------
  16. ssh $i "source /etc/profile;${SOLR_HOME}/bin/solr status"
  17. done
  18. exit 0

设置脚本执行权限:

  1. chmod +x start-solr-cloud

SolrCloud(HDFS)启动脚本(_start-solr-hdfscloud)_

  1. sudo su
  2. cd /bin
  3. vi start-solr-hdfscloud

脚本内容如下:

  1. #!/bin/bash
  2. SOLR_HOME=/home/vagrant/datas/solrcloud/solr-7.7.2
  3. # 启动SolrCloud
  4. echo "start SolrCloud(HDFS)-------------------------------------------------"
  5. for i in bigdata-node1 bigdata-node2 bigdata-node3
  6. do
  7. ssh $i "source /etc/profile;${SOLR_HOME}/bin/solr start -c -Dsolr.directoryFactory=HdfsDirectoryFactory -Dsolr.lock.type=hdfs -Dsolr.hdfs.home=hdfs://bigdata-node1:9000/solr -force"
  8. done
  9. sleep 3s
  10. echo "start done..."
  11. # 检查SolrCloud状态
  12. echo "SolrCloud status------------------------------------------------"
  13. for i in bigdata-node1 bigdata-node2 bigdata-node3
  14. do
  15. echo ------------------- $i --------------
  16. ssh $i "source /etc/profile;${SOLR_HOME}/bin/solr status"
  17. done
  18. exit 0

设置脚本执行权限:

  1. chmod +x start-solr-hdfscloud

SolrCloud重启脚本(restart-solr-cloud)

  1. sudo su
  2. cd /bin
  3. vi restart-solr-cloud

脚本内容如下:

  1. #!/bin/bash
  2. SOLR_HOME=/home/vagrant/datas/solrcloud/solr-7.7.2
  3. # 重新启动SolrCloud
  4. echo "restart SolrCloud-------------------------------------------------"
  5. for i in bigdata-node1 bigdata-node2 bigdata-node3
  6. do
  7. ssh $i "source /etc/profile;${SOLR_HOME}/bin/solr restart -cloud -force"
  8. done
  9. sleep 3s
  10. echo "start done..."
  11. # 检查SolrCloud状态
  12. echo "SolrCloud status------------------------------------------------"
  13. for i in bigdata-node1 bigdata-node2 bigdata-node3
  14. do
  15. echo ------------------- $i --------------
  16. ssh $i "source /etc/profile;${SOLR_HOME}/bin/solr status"
  17. done
  18. exit 0

设置脚本执行权限:

  1. chmod +x restart-solr-cloud

SolrCloud状态查看脚本(status-solr-cloud)

  1. sudo su
  2. cd /bin
  3. vi status-solr-cloud

脚本内容如下:

  1. #!/bin/bash
  2. SOLR_HOME=/home/vagrant/datas/solrcloud/solr-7.7.2
  3. # 检查SolrCloud状态
  4. echo "SolrCloud status------------------------------------------------"
  5. for i in bigdata-node1 bigdata-node2 bigdata-node3
  6. do
  7. echo ------------------- $i --------------
  8. ssh $i "source /etc/profile;${SOLR_HOME}/bin/solr status"
  9. done
  10. exit 0

设置脚本执行权限:

  1. chmod +x status-solr-cloud

SolrCloud停止脚本(stop-solr-cloud)

  1. sudo su
  2. cd /bin
  3. vi stop-solr-cloud

脚本内容如下:

  1. #!/bin/bash
  2. SOLR_HOME=/home/vagrant/datas/solrcloud/solr-7.7.2
  3. # 启动SolrCloud
  4. echo "stop SolrCloud-------------------------------------------------"
  5. for i in bigdata-node1 bigdata-node2 bigdata-node3
  6. do
  7. ssh $i "source /etc/profile;${SOLR_HOME}/bin/solr stop -V"
  8. done
  9. sleep 3s
  10. echo "stop done..."
  11. # 检查SolrCloud状态
  12. echo "SolrCloud status------------------------------------------------"
  13. for i in bigdata-node1 bigdata-node2 bigdata-node3
  14. do
  15. echo ------------------- $i --------------
  16. ssh $i "source /etc/profile;${SOLR_HOME}/bin/solr status"
  17. done
  18. exit 0

设置脚本执行权限:

  1. chmod +x stop-solr-cloud

分发(选做):

  1. # 使用root账户分发至其他节点
  2. scp -r /bin/*-solr-*cloud root@bigdata-node2:/bin/
  3. scp -r /bin/*-solr-*cloud root@bigdata-node3:/bin/