在云模式下设置 Apache Solr [英] Setting Up Apache Solr in Cloud Mode

查看:33
本文介绍了在云模式下设置 Apache Solr的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须做到以下几点:

  1. 我必须在 2 个服务器/节点上部署 Solr.
  2. 在另一台服务器上部署 Zookeeper.
  3. 上传自定义配置到 Zookeeper
  4. 创建一个包含 2 个分片和 2 个副本的自定义集合

Solr 7.4.0 & 版本动物园管理员: 3.4.12

我做了以下事情:

设置 Zookeeper:

  • 创建了一个 Zookeeper 数据文件夹 &做了一个 zoo.conf &将 dataDir 放在那里.
  • 使用./zkServer.sh start
  • 启动zookeeper

设置 Solr:

  • 使用以下代码启动 Solr:

    ./solr start -cloud -s/home/demo/LocalFolder/Downloads/SolrHome -p 8987 -z localhost:2181

  • 尝试使用以下命令在 Zookeeper 中上传配置:./solr create -c mycollection -d/media/sf_VM/Dump/conf

它给了我一个例外:

Caused by: javax.servlet.UnavailableException: 处理请求时出错.CoreContainer 未初始化或正在关闭.在 org.apache.solr.servlet.SolrDispatchFilter.doFilter(SolrDispatchFilter.java:341)在 org.apache.solr.servlet.SolrDispatchFilter.doFilter(SolrDispatchFilter.java:323)在 org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1634)在 org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:533)在 org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:146)在 org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:548)在 org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)在 org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:257)在 org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1595)在 org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:255)在 org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1253)在 org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:203)在 org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:473)在 org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1564)在 org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:201)在 org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1155)在 org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:144)在 org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:219)在 org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:126)……还有 17 个

我已经搜索了很多页面 &看过 Solr 教程,但他们在那里使用了默认示例.我只是没有任何一步一步的想法

  1. 如何在 Zookeeper 中上传配置?
  2. 然后我需要做什么来创建一个指向该配置的集合.我希望该集合有 2 个分片 &2 个副本.
  3. solr.xml 在哪里.如果它应该在 Zookeeper 中,我如何将其上传到那里
  4. 如何在 Zookeeper 中看到配置已上传?

我知道这个问题可能是重复的.我已经阅读了几篇文章,但无法提出解决方案.请帮忙.

解决方案

好吧,我想出了如何设置.请注意,我已经从不同的站点阅读了这些步骤 &一步步汇聚到这里:

1.设置 ZooKeeper:

这用于将集合特定的配置文件保存在中央空间中&用名字映射它.稍后我们可以使用这个名称来创建指向这个配置的集合.此配置与您在以下文件夹中找到的相同:solr-7.4.0\server\solr\configsets\sample_techproducts_configs\conf

1.1 下载最新的 Zookeeper.我用过3.4.12

1.2 解压下载的压缩包并将 conf/zoo_sample.cfg 复制到 conf/zoo.cfg

1.3 修改zoo.cfg:

1.3.1 将 dataDir 更改为要保存所有集群配置数据的目录.dataDir=/var/zookeeper/data

1.3.2 添加关于所有 Zookeeper 服务器的信息:我只使用了 1 个 ZooKeeper 服务器,所以这不是必需的.如果您想添加更多服务器,请访问以下链接:

DZone 教程

Apache 教程

1.3.3 使用ZooKeeper启动(进入zookeeper-3.4.12/后):

./bin/zkServer.sh start-foreground conf/zoo.cfg

./bin/zkServer.sh 启动conf/zoo.cfg

注意:您可以使用以下命令停止 ZooKeeper:

bin/zkServer.sh 停止

1.3.4 ZooKeeper 状态:

点击以下:

bin/zkServer.sh 状态

或者在连接时执行 telnet localhost 2181 并点击 stats.

2.设置 Solr

2.1 下载 Solr

2.2 从 .tar 文件中提取 install_solr_service.sh.Solr 包含一个服务安装脚本 (bin/install_solr_service.sh),可帮助您在 Linux 上将 Solr 作为服务安装.如需更多信息,请点击此处.>

