solr 集群搭建

搭建zookeeper集群

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
[root@iZuf6iq8e7ya9v3ix71k0pZ ~]# cd /usr/local/
[root@iZuf6iq8e7ya9v3ix71k0pZ local]# mkdir solr-cluster
[root@iZuf6iq8e7ya9v3ix71k0pZ local]# cd solr-cluster/
[root@iZuf6iq8e7ya9v3ix71k0pZ solr-cluster]# cp /usr/local/zookeeper/zookeeper-3.4.10.tar.gz /usr/local/solr-cluster/
[root@iZuf6iq8e7ya9v3ix71k0pZ solr-cluster]# tar zxvf zookeeper-3.4.10.tar.gz
[root@iZuf6iq8e7ya9v3ix71k0pZ solr-cluster]# mv zookeeper-3.4.10 zookeeper01
[root@iZuf6iq8e7ya9v3ix71k0pZ solr-cluster]# cp -r zookeeper01 zookeeper02
[root@iZuf6iq8e7ya9v3ix71k0pZ solr-cluster]# cp -r zookeeper01 zookeeper03
[root@iZuf6iq8e7ya9v3ix71k0pZ solr-cluster]# rm -rf zookeeper-3.4.10.tar.gz
[root@iZuf6iq8e7ya9v3ix71k0pZ solr-cluster]# ll
总用量 12
drwxr-xr-x 10 root root 4096 3月 13 16:33 zookeeper01
drwxr-xr-x 10 root root 4096 3月 13 16:32 zookeeper02
drwxr-xr-x 10 root root 4096 3月 13 16:32 zookeeper03
<!-- more -->

#创建 data 目录,并创建 myid 文件,编辑标识 1
[root@iZuf6iq8e7ya9v3ix71k0pZ solr-cluster]# mkdir data
[root@iZuf6iq8e7ya9v3ix71k0pZ data]# vim myid (或者echo 1 > myid)
1
~
~
~
~
~
:wq

# 重命名配置文件,修改配置文件
[root@iZuf6iq8e7ya9v3ix71k0pZ data]# cd ../conf
[root@iZuf6iq8e7ya9v3ix71k0pZ conf]# mv zoo_sample.cfg zoo.cfg
[root@iZuf6iq8e7ya9v3ix71k0pZ conf]# vim zoo.cfg
# 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 between
# sending a request and getting an acknowledgement
syncLimit=5
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just
# example sakes.
dataDir=/tmp/zookeeper
# the port at which the clients will connect
clientPort=2181
# the maximum number of client connections.
# increase this if you need to handle more clients
#maxClientCnxns=60
#
参数说明

clientPort=客户端连接端口
dataDir=data目录(/usr/local/solr-cluster/zookeeper01/data)
server.1=127.0.0.1:2881:3881 (1 myid标识,2881 zookeeper 连接内部通讯端口,3881 选举端口)

配置修改如下
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# 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 between
# sending a request and getting an acknowledgement
syncLimit=5
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just
# example sakes.
dataDir=/usr/local/solr-cluster/zookeeper01/data
# the port at which the clients will connect
clientPort=2182
# the maximum number of client connections.
# increase this if you need to handle more clients
#maxClientCnxns=60
#
# Be sure to read the maintenance section of the
# administrator guide before turning on autopurge.
#
# http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
#
# The number of snapshots to retain in dataDir
#autopurge.snapRetainCount=3
# Purge task interval in hours
# Set to "0" to disable auto purge feature
#autopurge.purgeInterval=1
server.1=127.0.0.1:2881:3881
server.2=127.0.0.1:2882:3882
server.3=127.0.0.1:2883:3883

# 配置zookeeper02,03
[root@iZuf6iq8e7ya9v3ix71k0pZ sorl-cluster]
生成批处理文件,启动并查看状态
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# 创建批处理文件
[root@iZuf6iq8e7ya9v3ix71k0pZ sorl-cluster] vim start-zookeeper.sh

