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

查看:98
本文介绍了如何自动启动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访问权限,则可以根据系统的初始化流程(初始化脚本,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天全站免登陆