docker配置solr集群

1.启动单独一个solr

docker pull solr:8.11.1
docker run --name my_solr -d -p 8983:8983 solr:8.11.1
//创建名为my_core的核心
docker exec -it --user=solr my_solr bin/solr create -c my_core
//删除核心命令
docker exec -it --user=solr my_solr bin/solr delete -c my_core

2.配置集群

搭建zookeeper集群

docker network create  itcast-zookeeper
docker network ls

#创建容器1
docker run -id --restart=always -v /tmp/zoo1/data:/data -v /tmp/zoo1/datalog:/datalog -e ZOO_MY_ID=1 -e ZOO_SERVERS="server.1=zookeeper1:2888:3888 server.2=zookeeper2:2888:3888 server.3=zookeeper3:2888:3888" -p 2181:2181 --name=zookeeper1 --net=itcast-zookeeper --privileged zookeeper:latest
#创建容器2
docker run -id --restart=always -v /tmp/zoo2/data:/data -v /tmp/zoo2/datalog:/datalog -e ZOO_MY_ID=2 -e ZOO_SERVERS="server.1=zookeeper1:2888:3888 server.2=zookeeper2:2888:3888 server.3=zookeeper3:2888:3888" -p 2182:2181 --name=zookeeper2 --net=itcast-zookeeper --privileged zookeeper:latest
#创建容器3
docker run -id --restart=always -v /tmp/zoo3/data:/data -v /tmp/zoo3/datalog:/datalog -e ZOO_MY_ID=3 -e ZOO_SERVERS="server.1=zookeeper1:2888:3888 server.2=zookeeper2:2888:3888 server.3=zookeeper3:2888:3888" -p 2183:2181 --name=zookeeper3 --net=itcast-zookeeper --privileged zookeeper:latest

docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' zookeeper1 #172.19.0.2

echo stat|nc 172.19.0.2 2181
zkServer.sh status

docker run --name solr1 --net=itcast-zookeeper -d -p 8983:8983 solr:latest bash -c '/opt/solr/bin/solr start -f -z zookeeper1:2181,zookeeper2:2181,zookeeper3:2181'

docker run --name solr2 --net=itcast-zookeeper -d -p 8984:8983 solr:latest bash -c '/opt/solr/bin/solr start -f -z zookeeper1:2181,zookeeper2:2181,zookeeper3:2181'

docker run --name solr3 --net=itcast-zookeeper -d -p 8985:8983 solr:latest bash -c '/opt/solr/bin/solr start -f -z zookeeper1:2181,zookeeper2:2181,zookeeper3:2181'

docker run --name solr4 --net=itcast-zookeeper -d -p 8986:8983 solr:latest bash -c '/opt/solr/bin/solr start -f -z zookeeper1:2181,zookeeper2:2181,zookeeper3:2181'

在这里插入图片描述

上传配置文件

docker exec -it solr1 bash

docker exec -it solr1 /opt/solr-9.4.0/server/scripts/cloud-scripts/zkcli.sh -zkhost zookeeper1:2181,zookeeper2:2181,zookeeper3:2181 -cmd upconfig -confdir /opt/solr-9.4.0/server/solr/configsets/sample_techproducts_configs/conf -confname myconfig

在这里插入图片描述在这里插入图片描述

solr的核心配置文件

  1. solrcore的数据
    在这里插入图片描述
1、solr.xml(全局)为整个 Solr 服务器实例指定配置选项,用于设置一些全局配置
	a、<solrcloud> 元素定义了与 SolrCloud 相关的参数:
	b、<shardHandlerFactory> 元素用于定义分片处理程序,可以在这里定义自定义的分片处理程序
2、core.properties(每个 core) 为每个 core 定义特定的属性,例如名称、核心所属的集合、模式的位置等

name:核心的名称,在使用 CoreAdminHandler 运行命令时,使用此名称来引用核心。
config:核心的配置文件名称,默认是 solrconfig.xml。
schema:核心的模式文件名,默认为 managed-schema。
dataDir:核心的数据目录(存储索引),绝对路径或相对于 instanceDir 的路径;默认是 data。
configSet:用于配核心的已定义配置集的名称。
properties:核心的属性文件的名称,该值可以是绝对路径名或相对于 instanceDir 的路径。