cd zookeeper01/bin
./zkServer.sh start
cd ../../
cd zookeeper02/bin
./zkServer.sh start
cd ../../
cd zookeeper03/bin
./zkServer.sh start
cd ../../
~
~
~
~
"start-zookeeper.sh" 9L, 147C

# 授权
[root@iZuf6iq8e7ya9v3ix71k0pZ solr-cluster]# chmod +x start-zookeeper.sh

# 启动查看状态
[root@iZuf6iq8e7ya9v3ix71k0pZ solr-cluster]# ./start-zookeeper.sh
ZooKeeper JMX enabled by default
Using config: /usr/local/solr-cluster/zookeeper01/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
ZooKeeper JMX enabled by default
Using config: /usr/local/solr-cluster/zookeeper02/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
ZooKeeper JMX enabled by default
Using config: /usr/local/solr-cluster/zookeeper03/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[root@iZuf6iq8e7ya9v3ix71k0pZ solr-cluster]# zookeeper01/bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /usr/local/solr-cluster/zookeeper01/bin/../conf/zoo.cfg
Mode: follower
[root@iZuf6iq8e7ya9v3ix71k0pZ solr-cluster]# zookeeper02/bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /usr/local/solr-cluster/zookeeper02/bin/../conf/zoo.cfg
Mode: leader
[root@iZuf6iq8e7ya9v3ix71k0pZ solr-cluster]# zookeeper03/bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /usr/local/solr-cluster/zookeeper03/bin/../conf/zoo.cfg
Mode: follower
[root@iZuf6iq8e7ya9v3ix71k0pZ solr-cluster]#

搭建solr集群

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
[root@iZuf6iq8e7ya9v3ix71k0pZ solr-cluster]# cp /usr/local/tomcat/apache-tomcat-8.5.27.tar.gz /usr/local/solr-cluster/
[root@iZuf6iq8e7ya9v3ix71k0pZ solr-cluster]# tar zxvf apache-tomcat-8.5.27.tar.gz
[root@iZuf6iq8e7ya9v3ix71k0pZ solr-cluster]# rm -rf apache-tomcat-8.5.27.tar.gz
[root@iZuf6iq8e7ya9v3ix71k0pZ solr-cluster]# mv apache-tomcat-8.5.27/ tomcat01
[root@iZuf6iq8e7ya9v3ix71k0pZ solr-cluster]# cp -r tomcat01/ tomcat02
[root@iZuf6iq8e7ya9v3ix71k0pZ solr-cluster]# cp -r tomcat01/ tomcat02
[root@iZuf6iq8e7ya9v3ix71k0pZ solr-cluster]# cp -r tomcat01/ tomcat03
[root@iZuf6iq8e7ya9v3ix71k0pZ solr-cluster]# cp -r tomcat01/ tomcat04
[root@iZuf6iq8e7ya9v3ix71k0pZ solr-cluster]# vim tomcat01/conf/server.xml
tomcat01 tomcat02 tomcat03 tomcat04
8005 +10 8015 8016 8017 8018
8080 +10 8090 8091 8092 8093
8009 +10 8019 8020 8021 8022

[root@iZuf6iq8e7ya9v3ix71k0pZ solr-cluster]# ll
总用量 32
-rwxr-xr-x 1 root root 147 3月 13 17:36 start-zookeeper.sh
drwxr-xr-x 9 root root 4096 3月 14 09:57 tomcat01
drwxr-xr-x 9 root root 4096 3月 14 10:00 tomcat02
drwxr-xr-x 9 root root 4096 3月 14 10:01 tomcat03
drwxr-xr-x 9 root root 4096 3月 14 10:01 tomcat04
drwxr-xr-x 11 root root 4096 3月 13 16:39 zookeeper01
drwxr-xr-x 11 root root 4096 3月 13 17:02 zookeeper02
drwxr-xr-x 11 root root 4096 3月 13 17:28 zookeeper03

