How to Install Apache SOLR 4.5 on CentOS 6.4

Source: Internet
Author: User
Tags apache solr localhost mysql solr

by Shay Anderson on October 2013Knowledge Base/Linux/How-to- Install Apache SOLR 4.5 on CentOS 6.4

In this tutorial I explain how to install the Apache SOLR 4.5 on CentOS 6.4. The examples below I am using the root user, if you is not your would need to prepend some of the examples with sudo .

Install Java

To start things off first check if you have a Java installed: If you don't have a # which java Java installed check for latest version : # yum list available | grep java and install Java, in my case it is: # yum install java-1.7.0-openjdk.x86_64 install Java-mysql DB connector:# yum install mysql-connector-java
Finally, check Java version:# java -version 
java version "1.7.0_25" 
OpenJDK Runtime Environment (rhel-2.3.10.4.el6_4-x86_64) 
OpenJDK 64-Bit Server VM (build 23.7-b01, mixed mode)


Install SOLR

Install the latest SOLR release by downloading from http://www.apache.org/dyn/closer.cgi/lucene/solr/. For example, I downloaded using:# wget http://apache.mirrors.tds.net/lucene/solr/4.5.0/solr-4.5.0.tgz /optExtract Download:# tar -xvf /opt/solr-4.5.0.tgzMove main directory for install:# mv -v /opt/solr-4.5.0 /opt/solrAnd move example directory to project name or simply core:# mv -v /opt/solr/example /opt/solr/core
Create a symlink to the Mysql-connector-java we installed earlier:# ln -s /usr/share/java/mysql-connector-java.jar /opt/solr/dist/mysql-connector-java.jarThen edit The/opt/solr/core/solr/collection1/conf/solrconfig.xml file and add these lines by the <lib dir= "..." > Li NES for using MySQL database connection and Data Import Handler (DIH):<!-- data import handler --> 
<lib dir="../../../contrib/dataimporthandler/lib/" regex=".*\.jar" /> 
<lib dir="../../../dist/" regex="solr-dataimporthandler-\d.*\.jar" /> 
<lib dir="../../../dist/" regex="mysql-connector-java.*\.jar" />


Firewall Exception

If iptables Add a rule to allow access to SOLR's admin section and query SOLR data (replace 0.0.0.0 with the Corre CT IP address): # iptables -A INPUT -s 0.0.0.0 -p tcp -m tcp --dport 8983 -j ACCEPT 
# service iptables save
Or, if you want to allow port 8983 for all requests use: # iptables -A INPUT -p tcp -m tcp --dport 8983 -j ACCEPT 
# service iptables save
Also, if you ' re using a MySQL database co Nnection for data importer you ll want to open a firewall exception for the localhost MySQL port:# iptables -A INPUT -s 127.0.0.1 -p tcp -m tcp --dport 3306 -j ACCEPT 
# service iptables save 
# iptables -L 
... 
ACCEPT tcp -- localhost anywhere tcp dpt:mysql 
...


Running SOLR

You should now is able to test running the SOLR server: # java -jar /opt/solr/core/start.jar If Everything works correctly you should being able to view the S OLR Server Admin by going to:
Http://[server hostname or ip]:8983/solr/#/

If this does don't work try viewing the Log/opt/solr/solr/logs/solr.log

You can view if SOLR are running with command:# lsof -i :8983

Auto Start Apache SOLR

Now we could want to configure Apache SOLR to auto start on server boot. First, create script for handling the SOLR Server service:# nano /etc/init.d/solrand add the following script (or one like it):#!/bin/sh
# chkconfig:2345 95 20
# DESCRIPTION:SOLR Server
# SOLR Server service start, stop, restart
# @author Shay Anderson 10.13

Solr_dir= "/opt/solr/core"
Java= "/usr/bin/java-dstop. Port=8079-dstop. Key=a09df7a0d-jar Start.jar "
Log_file= "/opt/solr/core/logs/solr-server.log"

Case $ in
Start
echo "Starting SOLR ..."
CD $SOLR _dir
$JAVA 2> $LOG _file &
Sleep 3
;;
Stop
echo "Stopping SOLR ..."
Pkill-f Start.jar >/dev/null
Retval=$?
If [$RETVAL-eq 0]; Then
echo "Stopped"
Else
echo "Failed to stop"
Fi
;;
Restart
$ stop
Sleep 2
$ start
;;
*)
echo "Usage: $ [Start|stop|restart]"
Exit 1
;;
Esac

Exit 0
Save the file and make it executable:# chmod +x /etc/init.d/solrNow register SOLR to run when server boots:# chkconfig --add solr 
# chkconfig --list | grep solr

How to Install Apache SOLR 4.5 on CentOS 6.4

Related Article

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: info-contact@alibabacloud.com 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.