四、SolrCloud的安装

安装Zookeeper

1.下载Zookeeper
官网地址:https://www.apache.org/dyn/closer.lua/zookeeper/zookeeper-3.6.3/apache-zookeeper-3.6.3-bin.tar.gz
或者也可访问地址:http://archive.apache.org/dist/zookeeper/
自行选择版本下载
下载完Zookeeper的压缩包后,解压压缩包,目录结构如下:

打开conf目录,拷贝该目录下的zoo_sample.cfg文件为zoo.cfg文件,并打开修改其内容如下

# The number of milliseconds of each ticktickTime=2000# The number of ticks that the initial # synchronization phase can takeinitLimit=10# The number of ticks that can pass between # sending a request and getting an acknowledgementsyncLimit=5# the directory where the snapshot is stored.# do not use /tmp for storage, /tmp here is just # example sakes.dataDir=D:/apache-zookeeper-3.6.3-bin/data# the port at which the clients will connectclientPort=2181

根据上述配置文件中配置的dataDir所在目录D:/apache-zookeeper-3.6.3-bin/data下创建一个文件myid,在myid文件中写入数字1,然后保存并关闭
2.启动zookeeper
进入zookeeper解压目录下的bin目录,目录结构如下:

启动zookeeper使用zkServer.cmd来启动即可

启动Solr

上传配置文件

启动Solr前需要把Solr单机运行时的配置文件上传到Zookeeper服务,否则会影响Solr创建collection操作,本人这里使用solr的样例目录example-DIH作为SolrCloud运行的配置基础,基于这个配置版本修改并上传到zookeeper服务,单机运行时的配置文件如下图:

进入目录 d:\solr-8.9.0\server\scripts\cloud-scripts,如下图:

可以发现该目录下有可执行文件,我们就是通过该目录的可执行文件进行配置文件上传到zookeeper服务,上传的命令格式如下:

D:\solr-8.9.0\server\scripts\cloud-scripts>zkcli
usage: ZkCLI
 -c,--collection <arg>      for linkconfig: name of the collection
 -cmd <arg>                    cmd to run: bootstrap, upconfig, downconfig,linkconfig, makepath, put, putfile,get,getfile, list, clear, updateacls, ls
 -d,--confdir <arg>          for upconfig: a directory of configuration files
 -h,--help                          bring up this help page
 -n,--confname <arg>     for upconfig, linkconfig: name of the config set
 -name <arg>                   name of the cluster property to set
 -r,--runzk <arg>              run zk internally by passing the solr run port - only for clusters on one machine (tests, dev)
 -s,--solrhome <arg>       for bootstrap, runzk: solrhome location
 -val <arg>                        value of the cluster to set
 -x,--excluderegex <arg> for upconfig: files matching this regular expression won't be uploaded
 -z,--zkhost <arg>             ZooKeeper host address
Examples:
zkcli.sh -zkhost localhost:9983 -cmd bootstrap -solrhome /opt/solr
zkcli.sh -zkhost localhost:9983 -cmd upconfig -confdir /opt/solr/collection1/conf -confname myconf
zkcli.sh -zkhost localhost:9983 -cmd downconfig -confdir /opt/solr/collection1/conf -confname myconf
zkcli.sh -zkhost localhost:9983 -cmd linkconfig -collection collection1 -confname myconf
zkcli.sh -zkhost localhost:9983 -cmd makepath /apache/solr
zkcli.sh -zkhost localhost:9983 -cmd put /solr.conf 'conf data'
zkcli.sh -zkhost localhost:9983 -cmd putfile /solr.xml /User/myuser/solr/solr.xml
zkcli.sh -zkhost localhost:9983 -cmd get /solr.xml
zkcli.sh -zkhost localhost:9983 -cmd getfile /solr.xml solr.xml.file
zkcli.sh -zkhost localhost:9983 -cmd clear /solr
zkcli.sh -zkhost localhost:9983 -cmd list
zkcli.sh -zkhost localhost:9983 -cmd ls /solr/live_nodes
zkcli.sh -zkhost localhost:9983 -cmd clusterprop -name urlScheme -val https
zkcli.sh -zkhost localhost:9983 -cmd updateacls /solr

本人这里执行的命令如下:

zkcli.bat -zkhost localhost:2181 -cmd upconfig -confdir D:\solr-8.9.0\example\example-DIH\solr\solr\conf -confname solrconfig

执行结果如下:

D:\solr-8.9.0\server\scripts\cloud-scripts>zkcli.bat -zkhost localhost:2181 -cmd upconfig -confdir D:\solr-8.9.0\example\example-DIH\solr\solr\conf -confname solrconfig
INFO  - 2021-09-16 17:31:54.525; org.apache.solr.common.cloud.ConnectionManager; Waiting for client to connect to ZooKeeper
INFO  - 2021-09-16 17:31:54.576; org.apache.solr.common.cloud.ConnectionManager; zkClient has connected
INFO  - 2021-09-16 17:31:54.577; org.apache.solr.common.cloud.ConnectionManager; Client is connected to ZooKeeper

看到上述输出结果,标识配置文件上传成功了,我们在后续的管理控制台会讲到如何查看配置文件

启动参数

SolrCloud方式命令跟单机的启动方式不同,有两种,一种时修改启动文件,一种是启动命令带参数
1.修改文件
打开目录d:\solr-8.9.0\bin,可以看到文件列表如下:

就是通过修改上述图中标红的文件来实现以SolrCloud的方式启动,找到solr.in.cmd文件,并找到set ZK_HOST的位置,如果没有自行添加即可

set ZK_HOST=localhost:2181

修改完配置后,通过solr.cmd start命令就可以启动SolrCloud了

2.启动命令带参数
除了修改solr.in.cmd文件外,还可以直接通过命令行参数启动SolrCloud,命令格式如下:

solr.cmd -z localhost:2181 -m 512m

SolrCloud的管理控制台

打开浏览器,输入地址:http://localhost:8983,可以看到如下页面:

collection的创建

Solr以Cloud模式启动后,要创建collection后才能进行数据的索引,创建步骤如下图:

点击Add Collection按钮后,弹出创建Collection的窗口,如下图:

在弹窗的config set中就可以下拉选择到上传到zookeeper的配置文件,我们上述步骤上传的配置文件名称为solrconfig,在shards中可以指定shard的名称,不过router必须要选择Implicit才可自行定义shard名称,一切都选择好后点击Add Collection按钮完成Collection的创建,创建结果如下图:

配置文件修改

如果需要修改配置文件,则可以通过修改本地的副本文件,然后再通过solr目录下的zkcli.bat的可执行文件再次上传即可。详细步骤参考前面的上传配置文件章节。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值