coreNodeName:仅在 SolrCloud 中使用,这是承载此副本的节点的唯一标识符。默认情况下 coreNodeName 会自动生成,但通过显式设置此属性允许您手动分配新的核心来替换现有的副本。例如,通过新计算机上进行备份恢复来更换发生硬件故障的计算机时,这可能很有用。
ulogDir:核心更新日志的绝对或相对目录。(SolrCloud模式下)
shard:核心所属的分片。(SolrCloud模式下)
collection:核心所属的集合。(SolrCloud模式下)
roles:SolrCloud 的未来参数或一种用户标记节点仅供自己使用的方法。

3、solrconfig.xml(每个 core)
a、请求处理程序,处理对 Solr 的请求,例如向索引添加文档的请求或查询文档的请求。
b、监听器,“监听”特定查询相关事件的过程;监听器可用于触发特殊代码的执行,例如调用一些常见查询来预热缓存
c、Request Dispatcher,用于管理 HTTP 通信
d、Admin Web 界面
e、复制和副本相关的参数

dataDir 和 directoryFactory

dataDir 用于指定索引数据的位置,默认情况下,== Solr 将其索引数据存储在 ${core_home}/data 目录==中
如果需要指定其他目录用于存储索引,可以在 core.properties 中配置 dataDir,或在 solrconfig.xml中配置 参数。可以使用绝对路径或相对于 Solr 核心的 instanceDir 路径名来指定另一个目录。

4、schema.xml/managed-schema(每个 core)

该配置文件用于定义索引库的数据类型,同时指明某个类型的字段是不是要进行索引
该文件包含四类信息:uniqueKey、fieldType、field、dynamicField、copyField。

[]$/opt/solr/bin/solr create_collection -help
 
