1. 安装jdk 1.8 环境
1.1 下载jdk 1.8 安装包jdk-8u181-linux-x64.rpm
下载地址:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
1.2 安装
rpm -ivh jdk-8u181-linux-x64.rpm
1.3 测试
# java -version
java version "1.8.0_181"
(可以返回正确的jdk版本号说明安装成功)

2. yum 安装 MySQL 5.7
2.1 配置MySQL yum 源
#wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm --no-check-certificate
# yum localinstall mysql57-community-release-el7-8.noarch.rpm
# ls /etc/yum.repos.d/ | grep mysql
mysql-community.repo
mysql-community-source.repo
2.2 安装MySQL并启动
#yum install mysql-community-server –y
#systemctl start mysqld
#systemctl enable mysqld
2.3 修改mysql root密码
#grep "password" /var/log/mysqld.log (查看MySQL启动时生成的默认密码)
2018-07-23T01:55:00.619594Z 1 [Note] A temporary password is generated for root@localhost: tEf7eoVcxk;;
# mysql -u root –p
Enter password:(输入刚才找到的密码)
mysql> SET PASSWORD = PASSWORD('your new password');
mysql> ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;
mysql> flush privileges;
2.4 创建数据库并导入数据
mysql> create database test_solr;
mysql> use test_solr;
mysql> source /opt/solr/article.sql;
3. 安装solr 7.4
3.1 修改系统打开的文件数量
修改 /etc/sysctl.conf 文件,在最后一行添加
fs.file-max = 655350
修改 /etc/security/limits.conf 文件,在最后一行添加
* soft nproc 65535
* hard nproc 65535
* soft nofile 65535
* hard nofile 65535
修改完后要重启系统
3.2 下载solr 安装包solr-7.4.0.tgz
下载地址:http://mirrors.hust.edu.cn/apache/lucene/solr/7.4.0/solr-7.4.0.tgz
3.3 安装 solr
#mkdir /usr/local/solr
#tar xf solr-7.4.0.tgz –C /usr/local/solr/solr
3.4 修改solr 时区和可用内存大小(在/usr/local/solr/solr/bin/solr.in.sh文件里配置)
# cat /usr/local/solr/solr/bin/solr.in.sh | grep -v '#'| grep -v ^$
SOLR_JAVA_MEM="-Xms4096m -Xmx4096m"
SOLR_TIMEZONE="Asia/Shanghai"
3.5 启动solr
#/usr/local/solr/solr/bin/solr start -p 8081 –force
访问测试192.168.64.100:8081/solr

1.png

4. 使用solr 查找数据
4.1 添加test_core
4.1.1 创建test_core  目录:
在/usr/local/solr/solr/server/solr/目录下创建目录
#mkdir  test_core
4.1.2 复制配置文件
将/usr/local/solr/solr/server/solr/configsets/_default下的conf目录复制到
/usr/local/solr/solr/server/solr/test_core下
# cd /usr/local/solr/solr/server/solr/configsets/_default/
#cp –r conf /usr/local/solr/solr/server/solr/test_core/
4.1.3 添加test_core

2.png


点击Add Core 添加成功后,在/usr/local/solr/solr/server/solr/test_core目录下会有出现
core.properties 文件和 data目录
4.2 导入数据库中的数据到solr  test_core 中
4.2.1 创建data-config.xml文件
在/usr/local/solr/solr/server/solr/test_core/conf新增文件data-config.xml,内容如下:
# cat data-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<dataConfig>
    <dataSource name="source1" type="JdbcDataSource"
              driver="com.mysql.jdbc.Driver"
              url="jdbc:mysql://192.168.64.100:3306/test_solr"
              user="root"
              password="12345678@Solr"
              batchSize="-1" />
    <document>
        <entity name="article" dataSource="source1"
            query="select pmid,article_title,author_list,abstract_text,keywords,pmcid,pub_med_pub_date,journal_issue,serch_text from article">
            <field column="pmid" name="pmid" />
            <field column="article_title" name="article_title" />
            <field column="author_list" name="author_list" />
            <field column="abstract_text" name="abstract_text" />
            <field column="keywords" name="description" />
            <field column="pmcid" name="pmcid" />
            <field column="pub_med_pub_date" name="pub_med_pub_date" />
            <field column="journal_issue" name="journal_issue" />
            <field column="serch_text" name="serch_text" />
        </entity>
    </document>
</dataConfig>         
4.2.2 修改solrconfig.xml文件
修改/usr/local/solr/solr/server/solr/test_core/conf/solrconfig.xml,在<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>
<requestHandler name="/select" class="solr.SearchHandler"> #在这一行上面添加
4.2.3 修改managed-schema文件
修改/usr/local/solr/solr/server/solr/test_core/conf/managed-schema,添加一下内容:
    <field name="_version_" type="plong" indexed="false" stored="false"/>
    <field name="_root_" type="string" indexed="true" stored="false" docValues="false" />
    <field name="_text_" type="text_general" indexed="true" stored="false" multiValued="true"/>
#以下为添加的内容:
    <field name="pmid" type="string" indexed="true" stored="true" />
    <field name="article_title" type="string" indexed="true" stored="true" />
    <field name="author_list" type="string" indexed="true" stored="true" />
    <field name="abstract_text" type="string" indexed="true" stored="true" />
    <field name="keywords" type="string" indexed="true" stored="true" />
    <field name="pmcid" type="string" indexed="true" stored="true" />
    <field name="pub_med_pub_date" type="string" indexed="true" stored="true" />
    <field name="journal_issue" type="string" indexed="true" stored="true" />
    <field name="serch_text" type="string" indexed="true" stored="true" />
4.2.4 下载连接数据库和导入数据的jar包mysql-connector-java-8.0.11.jar
下载地址:http://central.maven.org/maven2/mysql/mysql-connector-java/8.0.11/mysql-connector-java-8.0.11.jar
4.2.5 配置数据导入依赖包
将刚才现在的mysql-connector-java-8.0.11.jar 和/usr/local/solr/solr/dist 目录下的
solr-dataimporthandler-extras-7.4.0.jar 、solr-dataimporthandler-7.4.0.jar
这三个jar包一起拷贝到/usr/local/solr/solr/server/solr-webapp/webapp/WEB-INF/lib目录下
#cd /usr/local/solr/solr/server/solr-webapp/webapp/WEB-INF/lib
# ls | grep -E '(solr-dataimporthandler-*|mysql*)'
mysql-connector-java-8.0.11.jar
solr-dataimporthandler-7.4.0.jar
solr-dataimporthandler-extras-7.4.0.jar
4.2.6 导入数据

3.png

4.png

5.png


4.3 搜素数据

6.png

7.png

5. 参考文档:
https://blog.csdn.net/u013160017/article/details/81037279
https://www.cnblogs.com/jorzy/p/8455519.html
https://blog.csdn.net/heboblog/article/details/49002141
https://blog.csdn.net/qq_41665356/article/details/80374884