首先咱們看看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>)
只能後臺啓動,沒有啓動,中止,重啓,查看狀態等命令,很是不方面管理。
java
安裝servicewrapper
咱們在服務器環境下能夠使用elasticsearch-servicewrapper這個ES插件。下載地址是:https://github.com/elastic/elasticsearch-servicewrapper
下載完成後,將下來的項目的service目錄拷貝到elasticsearch的bin目錄中,而且設置service目錄下的elasticsearch文件的權限:git
- chmod a+x elasticsearch
以下就是${ES_HOME}/bin/service/elasticsearch的使用說明:[java] view plain copygithub
- [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)