tar -xzf solr-7.4.0.tgz solr-7.4.0/bin/install_solr_service.sh --strip-components=2

2.3 使用上述脚本将 Solr 安装为服务:

sudo bash ./install_solr_service.sh solr-7.4.0.tgz

这也会将 solr-7.4.0.tgz 解压到 /opt/solr

2.4 进入 /opt/solr 并执行以下操作:

mkdir solr/server/solr2mkdir solr/服务器/solr3mkdir solr/server/solr4

cp solr/server/solr/solr.xml solr/server/solr2cp solr/server/solr/solr.xml solr/server/solr3cp solr/server/solr/solr.xml solr/server/solr4

2.5 更改solr.xml 中的jetty 端口.对上述步骤中提到的所有 3 个 solr.xml 执行此操作:

vi solr/server/solr2/solr.xml

搜索端口 8983 &将其更改为 8984(对于 solr2),将其更改为 8985(对于 solr3),将其更改为 8986(对于 solr4)

2.6 停止在 8983 运行的 Solr

root@dev-base:/opt/solr/bin# ./solr stop -p 8983

2.7 启动所有 solr 实例:

root@dev-base:/opt/solr# bin/solr start -c -s server/solr -p 8983 -z localhost:2181 -noprompt -forceroot@dev-base:/opt/solr# bin/solr start -c -s server/solr2 -p 8984 -z localhost:2181 -noprompt -forceroot@dev-base:/opt/solr# bin/solr start -c -s server/solr3 -p 8985 -z localhost:2181 -noprompt -forceroot@dev-base:/opt/solr# bin/solr start -c -s server/solr4 -p 8986 -z localhost:2181 -noprompt -force

注意:出于安全原因,不建议以根用户身份运行 solr.

2.8 查看 Solr 状态:

root@dev-base:/opt/solr# bin/solr status

3 进行自定义配置

3.1 将 conf 目录从 solr-7.4.0\server\solr\configsets\sample_techproducts_configs\conf 复制到另一个位置 (在我的例子中是/media/sf_VM/Dump/new/conf ).

3.2 更改 conf 中的 managed-schema 文件以指定您正在使用的字段.

4 将配置上传到 ZooKeeper:

root@dev-base:/opt/solr# bin/solr zk -z localhost:2181 upconfig -d/media/sf_VM/Dump/new/conf -n myConf6

我上传的配置名称是myConf6

5 使用此自定义配置创建 Solr 集合

root@dev-base:/opt/solr# bin/solr create -c myNewCollection -n myConf6 -shards 2 -replicationFactor 2 -force

点击 Solr 管理 URL

6 使用 POST API 使用 Json 索引数据

网址:http://localhost:8983/solr/myNewCollection/update>

方法:POST

身体:

<代码>[{"_id": "99999999999999999999",作者": [新插入9000"],作者姓氏":[新插入9000"],"impn": "新插入的 9000","isbn10": "9999999999","isbn13": "9999999999999","title": "新插入的 9000","publisher": "新插入的 9000","sales_a": 5.0,sales_t":5.0,有图像":1,"页数": "76","image": "http://ip.ip.com/is/image/","格式": "纸","mtc_id": "99999999999",科目":[9000"]评分":0,"description_long": "Snahashis 在你的婚姻中呼唤我."}

在 Zookeeper 中删除配置:

如果要删除已上传到 ZooKeeper 的旧/错误配置,请运行以下命令:

./server/scripts/cloud-scripts/zkcli.sh -cmd clear -z ":"/configs/AAA

配置路径为/configs/<;配置集的名称 >

删除特定文件:

zkcli.sh --zkhost :-cmd clear/configs//solrconfig.xml

上传更新的文件:

zkcli.sh --zkhost :-cmd putfile/configs//solrconfig.xml//solrconfig.xml

然后我们需要重新启动 solr 节点.

通过 API 删除集合:

  1. 首先删除在此集合上创建的别名(如果有)