Usage: solr create_collection [-c collection] [-d confdir] [-n configName] [-shards #] [-replicationFactor #] [-p port]
 
  -c <collection>         Name of collection to create
 
  -d <confdir>            Configuration directory to copy when creating the new collection, built-in options are:
 
      basic_configs: Minimal Solr configuration
      data_driven_schema_configs: Managed schema with field-guessing support enabled
      sample_techproducts_configs: Example configuration with many optional features enabled to
         demonstrate the full power of Solr
 
      If not specified, default is: data_driven_schema_configs
 
      Alternatively, you can pass the path to your own configuration directory instead of using
      one of the built-in configurations, such as: bin/solr create_collection -c mycoll -d /tmp/myconfig
 
      By default the script will upload the specified confdir directory into Zookeeper using the same
      name as the collection (-c) option. Alternatively, if you want to reuse an existing directory
      or create a confdir in Zookeeper that can be shared by multiple collections, use the -n option
 
  -n <configName>         Name the configuration directory in Zookeeper; by default, the configuration
                            will be uploaded to Zookeeper using the collection name (-c), but if you want
                            to use an existing directory or override the name of the configuration in
                            Zookeeper, then use the -c option.
 
  -shards <#>             Number of shards to split the collection into; default is 1
 
  -replicationFactor <#>  Number of copies of each document in the collection, default is 1 (no replication)
 
  -p <port>               Port of a local Solr instance where you want to create the new collection
                            If not specified, the script will search the local system for a running
                            Solr instance and will use the port of the first server it finds.
 
使用命令创建
[julong@localhost solr-cloud]$ 
[julong@localhost solr-cloud]$ /opt/solr/bin/solr create_collection -c collect3 -shards 1 -replicationFactor 1
 
Connecting to ZooKeeper at 127.0.0.1:12181,127.0.0.1:22181,127.0.0.1:32181 ...
Uploading /home/julong/solr-cloud/solr-38983/server/solr/configsets/data_driven_schema_configs/conf for config julong_collections to ZooKeeper at 127.0.0.1:12181,127.0.0.1:22181,127.0.0.1:32181
 
Creating new collection 'julong_collections' using command:
http://localhost:38983/solr/admin/collections?action=CREATE&name=julong_collections&numShards=2&replicationFactor=3&maxShardsPerNode=2&collection.configName=julong_collections
 
{
  "responseHeader":{
    "status":0,
    "QTime":25258},
  "success":{
    "192.168.10.132:18983_solr":{
      "responseHeader":{
        "status":0,
        "QTime":14348},
      "core":"julong_collections_shard1_replica1"},
    "192.168.10.132:28983_solr":{
      "responseHeader":{
        "status":0,
        "QTime":14626},
      "core":"julong_collections_shard1_replica2"},
    "192.168.10.132:38983_solr":{
      "responseHeader":{
        "status":0,
        "QTime":14763},
      "core":"julong_collections_shard2_replica3"}}}
[julong@localhost solr-cloud]$ ls
使用网页url创建
http://192.168.10.132:18983/solr/admin/collections?action=CREATE&name=julong_collection&numShards=2&replicationFactor=3
参数说明:
 
numShards 要作为集合的一部分创建的分片的数量
replicationFactor 每一个分片的副本数量 

Solr之ZooKeeper管理配置文件

/usr/local/solrColud/solr1/solr-4.10.3/example/scripts/cloud-scripts/zkcli.sh -zkhost 192.168.66.100:2181, 192.168.66.100:2182, 192.168.66.100:2183 -cmd upconfig -confname myconf -confdir /usr/local/solrColud/solr1/solr-4.10.3/example/solr/collection1/conf/ 
 
#格式化一下啊,上传
/usr/local/solrColud/solr1/solr-4.10.3/example/scripts/cloud-scripts/zkcli.sh 
  -zkhost 192.168.66.100:2181, \ #指定连接的zookeeper服务器       192.168.66.100:2182, \
      192.168.66.100:2183  \
 -cmd upconfig \ #上传文件 -confname myconf \ #上传到zookeepr的目录 /configs/myconf #上传的配置文件目录
 -confdir /usr/local/solrColud/solr1/solr-4.10.3/example/solr/collection1/conf/ 

写任意数据到ZK中

# key /my_zk_file.txt 
# val 'test'
#类似于 set /my_zk_file.txt test
/opt/solr-9.4.0/server/scripts/cloud-scripts/zkcli.sh -zkhost 192.168.66.100:2181  -cmd put /my_zk_file.txt 'test'
 
#登录zk
/opt/solr-9.4.0/server/scripts/cloud-scripts/zkcli.sh -server 172.19.0.2:2181
/opt/solr-9.4.0/server/scripts/cloud-scripts/zkcli.sh -zkhost localhost:9983 -cmd upconfig -confdir /opt/solr/collection1/conf -confname myconf

#查看数据
ls /
#连接collection与configset #简单来说,就是修改conllection 的配置 
#下面例子是将connection3 的配置修改到 myconf2
/opt/solr-9.4.0/server/scripts/cloud-scripts/zkcli.sh -zkhost 172.19.0.2:2181 -cmd linkconfig -collection collect3 -confname myconfig
 
#登录zk
/opt/solr-9.4.0/server/scripts/cloud-scripts/zkcli.sh -server 172.19.0.2:2181
/opt/solr-9.4.0/server/scripts/cloud-scripts/zkcli.sh -zkhost 172.19.0.2:2181 -cmd ls /solr/live_nodes
#查看配置文件
ls /configs

sudo docker exec -u root -it bb85c1a8b1fec69b781d5257eab915b3d785f8fa0c412296f636aeecbdc99f3c /bin/bash

sudo cp -r /opt/solr-9.4.0/server/solr/configsets/sample_techproducts_configs/conf/ ./
mv collect3_shard1_replia_n1 collect4_shard1_replia_n1
zkServer.sh status

docker exec -it solr1 
/opt/solr-9.4.0/server/scripts/cloud-scripts/zkcli.sh 
-zkhost zookeeper1:2181,zookeeper2:2181,zookeeper3:2181 
-cmd upconfig 
-confdir /opt/solr-9.4.0/server/solr/configsets/sample_techproducts_configs/conf 
-confname myconfig

/opt/solr/bin/solr create_collection -c collect5 -shards 1 -replicationFactor 1

sudo docker exec -u root -it 0ca5cb8590ef123aa6be18c68c85024930f07ab3ed1463a5d356455b2fb3abfc /bin/bash
sudo docker exec -u root -it b4dd045a2d2aa1f8382e9d86cbcd480b5ca68d78f304ada2dd6824e054f521a2 /bin/bash

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值