elasticsearch 环境搭建
*************************************
相关配置参数
cluster.name:设置集群的名称,默认为elasticsearch
node.name:设置节点的名称,同一集群中节点的名称不能重复
node.master:设置节点为候选主节点,主节点只能在候选主节点中选举,默认为true
node.data:为true是表示节点能存储数据,false节点不能存储数据,默认为true
cluster.initial_master_nodes:设置集群的初始主节点名称,形式:["node-1","node-2","node-3"]
discovery.type:设置发现类型,单机使用single-node,集群zen、legacy-zen
index.number_of_shards:设置主分片的个数,默认为5
index.number_of_replicas:设置副本分片的个数,默认为1
path.conf:设置配置文件的路径
path.data:设置索引数据的存储路径
path.logs:设置日志数据路径
path.plugins:设置插件的存放路径
bootstrap.mlockall:设置为true可锁定内存,避免与磁盘发生内存交换
network.bind_host:节点绑定的ip地址,默认为0.0.0.0
network.publish_host:节点与其他节点交互地址,如果不设置会自动判断
network.host:同时设置network.bind_host、network.publish_host
http.port:http访问端口,默认为9200
transport.tcp.port:节点交互端口
transport.tcp.compress:节点传输的数据是否压缩
discovery.zen.minimum_master_nodes:设置选主时最少需要参与的候选主节点数,默认为1
discovery.zen.ping.timeout:设置节点通信的超时时间,默认为3s,网络环境较差时,可适当调大该值,避免误判
discovery.seed_hosts:设置master节点初始列表,形式为:["host1","host2","host3"]
*************************************
单机搭建:常用于测试,生产环境中应用集群
配置文件elasticsearch.yml
http.host: 0.0.0.0
discovery.type: single-node
discovery.seed_hosts: [172.18.0.2]
创建elasticsearch容器
docker run -it -d --net fixed --ip 172.18.0.2 -p 9200:9200 -p 9300:9300 \
-v /usr/elasticsearch/single/conf/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml \
--name es-single elasticsearch:7.5.1
浏览器显示
*************************************
集群搭建
配置文件elasticsearch.yml
http.host: 0.0.0.0
network.host: 0.0.0.0
node.name: node-1 //不同的节点node.name需设置为不同
http.cors.enabled: true
http.cors.alllow-origin: "*"
cluster.initial_master_nodes: ["node-1","node-2","node-3"]
discovery.seed_hosts: [172.18.0.10,172.18.0.11,172.18.0.12]
discovery.zen.minimum_master_nodes: 2
创建集群
docker run -it -d --net fixed --ip 172.18.0.10 -p 9201:9200 -p 9301:9300 -v /usr/elasticsearch/cluster/node-1/data:/usr/share/elasticsearch/data -v /usr/elasticsearch/cluster/node-1/conf/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml --name es-node-1 elasticsearch:7.5.1
docker run -it -d --net fixed --ip 172.18.0.11 -p 9202:9200 -p 9302:9300 -v /usr/elasticsearch/cluster/node-2/data:/usr/share/elasticsearch/data -v /usr/elasticsearch/cluster/node-2/conf/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml --name es-node-2 elasticsearch:7.5.1
docker run -it -d --net fixed --ip 172.18.0.12 -p 9203:9200 -p 9303:9300 -v /usr/elasticsearch/cluster/node-3/data:/usr/share/elasticsearch/data -v /usr/elasticsearch/cluster/node-3/conf/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml --name es-node-3 elasticsearch:7.5.1
测试集群:
curl localhost:9201
curl localhost:9202
curl localhost:9203