首先我们看看Elasticsearch的启动脚本:
[root@bicloud77 bin]# ./elasticsearch --help Usage: ./elasticsearch [-vdh] [-p pidfile] [-D prop] [-X prop] Start elasticsearch. -d daemonize (run in background) -p pidfile write PID to <pidfile> -h --help print command line options -v print elasticsearch version, then exit -D prop set JAVA system property -X prop set non-standard JAVA system property --prop=val --prop val set elasticsearch property (i.e. -Des.<prop>=<val>)
只能后台启动,没有启动,停止,重启,查看状态等命令,非常不方面管理。
安装servicewrapper
我们在服务器环境下可以使用elasticsearch-servicewrapper这个ES插件。下载地址是:https://github.com/elastic/elasticsearch-servicewrapper
下载完成后,将下来的项目的service目录拷贝到elasticsearch的bin目录中,并且设置service目录下的elasticsearch文件的权限:
chmod a+x elasticsearch
如下就是${ES_HOME}/bin/service/elasticsearch的使用说明:
[root@bicloud77 service]# ./elasticsearch --help
Unexpected command: --help
Usage: ./elasticsearch [ console | start | stop | restart | condrestart | status | install | remove | dump ]
Commands:
console Launch in the current console.#控制台启动
start Start in the background as a daemon process.#后台启动
stop Stop if running as a daemon or in another console.#停止
restart Stop if running and then start.#重启
condrestart Restart only if already running.#仅仅在已经运行的情况下启动
status Query the current status.#查看状态
install Install to start automatically when system boots.
remove Uninstall.
dump Request a Java thread dump if running.
servicewrapper配置文件
[root@bicloud75 service]# pwd /home/elasticsearch-1.4.0/bin/service [root@bicloud75 service]# vi elasticsearch.conf set.default.ES_HOME=<Path to Elasticsearch Home> set.default.ES_HEAP_SIZE=2048 //因为是测试机器,设置的内存比较少,服务器好的话,可以设置大一些 set.default.ES_MIN_SIZE=2048 set.default.ES_MAX_SIZE=2048 #Fish #JVM参数Elasticsearch默认值Environment变量: #-Xms 256m ES_MIN_MEM #-Xmx 1g ES_MAX_MEM #-Xms and -Xmx ES_HEAP_SIZE #-Xmn ES_HEAP_NEWSIZE #-XX:MaxDirectMemorySize ES_DIRECT_SIZE #******************************************************************** # Wrapper Timeout Properties #******************************************************************** # How long to wait for the JVM to start (in seconds) wrapper.startup.timeout=300 # How long to wait for the JVM to stop (in seconds) wrapper.shutdown.timeout=300 # When a ping will timeout to consider the JVM hung (in seconds) wrapper.ping.timeout=300 #******************************************************************** # Wrapper Java Properties #******************************************************************** # Java Application wrapper.java.command=java # Tell the Wrapper to log the full generated Java command line. #wrapper.java.command.loglevel=INFO wrapper.java.mainclass=org.tanukisoftware.wrapper.WrapperSimpleApp wrapper.working.dir=%ES_HOME% # Java Classpath (include wrapper.jar) Add class path elements as # needed starting from 1 wrapper.java.classpath.1=%ES_HOME%/bin/service/lib/wrapper.jar wrapper.java.classpath.2=%ES_HOME%/lib/elasticsearch*.jar wrapper.java.classpath.3=%ES_HOME%/lib/*.jar wrapper.java.classpath.4=%ES_HOME%/lib/sigar/*.jar # Java Library Path (location of Wrapper.DLL or libwrapper.so) wrapper.java.library.path.1=%ES_HOME%/bin/service/lib # Java Bits. On applicable platforms, tells the JVM to run in 32 or 64-bit mode. wrapper.java.additional.auto_bits=TRUE # Java Additional Parameters wrapper.java.additional.1=-Delasticsearch-service wrapper.java.additional.2=-Des.path.home=%ES_HOME% wrapper.java.additional.3=-Xss256k wrapper.java.additional.4=-XX:+UseParNewGC wrapper.java.additional.5=-XX:+UseConcMarkSweepGC # Initial Java Heap Size (in MB) wrapper.java.initmemory=%ES_HEAP_SIZE% # Maximum Java Heap Size (in MB) wrapper.java.maxmemory=%ES_HEAP_SIZE% ...(更多)
安装问题总汇
[root@bicloud75 service]# sh ./elasticsearch start
: command not foundne 2:
: command not foundne 4:
: command not foundne 6:
'/elasticsearch: line 138: syntax error near unexpected token `in
'/elasticsearch: line 138: `case $0 in
或者
[root@bicloud75service]# ./elasticsearch start
-bash: bin/service/elasticsearch: /bin/sh^M: bad interpreter: 没有那个文件或目录
在Linux中执行.sh脚本,异常/bin/sh^M: bad interpreter: No such file or directory。
分析:这是不同系统编码格式引起的:在windows系统中编辑的.sh文件可能有不可见字符,所以在Linux系统下执行会报以上异常信息。
解决:1)在windows下转换:
利用一些编辑器如UltraEdit或EditPlus等工具先将脚本编码转换,再放到Linux中执行。转换方式如下(UltraEdit):File-->Conversions-->DOS->UNIX即可。
如果是 Notepad++ 则是在: 编辑 -> EOL Conversion -> 转换为 UNIX 格式 中。
2)也可在Linux中转换:
首先要确保文件有可执行权限
#sh>chmod a+x filename
然后修改文件格式
#sh>vi filename
利用如下命令查看文件格式
:set ff 或 :set fileformat
可以看到如下信息
fileformat=dos 或 fileformat=unix
利用如下命令修改文件格式
:set ff=unix 或 :set fileformat=unix
:wq (存盘退出)
最后再执行文件
#sh>./filename
修改步骤:
vi elasticsearch
按esc
输入(:set ff=unix)
再按esc
再输入(:wq)