转载请表明出处 https://blog.csdn.net/Amor_Leo/article/details/85270383 谢谢
官网
docker pull solr
mkdir -p /usr/local/solr
chmod 777 /usr/local/solr
docker run --name solr -d -p 8983:8983 solr
docker cp solr:/opt/solr/server /usr/local/solr
docker rm -f solr
chmod 777 /usr/local/solr/server/contexts/
chmod 777 /usr/local/solr/server/etc/
chmod 777 /usr/local/solr/server/lib/
chmod 777 /usr/local/solr/server/logs/
chmod 777 /usr/local/solr/server/modules/
chmod 777 /usr/local/solr/server/resources/
chmod 777 /usr/local/solr/server/scripts/
chmod 777 /usr/local/solr/server/scripts/cloud-scripts/
chmod 777 /usr/local/solr/server/solr/
chmod 777 /usr/local/solr/server/solr-webapp/
chmod 777 /usr/local/solr/server/solr-webapp/webapp/
firewall-cmd --zone=public --add-port=8983/tcp --permanent
firewall-cmd --reload
docker run --name solr -d -v /usr/local/solr/server:/opt/solr/server -p 8983:8983 --privileged=true solr
docker exec -it --user=solr solr bin/solr create_core -c testcore
mkdir -p /usr/local/Ik
cd /usr/local/Ik
unzip ikanalyzer-solr6.5.zip
cd ikanalyzer-solr5/
cp ik-analyzer-solr5-5.x.jar /usr/local/solr/server/solr-webapp/webapp/WEB-INF/lib/
cp solr-analyzer-ik-5.1.0.jar /usr/local/solr/server/solr-webapp/webapp/WEB-INF/lib/
mkdir -p /usr/local/solr/server/solr-webapp/webapp/WEB-INF/classes
cp ext.dic /usr/local/solr/server/solr-webapp/webapp/WEB-INF/classes/
cp stopword.dic /usr/local/solr/server/solr-webapp/webapp/WEB-INF/classes/
cp IKAnalyzer.cfg.xml /usr/local/solr/server/solr-webapp/webapp/WEB-INF/classes/
vim /usr/local/solr/server/solr/testcore/conf/managed-schema
<fieldType name="text_ik" class="solr.TextField">
<analyzer type="index" useSmart="false"
class="org.wltea.analyzer.lucene.IKAnalyzer" />
<analyzer type="query" useSmart="true"
class="org.wltea.analyzer.lucene.IKAnalyzer" />
</fieldType>
下载jar
官网
cd /usr/local/solr/server/solr-webapp/webapp/WEB-INF/lib/
wget http://central.maven.org/maven2/mysql/mysql-connector-java/5.1.47/mysql-connector-java-5.1.47.jar
wget http://central.maven.org/maven2/org/apache/solr/solr-dataimporthandler-extras/7.6.0/solr-dataimporthandler-extras-7.6.0.jar
wget http://central.maven.org/maven2/org/apache/solr/solr-dataimporthandler/7.6.0/solr-dataimporthandler-7.6.0.jar
配置连接信息
vim /usr/local/solr/server/solr/testcore/conf/solrconfig.xml
<!-- mysql导入增加的包-->
<lib dir="${solr.install.dir:../../../..}/dist/" regex="mysql-connector-java-.*\.jar" />
<lib dir="${solr.install.dir:../../../..}/dist/" regex="solr-dataimporthandler-.*\.jar" />
在requestHandler name="/select" class="solr.SearchHandler"上添加
<requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler">
<lst name="defaults">
<str name="config">data-config.xml</str>
</lst>
</requestHandler>
vim /usr/local/solr/server/solr/testcore/conf/data-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<dataConfig>
<dataSource type="JdbcDataSource"
driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://192.168.0.109:3306/solrtest"
user="root"
password="root" />
<document>
<entity name="user" query="select * from user">
<field column="uid" name="uid" />
<field column="username" name="username" />
<field column="passward" name="passward" />
<field column="hobby" name="hobby" />
<field column="login_time" name="login_time" />
</entity>
</document>
</dataConfig>
vim /usr/local/solr/server/solr/testcore/conf/managed-schema
<!-- 自己导入的字段 -->
<field name="uid" type="pint" indexed="true" stored="true" />
<field name="username" type="text_ik" indexed="true" stored="true" />
<field name="passward" type="string" indexed="true" stored="true" />
<field name="hobby" type="string" indexed="true" stored="true" />
<field name="login_time" type="pdate" indexed="true" stored="true" />
重启Solr
docker restart solr
之前写过 Docker搭建zookeeper集群 或者 安装zookeeper集群
三台分别执行
官网
docker pull solr
三台分别执行
mkdir -p /usr/local/solrCloud
chmod 777 /usr/local/solrCloud
docker run --name solr -d -p 8983:8983 solr
docker cp solr:/opt/solr/server /usr/local/solrCloud/
docker rm -f solr
chmod 777 /usr/local/solrCloud/
chmod 777 /usr/local/solrCloud/server/
chmod 777 /usr/local/solrCloud/server/contexts/
chmod 777 /usr/local/solrCloud/server/etc/
chmod 777 /usr/local/solrCloud/server/lib/
chmod 777 /usr/local/solrCloud/server/logs/
chmod 777 /usr/local/solrCloud/server/modules/
chmod 777 /usr/local/solrCloud/server/resources/
chmod 777 /usr/local/solrCloud/server/scripts/
chmod 777 /usr/local/solrCloud/server/scripts/cloud-scripts/
chmod 777 /usr/local/solrCloud/server/solr/
chmod 777 /usr/local/solrCloud/server/solr-webapp/
chmod 777 /usr/local/solrCloud/server/solr-webapp/webapp/
mkdir -p /usr/local/Ik
cd /usr/local/Ik
unzip ikanalyzer-solr6.5.zip
cd ikanalyzer-solr5/
cp ik-analyzer-solr5-5.x.jar /usr/local/solrCloud/server/solr-webapp/webapp/WEB-INF/lib/
cp solr-analyzer-ik-5.1.0.jar /usr/local/solrCloud/server/solr-webapp/webapp/WEB-INF/lib/
mkdir -p /usr/local/solrCloud/server/solr-webapp/webapp/WEB-INF/classes
cp ext.dic /usr/local/solrCloud/server/solr-webapp/webapp/WEB-INF/classes/
cp stopword.dic /usr/local/solrCloud/server/solr-webapp/webapp/WEB-INF/classes/
cp IKAnalyzer.cfg.xml /usr/local/solrCloud/server/solr-webapp/webapp/WEB-INF/classes/
下载jar
官网
cd /usr/local/solrCloud/server/solr-webapp/webapp/WEB-INF/lib/
wget http://central.maven.org/maven2/mysql/mysql-connector-java/5.1.47/mysql-connector-java-5.1.47.jar
wget http://central.maven.org/maven2/org/apache/solr/solr-dataimporthandler-extras/7.6.0/solr-dataimporthandler-extras-7.6.0.jar
wget http://central.maven.org/maven2/org/apache/solr/solr-dataimporthandler/7.6.0/solr-dataimporthandler-7.6.0.jar
我用的是之前搭建的单机版solr
docker exec -it solr /opt/solr/server/scripts/cloud-scripts/zkcli.sh -zkhost 192.168.0.111:2181,192.168.0.112:2181,192.168.0.113:2181 -cmd upconfig -confdir /opt/solr/server/solr/testcore/conf -confname myconf
或者用安装Solr7
cd /usr/local/solr/solr-7.6.0/server/scripts/cloud-scripts
./zkcli.sh -zkhost 192.168.0.111:2181,192.168.0.112:2181,192.168.0.113:2181 -cmd upconfig -confdir /usr/local/solr/solr-7.6.0/server/solr/new_core/conf -confname myconf
三台分别执行
firewall-cmd --zone=public --add-port=8983/tcp --permanent
firewall-cmd --zone=public --add-port=7983/tcp --permanent
firewall-cmd --reload
docker run --name solr -d --hostname=192.168.0.111 --net=host -v /usr/local/solrCloud/server:/opt/solr/server --privileged=true solr bash -c 'solr start -f -z 192.168.0.111:2181,192.168.0.112:2181,192.168.0.113:2181'
docker run --name solr -d --hostname=192.168.0.112 --net=host -v /usr/local/solrCloud/server:/opt/solr/server --privileged=true solr bash -c 'solr start -f -z 192.168.0.111:2181,192.168.0.112:2181,192.168.0.113:2181'
docker run --name solr -d --hostname=192.168.0.113 --net=host -v /usr/local/solrCloud/server:/opt/solr/server --privileged=true solr bash -c 'solr start -f -z 192.168.0.111:2181,192.168.0.112:2181,192.168.0.113:2181'
http://192.168.0.111:8983/
http://192.168.0.112:8983/
http://192.168.0.113:8983/
选取其中一个节点运行
http://其中一个solr节点的IP:8983/solr/admin/collections?action=CREATE&name=testcore&numShards=3&replicationFactor=3&maxShardsPerNode=3&autoAddReplicas=true&collection.configName=myconf
如果不指定配置文件 &collection.configName=myconf 那么就是默认_default/conf
http://192.168.0.111:8983/solr/admin/collections?action=CREATE&name=testcore&numShards=3&replicationFactor=3&maxShardsPerNode=3&autoAddReplicas=true&collection.configName=myconf
http://其中一个solr节点的IP:8983/solr/admin/collections?action=DELETE&name=testcore&numShards=3&replicationFactor=3&maxShardsPerNode=3&autoAddReplicas=true
http://192.168.0.111:8983/solr/admin/collections?action=DELETE&name=testcore&numShards=3&replicationFactor=3&maxShardsPerNode=3&autoAddReplicas=true