Setting Up Apache Solr in Cloud Mode

ⅰ亾dé卋堺 提交于 2019-12-02 11:48:21

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": "Introduces the core functionality of SAS Enterprise "
}

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!