EnterpriseApps/ApacheSolr: различия между версиями

Материал из ALT Linux Wiki
Нет описания правки
Нет описания правки
Строка 7: Строка 7:
3. распаковываем его в /opt
3. распаковываем его в /opt


tar zxf /home/petr/Загрузки/solr-9.4.0.tgz -C /opt
tar zxf /home/petr/Загрузки/solr-9.4.0.tgz -C /opt


4. Создаем системного пользователя solr
4. Создаем системного пользователя solr


adduser --system -U -m --home-dir /home/solr solr
adduser --system -U -m --home-dir /home/solr solr


5. Назначаем права на каталоги Solr
5. Назначаем права на каталоги Solr


chown -R root: /opt/solr-9.4.0
chown -R root: /opt/solr-9.4.0
chmod -R 0755 /opt/solr-9.4.0/bin
chmod -R 0755 /opt/solr-9.4.0/bin


6. Создаем каталог с настройками и копируем в него файл с параметрами программы
6. Создаем каталог с настройками и копируем в него файл с параметрами программы


mkdir /etc/default
mkdir /etc/default
chown root: /etc/default
chown root: /etc/default
chmod 0755 /etc/default
chmod 0755 /etc/default
cp "/opt/solr-9.4.0/bin/solr.in.sh" "/etc/default/solr.in.sh"
cp "/opt/solr-9.4.0/bin/solr.in.sh" "/etc/default/solr.in.sh"
 


/etc/default/solr.in.sh
/etc/default/solr.in.sh
SOLR_PID_DIR="/home/solr"
SOLR_PID_DIR="/home/solr"
SOLR_HOME="/home/solr/data"
SOLR_HOME="/home/solr/data"
LOG4J_PROPS="/home/solr/log4j2.xml"
LOG4J_PROPS="/home/solr/log4j2.xml"
SOLR_LOGS_DIR="/home/solr/logs"
SOLR_LOGS_DIR="/home/solr/logs"
SOLR_PORT="8983"
SOLR_PORT="8983"


Создаем каталоги и назначаем права
Создаем каталоги и назначаем права


mkdir -p "/home/solr/data"
mkdir -p "/home/solr/data"
mkdir -p "/home/solr/logs"
mkdir -p "/home/solr/logs"
chown -R solr: /opt/solr-9.4.0/
chown -R solr: /opt/solr-9.4.0/


Копируем файл с настройками, назначаем права и создаем символьную ссылку
Копируем файл с настройками, назначаем права и создаем символьную ссылку


cp /opt/solr-9.4.0/server/resources/log4j2.xml /home/solr/log4j2.xml
cp /opt/solr-9.4.0/server/resources/log4j2.xml /home/solr/log4j2.xml
chown -R solr: /home/solr
chown -R solr: /home/solr
ln -s '/opt/solr-9.4.0' /opt/solr
ln -s '/opt/solr-9.4.0' /opt/solr




Создаем файл
Создаем файл


/etc/init.d/solr
/etc/init.d/solr
-----
-----
#!/bin/sh
#!/bin/sh
# Licensed to the Apache Software Foundation (ASF) under one or more
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
# the License.  You may obtain a copy of the License at
#
#
#    http://www.apache.org/licenses/LICENSE-2.0
#    http://www.apache.org/licenses/LICENSE-2.0
#
#
# Unless required by applicable law or agreed to in writing, software
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# See the License for the specific language governing permissions and
# limitations under the License.
# limitations under the License.
 
### BEGIN INIT INFO
### BEGIN INIT INFO
# Provides: solr
# Provides: solr
# Required-Start:    $remote_fs $syslog
# Required-Start:    $remote_fs $syslog
# Required-Stop:    $remote_fs $syslog
# Required-Stop:    $remote_fs $syslog
# Default-Start:    2 3 4 5
# Default-Start:    2 3 4 5
# Default-Stop:      0 1 6
# Default-Stop:      0 1 6
# Description:      Controls Apache Solr as a Service
# Description:      Controls Apache Solr as a Service
### END INIT INFO
### END INIT INFO
 
# Example of a very simple *nix init script that delegates commands to the bin/solr script
# Example of a very simple *nix init script that delegates commands to the bin/solr script
# Typical usage is to do:
# Typical usage is to do:
#
#
#  cp bin/init.d/solr /etc/init.d/solr
#  cp bin/init.d/solr /etc/init.d/solr
#  chmod 755 /etc/init.d/solr
#  chmod 755 /etc/init.d/solr
#  chown root:root /etc/init.d/solr
#  chown root:root /etc/init.d/solr
#  update-rc.d solr defaults
#  update-rc.d solr defaults
#  update-rc.d solr enable
#  update-rc.d solr enable
 
