1. 程式人生 > >Centos 7.5 + solr 7.4 (jetty啟動)+MySQL 5.7

Centos 7.5 + solr 7.4 (jetty啟動)+MySQL 5.7

技術分享 內容 rop 版本 -o 復制 tails 依賴 manage

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

技術分享圖片

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

技術分享圖片


點擊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 導入數據

技術分享圖片

技術分享圖片

技術分享圖片


4.3 搜素數據

技術分享圖片

技術分享圖片

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

Centos 7.5 + solr 7.4 (jetty啟動)+MySQL 5.7