# 复制solr相关配置
[root@iZuf6iq8e7ya9v3ix71k0pZ solr-cluster]# cp -r /usr/local/solr/tomcat-8082/webapps/solr/ /usr/local/solr-cluster/tomcat01/webapps/
[root@iZuf6iq8e7ya9v3ix71k0pZ solr-cluster]# cp -r /usr/local/solr/tomcat-8082/webapps/solr/ /usr/local/solr-cluster/tomcat02/webapps/
[root@iZuf6iq8e7ya9v3ix71k0pZ solr-cluster]# cp -r /usr/local/solr/tomcat-8082/webapps/solr/ /usr/local/solr-cluster/tomcat03/webapps/
[root@iZuf6iq8e7ya9v3ix71k0pZ solr-cluster]# cp -r /usr/local/solr/tomcat-8082/webapps/solr/ /usr/local/solr-cluster/tomcat04/webapps/
[root@iZuf6iq8e7ya9v3ix71k0pZ solr-cluster]# cp -r /usr/local/solr/solrhome /usr/local/solr-cluster/solrhome01
[root@iZuf6iq8e7ya9v3ix71k0pZ solr-cluster]# cp -r /usr/local/solr/solrhome /usr/local/solr-cluster/solrhome02
[root@iZuf6iq8e7ya9v3ix71k0pZ solr-cluster]# cp -r /usr/local/solr/solrhome /usr/local/solr-cluster/solrhome03
[root@iZuf6iq8e7ya9v3ix71k0pZ solr-cluster]# cp -r /usr/local/solr/solrhome /usr/local/solr-cluster/solrhome04


# 修改solrcloud配置(solrtomcat01为例)
[root@iZuf6iq8e7ya9v3ix71k0pZ solr-cluster]# vim solrhome01/solr.xml
[root@iZuf6iq8e7ya9v3ix71k0pZ solr-cluster]# vim solrhome02/solr.xml
[root@iZuf6iq8e7ya9v3ix71k0pZ solr-cluster]# vim solrhome03/solr.xml
[root@iZuf6iq8e7ya9v3ix71k0pZ solr-cluster]# vim solrhome04/solr.xml
<solr>

<solrcloud>

<str name="host">${host:}</str>
<int name="hostPort">${jetty.port:8983}</int>
...
...

<solr>

<solrcloud>

<str name="host">127.0.0.1</str>
<int name="hostPort">8090</int>

# solr实例绑定对应的solrhome(solrhome1为例)
[root@iZuf6iq8e7ya9v3ix71k0pZ solr-cluster]# vim tomcat01/webapps/solr/WEB-INF/web.xml
[root@iZuf6iq8e7ya9v3ix71k0pZ solr-cluster]# vim tomcat02/webapps/solr/WEB-INF/web.xml
[root@iZuf6iq8e7ya9v3ix71k0pZ solr-cluster]# vim tomcat03/webapps/solr/WEB-INF/web.xml
[root@iZuf6iq8e7ya9v3ix71k0pZ solr-cluster]# vim tomcat04/webapps/solr/WEB-INF/web.xml
<env-entry>
<env-entry-name>solr/home</env-entry-name>
<env-entry-value>/usr/local/solr/solrhome</env-entry-value>
<env-entry-type>java.lang.String</env-entry-type>
</env-entry>
...
...
<env-entry>
<env-entry-name>solr/home</env-entry-name>
<env-entry-value>/usr/local/solr-cluster/solrhome01</env-entry-value>
<env-entry-type>java.lang.String</env-entry-type>
</env-entry>