# Where you extracted the Solr distribution bundle
# Where you extracted the Solr distribution bundle
SOLR_INSTALL_DIR="/opt/solr"
SOLR_INSTALL_DIR="/opt/solr"
 
if [ ! -d "$SOLR_INSTALL_DIR" ]; then
if [ ! -d "$SOLR_INSTALL_DIR" ]; then
  echo "$SOLR_INSTALL_DIR not found! Please check the SOLR_INSTALL_DIR setting in your $0 script."
  echo "$SOLR_INSTALL_DIR not found! Please check the SOLR_INSTALL_DIR setting in your $0 script."
  exit 1
  exit 1
fi
fi
 
# Path to an include file that defines environment specific settings to override default
# Path to an include file that defines environment specific settings to override default
# variables used by the bin/solr script. It's highly recommended to define this script so
# variables used by the bin/solr script. It's highly recommended to define this script so
# that you can keep the Solr binary files separated from live files (pid, logs, index data, etc)
# that you can keep the Solr binary files separated from live files (pid, logs, index data, etc)
# see bin/solr.in.sh for an example
# see bin/solr.in.sh for an example
SOLR_ENV="/etc/default/solr.in.sh"
SOLR_ENV="/etc/default/solr.in.sh"
 
if [ ! -f "$SOLR_ENV" ]; then
if [ ! -f "$SOLR_ENV" ]; then
  echo "$SOLR_ENV not found! Please check the SOLR_ENV setting in your $0 script."
  echo "$SOLR_ENV not found! Please check the SOLR_ENV setting in your $0 script."
  exit 1
  exit 1
fi
fi
 
# Specify the user to run Solr as; if not set, then Solr will run as root.
# Specify the user to run Solr as; if not set, then Solr will run as root.
# Running Solr as root is not recommended for production environments
# Running Solr as root is not recommended for production environments
RUNAS="solr"
RUNAS="solr"
 
# verify the specified run as user exists
# verify the specified run as user exists
runas_uid="`id -u "$RUNAS"`"
runas_uid="`id -u "$RUNAS"`"
if [ $? -ne 0 ]; then
if [ $? -ne 0 ]; then
  echo "User $RUNAS not found! Please create the $RUNAS user before running this script."
  echo "User $RUNAS not found! Please create the $RUNAS user before running this script."
  exit 1
  exit 1
fi
fi
 
case "$1" in
case "$1" in
  start|stop|restart|status)
  start|stop|restart|status)
    SOLR_CMD="$1"
    SOLR_CMD="$1"
    ;;
    ;;
  *)
  *)
    echo "Usage: $0 {start|stop|restart|status}"
    echo "Usage: $0 {start|stop|restart|status}"
    exit
    exit
esac
esac
 
if [ -n "$RUNAS" ]; then
if [ -n "$RUNAS" ]; then
  su -c "SOLR_INCLUDE=\"$SOLR_ENV\" \"$SOLR_INSTALL_DIR/bin/solr\" $SOLR_CMD" - "$RUNAS"
  su -c "SOLR_INCLUDE=\"$SOLR_ENV\" \"$SOLR_INSTALL_DIR/bin/solr\" $SOLR_CMD" - "$RUNAS"
else
else
  SOLR_INCLUDE="$SOLR_ENV" "$SOLR_INSTALL_DIR/bin/solr" "$SOLR_CMD"
  SOLR_INCLUDE="$SOLR_ENV" "$SOLR_INSTALL_DIR/bin/solr" "$SOLR_CMD"
fi
fi
-----
-----
Создаем файлы служб
Создаем файлы служб


chmod +x /etc/init.d/solr
chmod +x /etc/init.d/solr
-----
-----


/etc/systemd/system/solr.service
/etc/systemd/system/solr.service
-----
-----


[Unit]
[Unit]
SourcePath=/etc/init.d/solr
SourcePath=/etc/init.d/solr
Description=Apache Solr as a Service
Description=Apache Solr as a Service
Before=multi-user.target
Before=multi-user.target
Before=graphical.target
Before=graphical.target
After=remote-fs.target
After=remote-fs.target
 
[Service]
[Service]
Type=forking
Type=forking
Restart=no
Restart=no
TimeoutSec=5min
TimeoutSec=5min
IgnoreSIGPIPE=no
IgnoreSIGPIPE=no
KillMode=process
KillMode=process
GuessMainPID=no
GuessMainPID=no
RemainAfterExit=yes
RemainAfterExit=yes
SuccessExitStatus=5 6
SuccessExitStatus=5 6
ExecStart=/etc/init.d/solr start
ExecStart=/etc/init.d/solr start
ExecStop=/etc/init.d/solr stop
ExecStop=/etc/init.d/solr stop
-----
-----


