1. Introduction to the environment
Linux:~
CentOS Linux release 7.6.1810 ( Core)
2, pulling elasticserach
the mirror
Linux:~
"不加版本,表示拉取最新版本"
3. Create a elasticsearch
data directory
Linux:~
Linux:~
/opt/elasticsearch/
| -- es1
| | -- config
| | -- data
| ` -- logs
| -- es2
| | -- config
| | -- data
| ` -- logs
` -- es3
| -- config
| -- data
` -- logs
12 directories, 0 files
4. Create a elasticsearch
configuration file
Note that in the following 本机IP
fields, replacing 自己机器的IP地址
Linux:~
cluster.name: elasticsearch-cluster
node.name: es-node1
network.bind_host: 0.0.0.0
network.publish_host: 本机IP
http.port: 9200
transport.tcp.port: 9300
http.cors.enabled: true
http.cors.allow-origin: "*"
node.master: true
node.data: true
discovery.zen.ping.unicast.hosts: [ "本机IP:9300" ,"本机IP:9301" ,"本机IP:9302" ]
discovery.zen.minimum_master_nodes: 1
EOF
Linux:~
cluster.name: elasticsearch-cluster
node.name: es-node2
network.bind_host: 0.0.0.0
network.publish_host: 本机IP
http.port: 9201
transport.tcp.port: 9301
http.cors.enabled: true
http.cors.allow-origin: "*"
node.master: true
node.data: true
discovery.zen.ping.unicast.hosts: [ "本机IP:9300" ,"本机IP:9301" ,"本机IP:9302" ]
discovery.zen.minimum_master_nodes: 1
EOF
Linux:~
cluster.name: elasticsearch-cluster
node.name: es-node3
network.bind_host: 0.0.0.0
network.publish_host: 本机IP
http.port: 9202
transport.tcp.port: 9302
http.cors.enabled: true
http.cors.allow-origin: "*"
node.master: true
node.data: true
discovery.zen.ping.unicast.hosts: [ "本机IP:9300" ,"本机IP:9301" ,"本机IP:9302" ]
discovery.zen.minimum_master_nodes: 1
EOF
5. Configure the limit on the number of JVM threads
Linux:~
Linux:~
Note: This step is to prevent the following error from being reported when starting the container: bootstrap checks failed max virtual memory areas vm.max_map_count [65530] likely too low, increase to at least [262144]*
6, start elasticsearch docker 集群
#!/bin/bash
xms= '-Xms256m'
xmx= '-Xmx256m'
portes= (
9200
9201
9202
)
portcluster= (
9300
9301
9302
)
espath= '/opt/elasticsearch'
dockerespath= '/usr/share/elasticsearch'
image= 'elasticsearch:latest'
num= 1
portc= 0
for port in ${portes[*]}
do
portc= $(( ${num} - 1 ))
docker run -d -e ES_JAVA_OPTS= "" ${xms} " " ${xmx} "" \
-p ${port} : ${port} \
-p ${portcluster[$portc]} : ${portcluster[$portc]} \
-v ${espath} /es${num} /config/elasticsearch.yml:${dockerespath} /config/elasticsearch.yml \
-v ${espath} /es${num} /data:${dockerespath} /data \
-v ${espath} /es${num} /logs:${dockerespath} /logs \
--name es-0${num} ${image}
let num++
done
7. Verify elasticsearch
cluster
"因为是在公有云服务器上部署的,ip不方便透露,就用localhostip代替了"
Linux:~
localhostip 31 96 2 0.15 1.12 1.06 mdi - es-node2
localhostip 36 96 2 0.15 1.12 1.06 mdi - es-node1
localhostip 32 96 2 0.15 1.12 1.06 mdi * es-node3
Linux:~
{
"cluster_name" : "elasticsearch-cluster" ,
"status" : "green" ,
"timed_out" : false,
"number_of_nodes" : 3,
"number_of_data_nodes" : 3,
"active_primary_shards" : 0,
"active_shards" : 0,
"relocating_shards" : 0,
"initializing_shards" : 0,
"unassigned_shards" : 0,
"delayed_unassigned_shards" : 0,
"number_of_pending_tasks" : 0,
"number_of_in_flight_fetch" : 0,
"task_max_waiting_in_queue_millis" : 0,
"active_shards_percent_as_number" : 100.0
}
8, insert and view elasticsearch
indexing information
"插入索引"
Linux: ~ # curl - XPUT "http://localhostip:9200/2021-01-21/myelasticsearch/1?pretty" - H "Content-type: application/json" - d '{"name": "bandian", "country": "China", "age": "25", "birthday": "1995-03-20", "sex": "gentleman", "style":"tie han han"}'
{
"_index" : "2021-01-21" ,
"_type" : "myelasticsearch" ,
"_id" : "1" ,
"_version" : 1 ,
"result" : "created" ,
"_shards" : {
"total" : 2 ,
"successful" : 2 ,
"failed" : 0
} ,
"created" : true
}
"查看索引"
Linux: ~ # curl - XGET "http://localhostip:9200/2021-01-21/myelasticsearch/1?pretty" - H "Content-type: application/json"
{
"_index" : "2021-01-21" ,
"_type" : "myelasticsearch" ,
"_id" : "1" ,
"_version" : 1 ,
"found" : true ,
"_source" : {
"name" : "bandian" ,
"country" : "China" ,
"age" : "25" ,
"birthday" : "1995-03-20" ,
"sex" : "gentleman" ,
"style" : "tie han han"
}
}
"从这里可以看出,索引的创建模板格式:_index,_type,_id,_version,found,_source"