http://localhost:8983/solr/admin/collections?action=DELETEALIAS&name=aliasName

  1. 删除收藏:

http://localhost:8983/solr/admin/collections?action=DELETE&name=collectionName

I have to do the following:

  1. I have to deploy Solr on 2 servers/nodes.
  2. Deploy Zookeeper on another server.
  3. Upload a custom config to Zookeeper
  4. Create a custom collection with 2 shards and 2 replicas

Version of Solr 7.4.0 & Zookeeper: 3.4.12

I have done the following:

Set Up Zookeeper:

  • Created a Zookeeper data folder & made a zoo.conf & put the dataDir there.
  • Started zookeeper using ./zkServer.sh start

Set up Solr:

  • Started Solr using:

    ./solr start -cloud -s /home/demo/LocalFolder/Downloads/SolrHome -p 8987 -z localhost:2181

  • Trying to upload config in Zookeeper using: ./solr create -c mycollection -d /media/sf_VM/Dump/conf

It is giving me an exception:

Caused by: javax.servlet.UnavailableException: Error processing the request. CoreContainer is either not initialized or shutting down.
    at org.apache.solr.servlet.SolrDispatchFilter.doFilter(SolrDispatchFilter.java:341)
    at org.apache.solr.servlet.SolrDispatchFilter.doFilter(SolrDispatchFilter.java:323)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1634)
    at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:533)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:146)
    at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:548)
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
    at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:257)
    at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1595)
    at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:255)
    at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1253)
    at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:203)
    at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:473)
    at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1564)
    at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:201)
    at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1155)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:144)
    at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:219)
    at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:126)
    ... 17 more
</pre>

I have searched many pages & seen Solr tutorials but there they have used the default examples. I just dont have any step by step idea to

  1. How to Upload a config in Zookeeper?
  2. Then what I need to do to create a collection pointing to that config. I want that collection to have 2 shards & 2 replicas.
  3. Where will be the solr.xml. If it should be in Zookeeper how do I upload it there
  4. How do I see in Zookeeper that the config has been uploaded?

I know this question might be a duplicate. I have read several of posts but not able to come up a solution. Please help.

解决方案

Well I figured out how to setup. Please note that I have read these steps from different site & gathered here step by step:

1. Set Up ZooKeeper:

This is used to keep the collection specific configuration files to store in a central space & map it with a name. Later we can use this name to create collection which would point to this config. This config is the same as you find in the below folder: solr-7.4.0\server\solr\configsets\sample_techproducts_configs\conf

1.1 Download latest Zookeeper. I have used 3.4.12

1.2 Unpack downloaded archive and copy conf/zoo_sample.cfg to conf/zoo.cfg

1.3 Modify zoo.cfg:

1.3.1 Change dataDir to directory where you want to hold all cluster configuration data. dataDir=/var/zookeeper/data

1.3.2 Add information about all Zookeeper servers: I have used only 1 ZooKeeper server so this is not required. If you want to add more servers then please go through the below links:

DZone Tutorial

Apache Tutorial

1.3.3 Start ZooKeeper using (after going to zookeeper-3.4.12/):

./bin/zkServer.sh start-foreground conf/zoo.cfg

OR

./bin/zkServer.sh start conf/zoo.cfg

Note: You can stop the ZooKeeper using the below command:

bin/zkServer.sh stop

1.3.4 ZooKeeper Status:

Hit the below:

bin/zkServer.sh status

Or do telnet localhost 2181 and hit stats when connected.

2. Set Up Solr

2.1 Download the Solr

2.2 Extract install_solr_service.sh from the .tar file. Solr includes a service installation script (bin/install_solr_service.sh) to help you install Solr as a service on Linux. For more info click here.

tar -xzf solr-7.4.0.tgz solr-7.4.0/bin/install_solr_service.sh --strip-components=2

2.3 Install Solr as a service using the above script:

sudo bash ./install_solr_service.sh solr-7.4.0.tgz

This will also extracting solr-7.4.0.tgz to /opt/solr

2.4 Go to /opt/solr and do the following:

