Search engine - Solr cluster deployment

Keywords: solr Zookeeper Tomcat xml

Key contents

Three zookeeper nodes are required
Four solr nodes.

Using pseudo distributed to implement solr cluster. Three zookeeper instances and four tomcat instances are required, which can be simulated on a virtual machine. More than 1G memory is recommended for virtual machines.

Solr instance building

Step 1: create 4 tomcat instances and modify their ports. 8080-8083
 Step 2: extract the solr-4.10.3.tar.gz package. Copy solr.war to tomcat from the compressed package.
Step 3: start tomcat to decompress the war package. Add the log related jar package in the example directory of solr-4.10.3 to the Solr project.
Step 4: create solrhome. Modify web.xml to specify the location of solrhome.

The construction of solr cluster

Step 1:

Upload the configuration file from solrhome to the zookeeper cluster. Upload using the client side of zookeeper.
Client command location / root/solr-4.10.3/example/scripts/cloud-scripts

./zkcli.sh -zkhost 192.168.25.154:2181,192.168.25.154:2182,192.168.25.154:2183 -cmd upconfig -confdir /usr/local/solrcloud/solrhome1/collection1/conf -confname myconf

// Mining pit, error reporting on operation, solution: http://blog.csdn.net/only_wan/article/details/53678901

//Check whether the profile is uploaded successfully:
[root@bogon bin]# ./zkCli.sh
Connecting to localhost:2181
[zk: localhost:2181(CONNECTED) 0] ls /
[configs, zookeeper]
[zk: localhost:2181(CONNECTED) 1] ls /configs
[myconf]
[zk: localhost:2181(CONNECTED) 2] ls /configs/myconf
[admin-extra.menu-top.html, currency.xml, protwords.txt, mapping-FoldToASCII.txt, _schema_analysis_synonyms_english.json, _rest_managed.json, solrconfig.xml, _schema_analysis_stopwords_english.json, stopwords.txt, lang, spellings.txt, mapping-ISOLatin1Accent.txt, admin-extra.html, xslt, synonyms.txt, scripts.conf, update-script.js, velocity, elevate.xml, admin-extra.menu-bottom.html, clustering, schema.xml]
[zk: localhost:2181(CONNECTED) 3]

The second step:

Modify the solr.xml file under solrhome to specify the ip address and port number of the current instance.

The third step:

Modify the catalina.sh file in the bin directory of tomcat of each solr to add DzkHost to specify the zookeeper server address:
JAVA_OPTS="-DzkHost=192.168.25.154:2181,192.168.25.154:2182,192.168.25.154:2183"
(you can use vim's find function to find the location defined by Java "opts", and then add it)

The fourth step:

Restart tomcat.

The fifth step:
Create a two-piece collection, one for the primary and one for the secondary.

Use the following command to create:
http://192.168.25.154:8080/solr/admin/collections?action=CREATE&name=collection2&numShards=2&replicationFactor=2

The sixth step:

Delete collection1
http://192.168.25.154:8080/solr/admin/collections?action=DELETE&name=collection1

Use of Solr clusters

public class SolrCloudTest {

    @Test
    public void testAddDocument() throws Exception {
        //Create a connection to the solr cluster
        //The parameter is the address list of zookeeper, separated by commas
        String zkHost = "192.168.25.154:2181,192.168.25.154:2182,192.168.25.154:2183";
        CloudSolrServer solrServer = new CloudSolrServer(zkHost);
        //Set the default collection
        solrServer.setDefaultCollection("collection2");
        //Create a document object
        SolrInputDocument document = new SolrInputDocument();
        //Add domain to document
        document.addField("id", "test001");
        document.addField("item_title", "Testing commodity");
        //Add document to index library
        solrServer.add(document);
        //Submission
        solrServer.commit();
    }

    @Test
    public void deleteDocument() throws SolrServerException, IOException {
        //Create a connection to the solr cluster
        //The parameter is the address list of zookeeper, separated by commas
        String zkHost = "192.168.25.154:2181,192.168.25.154:2182,192.168.25.154:2183";
        CloudSolrServer solrServer = new CloudSolrServer(zkHost);
        //Set the default collection
        solrServer.setDefaultCollection("collection2");


        solrServer.deleteByQuery("*:*");
        solrServer.commit();
    }
}

Solrj and spring integration

//Modify the configuration file of spring and add the configuration of cluster version:
<!-- Cluster Edition -->
    <bean id="cloudSolrServer" class="org.apache.solr.client.solrj.impl.CloudSolrServer">
        <constructor-arg name="zkHost" value="192.168.25.154:2181,192.168.25.154:2182,192.168.25.154:2183"></constructor-arg>
        <property name="defaultCollection" value="collection2"></property>
    </bean>

Posted by zorgon on Wed, 01 Apr 2020 19:42:14 -0700