在三台服务器上搭建solr集群,具体架构如下所示:
192.168.184.127 solr1/zk1
192.168.184.128 solr2/zk2
192.168.184.129 solr3/zk3
1.安装docker
三台服务器上都执行以下命令
# setenforce 0
# systemctl stop firewalld
# systemctl disable firewalld
# sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
安装docker
# yum -y install docker
# systemctl start docker
# systemctl enable docker
2.安装zk集群,三台服务器上都执行以下命令
# mkdir -p /usr/local/solr-zk/zk/{conf,data,datalog}
solr1服务器执行:
# vim /usr/local/solr-zk/zk/conf/zoo.cfg
dataDir=/data
dataLogDir=/datalog
clientPort=2181
tickTime=2000
initLimit=5
syncLimit=2
autopurge.snapRetainCount=3
autopurge.purgeInterval=0
maxClientCnxns=60
standaloneEnabled=true
admin.enableServer=false
server.1=0.0.0.0:2888:3888
server.2=192.168.184.128:2888:3888
server.3=192.168.184.129:2888:3888
solr2服务器执行:
# vim /usr/local/solr-zk/zk/conf/zoo.cfg
dataDir=/data
dataLogDir=/datalog
clientPort=2181
tickTime=2000
initLimit=5
syncLimit=2
autopurge.snapRetainCount=3
autopurge.purgeInterval=0
maxClientCnxns=60
standaloneEnabled=true
admin.enableServer=false
server.1=192.168.184.127:2888:3888
server.2=0.0.0.0:2888:3888
server.3=192.168.184.129:2888:3888
solr3服务器执行:
# vim /usr/local/solr-zk/zk/conf/zoo.cfg
dataDir=/data
dataLogDir=/datalog
clientPort=2181
tickTime=2000
initLimit=5
syncLimit=2
autopurge.snapRetainCount=3
autopurge.purgeInterval=0
maxClientCnxns=60
standaloneEnabled=true
admin.enableServer=false
server.1=192.168.184.127:2888:3888
server.2=192.168.184.128:2888:3888
server.3=0.0.0.0:2888:3888
新建myid文件
192.168.184.127上执行
# echo "1" > /usr/local/solr-zk/zk/data/myid
192.168.184.128上执行
# echo "2" > /usr/local/solr-zk/zk/data/myid
192.168.184.129上执行
# echo "3" > /usr/local/solr-zk/zk/data/myid
启动容器
192.168.184.127上执行
# docker run -d \
-p 2181:2181 \
-p 2888:2888 \
-p 3888:3888 \
--privileged=true \
--restart=always \
-v /usr/local/solr-zk/zk/data/:/data/ \
-v /usr/local/solr-zk/zk/datalog/:/datalog/ \
-v /usr/local/solr-zk/zk/conf/zoo.cfg:/conf/zoo.cfg \
-v /etc/localtime:/etc/localtime:ro \
--name zk \
-h 192.168.184.127 \
zookeeper:3.4.14
192.168.184.128上执行
# docker run -d \
-p 2181:2181 \
-p 2888:2888 \
-p 3888:3888 \
--privileged=true \
--restart=always \
-v /usr/local/solr-zk/zk/data/:/data/ \
-v /usr/local/solr-zk/zk/datalog/:/datalog/ \
-v /usr/local/solr-zk/zk/conf/zoo.cfg:/conf/zoo.cfg \
-v /etc/localtime:/etc/localtime:ro \
--name zk \
-h 192.168.184.128 \
zookeeper:3.4.14
192.168.184.129上执行
# docker run -d \
-p 2181:2181 \
-p 2888:2888 \
-p 3888:3888 \
--privileged=true \
--restart=always \
-v /usr/local/solr-zk/zk/data/:/data/ \
-v /usr/local/solr-zk/zk/datalog/:/datalog/ \
-v /usr/local/solr-zk/zk/conf/zoo.cfg:/conf/zoo.cfg \
-v /etc/localtime:/etc/localtime:ro \
--name zk \
-h 192.168.184.129 \
zookeeper:3.4.14
查看容器状态
# docker ps
3.安装solr集群,三台服务器上都执行以下命令
# mkdir -p /usr/local/solr-zk/solr/config
192.168.184.127上执行
# vim /usr/local/solr-zk/solr/config/solr.in.sh
SOLR_HEAP="1g"
ZK_HOST="192.168.184.127:2181,192.168.184.128:2181,192.168.184.129:2181" #zk集群地址
SOLR_HOST="192.168.184.127" #本机ip地址
SOLR_TIMEZONE="UTC+8"
ENABLE_REMOTE_JMX_OPTS="false"
SOLR_OPTS="$SOLR_OPTS -Xss256k"
SOLR_OPTS="$SOLR_OPTS -Dsun.net.inetaddr.ttl=60 -Dsun.net.inetaddr.negative.ttl=60"
SOLR_HOME="/var/solr/data/"
SOLR_LOGS_DIR="/var/solr/logs/"
SOLR_PORT=8983 #solr端口
192.168.184.128上执行
# vim /usr/local/solr-zk/solr/config/solr.in.sh
SOLR_HEAP="1g"
ZK_HOST="192.168.184.127:2181,192.168.184.128:2181,192.168.184.129:2181"
SOLR_HOST="192.168.184.128"
SOLR_TIMEZONE="UTC+8"
ENABLE_REMOTE_JMX_OPTS="false"
SOLR_OPTS="$SOLR_OPTS -Xss256k"
SOLR_OPTS="$SOLR_OPTS -Dsun.net.inetaddr.ttl=60 -Dsun.net.inetaddr.negative.ttl=60"
SOLR_HOME="/var/solr/data/"
SOLR_LOGS_DIR="/var/solr/logs/"
SOLR_PORT=8983
192.168.184.129上执行
# vim /usr/local/solr-zk/solr/config/solr.in.sh
SOLR_HEAP="1g"
ZK_HOST="192.168.184.127:2181,192.168.184.128:2181,192.168.184.129:2181"
SOLR_HOST="192.168.184.129"
SOLR_TIMEZONE="UTC+8"
ENABLE_REMOTE_JMX_OPTS="false"
SOLR_OPTS="$SOLR_OPTS -Xss256k"
SOLR_OPTS="$SOLR_OPTS -Dsun.net.inetaddr.ttl=60 -Dsun.net.inetaddr.negative.ttl=60"
SOLR_HOME="/var/solr/data/"
SOLR_LOGS_DIR="/var/solr/logs/"
SOLR_PORT=8983
分别启动容器
192.168.184.127上执行
# docker run -d \
--restart=always \
-p 8983:8983 \
-l io.rancher.container.network=true \
-v /usr/local/solr-zk/solr/solrhome/:/var/solr/solrhome/ \
-v /usr/local/solr-zk/solr/log/:/var/solr/log/ \
-v /usr/local/solr-zk/solr/dist/:/var/solr/dist/ \
-v /usr/local/solr-zk/solr/config/solr.in.sh:/etc/default/solr.in.sh \
-v /etc/localtime:/etc/localtime:ro \
--name solr \
-h 192.168.184.127 \
solr:latest
192.168.184.128上执行
# docker run -d \
--restart=always \
-p 8983:8983 \
-l io.rancher.container.network=true \
-v /usr/local/solr-zk/solr/solrhome/:/var/solr/solrhome/ \
-v /usr/local/solr-zk/solr/log/:/var/solr/log/ \
-v /usr/local/solr-zk/solr/dist/:/var/solr/dist/ \
-v /usr/local/solr-zk/solr/config/solr.in.sh:/etc/default/solr.in.sh \
-v /etc/localtime:/etc/localtime:ro \
--name solr \
-h 192.168.184.128 \
solr:latest
192.168.184.129上执行
# docker run -d \
--restart=always \
-p 8983:8983 \
-l io.rancher.container.network=true \
-v /usr/local/solr-zk/solr/solrhome/:/var/solr/solrhome/ \
-v /usr/local/solr-zk/solr/log/:/var/solr/log/ \
-v /usr/local/solr-zk/solr/dist/:/var/solr/dist/ \
-v /usr/local/solr-zk/solr/config/solr.in.sh:/etc/default/solr.in.sh \
-v /etc/localtime:/etc/localtime:ro \
--name solr \
-h 192.168.184.129 \
solr:latest
查看容器状态
# docker ps
访问solr集群:http://192.168.184.127:8983/solr/index.html
用命令创建cllocetion
curl 'http://127.0.0.1:8983/solr/admin/collections?action=CREATE&name=a&numShards=1&replicationFactor=3&maxShardsPerNode=1'