elasticsearch官網(wǎng)地址為:
https://www.elastic.co/
本文檔詳細(xì)描述elastic search集群安裝和基本使用殴蹄。本例采用3臺服務(wù)器止吁,搭建四節(jié)點elastic search集群,其中一臺服務(wù)器上運行兩個elastic search程序窝稿。
安裝環(huán)境如下:
- CPU:六核心
- 內(nèi)存:8GB
- 操作系統(tǒng)版本centos7.6
- elasticsearch-6.5.4、kibana-6.5.4、cerebro-0.8.1
- jdk1.8.0_171
- 服務(wù)器名稱分別是myserver01仪缸、myserver02、myserver03
kibana是web端的elasticsearch管理工具可以在里面很方便的寫命令
cerebro可以在web端可視化查看節(jié)點列肢、索引恰画、分片等的信息
準(zhǔn)備需要的軟件
新建/u01/soft和/u01/app兩個目錄
[root@myserver01 /]#mkdir -p /u01/soft
[root@myserver01 /]#mkdir -p /u01/app
[root@myserver01 /]cd /u01
[root@myserver01 u01]# ls
app soft
本例中下載的所有軟件放在/u01/soft
所有的軟件解壓后都放在/u01/app
java可以直接到oracle官網(wǎng)去下載https://www.java.com/en/download/manual.jsp
[root@myserver01 /]cd /u01/soft
[root@myserver01 /u01/soft]wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.5.4.tar.gz
[root@myserver01 /u01/soft]wget https://github.com/lmenezes/cerebro/releases/download/v0.8.1/cerebro-0.8.1.tgz
[root@myserver01 /u01/soft]wget https://artifacts.elastic.co/downloads/kibana/kibana-6.5.4-linux-x86_64.tar.gz
[root@myserver01 soft]# ls
cerebro-0.8.1.tgz kibana-6.5.4-linux-x86_64.tar.gz
elasticsearch-6.5.4.tar.gz jdk-8u171-linux-x64.tar.gz
解壓下載的軟件
[root@myserver01 /]cd /u01/app
[root@myserver01 /u01/app]tar -xzvf /u01/soft/elasticsearch-6.5.4.tar.gz
[root@myserver01 /u01/app]tar -xzvf /u01/soft/cerebro-0.8.1.tgz
[root@myserver01 /u01/app]tar -xzvf /u01/soft/kibana-6.5.4-linux-x86_64.tar.gz
[root@myserver01 /u01/app]tar -xzvf /u01/soft/jdk-8u171-linux-x64.tar.gz
[root@myserver01 app]# ls
cerebro-0.8.1 elasticsearch-6.5.4 jdk1.8.0_171 kibana-6.5.4-linux-x86_64
將elasticsearch-6.5.4和jdk1.8.0_171目錄用scp拷貝到其余兩個節(jié)點,另外再myserver02中額外拷貝一份elasticsearch-6.5.4瓷马。
拷貝完成后myserver02和myserver03目錄為
[root@myserver02 app]# ls
elasticsearch-6.5.4-2
elasticsearch-6.5.4
jdk1.8.0_171
[root@myserver03 app]# ls
elasticsearch-6.5.4
jdk1.8.0_171
操作系統(tǒng)配置
操作配置拴还,三臺主機都要做
- 配置hosts
[root@myserver01 app]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.16.9.32 myserver02
192.16.9.30 myserver01
192.16.9.33 myserver03
- 添加用戶
[root@localhost ~]# groupadd elastic
[root@localhost ~]# useradd elastic -g elastic
- 修改操作系統(tǒng)參數(shù)
[root@localhost ~]# vi /etc/security/limits.conf
* hard nofile 65536
* soft nofile 65536
[root@localhost ~]# vi /etc/sysctl.conf
vm.max_map_count = 262144
- 修改文件權(quán)限
[root@localhost app]# cd /u01/app
[root@localhost app]# chown -R elastic:elastic *
[root@localhost app]# ll
total 12
drwxr-xr-x. 5 elastic elastic 53 Jun 20 2018 cerebro-0.8.1
drwxr-xr-x. 8 elastic elastic 4096 Dec 17 16:21 elasticsearch-6.5.4
drwxr-xr-x. 6 elastic elastic 4096 Dec 15 14:45 jdk1.8.0_171
drwxrwxr-x. 11 elastic elastic 4096 Dec 17 16:36 kibana-6.5.4-linux-x86_64
- 為elastic用戶添加環(huán)境變量
[root@myserver01 ~]# su - elastic
[elastic@myserver01 ~]$ vi .bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
JAVA_HOME=/u01/app/jdk1.8.0_171
export JAVA_HOME
PATH=$PATH:$HOME/.local/bin:$HOME/bin:$JAVA_HOME/bin
export PATH
- 重啟三臺服務(wù)器
配置elasticsearch
- 編輯elasticsearch.yml
實際使用的時候還可以修改端口號等,具體可以查看官方文檔
myserver01修改如下:
[root@myserver01 ~]# su - elastic
[elastic@myserver01 ~]$ cd /u01/app/elasticsearch-6.5.4/config/
[elastic@myserver01 config]$ vi elasticsearch.yml
cluster.name: my-cluster
node.name: node-0
network.host: 0.0.0.0
discovery.zen.ping.unicast.hosts: ["myserver01", "myserver02","myserver03"]
myserver02修改如下:
[root@myserver02 ~]# su - elastic
[elastic@myserver02 ~]$ cd /u01/app/elasticsearch-6.5.4/config/
[elastic@myserver02 config]$ vi elasticsearch.yml
cluster.name: my-cluster
node.name: node-1
network.host: 0.0.0.0
discovery.zen.ping.unicast.hosts: ["myserver01", "myserver02","myserver03"]
[elastic@myserver02 ~]$ cd /u01/app/elasticsearch-6.5.4-2/config/
[elastic@myserver02 config]$ vi elasticsearch.yml
cluster.name: my-cluster
node.name: node-1-1
network.host: 0.0.0.0
discovery.zen.ping.unicast.hosts: ["myserver01", "myserver02","myserver03"]
myserver03修改如下:
[root@myserver03 ~]# su - elastic
[elastic@myserver03 ~]$ cd /u01/app/elasticsearch-6.5.4/config/
[elastic@myserver03 config]$ vi elasticsearch.yml
cluster.name: my-cluster
node.name: node-2
network.host: 0.0.0.0
discovery.zen.ping.unicast.hosts: ["myserver01", "myserver02","myserver03"]
- 修改kibana.yml
只在myserver01修改
[elastic@myserver01 ~]$ cd /u01/app/kibana-6.5.4-linux-x86_64/config
[elastic@myserver01 config]$ vi kibana.yml
elasticsearch.url: "http://myserver01:9200"
- 依次啟動elasticsearch
啟動myserver01
[elastic@myserver01 app]$ cd /u01/app/elasticsearch-6.5.4/
[elastic@myserver01 elasticsearch-6.5.4]$ ./bin/elasticsearch -d -Ecluster.name=my_cluster -Ehttp.port=9200 -Epath.data=node_0 -Enode.name=node_0 -Enode.attr.box_type=hot
[elastic@myserver01 app]$ cd /u01/app/kibana-6.5.4-linux-x86_64/
[elastic@myserver01 kibana-6.5.4-linux-x86_64]$./bin/kibana &
log [07:38:33.812] [info][listening] Server running at http://192.16.9.30:5601
kibana端口是5601
[elastic@myserver01 app]$ cd /u01/app/kibana-6.5.4-linux-x86_64/
[elastic@myserver01 cerebro-0.8.1]$./bin/cerebro &
[info] p.c.s.AkkaHttpServer - Listening for HTTP on /0:0:0:0:0:0:0:0:9000
cerebro端口是9000
啟動myserver02
[elastic@myserver02 app]$ cd /u01/app/elasticsearch-6.5.4/
[elastic@myserver02 elasticsearch-6.5.4]$ ./bin/elasticsearch -d -Ecluster.name=my_cluster -Ehttp.port=9200 -Epath.data=node_0 -Enode.name=node_1 -Enode.attr.box_type=hot
[elastic@myserver02 app]$ cd /u01/app/elasticsearch-6.5.4-2/
[elastic@myserver02 elasticsearch-6.5.4-2]$ ./bin/elasticsearch -d -Ecluster.name=my_cluster -Ehttp.port=9201 -Epath.data=node_0 -Enode.name=node_1-1 -Enode.attr.box_type=cold
啟動myserver03
[elastic@myserver03 elasticsearch-6.5.4]$ ./bin/elasticsearch -d -Ecluster.name=my_cluster -Ehttp.port=9200 -Epath.data=node_0 -Enode.name=node_2 -Enode.attr.box_type=hot
測試四個節(jié)點正常開啟
[elastic@myserver01 elasticsearch-6.5.4]$ curl 192.16.9.30:9200
{
"name" : "node_0",
"cluster_name" : "my_cluster",
"cluster_uuid" : "irt9WwVMQ4ut-i4H6oTw1A",
"version" : {
"number" : "6.5.4",
"build_flavor" : "default",
"build_type" : "tar",
"build_hash" : "d2ef93d",
"build_date" : "2018-12-17T21:17:40.758843Z",
"build_snapshot" : false,
"lucene_version" : "7.5.0",
"minimum_wire_compatibility_version" : "5.6.0",
"minimum_index_compatibility_version" : "5.0.0"
},
"tagline" : "You Know, for Search"
}
[elastic@myserver01 elasticsearch-6.5.4]$ curl 192.16.9.32:9200
{
"name" : "node_1",
"cluster_name" : "my_cluster",
"cluster_uuid" : "irt9WwVMQ4ut-i4H6oTw1A",
"version" : {
"number" : "6.5.4",
"build_flavor" : "default",
"build_type" : "tar",
"build_hash" : "d2ef93d",
"build_date" : "2018-12-17T21:17:40.758843Z",
"build_snapshot" : false,
"lucene_version" : "7.5.0",
"minimum_wire_compatibility_version" : "5.6.0",
"minimum_index_compatibility_version" : "5.0.0"
},
"tagline" : "You Know, for Search"
}
[elastic@myserver01 elasticsearch-6.5.4]$ curl 192.16.9.32:9201
{
"name" : "node_1-1",
"cluster_name" : "my_cluster",
"cluster_uuid" : "irt9WwVMQ4ut-i4H6oTw1A",
"version" : {
"number" : "6.5.4",
"build_flavor" : "default",
"build_type" : "tar",
"build_hash" : "d2ef93d",
"build_date" : "2018-12-17T21:17:40.758843Z",
"build_snapshot" : false,
"lucene_version" : "7.5.0",
"minimum_wire_compatibility_version" : "5.6.0",
"minimum_index_compatibility_version" : "5.0.0"
},
"tagline" : "You Know, for Search"
}
[elastic@myserver01 elasticsearch-6.5.4]$ curl 192.16.9.33:9200
{
"name" : "node_2",
"cluster_name" : "my_cluster",
"cluster_uuid" : "irt9WwVMQ4ut-i4H6oTw1A",
"version" : {
"number" : "6.5.4",
"build_flavor" : "default",
"build_type" : "tar",
"build_hash" : "d2ef93d",
"build_date" : "2018-12-17T21:17:40.758843Z",
"build_snapshot" : false,
"lucene_version" : "7.5.0",
"minimum_wire_compatibility_version" : "5.6.0",
"minimum_index_compatibility_version" : "5.0.0"
},
"tagline" : "You Know, for Search"
}
通過cerebro查看節(jié)點信息
訪問cerebro http://192.16.9.30:9000
通過kibana簡單運行幾個命令
瀏覽器訪問http://172.16.9.30:5601/
在Dev tool頁簽 在文本框輸入命令欧聘,命令的作用是:
刪除test索引
新建test索引并插入一個文檔片林,文檔id為1
插入id為2的文檔
查詢test索引的所有記錄
獲取test索引文檔id為1的文檔
獲取節(jié)點的健康信息
delete /test
post /test/_doc/1
{
"title":"test"
}
post /test/_doc/2
{
"title":"test2"
}
get /test/_search
get /test/_doc/1
get /_cat/health?v
kibana截圖
在kibana中運行一下語句
PUT /gjw_index
{
"settings": {
"number_of_shards": 4,
"number_of_replicas": 1,
"index.routing.allocation.include.box_type":"hot"
}
}
POST /gjw_index/_doc/1
{
"name":"shrink1"
}
POST /gjw_index/_doc/2
{
"name":"shrink2"
}
POST /gjw_index/_doc/3
{
"name":"shrink3"
}
POST /gjw_index/_doc/4
{
"name":"shrink4"
}
POST /gjw_index/_doc/5
{
"name":"shrink5"
}
POST /gjw_index/_doc/6
{
"name":"shrink6"
}
POST /gjw_index/_doc/7
{
"name":"shrink7"
}
POST /gjw_index/_doc/8
{
"name":"shrink8"
}
之后刷新cerebro頁面