systemctl enable --now solr
systemctl enable --now solr
systemctl status solr
systemctl status solr


----------------------
----------------------

Версия от 13:51, 7 декабря 2023

1. Ставим java-1.8.0-openjdk

2.Качаем бинарный релиз

https://solr.apache.org/downloads.html

3. распаковываем его в /opt

tar zxf /home/petr/Загрузки/solr-9.4.0.tgz -C /opt

4. Создаем системного пользователя solr

adduser --system -U -m --home-dir /home/solr solr

5. Назначаем права на каталоги Solr

chown -R root: /opt/solr-9.4.0
chmod -R 0755 /opt/solr-9.4.0/bin

6. Создаем каталог с настройками и копируем в него файл с параметрами программы

mkdir /etc/default
chown root: /etc/default
chmod 0755 /etc/default
cp "/opt/solr-9.4.0/bin/solr.in.sh" "/etc/default/solr.in.sh"

/etc/default/solr.in.sh

SOLR_PID_DIR="/home/solr"
SOLR_HOME="/home/solr/data"
LOG4J_PROPS="/home/solr/log4j2.xml"
SOLR_LOGS_DIR="/home/solr/logs"
SOLR_PORT="8983"

Создаем каталоги и назначаем права

mkdir -p "/home/solr/data"
mkdir -p "/home/solr/logs"
chown -R solr: /opt/solr-9.4.0/

Копируем файл с настройками, назначаем права и создаем символьную ссылку

cp /opt/solr-9.4.0/server/resources/log4j2.xml /home/solr/log4j2.xml
chown -R solr: /home/solr
ln -s '/opt/solr-9.4.0' /opt/solr


Создаем файл

/etc/init.d/solr

#!/bin/sh
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

### 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
# Description:       Controls Apache Solr as a Service
### END INIT INFO

# Example of a very simple *nix init script that delegates commands to the bin/solr script
# Typical usage is to do:
#
#   cp bin/init.d/solr /etc/init.d/solr
#   chmod 755 /etc/init.d/solr
#   chown root:root /etc/init.d/solr
#   update-rc.d solr defaults
#   update-rc.d solr enable

# Where you extracted the Solr distribution bundle
SOLR_INSTALL_DIR="/opt/solr"

if [ ! -d "$SOLR_INSTALL_DIR" ]; then
  echo "$SOLR_INSTALL_DIR not found! Please check the SOLR_INSTALL_DIR setting in your $0 script."
  exit 1
fi

# Path to an include file that defines environment specific settings to override default
# variables used by the bin/solr script. It's highly recommended to define this script so
# that you can keep the Solr binary files separated from live files (pid, logs, index data, etc)
# see bin/solr.in.sh for an example
SOLR_ENV="/etc/default/solr.in.sh"

if [ ! -f "$SOLR_ENV" ]; then
  echo "$SOLR_ENV not found! Please check the SOLR_ENV setting in your $0 script."
  exit 1
fi

# Specify the user to run Solr as; if not set, then Solr will run as root.
# Running Solr as root is not recommended for production environments
RUNAS="solr"

# verify the specified run as user exists
runas_uid="`id -u "$RUNAS"`"
if [ $? -ne 0 ]; then
  echo "User $RUNAS not found! Please create the $RUNAS user before running this script."
  exit 1
fi

case "$1" in
  start|stop|restart|status)
    SOLR_CMD="$1"
    ;;
  *)
    echo "Usage: $0 {start|stop|restart|status}"
    exit
esac

if [ -n "$RUNAS" ]; then
  su -c "SOLR_INCLUDE=\"$SOLR_ENV\" \"$SOLR_INSTALL_DIR/bin/solr\" $SOLR_CMD" - "$RUNAS"
else
  SOLR_INCLUDE="$SOLR_ENV" "$SOLR_INSTALL_DIR/bin/solr" "$SOLR_CMD"
fi

Создаем файлы служб

chmod +x /etc/init.d/solr

/etc/systemd/system/solr.service

[Unit]
SourcePath=/etc/init.d/solr
Description=Apache Solr as a Service
Before=multi-user.target
Before=graphical.target
After=remote-fs.target

[Service]
Type=forking
Restart=no
TimeoutSec=5min
IgnoreSIGPIPE=no
KillMode=process
GuessMainPID=no
RemainAfterExit=yes
SuccessExitStatus=5 6
ExecStart=/etc/init.d/solr start
ExecStop=/etc/init.d/solr stop

systemctl enable --now solr
systemctl status solr

Веб-интерфейс:

http://127.0.0.1:8983/solr/