首页 > 代码库 > How to Install Apache Solr 4.5 on CentOS 6.4
How to Install Apache Solr 4.5 on CentOS 6.4
In this tutorial I explain how to install Apache Solr 4.5 on CentOS 6.4. In all the examples below I am using the root user, if you are not you will need to prepend some of the examples with sudo.
Install Java
To start things off first check if you have Java installed:# which java
If you do not have Java installed check for latest version:# yum list available | grep java
And install Java, in my case it was:# 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 /opt
Extract download:# tar -xvf /opt/solr-4.5.0.tgz
Move main directory for install:# mv -v /opt/solr-4.5.0 /opt/solr
And 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.jar
Then edit the /opt/solr/core/solr/collection1/conf/solrconfig.xml file and add these lines by the <lib dir="..."> lines 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 you use iptables add a rule to allow access to Solr‘s admin section and query Solr data (replace 0.0.0.0 with the correct IP address):# iptables -A INPUT -s 0.0.0.0 -p tcp -m tcp --dport 8983 -j ACCEPT
Or, if you want to allow port 8983 for all requests use:
# service iptables save# iptables -A INPUT -p tcp -m tcp --dport 8983 -j ACCEPT
Also, if you‘re using a MySQL database connection for data importer you‘ll want to open a firewall exception for the localhost MySQL port:
# service iptables save# 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 be able to test running the Solr server:# java -jar /opt/solr/core/start.jar
If everything works correctly you should be able to view the Solr server admin by going to:
http://[server hostname or IP]:8983/solr/#/
If this does not work try viewing the log /opt/solr/solr/logs/solr.log
You can view if Solr is running with command:# lsof -i :8983
Auto Start Apache Solr
Now we may want to configure Apache Solr to auto start on server boot. First, create script for handling the Solr server service:# nano /etc/init.d/solr
And add the following script (or one like it):#!/bin/sh
Save the file and make it executable:
# 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 $1 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)
$0 stop
sleep 2
$0 start
;;
*)
echo "Usage: $0 [start|stop|restart]"
exit 1
;;
esac
exit 0# chmod +x /etc/init.d/solr
Now 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