如何自动启动 Solr? [英] How to start Solr automatically?

查看:33
本文介绍了如何自动启动 Solr?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我必须去 /usr/java/apache-solr-1.4.0/example 然后做:

At the moment I have to go to /usr/java/apache-solr-1.4.0/example and then do:

java -jar start.jar

如何让它在启动时自动启动?

How do I get this to start automatically on boot?

我在共享 Linux 服务器上.

I'm on a shared Linux server.

推荐答案

如果您对您的机器有 root 访问权限,那么根据您系统的初始化流程(init 脚本、systemd 等),有多种方法可以做到这一点

If you have root access to your machine, there are a number of ways to do this based on your system's initialization flow (init scripts, systemd, etc.)

但如果您没有 root,cron 有一种干净且一致的方式在重新启动时执行程序.

But if you don't have root, cron has a clean and consistent way to execute programs upon reboot.

首先,找出java在你机器上的位置.下面的命令会告诉你它在哪里:

First, find out where java is located on your machine. The command below will tell you where it is:

$ which java

然后,将以下代码粘贴到 shell 脚本中,将下面的 java 路径 (/usr/bin) 替换为您从上述命令中获得的路径.

Then, stick the following code into a shell script, replacing the java path below (/usr/bin) with the path you got from the above command.

#!/bin/bash

cd /usr/java/apache-solr-1.4.0/example
/usr/bin/java -jar start.jar

您可以将此脚本保存在某个位置(例如 $HOME)作为 start.sh.通过运行以下命令为其授予全局执行权限(以简化):

You can save this script in some location (e.g., $HOME) as start.sh. Give it world execute permission (to simplify) by running the following command:

$ chmod og+x start.sh

现在,测试脚本并确保它从命令行正常工作.

Now, test the script and ensure that it works correctly from the command line.

$ ./start.sh

如果一切正常,您需要将其添加到您机器的启动脚本之一.最简单的方法是将以下行添加到 /etc/rc.local 的末尾.

If all works well, you need to add it to one of your machine's startup scripts. The simplest way to do this is to add the following line to the end of /etc/rc.local.

# ... snip contents of rc.local ...
# Start Solr upon boot.
/home/somedir/start.sh

或者,如果您没有编辑 rc.local 的权限,那么您可以将其添加到您的用户 crontab 中.首先在命令行输入以下内容:

Alternatively, if you don't have permission to edit rc.local, then you can add it to your user crontab as so. First type the following on the commandline:

$ crontab -e

这将调出一个编辑器.向其中添加以下行:

This will bring up an editor. Add the following line to it:

@reboot /home/somedir/start.sh

如果您的 Linux 系统支持它(通常支持),这将确保您的脚本在启动时运行.

If your Linux system supports it (which it usually does), this will ensure that your script is run upon startup.

如果我上面没有任何错别字,它应该适合你.让我知道进展如何.

If I don't have any typos above, it should work out well for you. Let me know how it goes.

这篇关于如何自动启动 Solr?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