ElasticSearch - 環境架設、基本運維
阿新 • • 發佈:2018-11-08
-
ElasticSearch環境架設
-
先下載想要的版本ES
-
ElasticSearch : https://www.elastic.co/downloads/elasticsearch
-
-
確保每臺機器都升級 jdk 到 1.8
sudo salt-call state.sls java_8u60 sudo salt-call state.sls tomcat8
-
在每臺機器上都安裝ElasticSearch
sudo rpm -ivh elasticsearch-6.1.1.rpm
-
配置ES (每臺機器都得配置)
-
執行
sudo vim /etc/elasticsearch/elasticsearch.yml
,並填入以下配置#叢集的名字 cluster.name: comments #這臺節點的名字 node.name: node-1 node.master: true node.data: true #設定data和log的存放位置 path.data: /home/elasticsearch/data path.logs: /home/elasticsearch/logs # 10.88.100.1 是指這臺機器的ip,如果換機器要換ip network.host: 10.88.100.1 network.bind_host: 10.88.100.1 network.publish_host: 10.88.100.1 #這個叢集裡的所有機器的ip(包含此臺機器) discovery.zen.ping.unicast.hosts: ["10.88.100.1", "10.88.100.2", ...] bootstrap.system_call_filter: false xpack.security.enabled: false xpack.monitoring.enabled: true xpack.graph.enabled: false xpack.watcher.enabled: false
-
-
建立配置中data/log存放的資料夾,並修改許可權
sudo mkdir /home/elasticsearch sudo mkdir /home/elasticsearch/data sudo mkdir /home/elasticsearch/logs sudo chown -R elasticsearch:elasticsearch /home/elasticsearch
-
改變 jvm的記憶體大小,設為6G,執行
sudo vim /etc/elasticsearch/jvm.options
-Xms6g -Xmx6g
-
安裝外掛
-
ik分詞 (注意版本要和ES版本一致)
sudo /usr/share/elasticsearch/bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.1.1/elasticsearch-analysis-ik-6.1.1.zip
-
拼音分詞 (注意版本一致)
sudo /usr/share/elasticsearch/bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-pinyin/releases/download/v6.1.1/elasticsearch-analysis-pinyin-6.1.1.zip
-
x-pack
sudo /usr/share/elasticsearch/bin/elasticsearch-plugin install x-pack
-
如果因為網路原因導致某些機器下載速度很慢的話,也可以使用zip檔進行安裝
sudo /usr/share/elasticsearch/bin/elasticsearch-plugin install file:///[path]
-
-
最後,每臺機器都啟動elasticsearch,就完成了叢集的搭建
sudo service elasticsearch start
-
可以挑選叢集中的一臺機器,額外安裝管理介面 kibana
-
注意kibana和elasticsearch的版本要一致
sudo rpm -ivh kibana-6.1.1-x86_64.rpm sudo /usr/share/kibana/bin/kibana-plugin install x-pack
-
執行
sudo vim /etc/kibana/kibana.yml
,配置kibanaserver.host: "commentes1.mytest.com" elasticsearch.url: "http://commentes1.mytest.com:9200"
-
啟動 kibana
sudo /usr/share/kibana/bin/kibana
-
接著在瀏覽器輸入
commentes1.mytest.com:5601
,就能開啟kibana管理介面-
而這臺機器也可以作為es的節點之一,使用
http://commentes1.mytest.com:9200
就能像使用其他節點一樣,去索引/查詢es資料
-
-
-
-
基本運維
-
建立索引
curl -H "Content-Type: application/json" -XPUT 'http://localhost:9200/mytest_v1' -d ' { "mappings": .... } '
-
建立索引別名
curl -H "Content-Type: application/json" -XPOST 'http://localhost:9200/_aliases' -d ' { "actions" : [ { "add" : { "index" : "mytest_v1", "alias" : "mytest" } } ] } '
-
刪除索引別名
curl -H "Content-Type: application/json" -XPOST 'http://localhost:9200/_aliases' -d ' { "actions" : [ { "remove" : { "index" : "mytest_v1", "alias": "mytest" } } ] } '
-
刪除索引
curl -H "Content-Type: application/json" -XDELETE 'http://localhost:9200/mytest_v1'
-