以前講過在Windows上安裝Elasticsearch5.x,但實際生產環境仍是須要Linux支持,並且ES在Linux環境下運行要比Windows環境下要高,So...Linux上仍是要學會安裝。通過本身的研究還有同事的幫助,終於搞定Linux下安裝Elasticsearch5.x了。css
一、這裏個人系統是阿里雲的 CentOS 7.2 64位,2核4Ghtml
二、$
開始的命令表示你要輸入的命令java
ElasticSearch是基於lucence開發的,也就是運行須要java支持。因此要先安裝JAVA環境。
因爲ElasticSearch 5.x 依賴於JDK 1.8
的,因此如今咱們下載JDK 1.8或者更高版本。如下命令將會下載最新的jdknode
$ yum install java
安裝完畢後測試sql
$ java -version
官方文檔上說Elasticsearch不適合在root管理員賬號下運行,因此要先創建一個帳號專門運行Elasticsearch.編程
建立一個elsearch帳戶json
$ adduser elsearch
設置密碼bootstrap
$ passwd elsearch
按照提示輸入密碼和確認密碼就成功建立elsearch帳戶了。swift
修改用戶權限,這一步很是重要vim
使用vim 編輯器打開文件打開/etc 目錄下面的文件sudoers
$ vim /etc/sudoers
找到以下位置:
## Allow root to run any commands anywhere root ALL=(ALL) ALL
在這個區塊下面添加一行命令,使elsearch這個賬號能夠得到更高的操做權限
## Allow root to run any commands anywhere root ALL=(ALL) ALL elsearch ALL=(ALL) NOPASSWD: ALL
ok保存。
退出root帳戶,使用剛剛建立的elsearch帳戶登陸服務器想,下載Elasticsearch安裝包。
$ wget -c https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.3.2.zip
文件校驗
$ sha1sum elasticsearch-5.3.2.zip
解壓
$ unzip elasticsearch-5.3.2.zip
解壓完將有兩個文件,zip能夠刪掉。
$ ls
elasticsearch-5.3.2 elasticsearch-5.3.2.zip
進到elasticsearch-5.3.2目錄下
# cd elasticsearch-5.3.2/
啓動引擎(-d表示爲後臺啓動)
$ ./bin/elasticsearch -d
查看elasticsearch進程狀況
$ ps -ef |grep elasticsearch
若是看到以下一串東西則表示啓動成功
elsearch 22042 1 20 00:36 pts/2 00:00:09 /bin/java -Xms2g -Xmx2g -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -XX:+DisableExplicitGC -XX:+AlwaysPreTouch -server -Xss1m -Djava.awt.headless=true -Dfile.encoding=UTF-8 -Djna.nosys=true -Djdk.io.permissionsUseCanonicalPath=true -Dio.netty.noUnsafe=true -Dio.netty.noKeySetOptimization=true -Dio.netty.recycler.maxCapacityPerThread=0 -Dlog4j.shutdownHookEnabled=false -Dlog4j2.disable.jmx=true -Dlog4j.skipJansi=true -XX:+HeapDumpOnOutOfMemoryError -Des.path.home=/home/elsearch/elasticsearch-5.3.2 -cp /home/elsearch/elasticsearch-5.3.2/lib/elasticsearch-5.3.2.jar:/home/elsearch/elasticsearch-5.3.2/lib/* org.elasticsearch.bootstrap.Elasticsearch -d
或者使用 curl測試,es端口默認狀況下是9200
$ curl "localhost:9200"
返回以下信息則說明啓動成功
{
"name" : "nHlYWW8", "cluster_name" : "elasticsearch", "cluster_uuid" : "SNUvV-1fQLKaGnfXrA4UXg", "version" : { "number" : "5.3.2", "build_hash" : "3068195", "build_date" : "2017-04-24T16:15:59.481Z", "build_snapshot" : false, "lucene_version" : "6.4.2" }, "tagline" : "You Know, for Search" }
$ curl "localhost:9200/_cat/health?v" epoch timestamp cluster status node.total node.data shards pri relo init unassign pending_tasks max_task_wait_time active_shards_percent 1493916286 00:44:46 elasticsearch green 1 1 0 0 0 0 0 0 - 100.0%
若是出現這條信息,說明你的elastic search已經正常運行了,恭喜你
標題 | 含義 |
---|---|
epoch | unix 的時間 |
timestamp | 時間戳 |
cluster | 集羣 |
status | 健康狀態:紅爲異常, 綠黃爲健康 |
node.total | 節點的總數 |
node.data | 節點的數據 |
shards | 分片 |
pri | active_primary_shards 已激活的主要分片 |
relo | 回收的切片 |
init | 已經初始的切片數量 |
unassign | 未分配切片數量 |
pending_tasks | 被擱置的任務數量 |
max_task_wait_time | 任務等待的最大時間 |
active_shards_percents | 激活分片的百分比 |
注意 status黃色和綠色的區別:
官方詳情請參閱https://www.elastic.co/guide/en/elasticsearch/reference/current/install-elasticsearch.html
仍然使用elsearch登陸,而後切換目錄到elsearchsearch 所在的文件夾
$ cd elasticsearch-5.3.2
執行安裝命令
$ sudo ./bin/elasticsearch-plugin install analysis-smartcn
卸載命名
$ sudo ./bin/elasticsearch-plugin remove analysis-smartcn
測試分詞,使用"人人編程,世界和平"爲例子,進行測試,使用站長工具 將例子中的字斷轉換成unicode編碼的字斷 在的終端中,調用下面方法,驗證smartcn分詞插件是否已經成功運行
$ curl -XGET 'localhost:9200/_analyze?pretty' -d '{"analyzer":"smartcn", "text": "\u4eba\u4eba\u7f16\u7a0b\uff0c\u4e16\u754c\u548c\u5e73"}'
出現以下結果證實分詞成功。若沒有添加"analyzer":"smartcn"
指定分詞,將使用默認分詞。對於中文來說,將會把全部的字單獨分出來。
{
"tokens" : [ { "token" : "人人", "start_offset" : 0, "end_offset" : 2, "type" : "word", "position" : 0 }, { "token" : "編程", "start_offset" : 2, "end_offset" : 4, "type" : "word", "position" : 1 }, { "token" : "世界", "start_offset" : 5, "end_offset" : 7, "type" : "word", "position" : 3 }, { "token" : "和平", "start_offset" : 7, "end_offset" : 9, "type" : "word", "position" : 4 } ] }
$ cd elasticsearch-5.3.2 $ vim ./config/elasticsearch.yml
根據需求修改一下節點:
cluster.name: es-5.3-test #換個集羣的名字,省得跟別人的集羣混在一塊兒 node.name: node-es-101 #換個節點名字 network.host: 0.0.0.0 #修改一下ES的監聽地址,這樣別的機器也能夠訪問 http.port: 9200 #端口號,默認就好 # 增長新的參數,這樣head插件能夠訪問es http.cors.enabled: true http.cors.allow-origin: "*" #增長新的參數,這樣ES能夠經過外網進行訪問,只設置network.host: 0.0.0.0 公網仍舊沒法訪問 transport.host: localhost transport.tcp.port: 9300 @注意,設置參數的時候:後面要有空格!
對於不熟悉Linux的人來說,使用curl是個硬傷,因此 Chrome有個插件Sense能夠幫咱們很方便的操做Elasticsearch。國內須要FQ。
先來測試下分詞
Kibana是一個開源爲elasticsearch 引擎提供數據和數據分析
切換到root帳戶,按順序依次執行如下命令
$ wget -c https://artifacts.elastic.co/downloads/kibana/kibana-5.3.2-x86_64.rpm $ sha1sum kibana-5.3.2-x86_64.rpm $ sudo rpm --install kibana-5.3.2-x86_64.rpm
$ whereis kibana
kibana: /etc/kibana /usr/share/kibana
若是顯示以上結果代表kibana已經正確安裝完成,兩個目錄
/etc/kibana
爲kibana config文件所在的目錄
/usr/share/kibana
爲程序所在的目錄
修改Kibana的配置文件,容許公網訪問
$ vim /etc/kibana/kibana.yml
將server.host
修改成
server.host: "0.0.0.0"
配置kibana可以自動啓動
$ sudo chkconfig --add kibana
啓動和中止
$ sudo -i service kibana start $ sudo -i service kibana stop
接下來便可使用公網訪問http://IP:5601
打開Kibana了。
官方詳情請參閱https://www.elastic.co/guide/en/kibana/5.3/targz.html