前文概述
上篇介绍solr集群的搭建,本文将介绍如何创建,删除,更新集群索引配置
创建索引
1)查看集群索引配置文件,发现solrconf
2)如果使用集群默认的索引配置文件solrconf,设置collection.configName=solrconf
http://127.0.0.1:8891/solr/admin/collections?
action=CREATE (操作)
&name=testcore (core名称)
&numShards=3 (分片数)
&replicationFactor=2 (副本数)
&maxShardsPerNode=2 (每个节点分片数)
&collection.configName=solrconf (配置文件路径)
3) 发送请求
4)请求结果
5) solr admin
上传配置
利用solr自带zkcli.bat实现上传
目录:solr-4.7.2\example\scripts\cloud-scripts\zkcli.bat
1) 本地文件路径
最好配置文件路径和zkcli.bat在同一个磁盘,这样可以用是linux目录形式
D:\Soft\solr-cloud\solrhome1\solr\collection1\conf
2)执行上传命令
D:\Soft\solr-4.7.2\example\scripts\cloud-scripts>zkcli.bat -zkhost 127.0.0.1:2181 -cmd upconfig -confdir /Soft/solr-cloud/solrhome1/solr/collection1/conf -confname democore
发现报错
D:\Soft\solr-4.7.2\example\scripts\cloud-scripts>"java" -Dlog4j.configuration="file:D:\Soft\solr-4.7.2\example\scripts\cloud-scripts\log4j.properties" -classpath "D:\Soft\solr-4.7.2\example\scripts\cloud-scripts\..\..\solr-webapp\webapp\WEB-INF\lib\*;D:\Soft\solr-4.7.2\example\scripts\cloud-scripts\..\..\lib\ext\*" org.apache.solr.cloud.ZkCLI -zkhost 127.0.0.1:2181 -cmd upconfig -confdir /Soft/solr-cloud/solrhome1/solr/collection1/conf -confname democore
错误: 找不到或无法加载主类 org.apache.solr.cloud.ZkCLI
3)查看zkcli.bat源码
REM Find location of this script
set SDIR=%~dp0
if "%SDIR:~-1%"=="\" set SDIR=%SDIR:~0,-1%
"%JVM%" -Dlog4j.configuration="file:%SDIR%\log4j.properties" -classpath "%SDIR%\..\..\solr-webapp\webapp\WEB-INF\lib\*;%SDIR%\..\..\lib\ext\*" org.apache.solr.cloud.ZkCLI %*
发现solr-4.7.2\example\solr-webapp中是空白目录,缺少依赖jar包,导致org.apache.solr.cloud.ZkCLI类不存在
将apache-tomcat-7.0.69-1\webapps\solr\WEB-INF\lib中的jar包(solr.war)全部拷贝到solr-4.7.2\example\solr-webapp\webapp\WEB-INF\lib目录中
4)执行上传命令
D:\Soft\solr-4.7.2\example\scripts\cloud-scripts>zkcli.bat -zkhost 127.0.0.1:2181 -cmd upconfig -confdir /Soft/solr-cloud/solrhome1/solr/collection1/conf -confname democore
5) 执行成功
删除索引
http://127.0.0.1:8891/solr/admin/collections?action=DELETE&name=testcore
重新加载索引
http://127.0.0.1:8891/solr/admin/collections?action=RELOAD&name=collection1