tomcat关联zookeeper
1
2
3
4
5
6
7
[root@iZuf6iq8e7ya9v3ix71k0pZ solr-cluster]# vim tomcat01/bin/catalina.sh
[root@iZuf6iq8e7ya9v3ix71k0pZ solr-cluster]# vim tomcat02/bin/catalina.sh
[root@iZuf6iq8e7ya9v3ix71k0pZ solr-cluster]# vim tomcat03/bin/catalina.sh
[root@iZuf6iq8e7ya9v3ix71k0pZ solr-cluster]# vim tomcat04/bin/catalina.sh
...
...
JAVA_OPTS="-DzkHost=127.0.0.1:2182,127.0.0.1:2183,127.0.0.1:2184"
zookeeper 统一管理配置文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# 让zookeeper统一管理配置文件。需要把solrhome/mycore/conf目录上传到zookeeper。上传任意solrhome中的配置文件即可。
# ./zkcli.sh -zkhost 127.0.0.1:2182,127.0.0.1:2183,127.0.0.1:2184 -cmd upconfig -confdir /usr/local/solr-cluster/solrhome01/mycore/conf/ -confname myconf

[root@iZuf6iq8e7ya9v3ix71k0pZ ~]# cd solr-7.2.1/server/scripts/cloud-scripts/
[root@iZuf6iq8e7ya9v3ix71k0pZ cloud-scripts]# ./zkcli.sh -zkhost 127.0.0.1:2182,127.0.0.1:2183,127.0.0.1:2184 -cmd upconfig -confdir /usr/local/solr-cluster/solrhome01/mycore/conf/ -confname myconf

# 查看上传的文件
[root@iZuf6iq8e7ya9v3ix71k0pZ cloud-scripts]# cd /usr/local/solr-cluster/zookeeper01/bin/
[root@iZuf6iq8e7ya9v3ix71k0pZ bin]# ./zkCli.sh -server 127.0.0.1:2182
[zk: 127.0.0.1:2182(CONNECTED) 2] ls /configs/myconf
[data-config.xml, managed-schema, protwords.txt, solrconfig.xml, synonyms.txt, stopwords.txt, dataimport.properties, params.json, lang, managed-schema的副本]
[zk: 127.0.0.1:2182(CONNECTED) 3]

# 创建快速启动文件
[root@iZuf6iq8e7ya9v3ix71k0pZ solr-cluster]# vim start-tomcat.sh
[root@iZuf6iq8e7ya9v3ix71k0pZ solr-cluster]# chmod +x start-tomcat.sh
/usr/local/solr-cluster/tomcat01/bin/startup.sh
/usr/local/solr-cluster/tomcat02/bin/startup.sh
/usr/local/solr-cluster/tomcat03/bin/startup.sh
/usr/local/solr-cluster/tomcat04/bin/startup.sh
[root@iZuf6iq8e7ya9v3ix71k0pZ solr-cluster]# vim stop-tomcat.sh
[root@iZuf6iq8e7ya9v3ix71k0pZ solr-cluster]# chmod +x stop-tomcat.sh
/usr/local/solr-cluster/tomcat01/bin/shutdown.sh
/usr/local/solr-cluster/tomcat02/bin/shutdown.sh
/usr/local/solr-cluster/tomcat03/bin/shutdown.sh
/usr/local/solr-cluster/tomcat04/bin/shutdown.sh
[root@iZuf6iq8e7ya9v3ix71k0pZ solr-cluster]# ./start-tomcat.sh

访问xxxxxx:8090/solr/index.html 报错:SolrCore Initialization Failures
https://segmentfault.com/q/1010000012076404/a-1020000012123299
原因:solr启动的时候会去检测home的collection,但是你那个core1是从单节点拷贝过来的,结构上肯定不一样,单节点上core和collection可以理解成相等的,集群中collection是有分布在不通节点上的core组成的

1
2
3
4
[root@iZuf6iq8e7ya9v3ix71k0pZ solr-cluster]# rm -rf solrhome01/mycore
[root@iZuf6iq8e7ya9v3ix71k0pZ solr-cluster]# rm -rf solrhome02/mycore
[root@iZuf6iq8e7ya9v3ix71k0pZ solr-cluster]# rm -rf solrhome03/mycore
[root@iZuf6iq8e7ya9v3ix71k0pZ solr-cluster]# rm -rf solrhome04/mycore