首先我們看看Elasticsearch的啟動(dòng)腳本:只能后臺啟動(dòng),沒(méi)有啟動(dòng),停止,重啟,查看狀態(tài)等命令,非常不方面管理。
- [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
我們在服務(wù)器環(huán)境下可以使用elasticsearch-servicewrapper這個(gè)ES插件。下載地址是:https://github.com/elastic/elasticsearch-servicewrapper
下載完成后,將下來(lái)的項目的service目錄拷貝到elasticsearch的bin目錄中,并且設置service目錄下的elasticsearch文件的權限:
- chmod a+x elasticsearch
如下就是${ES_HOME}/bin/service/elasticsearch的使用說(shuō)明:
- [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.#控制臺啟動(dòng)
- start Start in the background as a daemon process.#后臺啟動(dòng)
- stop Stop if running as a daemon or in another console.#停止
- restart Stop if running and then start.#重啟
- condrestart Restart only if already running.#僅僅在已經(jīng)運行的情況下啟動(dòng)
- status Query the current status.#查看狀態(tài)
- install Install to start automatically when system boots.
- remove Uninstall.
- dump Request a Java thread dump if running.
- [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 //因為是測試機器,設置的內存比較少,服務(wù)器好的話(huà),可以設置大一些
- 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: 沒(méi)有那個(gè)文件或目錄
在Linux中執行.sh腳本,異常/bin/sh^M: bad interpreter: No such file or directory。
分析:這是不同系統編碼格式引起的:在windows系統中編輯的.sh文件可能有不可見(jiàn)字符,所以在Linux系統下執行會(huì )報以上異常信息。
解決: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 (存盤(pán)退出)
最后再執行文件
#sh>./filename
修改步驟:vi elasticsearch按esc輸入(:set ff=unix)再按esc再輸入(:wq)
聯(lián)系客服