Блог экспериментатора инженера-разработчика: Infanty.
Я пишу how-to статьи на редкие темы или статьи обзоры - для себя и тех кто со мной работает.
Блог существует при поддержке: "Оккупационных сил Марса".

Рассмотрим установку Solr 4.x (установка версии 5.x несколько отличается) в Ubuntu 14.04 (или старше). Для начала установим Java набрав в консоли:

sudo aptitude install default-jre-headless 

Скачиваем Apache Solr по ссылке: http://archive.apache.org/dist/lucene/solr/4.10.4/solr-4.10.4.zip. И распаковываем дистрибутив в: "/opt/solr" (каталог "/opt" предполагает установку программного обеспечения не из репозиториев).

sudo -s

cd /tmp
wget http://archive.apache.org/dist/lucene/solr/4.10.4/solr-4.10.4.zip
unzip -xzf solr-4.10.4.zip
mv /tmp/solr-4.10.4/example /opt/solr 

Создаем пользователя с именем "solr" с исходным каталогом в "/opt/solr" и поменяем владельца данного каталога на только что созданного пользователя.

useradd -d /opt/solr -M -s /dev/null -U solr
chown -R solr:solr /opt/solr 

Перенастроим сохранение логов Apache Solr из "/opt/solr/logs" в более привычную папку: "/var/log/solr". Для этого в файле: "/opt/solr/resources/log4j.properties", меняем строку "solr.log=logs/" на "solr.log=/var/log/solr/". После чего создаем каталог для логов и даём доступ к этому каталогу для Apache Solr:

mkdir /var/log/solr
chown -R solr:solr /var/log/solr 

Создаём скрипт автозапуска Apache Solr: "/etc/init.d/solr", следующего содержания:

#!/bin/sh

# init.d script to start Apache Solr

### BEGIN INIT INFO
# Provides:          solr
# Required-Start:    $remote_fs $network
# Required-Stop:     $remote_fs $network
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts Apache Solr
# Description:       Starts Apache Solr
### END INIT INFO


SOLR_USER=solr
PID_FILE=/var/run/solr.pid

# SOLR home directory
SOLR_HOME=/opt/solr

do_start() {
  export SOLR_HOME

  cd $SOLR_HOME

  echo -n "Starting Solr ..."
  start-stop-daemon --start \
    --pidfile $PID_FILE \
    --chuid $SOLR_USER -d $SOLR_HOME \
    --background --make-pidfile \
    --startas /usr/bin/java \
    -- \
    -Dsolr.solr.home=$SOLR_HOME/solr \
    -Djetty.home=$SOLR_HOME \
    -Djava.io.tmpdir=/tmp \
    -jar $SOLR_HOME/start.jar \
    --daemon

  RC="$?"
  if [ "$RC" = 0 ]; then
    echo "OK"
  else
    echo "Failed"
  fi

  return $RC
}

do_stop() {
  echo -n "Stopping Solr ..."
  start-stop-daemon --stop --pidfile $PID_FILE

  RC="$?"
  if [ "$RC" = 0 ]; then
    echo "OK"
  else
    echo "Failed"
  fi

  return $RC
}

COMMAND=$1

case "$COMMAND" in
start)
  do_start
  exit $RC
  ;;

stop)
  do_stop
  exit $RC
  ;;

restart)
  do_stop
  sleep 3
  do_start
  exit $RC
  ;;

*)
  echo "Usage: $0 {start|stop|restart}"
  exit 1
  ;;
esac

 

Даём скрипту права на запуск и добавляем его в автозагрузку.

chmod 755 /etc/init.d/solr
update-rc.d solr defaults 

Для запуска Apache Solr наберём в консоли:

sudo service solr start 

После чего по URL: http://x.x.x.x/solr/ будет доступен web-интерфейс Apache Solr, а его логи можно посмотреть командой:

 sudo tail /var/log/solr/solr.log 

P.S.: Вариант скрипта автозапуска Apache Solr в режиме multicore:

 #! /bin/sh

### BEGIN INIT INFO
# Provides:          solr
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Solr
# Description:       Solr advanced search engine
### END INIT INFO

# Author: Mac_Weber

# Do NOT "set -e"

# PATH should only include /usr/* if it runs after the mountnfs.sh script
PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="Solr"
# Process name ( For display )
NAME="solr"
# Daemon name, where is the actual executable
DAEMON=/usr/bin/java

