solrCloud分布式集群安装配置
1.前提
安装Zookeeper集群
2.安装部署多个solr节点
10.41.2.82
10.41.2.83
10.41.2.84
10.41.2.86
mkdir -p /usr/local/search
scp -r 10.41.2.82:/usr/local/search/solr /usr/local/search/
scp -r 10.41.2.82:/usr/local/search/tomcat /usr/local/search/
2.配置
配置主要是将tomcat与Zookeeper相关联。
修改
tomcat
的
bin
目录下
catalina.sh
文件。
2.1配置第一个节点(10.41.2.82)
solrCloud将配置信息存放在Zookeeper中,供其他节点共享。因此需要在一个节点上配置solrCloud的信息,其他节点无需配置,即可从Zookeeper中获取。
vi /usr/local/search/tomcat/apache-tomcat-7.0.55/bin/catalina.sh
JAVA_OPTS="-Dbootstrap_confdir=/usr/local/search/solr/solrhome/data/solr/collection1/conf -Dcollection.configName=solrconf -DzkHost=10.41.2.82:2181,10.41.2.83:2181,10.41.2.84:2181,10.41.2.85:2181,10.41.2.86:2181 -DnumShards=2 $JAVA_OPTS
"
2.2配置其他节点(10.41.2.83,10.41.2.84,10.41.2.86)
vi /usr/local/search/tomcat/apache-tomcat-7.0.55/bin/catalina.sh
JAVA_OPTS="-DzkHost=10.41.2.82:2181,10.41.2.83:2181,10.41.2.84:2181,10.41.2.85:2181,10.41.2.86:2181 $JAVA_OPTS"
2.3配置solr Collection
vi /usr/local/search/solr/solrhome/data/solr/solr.xml
<solr>
<solrcloud>
<str name="host">${host:}</str>
<int name="hostPort">8080</int>
<str name="hostContext">${hostContext:solr}</str>
<int name="zkClientTimeout">${zkClientTimeout:30000}</int>
<bool name="genericCoreNodeNames">${genericCoreNodeNames:true}</bool>
<str name="zkHost">10.41.2.82:2181,10.41.2.83:2181,10.41.2.84:2181,10.41.2.85:2181,10.41.2.86:2181</str>
</solrcloud>
<shardHandlerFactory name="shardHandlerFactory"
class="HttpShardHandlerFactory">
<int name="socketTimeout">${socketTimeout:0}</int>
<int name="connTimeout">${connTimeout:0}</int>
</shardHandlerFactory>
</solr>
rm -fr /usr/local/search/solr/solrhome/data/solr/collection1/core.properties
(这样集群启动后就没有core)
3.启停
3.1启动
3.1.1启动Zookeeper
/usr/local/zookeeper/zookeeper-3.4.5/bin/zkServer.sh start
3.1.2启动tomcat
注意:先启动有solrCloud配置信息的那个节点,这里是10.41.2.82
/usr/local/search/tomcat/apache-tomcat-7.0.55/bin/startup.sh
3.2停止
3.2.1停止tomcat
/usr/local/search/tomcat/apache-tomcat-7.0.55/bin/shutdown.sh
3.2.2停止Zookeeper
/usr/local/zookeeper/zookeeper-3.4.5/bin/zkServer.sh stop
4.测试
4.1访问Web-UI
http://10.41.2.82:8080/solr
http://10.41.2.82:8080/solr/#/~cloud
4.2创建collection,shard ,core
4.2.1创建Collection,自动分配shard和replica
curl "http://10.41.2.82:8080/solr/admin/collections?action=CREATE&name=jinan&numShards=2&replicationFactor=2&maxShardsPerNode=2”
这样会出来一个名称为jinan的collection,它有2个shard,每个shard有1个数据节点,1个备份节点,即该collection共有4个core
缺点:不灵活,不能选择适合的节点,不能选择数据存放路径,不能选择实例存放路径
访问:
http://10.41.2.82:8080/solr/#/~cloud
可以看出创建了一个connection
【
删除Collection:
http://10.41.2.82:8080/solr/admin/collections?action=DELETE&name=jinan
】
4.2.2创建Collection,手动分配shard和replica(推荐使用该方法,因为可控性强)
curl "http://10.41.2.82:8080/solr/admin/cores?action=CREATE&name=inspur-shard1-replica1&instanceDir=/usr/local/search/solr/solrhome/data/solr/inspur-shard1-replica1&dataDir=/usr/local/search/solr/solrhome/data/solr/inspur-shard1-replica1/data&collection=inspur&shard=shard1"
curl "http://10.41.2.83:8080/solr/admin/cores?action=CREATE&name=inspur-shard1-replica2&instanceDir=/usr/local/search/solr/solrhome/data/solr/inspur-shard1-replica2&dataDir=/usr/local/search/solr/solrhome/data/solr/inspur-shard1-replica2/data&collection=inspur&shard=shard1"
curl "http://10.41.2.84:8080/solr/admin/cores?action=CREATE&name=inspur-shard2-replica1&instanceDir=/usr/local/search/solr/solrhome/data/solr/inspur-shard2-replica1&dataDir=/usr/local/search/solr/solrhome/data/solr/inspur-shard2-replica1/data&collection=inspur&shard=shard2"
curl "http://10.41.2.86:8080/solr/admin/cores?action=CREATE&name=inspur-shard2-replica2&instanceDir=/usr/local/search/solr/solrhome/data/solr/inspur-shard2-replica2&dataDir=/usr/local/search/solr/solrhome/data/solr/inspur-shard2-replica2/data&collection=inspur&shard=shard2"
访问
http://10.41.2.82:8080/solr/#/~cloud
5.添加节点
5.1部署新的节点(10.41.2.85)
mkdir -p /usr/local/search
scp -r 10.41.2.82:/usr/local/search/solr /usr/local/search/
scp -r 10.41.2.82:/usr/local/search/tomcat /usr/local/search/
因为是直接拷贝过来的,路径都是一样的,所以无需配置
5.3删除拷贝过来一些已经创建的core目录
rm -fr /usr/local/search/solr/solrhome/data/solr/inspur-shard1-replica1/*
rm -fr /usr/local/search/solr/solrhome/data/solr/jinan_shard1_replica1
rm -fr /usr/local/search/solr/solrhome/data/solr/jinan_shard1_replica2
rm -fr /usr/local/search/solr/solrhome/data/solr/collection1/data/*
5.4启动节点
5.4.1修改启动脚本catalina.sh
JAVA_OPTS="-DzkHost=10.41.2.82:2181,10.41.2.83:2181,10.41.2.84:2181,10.41.2.85:2181,10.41.2.86:2181 $JAVA_OPTS"
5.4.2启动
/usr/local/search/tomcat/apache-tomcat-7.0.55/bin/startup.sh
5.5访问Web-UI
http://10.41.2.82:8080/solr/#/~cloud
可以看出节点10.41.2.85已经加入到了名称为jinan的collection中了。
5.5手工新增core
curl "
http://10.41.2.85:8080/solr/admin/cores?action=CREATE&name=inspur-shard2-replica3&instanceDir=/usr/local/search/solr/solrhome/data/solr/inspur-shard2-replica3&dataDir=/usr/local/search/solr/solrhome/data/solr/inspur-shard2-replica3/data&collection=inspur&shard=shard2"
可以看出新增节点已经加入到名称为inspur的collection中。
6.删除节点
只要每个shard中至少有一个节点存活就可以保证solrCloud的可用性。
将节点10.41.2.83停掉
/usr/local/search/tomcat/apache-tomcat-7.0.55/bin/shutdown.sh
可以看出节点10.41.2.83节点的状态已经变成不可用的,使用其他的节点来替代它