【问题标题】:How to create solr service for starting solr on reboot如何创建 solr 服务以在重启时启动 solr
【发布时间】:2020-05-28 10:41:03
【问题描述】:

我正在尝试创建一个可用于在重新启动时自动启动 solr 的 solr 服务脚本。这是我看到推荐的一个脚本:

#!/bin/sh

# Starts, stops, and restarts Apache Solr.
#
# chkconfig: 35 92 08
# description: Starts and stops Apache Solr

SOLR_DIR="/var/www/html/fas/solr/solr-latest"
JAVA_OPTIONS="-Xmx1024m -DSTOP.PORT=8983 -DSTOP.KEY=mustard -jar /var/www/html/fas/solr/solr-latest/server/start.jar"
LOG_FILE="/var/log/solr.log"
JAVA="/bin/java"

case $1 in
    start)
        echo "Starting Solr"
        cd $SOLR_DIR
        $JAVA $JAVA_OPTIONS 2> $LOG_FILE &
        ;;
    stop)
        echo "Stopping Solr"
        cd $SOLR_DIR
        $JAVA $JAVA_OPTIONS --stop
        ;;
    restart)
        $0 stop
        sleep 1
        $0 start
        ;;
    *)
        echo "Usage: $0 {start|stop|restart}" >&2
        exit 1
        ;;
esac

我想我已经为脚本中的变量设置了适当的值。但是当我尝试运行脚本时,我得到“连接被拒绝”。

$ service solr stop
Stopping Solr
java.net.ConnectException: Connection refused (Connection refused)

无论我是否以 root 身份运行脚本,我都会得到相同的结果。

不过,我可以通过这种方式停止和启动 solr:

/path/to/my/solr/bin/solr start

所以我也尝试在 /etc/init.d/solr-start 创建这个脚本

#!/bin/sh

# Starts Apache Solr.
#
# chkconfig: 35 92 08
# description: Starts Apache Solr

/var/www/html/fas/solr/solr-latest/bin/solr start

此脚本在命令行下工作,但在重新启动时不起作用。为了让它在重启时运行,我做了......

sudo systemctl enable solr-start

但是重启时 solr 没有启动。

我的版本: RHEL 7,Solr 6.6.6

【问题讨论】:

    标签: bash solr boot rhel


    【解决方案1】:

    很遗憾,您几乎没有提供有关特定 Solr 安装的详细信息。不过,以下 systemd 单元示例可能会提供一个起点。

    使用以下内容创建文件/etc/systemd/system/solr.service(并进行调整以使其适合您的 Solr 安装):

    [Unit]
    Description=Apache SOLR
    After=syslog.target network.target remote-fs.target nss-lookup.target systemd-journald-dev-log.socket
    Before=multi-user.target
    Conflicts=shutdown.target
    
    [Service]
    User=solr
    # Assumes SOLR_PID_DIR; change port if it differs
    PIDFile=/var/lib/solr/solr-8983.pid
    # Assumes proper configuration in /etc/default/solr.in.sh
    Environment=SOLR_INCLUDE=/etc/default/solr.in.sh
    ExecStart=/path/to/my/solr/bin/solr start
    ExecStop=/path/to/my/solr/bin/solr stop
    Restart=on-failure
    
    [Install]
    WantedBy=multi-user.target
    

    以 root 身份执行以下命令或在它们前面加上 sudo

    • systemctl daemon-reload
    • systemctl enable solr.service
    • systemctl start solr.service
    • systemctl status solr.service

    如果您在 systemd 单元中需要不同(或更多)选项,则 GitHub Gistsuggested to upstream 作为上游包含的可能起点。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-10
      相关资源
      最近更新 更多