mkdir solr/server/solr2 mkdir solr/server/solr3 mkdir solr/server/solr4

cp solr/server/solr/solr.xml solr/server/solr2 cp solr/server/solr/solr.xml solr/server/solr3 cp solr/server/solr/solr.xml solr/server/solr4

2.5 Change the jetty port in solr.xml. Do this for all the 3 solr.xml mentioned in the above step:

vi solr/server/solr2/solr.xml

Search for the port 8983 & change it 8984 (for solr2), change it 8985 (for solr3), change it 8986 (for solr4)

2.6 Stop the Solr running at 8983

root@dev-base:/opt/solr/bin# ./solr stop -p 8983

2.7 Start all the solr instances:

root@dev-base:/opt/solr# bin/solr start -c -s server/solr -p 8983 -z localhost:2181 -noprompt -force root@dev-base:/opt/solr# bin/solr start -c -s server/solr2 -p 8984 -z localhost:2181 -noprompt -force root@dev-base:/opt/solr# bin/solr start -c -s server/solr3 -p 8985 -z localhost:2181 -noprompt -force root@dev-base:/opt/solr# bin/solr start -c -s server/solr4 -p 8986 -z localhost:2181 -noprompt -force

Note: Running solr as a root is not recommended for security reason.

2.8 See Solr Status:

root@dev-base:/opt/solr# bin/solr status

3 Make a Custom Config

3.1 Copy the conf directory from solr-7.4.0\server\solr\configsets\sample_techproducts_configs\conf to another location (In my case it is /media/sf_VM/Dump/new/conf ).

3.2 Change the managed-schema file inside conf to specify the fields you are using.

4 Upload the config to ZooKeeper:

root@dev-base:/opt/solr# bin/solr zk -z localhost:2181 upconfig -d /media/sf_VM/Dump/new/conf -n myConf6

The name of the config I have uploaded is myConf6

5 Create a Solr Collection using this custom config

root@dev-base:/opt/solr# bin/solr create -c myNewCollection -n myConf6 -shards 2 -replicationFactor 2 -force

Hit Solr Admin URL

6 Index Data Using POST API using Json

URL: http://localhost:8983/solr/myNewCollection/update

Method: POST

Body:

[{
    "_id": "99999999999999999999",
    "author": [
        "New Inserted 9000"
    ],
    "authorLastName": [
        "New Inserted 9000"
    ],
    "impn": "New Inserted 9000",
    "isbn10": "9999999999",
    "isbn13": "9999999999999",
    "title": "New Inserted 9000",
    "publisher": "New Inserted 9000",
    "sales_a": 5.0,
    "sales_t": 5.0,
    "haveImage": 1,
    "pages": "76",
    "image": "http://ip.ip.com/is/image/",
    "format": "Paper",
    "mtc_id": "99999999999",
    "subjects" : [         
        "9000"
    ]
    "rating": 0,
    "description_long": "Snahashis call me in your marriage."
}

Delete a configuration in Zookeeper:

If you want to delete an old/wrong configuration already uploaded to ZooKeeper run the below command:

./server/scripts/cloud-scripts/zkcli.sh -cmd clear -z "<ZK_HOST>:<ZK_PORT>" /configs/AAA

The path of the configuration is /configs/< name of the configset >

To delete a specific file:

zkcli.sh --zkhost <ZK_HOST>:<ZK_PORT> -cmd clear /configs/<MY_COLLECTION>/solrconfig.xml

Upload an updated file:

zkcli.sh --zkhost <ZK_HOST>:<ZK_PORT> -cmd putfile /configs/<MY_COLLECTION>/solrconfig.xml /<MY_UPDATED_FILE_LOCAL_FOLDER>/solrconfig.xml

Then we need to restart the solr nodes.

To Delete a Collection Via API:

  1. First delete alias created on this collection (if any)

http://localhost:8983/solr/admin/collections?action=DELETEALIAS&name=aliasName

  1. Delete Collection:

http://localhost:8983/solr/admin/collections?action=DELETE&name=collectionName

这篇关于在云模式下设置 Apache Solr的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