This scenario is to deploy multiple SOLR nodes on a single Linux host, ultimately achieving the solrcloud effect. Show the effect of the next Solrcloud standalone deployment first:
Two collection have been created on the Solrcloud.
Now let's talk about this deployment process:
Start by creating a Solrcloud directory that holds all the relevant software and configurations for Solrcloud.
1. Download and install Zookeeper
A multi-node deployment zookeeper is arguably required, and because of this simple work, it is possible to search for deployments from elsewhere on the network. This time using a single node zookeeper, the test environment is sufficient. After downloading the decompression zookeeper, go to the Zookeeper directory and execute the following command:
./bin/zkserver.sh Start
All zookeeper logs will be stored in./bin/zookeeper.out
2. Download Configuration solr-4.10.4 and tomcat7.0.61
After the decompression is complete:
Unzip the Solr-4.10.4/example/webapps/solr.war into the TOMCAT/WEBAPPS/SOLR directory
Unzip solr-4. 4./example/webapps/solr.war TOMCAT/WEBAPPS/SOLR
Copy the log4j configuration file and the jar package to Tomcat
CP solr-4. 4/example/lib/ext/* tomcat/webapps/solr/web-inf/lib/
mkdir -P tomcat/webapps/solr/web-inf/classes/
CP solr-4.10. 4/example/resources/log4j.properties tomcat/webapps/solr/web-inf/classes
Upload the configuration file to zookeeper for cluster sharing configuration: Mainly the two files of Solrconfig.xml and Schema.xml.
The upload requires the Zookeeper toolkit that comes with SOLR to copy the tools into your own tool files.
CP -R solrcloud/tomcat/webapps/solr/web-inf/lib/* solrcloud/solr-lib
What we need to use is actually the Org.apache.solr.cloud.ZkCLI class.
Save the configuration files that need to be uploaded to the Solrcloud directory separately
CP -R solrcloud/solr-4.10. 4/example/solr/collection1/conf/* solrcloud/config-files
Upload these configuration files to zookeeper
Java-classpath solrcloud/solr-lib/* org.apache.solr.cloud.zkcli-cmd upconfig-zkhost 172.20.5.161:2181-confdir solrcloud/config-files/-confname solrconf
You can use Zookeeper's own client to view the data on the zookeeper
Zookeeper-3.4.6/bin/zkcli. SH 172.20. 5.161:2181
You can see that the SOLR cluster configuration data already exists
Associating the solrconf configuration file on zookeeper to the collection directory of Zookeeper
Java-classpath solrcloud/solr-lib/* org.apache.solr.cloud.zkcli-cmd linkconfig-collection Mycollection-confname solrconf-zkhost 172.20.5.161:2181
The above steps have already deployed the configuration file
Next, you need to configure SOLR in Tomcat:
Create the Index1 directory under the Solrcloud directory as the index store. Create the Solr.xml file under the Index1 directory as the configuration for node 1. The contents of Solrcloud/index1/solr.xml are as follows:
<?XML version= "1.0" encoding= "UTF-8"?><SOLRPersistent= "true"> <coresHost= "172.20.5.161"AdminPath= "/admin/cores"Zkclienttimeout= "${zkclienttimeout:15000}"Hostport= "8080"Hostcontext= "${HOSTCONTEXT:SOLR}"></SOLR>
* The Hostport need to match Tomcat's external port address
Write the location of this file to the SOLR application of Tomcat.
Locate the env-entry tag in the Tomcat/webapps/solr/web-inf/web.xml file, enable it, and configure the following:
<!--<env-entry> <env-entry-name>solr/home</env-entry-name> <env-entry-value>/put/y Our/solr/home/here</env-entry-value> <env-entry-type>java.lang.String</env-entry-type> </en V-entry> - <Env-entry> <Env-entry-name>Solr/home</Env-entry-name> <Env-entry-value>/home/clare/soft/solr/index1</Env-entry-value> <Env-entry-type>Java.lang.String</Env-entry-type> </Env-entry>
Replace the env-entry-value with your index1 directory.
Now ready to run, before running the tomcat boot parameter configuration, tomcat/bin/catalina.sh:
* Note is the first line of the script, not the last line
#!/bin/shexport java_opts="-dzkhost=172.20.5.161:2181"
The first node is configured so that it waits for a start.
===============================
Next, configure the second and third nodes:
Copy the Tomcat directory two copies to the current directory, named Tomcat-2 and tomcat-3
Copy the Index1 directory two copies to the current directory, named Index2 and Index3
So down, your directory should be as follows
First modify the Tomcat2/conf/server.xml file
The part that needs to be modified is the number +1 that will all port, making it inconsistent with the first node of Tomcat. The third node is similarly modified.
Then modify the Tomcat2/webapps/solr/web-inf/web.xml
Replace the value of Env-entry-value with the path to Index2
Finally, modify the Solr.xml file in Index2
Change the hostport here to Tomcat2 in the Conf/server.xml file in the same connector port
<port= "8081" protocol= "http/1.1" connectiontimeout = "20000" redirectport= "8444"/>
Start starting three nodes:
Execute the bin/catalina.sh start command under each Tomcat directory.
Then you can see the control panel by entering the machine IP:PORT/SOLR in the browser.
When there is no data in the cloud directory, you need to create a collection
Enter the Create command in the address bar in the browser to know that the index was created successfully:
Http://172.20.5.161:8080/solr/admin/collections?action=CREATE&name=secondindex&numshards =3&replicationfactor=1
You can then see the newly created index in the control Panel:
The next step is to pass the data to Solrcloud:
Cut to Directory/solr-4.10.4/example/exampledocs, execute the following directives, and upload some example documents to Solrcloud to create an index
Java-durl=http://172.20.5.161:8080/solr/secondindex/update-jar post.jar./*
Then perform the search test in the control Panel:
In this way the whole set of Solrcloud is basically built successfully.
Try the Java SDK again:
Wrote a Solrcloudhelper.java to test:
Importjava.io.IOException;ImportOrg.apache.solr.client.solrj.SolrQuery;ImportOrg.apache.solr.client.solrj.SolrResponse;Importorg.apache.solr.client.solrj.SolrServerException;ImportOrg.apache.solr.client.solrj.impl.CloudSolrServer;ImportOrg.apache.solr.client.solrj.response.QueryResponse;Importorg.apache.solr.common.SolrDocument;Importorg.apache.solr.common.SolrDocumentList;Importorg.apache.solr.common.SolrInputDocument;ImportOrg.slf4j.Logger;Importorg.slf4j.LoggerFactory;Importcom.clare.exception.SolrCloudAddDocException;Importcom.clare.exception.SolrCloudSearchException; Public classSolrcloudhelper {Private Final StaticLogger Logger =loggerfactory. GetLogger (solrcloudhelper.class); Private Final StaticString zkhoststring = "172.20.5.161:2181";//This cannot be used with localhost, which is consistent with the config file. PrivateCloudsolrserver Server =NULL; PublicSolrcloudhelper () {Server=NewCloudsolrserver (zkhoststring); Server.setdefaultcollection ("Secondindex"); Server.connect (); } Publiccloudsolrserver Getserver () {returnserver; } Public voidAdddoc (solrinputdocument Doc)throwssolrcloudadddocexception {Try{Server.add (doc); } Catch(Exception e) {Throw Newsolrcloudadddocexception (e); } } PublicSolrresponse Search (solrquery query)throwssolrcloudsearchexception {Try { returnserver.query (query); } Catch(solrserverexception e) {Throw Newsolrcloudsearchexception (e); } } Public voidAdddoc ()throwssolrserverexception, IOException {solrinputdocument doc=Newsolrinputdocument (); Doc.addfield ("id", "1234"); Doc.addfield ("Name", "A lovely summer holiday dong Dong"); Server.add (DOC); Server.commit (); } Public voidDocsearch ()throwssolrserverexception {solrquery solrquery=NewSolrquery (); Solrquery.set ("Q", "Holiday Dong"); Queryresponse Response=server.query (solrquery); Solrdocumentlist List=response.getresults (); System.out.println ("Hit Doc number:" +List.getnumfound ()); for(solrdocument doc:list) {System.out.println (Doc.get ("id") + "--->" + (String) doc.get ("name"))); } } Public Static voidMain (string[] args) {Solrcloudhelper helper=NewSolrcloudhelper (); Try{Helper.adddoc (); Helper.docsearch (); } Catch(solrserverexception e) {e.printstacktrace (); } Catch(IOException e) {e.printstacktrace (); } }}
Execute Adddoc () First,
Then execute Docsearch ():
At this point, the Solrcloud test ends, and the operating principle will be served.
Solrcloud single-Machine Multi-node deployment (zookeeper3.4.6+solr4.10.4+tomcat7.0.61)