假设有4台机,IP及主机名如下:
192.168.100.105 c1 192.168.100.110 c2 192.168.100.115 c3 192.168.100.120 c4
假设Solr安装在/home/目录下,也就是/home/solr/
* 先登录root账号再进行以下操作
1.创建脚本
创建并赋予运行权限
mk batch-solr.sh chmod u+x batch-solr.sh
2.编辑脚本
vim batch-solr.sh
添加以下内容:
#!/bin/bash usage="Usage: $0 (start|stop)" if [ $# -lt 1 ]; then echo $usage exit 1 fi action=$1 iparray=(c1 c2 c3 c4) path="/home/solr/bin" echo "$action Solr cluster" for ip in ${iparray[*]} do echo "ssh to $ip" case $action in "start") ssh $ip $path/solr start -c -force ;; "stop") ssh $ip $path/solr stop ;; esac sleep 1s done exit 0
3.运行脚本
只需要在其中一台机运行即可
批量启动:
./batch-solr.sh start
批量停止:
./batch-solr.sh stop