MacOS installs SOLR and indexes Mysql_mysql

Source: Internet
Author: User
Tags solr create database brew cask

Install the Java language Software Development Kit

Brew Cask Install Java

Alternatively, select the Mac version jdk-8u111-macosx-x64.dmg download and install on the Oracle website.

Install SOLR

Brew Install SOLR

The SOLR version of the current (2016-11-10) Brew source is 6.1.0, you can modify the version you want to install through brew edit SOLR, or download the source package from the official website to compile the installation.

Start SOLR

SOLR start

Returning the following text hint indicates that the SOLR server was successfully installed and the default listener port number is 8983:

Waiting up to seconds to the running on the port 8983 [\]
started SOLR server on port 8983 (pid=890). Happy searching!

accessing in the browser

SOLR provides a visual management interface, SOLR Admin, and the default access URL is: http://localhost:8983/solr/

Create a core that is named Test

SOLR create-c Test

Returns the following information, which indicates a successful creation:

Copying configuration to new core instance directory:
creating New core ' test ' using command:
http://localhost:8983/solr/admin/cores?action=create&name=test& Instancedir=test
Responseheader": {"
status": 0,
"qtime": 8845},
"core": "Test"}

This command creates a directory of command test/in the/usr/local/cellar/solr/6.1.0/server/solr/directory that contains the test core-related data files and configuration files in the test/directory.

You can see test core information in the SOLR Admin admin interface:

Installing the MySQL Database

Brew Install MySQL

Change the password of root to 123456. or any other password you like:

mysqladmin-u root password ' 123456 '

This MySQL account will be used when configuring the SOLR index MySQL information.

To add the data that tests are used for testing:

Create database Solrdata;
Use Solrdata;
CREATE TABLE goods (ID int not NULL auto_increment, name varchar () NOT NULL default ", number varchar NOT NULL DEFAU Lt ', updatetime timestamp NOT NULL default current_timestamp on update Current_timestamp, primary key (ID));
INSERT into goods (name, number) values (' Shoes ', m);
INSERT into goods (name, number) values (' clothes ');
INSERT into goods (name, number) values (' trousers ', 300);

Download MySQL Driver

Download the Mysql-connector-java driver package from the official MySQL address. Or just run the command to get the 5.1.40 version of the drive:


Copy this driver package to the/usr/local/cellar/solr/6.1.0/libexec/dist/directory:

TAR-ZXVF mysql-connector-java-5.1.40.tar.gz
CD mysql-connector-java-5.1.40
CP mysql-connector-java-5.1.40-bin.jar/usr/local/cellar/solr/6.1.0/libexec/dist/

Modify Solrconfig.xml Configuration


Introduction of related driver packages

Enter the 3 related jar packages in the/usr/local/cellar/solr/6.1.0/libexec/dist/:

<lib dir= "${solr.install.dir}/libexec/dist/" regex= "Mysql-connector-java-5.1.40-bin.jar"/> <lib dir=
"${solr.install.dir}/libexec/dist/" regex= "Solr-dataimporthandler-.*\.jar"/>

Add MySQL configuration information

In <requesthandler name= "/select" class= "SOLR." Add the following information to the front of the Searchhandler >:

<requesthandler name= "/dataimport" class= "Org.apache.solr.handler.dataimport.DataImportHandler" > 
< LST name= "Defaults" > 
<str name= "config" >data-config.xml</str> 
</ Requesthandler>

Create a new Data-config.xml file in the same directory


Add the following information:

<?xml version= "1.0" encoding= "UTF-8"?>
<datasource name= "Source1" type= "
Jdbcdatasource "
driver=" Com.mysql.jdbc.Driver "
url=" Jdbc:mysql://localhost:3306/solrdata "
user=" Root "
password=" 123456 "
batchsize="-1 "/>
<entity name="
goods "pk=" ID "
datasource=" Source1 "
query=" SELECT * from goods "
deltaimportquery=" select * from goods where id= ' ${} ' "
deltaquery=" SELECT ID from goods where updatetime> ' ${dataimporter.last_index_time} ' ">
<field column= "id"
name= "id"/>
<field column= "name"
name= "name"/>
< Field column= "number"
name= "number"/>
<field column= "updatetime"
name= "UpdateTime"/>

Managed-schema Configuration Field Information


Add the following information:

<field name= "Name" type= "string" indexed= "true" stored= "false"/> <field name= "number
" type= "int" indexed = "true" stored= "false"/> <field name= "updatetime" type= "date" indexed=
"true" stored= "false"/>

Restart the SOLR service

SOLR restart

Returns the following information stating that the SOLR server restarted successfully:

Sending stop command to SOLR running on port 8983 ... waiting 5 seconds to allow Jetty process 1446 to stop gracefully.
   waiting up to seconds to the running on the port 8983 [/]
started SOLR server on port 8983 (pid=1784). Happy searching!

DataImport operation

Open the browser into SOLR Admin, and in the following interface, click the Execute button:

After successful, the following interface is displayed:

Query queries

Enter the Query page and click the Execute button:

The above is a small set to introduce the MacOS installation SOLR and index MySQL, I hope to help you, if you have any questions please give me a message, small set will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.