安装Solr
1.拉取solr镜像:docker pull solr:版本号
docker pull solr:7.7.2
2.默认安装solr-tmp-server:
docker run -itd -p 8982:8983 --restart=always --name=solr-tmp-server --privileged=true solr:7.7.2
[root@ReverseProxy ~]# docker run -itd -p 8982:8983 --restart=always --name=solr-tmp-server --privileged=true solr:7.7.2
eeba37a6caf0085ca35a32bdffdbbe1d8e05e2d23f0d502efc48f9ccb0c65be0
[root@ReverseProxy ~]#
3.实际安装服务:solr7-server
创建实际安装目录:/docker/workspace/common/solr7
[root@ReverseProxy ~]# cd /docker/workspace/common/
[root@ReverseProxy common]# ls
elasticsearch gitlab jenkins mysql nexus nginx rocketmq solr subversion vsftpd
[root@ReverseProxy common]# mkdir solr7
[root@ReverseProxy common]# ls
elasticsearch gitlab jenkins mysql nexus nginx rocketmq solr solr7 subversion vsftpd
[root@ReverseProxy common]#
3.复制solr-tmp-server的/opt/solr/server到/docker/workspace/common/solr7
查看容器列表: docker ps --format "table {}\t{}\t{}"
[root@ReverseProxy ~]# docker ps --format "table {{.ID}}\t{{.Names}}\t{{.Ports}}"
CONTAINER ID NAMES PORTS
eeba37a6caf0 solr-tmp-server 0.0.0.0:8982->8983/tcp
59696cbcdc89 rocketmq-console-server 0.0.0.0:8686->8080/tcp
a585377d27f9 rocketmq-broker-server 0.0.0.0:10909->10909/tcp, 9876/tcp, 0.0.0.0:10911->10911/tcp
77f002077e21 rocketmq-namesrv-server 10909/tcp, 0.0.0.0:9876->9876/tcp, 10911/tcp
b32eef9fae32 dubbo-server 0.0.0.0:9200->8080/tcp
1a3a06522431 jira-software-server 0.0.0.0:5601->8080/tcp
9df44a388458 mysql5-test-server 33060/tcp, 0.0.0.0:3407->3306/tcp
4504209184f5 mysql5-server 33060/tcp, 0.0.0.0:3409->3306/tcp
80a3df8e7570 activemq-test-server 1883/tcp, 5672/tcp, 61613-61614/tcp, 0.0.0.0:9092->8161/tcp, 0.0.0.0:61618->61616/tcp
f9f0788f1118 activemq-develop-server 1883/tcp, 5672/tcp, 61613-61614/tcp, 0.0.0.0:8886->8161/tcp, 0.0.0.0:61617->61616/tcp
d5beddf650de jenkins-server 0.0.0.0:12345->8080/tcp, 0.0.0.0:32809->50000/tcp
27dbed560e89 nginx-server 0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp
ee506d85d47d nexus-server 0.0.0.0:8088->8081/tcp
963dd344d6e2 redis-develop-server 0.0.0.0:30001->6379/tcp
7779a62d3bd9 redis-test-server 0.0.0.0:30002->6379/tcp
6a9126755c02 zookeeper-remote-server 2888/tcp, 3888/tcp, 8080/tcp, 0.0.0.0:2182->2181/tcp
12ff9c292dd4 zookeeper-develop-server 2888/tcp, 3888/tcp, 0.0.0.0:2181->2181/tcp, 8080/tcp
9ffb273b9090 portainer-server 0.0.0.0:9000->9000/tcp
[root@ReverseProxy ~]#
执行docker cp 命令:
docker cp eeba37a6caf0:/opt/solr/server /docker/workspace/common/solr7
[root@ReverseProxy ~]# docker cp eeba37a6caf0:/opt/solr/server /docker/workspace/common/solr7
[root@ReverseProxy ~]#
4.创建solr的相关配置文件夹:
在/docker/workspace/common/solr7创建cofig配置目录:
mkdir -p /docker/workspace/common/solr7/config
并且在config目录创建data和logs目录:
mkdir -p /docker/workspace/common/solr7/config/{data,logs}
授权/docker/solr/config/目录所有文件:
chmod -R 777 /docker/workspace/common/solr7/config
chmod -R 777 /docker/workspace/common/solr7/config/data
chmod -R 777 /docker/workspace/common/solr7/config/logs
docker cp 4c6c67503060:/opt/solr/server/solr/solr.xml /docker/workspace/common/solr7/config/
docker cp 4c6c67503060:/opt/solr/server/solr/zoo.cfg /docker/workspace/common/solr7/config/
docker cp 4c6c67503060:/opt/solr/server/solr/configsets /docker/workspace/common/solr7/config/
5.正式安装solr7-server:
docker run -itd -p 8983:8983 --restart=always --privileged=true --name solr7-server -v /docker/workspace/common/solr7/server:/opt/solr/server -v /docker/workspace/common/solr7/config/logs:/opt/solr/server/logs -e TZ="Asia/Shanghai" -e JAVA_OPTS="-server -verbose:gc -Xms256m -Xmx256m -Xmn128m -Xss128M -XX:MetaspaceSize=256m -XX:MaxMetaspaceSize=256m -XX:SurvivorRatio=8 -XX:+AlwaysPreTouch -XX:-UseBiasedLocking -XX:+UseG1GC -XX:G1HeapRegionSize=128m -XX:G1ReservePercent=25 -XX:InitatingHeapOccupancyPercent=80 -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=128m" solr:7.7.2
[⚠️注意事项] 一定而且必须要对宿主机文件目录操作授权
配置Solr服务
1.创建核心选择器
docker exec -it --user=solr solr7-server bin/solr create_core -c new_core
docker exec -it --user=solr solr7-server bin/solr create_core -c query-server
docker exec -it --user=solr solr7-server bin/solr create_core -c inquiry-server
docker exec -it --user=solr solr7-server bin/solr create_core -c collection-server
[root@ReverseProxy ~]# docker exec -it --user=solr solr7-server bin/solr create_core -c query-server
WARNING: Using _default configset with data driven schema functionality. NOT RECOMMENDED for production use.
To turn off: bin/solr config -c query-server -p 8983 -action set-user-property -property update.autoCreateFields -value false
Created new core 'query-server'
[root@ReverseProxy ~]# docker exec -it --user=solr solr7-server bin/solr create_core -c inquiry-server
WARNING: Using _default configset with data driven schema functionality. NOT RECOMMENDED for production use.
To turn off: bin/solr config -c inquiry-server -p 8983 -action set-user-property -property update.autoCreateFields -value false
Created new core 'inquiry-server'
[root@ReverseProxy ~]# docker exec -it --user=solr solr7-server bin/solr create_core -c collection-server
WARNING: Using _default configset with data driven schema functionality. NOT RECOMMENDED for production use.
To turn off: bin/solr config -c collection-server -p 8983 -action set-user-property -property update.autoCreateFields -value false
Created new core 'collection-server'
[root@ReverseProxy ~]#
2.配置中文分词:
1.下载中文分词jar:ik-analyzer-solr7-7.x.jar
2.上传到/docker/workspace/common/solr7/libs 目录
- 拷贝依赖到容器目录
/docker/workspace/common/solr7/server/solr-webapp/webapp/WEB-INF/lib
在对应/docker/workspace/common/solr7/config/data
的核心选择器的[inquiry-server/conf/,collection-server/conf/,query-server/conf/] 中编辑managed-schema 追加如下配置:
<!-- ik分词器 -->
<fieldType name="ikanalyzer" class="solr.TextField">
<analyzer type="index">
<tokenizer class="org.wltea.analyzer.lucene.IKTokenizerFactory" useSmart="false" conf="ik.conf"/>
<filter class="solr.LowerCaseFilterFactory"/>
</analyzer>
<analyzer type="query">
<tokenizer class="org.wltea.analyzer.lucene.IKTokenizerFactory" useSmart="true" conf="ik.conf"/>
<filter class="solr.LowerCaseFilterFactory"/>
</analyzer>
</fieldType>
4.配置mysql数据库:
需要用到的mysql-jdbc依赖:
mysql-connector-java-8.0.18.jar
mysql-connector-java-5.1.48.jar
[root@ReverseProxy libs]# cp mysql-connector-java-5.1.48.jar /docker/workspace/common/solr7/server/solr-webapp/webapp/WEB-INF/lib/
[root@ReverseProxy libs]# cp mysql-connector-java-8.0.18.jar /docker/workspace/common/solr7/server/solr-webapp/webapp/WEB-INF/lib/
[root@ReverseProxy libs]#
[⚠️注意事项] 可以在宿主机操作,也可以使用Docker cp 命令操作
还有solr 数据操作依赖[/opt/solr/dist]:
solr-dataimporthandler-7.7.2.jar
solr-dataimporthandler-extras-7.7.2.jar
root@79d2c917942e:/opt/solr/dist# cp solr-dataimporthandler-7.7.2.jar /opt/solr/server/solr-webapp/webapp/WEB-INF/lib/
root@79d2c917942e:/opt/solr/dist# cp solr-dataimporthandler-extras-7.7.2.jar /opt/solr/server/solr-webapp/webapp/WEB-INF/lib/
root@79d2c917942e:/opt/solr/dist#
[⚠️注意事项] 必须在容器的/opt/solr/dist操作
编写配置文件:mysql-datasource-config.xml
<?xml version="1.0" encoding="UTF-8" ?>
<dataConfig>
<dataSource type="JdbcDataSource"
name="BpsDataSource"
driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://118.190.209.86:3409/qdgd_bps?useUnicode=true&characterEncoding=utf8&autoReconnect=true&useSSL=false"
user="root"
password="GuangDian@2019" />
<dataSource type="JdbcDataSource"
name="ShakerDataSource"
driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://118.190.209.86:3409/shaker_test?useUnicode=true&characterEncoding=utf8&autoReconnect=true&useSSL=false"
user="root"
password="GuangDian@2019"/>
<document>
<entity name="item-user" dataSource="BpsDataSource" query="select * from system_user" deltaQuery="select * from system_user where name > '${dataimporter.last_index_time}'">
<field column="ID" name="id" />
<field column="userName" name="user_name" />
<field column="account" name="account" />
</entity>
<entity name="items-user" dataSource="ShakerDataSource" query="select * from system_user" deltaQuery="select * from system_user where name > '${dataimporter.last_index_time}'">
<field column="ID" name="id" />
<field column="userName" name="user_name" />
<field column="account" name="account" />
</entity>
</document>
</dataConfig>
编辑配置文件:solrconfig.xml
追加数据库数据导入配置:
<requestHandler name="/dataimport" class="solr.DataImportHandler">
<lst name="defaults">
<str name="config">database/mysql-datasource-config.xml</str>
</lst>
</requestHandler>
增加solr-dataimporthandler等jar配置,放到在
<lib dir="${solr.install.dir:../../../..}/dist/" regex="solr-dataimporthandler-\d.*\.jar" />