# Read about the available options at: http://docs.oracle.com/javase/1.3/docs/tooldocs/solaris/java.html
DAEMON_ARGS="-Xmx1024m -DSTOP.PORT=8079 -DSTOP.KEY=stopkey -Dsolr.solr.home=multicore -jar start.jar"

# pid file for the daemon
PIDFILE=/var/run/$NAME.pid
# script name
SCRIPTNAME=/etc/init.d/$NAME

# Solr home
SOLR_HOME=/opt/solr

# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh

# Define LSB log_* functions.
# Depend on lsb-base (>= 3.2-14) to ensure that this file is present
# and status_of_proc is working.
. /lib/lsb/init-functions

# Exit if the package is not installed
[ -x $DAEMON ] || exit 5

# Read configuration variable file if it is present
[ -r /etc/default/$NAME ] && . /etc/default/$NAME

#
# Function that starts the daemon/service
#
do_start()
{
        # Return
        #   0 if daemon has been started
        #   1 if daemon was already running
        #   2 if daemon could not be started
        start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
                || return 1
        start-stop-daemon --start --quiet --pidfile $PIDFILE --chdir $SOLR_HOME --background --make-pidfile --exec $DAEMON -- \
                $DAEMON_ARGS \
                || return 2
        # Add code here, if necessary, that waits for the process to be ready
        # to handle requests from services started subsequently which depend
        # on this one.  As a last resort, sleep for some time.
}

#
# Function that stops the daemon/service
#
do_stop()
{
        # Return
        #   0 if daemon has been stopped
        #   1 if daemon was already stopped
        #   2 if daemon could not be stopped
        #   other if a failure occurred
        # there was on both:--retry=TERM/30/KILL/5
        start-stop-daemon --stop --quiet --retry=TERM/4/KILL/5 --pidfile $PIDFILE --name $NAME
        RETVAL="$?"
        [ "$RETVAL" = 2 ] && return 2
        # Wait for children to finish too if this is a daemon that forks
        # and if the daemon is only ever run from this initscript.
        # If the above conditions are not satisfied then add some other code
        # that waits for the process to drop all resources that could be
        # needed by services started subsequently.  A last resort is to
        # sleep for some time.
        start-stop-daemon --stop --quiet --oknodo --retry=TERM/4/KILL/5 --exec $DAEMON
        [ "$?" = 2 ] && return 2
        # Many daemons don't delete their pidfiles when they exit.
        rm -f $PIDFILE
        return "$RETVAL"
}

#
# Function that sends a SIGHUP to the daemon/service
#
do_reload() {
        #
        # If the daemon can reload its configuration without
        # restarting (for example, when it is sent a SIGHUP),
        # then implement that here.
        #
        start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
        return 0
}

case "$1" in
  start)
        echo "$DESC: Starting $NAME" >&2
        do_start
        case "$?" in
                0) log_daemon_msg "$DESC" "is now running" && log_end_msg 0 ;;
                1) log_daemon_msg "$DESC" "was already running" && log_end_msg 0 ;;
                2) log_daemon_msg "$DESC" "could not be started" && log_end_msg 2 ;;
        esac
        ;;
  stop)
        echo "$DESC: Stopping $NAME" >&2
        do_stop
        case "$?" in
                0|1) log_daemon_msg "$DESC" "is stopped" && log_end_msg 0 ;; #It is always returning 0
                2) log_daemon_msg "$DESC" "could not be stopped" && log_end_msg 2 ;;
        esac
        ;;
  status)
       status_of_proc "$DAEMON" "$NAME" && exit 0
       ;;
  restart)
        echo "$DESC: Restarting $NAME" >&2
        do_stop
        case "$?" in
          0|1)
                do_start
                case "$?" in
                        0) log_daemon_msg "$DESC" "restarted" && log_end_msg 0 ;;
                        1) log_daemon_msg "$DESC" "old precess is still running" && log_end_msg 1 ;;
                        *) log_daemon_msg "$DESC" "failed to restart" && log_end_msg 1 ;;
                esac
                ;;
          *)
                # Failed to stop
                log_daemon_msg "$DESC" "failed to stop" && log_end_msg 1
                ;;
        esac
        ;;
  *)
        echo "Usage: $SCRIPTNAME {start|stop|status|restart}" >&2
        exit 3
        ;;
esac

: