1. Introduction
Solrcloud coordinates through the zookeeper cluster to split an index. Each shard can be distributed on different physical nodes. Multiple Physical shards form a complete index collection. Solrcloud automatically supports SOLR replication, which can replicate shards and store them in redundancy. Next, we will install and configure the solrcloud Cluster Based on SOLR's latest version 4.4.0.
2. installation environment
The following are the installation versions:
- SOLR: Apache Solr-4.4.0
- Tomcat: Apache Tomcat 7.0.47
- Zookeeper: Apache zookeeper 3.3.6
Descriptions of directories:
- All programs are installed in the/OPT directory. You can modify the installation directory according to your actual situation.
- The data directory of zookeeper is in/data/zookeeper/Data
- Set SOLR/home in/usr/local/solrhome
3. Plan solrcloud
- Single solrcloud data set: Product
- Zookeeper cluster: 3
- Solrcloud instance: 3 nodes
- Index sharding: 3
- Replication factor: 2
Manually distribute copies of three index shards (shard) on three solrcloud nodes.
Three nodes:
- 192.168.137.101
- 192.168.137.102
- 192.168.137.103
4. Install the zookeeper Cluster
To use zookeeper, We have installed the zookeeper cluster first.
First, unzip zookeeper-3.3.6.zip to the/OPT directory on the first node:
Unzip zookeeper-3.3.6-D/opt/
The zookeeper-3.3.6/CONF/zoo. cfg of the zookeeper configuration file is created as follows:
# The number of milliseconds of each tick
Ticktime = 2000
# The number of ticks that the initial
# Synchronization phase can take
Initlimit = 10
# The number of ticks that can pass
# Sending a request and getting an acknowledgement
Synclimit = 5
# The directory where the snapshot is stored.
Datadir =/data/zookeeper/Data
Datalogdir =/data/zookeeper/logs
# The port at which the clients will connect
Clientport = 2181
Server.1 = 192.168.137.101: 2888: 3888
Server.2 = 192.168.137.102: 2888: 3888
Server.3 = 192.168.137.103: 2888: 3888
The data directory of zookeeper is specified in/data/zookeeper/data
, Specify the directory/data/zookeeper/logs for the log file. You can also use other directories and run the following command to create the directory.
Mkdir/data/zookeeper/data-P
Initialize the myid. The three node numbers are1,2,3
To execute commands on other nodes.
echo
"1"
>/data/zookeeper/data/myid
Repeat the preceding operations on the second and third nodes. In this way, the content of myid In the first node is 1, the content of the second node is 2, and the content of the third node is 3.
Start the zookeeper cluster and start the zookeeper service on each node:
SH/opt/zookeeper-3.3.6/bin/zkserver. Sh start
You can view the status of the zookeeper cluster to ensure that the cluster is not started properly:
[[Email protected] ~] # Sh/opt/zookeeper-3.3.6/bin/zkserver. Sh status
JMX enabled by default
Using config:/opt/zookeeper-3.3.6/bin/../CONF/zoo. cfg
Mode: follower
5. Install SOLR
Run the following command:
tar zxvf apache-tomcat-7.0.47.tar.gz
-C /opt/
unzip solr-
4.4
.
0
.zip -d /opt
cd /opt
chmod +x apache-tomcat-
6.0
.
36
/bin/*.sh
cp solr-
4.4
.
0
/example/webapps/solr.war apache-tomcat-
6.0
.
36
/webapps/
Decompress SOLR. War
Unzip SOLR. War-D SOLR
cp solr-
4.4
.
0
/example/lib/ext/* apache-tomcat-
6.0
.
36
/webapps/solr/WEB-INF/lib/
cp solr-
4.4
.
0
/example/resources/log4j.properties apache-tomcat-
6.0
.
36
/lib/
Copy the operation of this node to another node.
6. zookeeper Management Configuration File
Decompress the configuration file in the attachment and copy it to the/usr/local/solrhome/core0/conf directory (each node)
1. Create a solrcloud directory and copy the SOLR lib file to this directory:
mkdir -p /usr/local/SolrCloud/solr-lib/
cp apache-tomcat-7
.0
.47
/webapps/solr/WEB-INF/lib/* /usr/local/SolrCloud/solr-lib/
2. Set solrhome: Java-classpath through Bootstrap. :/usr/local/solrcloud/SOLR-lib/* Org. apache. SOLR. cloud. zkcli-zkhost 192.168.137.101: 2181,192.168 .137.102: 2181,192.168 .137.103: 2181-cmd Bootstrap-solrhome/usr/local/solrhome/3. solrcloud ensures that configuration file changes are synchronized to each node in a timely manner through the zookeeper cluster, you need to upload the configuration file to the zookeeper cluster: Java-classpath. :/usr/local/solrcloud/SOLR-lib/* Org. apache. SOLR. cloud. zkcli-zkhost 192.168.137.101: 2181,192.168 .137.102: 2181,192.168 .137.103: 2181-cmd upconfig-confdir/usr/local/solrhome/core0/conf-confname productconf
Note:
- Zkhost specifies the zookeeper address, separated by commas
/usr/local/solrhome/core0/conf
The schema. xml and solrconfig. xml configuration files exist in the directory. You can modify them to your own directory.
- Productconf is the name of the configuration file on zookeeper.
4. Associate the configuration file with the target collection:
Java-classpath. :/usr/local/solrcloud/SOLR-lib/* Org. apache. SOLR. cloud. zkcli-zkhost 192.168.137.101: 2181,192.168 .137.102: 2181,192.168 .137.103: 2181-cmd linkconfig-collection product-confname productconf
Note:
- The created collection is called product and is connected to productconf.
5. view the status on zookeeper
Run the following command in the/OPT directory of any node:
[root
@localhost
opt]# zookeeper-
3.3
.6
/bin/zkCli.sh
[zk: localhost:
2181
(CONNECTED)
0
] ls /
[configs, zookeeper, clusterstate.json, aliases.json, live_nodes, overseer, collections, overseer_elect]
[zk: localhost:
2181
(CONNECTED)
1
] ls /configs
[productconf]
[zk: localhost:
2181
(CONNECTED)
1
] ls /collections
[product]
View
/configs
And
/collections
The configuration file has been uploaded to zookeeper. Then start SOLR.
7. tomcat configuration and startup
1. Modify the tomcat configuration file on each node and add the zkhost variable to the environment variable.
Editapache-tomcat-6.0.36/bin/catalina.sh
, Add the following code:
Java_opts = '-dsolr. SOLR. Home =/usr/local/solrhome-dzkhost = 192.168.137.101: 2181,192.168 .137.102: 2181,192.168 .137.103: 100'
In/usr/local/solrhome/
Directory to create SOLR. xml:
<?xml version=
"1.0"
encoding=
"UTF-8"
?>
<solr persistent=
"true"
sharedLib=
"lib"
>
<cores adminPath=
"/admin/cores"
zkClientTimeout=
"20000"
hostPort=
"${jetty.port:8080}"
hostContext=
"${hostContext:solr}"
></cores>
</solr>
Note:
- The hostport value must be consistent with the Tomcat port.
- SOLR uses the jetty server by default, and the default port is 8983.
Finally, start Tomcat in the/OPT directory:
Sh APACHE-Tomcat-7.0.47/bin/startup. Sh
Access through http: // 192.168.56.121: 8080/SOLR/. The interface prompt is displayed.There are no SolrCores running.
This is because solrcore has not been configured in the configuration file.
8. Create collection, Shard, and replication
Create collection and initial shard
You can directly create a collection using the rest interface. You can also access the following address through a browser, as shown below:
curl
‘http://192.168.137.101:8080/solr/admin/collections?action=CREATE&name=product&numShards=3&replicationFactor=1‘
If the response is successful, the following response is output:
The meanings of several parameters in the above link are described as follows:
- Name: name of the collection to be created
- Number of numshards shards
- Replicationfactor
You can accesshttp://192.168.137.101:8080/solr/#/~cloud
To view the shard information of the solrcloud cluster:
In fact, we can see from the 192.168.137.101 node that the SOLR configuration file has changed, as shown below:
You can also view the changes in SOLR. xml files on the other two nodes.
Manually create Replication
Next, copy the created initial parts. Shard1 is already on 192.168.137.102. Copy the sharded part to 192.168.56.101 and 192.168.56.103 and run the following command:
curl
‘http://192.168.137.101:8080/solr/admin/cores?action=CREATE&collection=product&name=product_shard1_replica_2&shard=shard1‘
curl
‘http://192.168.137.103:8080/solr/admin/cores?action=CREATE&collection=product&name=product_shard1_replica_3&shard=shard1‘
Result shard1 on 192.168.137.102 has a copy on the 192.168.137.101 node named
product_shard1_replica_2
There is a copy on the 192.168.137.103 node named
product_shard1_replica_3
. You can also view the directory changes on 192.168.137.102 and 192.168.137.103 as follows:
You can also add copies to shard2 and shard3.
Again, we can see from the 192.168.137.101 node that the content of the SOLR configuration file has changed again, as shown below:
So far, the solrcloud cluster has been configured based on three nodes.
Install Apache solrcloud