首先我们采用docker进行ES集群的搭建,可以方便将来ES环境的移植.
安装ES的docker镜像
- 拉去镜像
sudo docker pull elasticsearch:5.6.8
- 创建集群的配置文化和挂载位置
mkdir -p /opt/ES/config
mkdir data1 data2 data3
- 创建es配置文件
/opt/ES/config/es1.yml
cluster.name: elasticsearch-cluster
node.name: es-node1
network.bind_host: 0.0.0.0
network.publish_host: 10.108.112.206
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: ["10.108.112.206:9300","10.108.112.206:9301","10.108.112.206:9302"]
discovery.zen.minimum_master_nodes: 2
es2.yml
cluster.name: elasticsearch-cluster
node.name: es-node2
network.bind_host: 0.0.0.0
network.publish_host: 10.108.112.206
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: ["10.108.112.206:9300","10.108.112.206:9301","10.108.112.206:9302"]
discovery.zen.minimum_master_nodes: 2
es3.yml
cluster.name: elasticsearch-cluster
node.name: es-node3
network.bind_host: 0.0.0.0
network.publish_host: 10.108.112.206
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: ["10.108.112.206:9300","10.108.112.206:9301","10.108.112.206:9302"]
discovery.zen.minimum_master_nodes: 2
这里集群的配置是通过ElasticSearch的內建模块Zen Discovery机制,它提供单播和双播发现集群机制.
同一个集群只需配置相同的集群名称就可以识别为一个集群
discovery.zen.ping.unicast.hosts: ["10.108.112.206:9300","10.108.112.206:9301","10.108.112.206:9302"]
来配置集群
index.number_of_shards: 默认的配置是把索引分为5个分片
index.number_of_replicas:设置每个index的默认的冗余备份的分片数,默认是1
network.bind_host: 设置可以访问的ip,可以是ipv4或ipv6的,默认为0.0.0.0,这里全部设置通过
network.publish_host:设置其它结点和该结点交互的ip地址,如果不设置它会自动判断,值必须是个真实的ip地址
http.cors.enabled: 是否允许跨域REST请求
http.cors.allow-origin: 允许 REST 请求来自何处
node.master: true 配置该结点有资格被选举为主结点(候选主结点),用于处理请求和管理集群。如果结点没有资格成为主结点,那么该结点永远不可能成为主结点;如果结点有资格成为主结点,只有在被其他候选主结点认可和被选举为主结点之后,才真正成为主结点。
node.data: true 配置该结点是数据结点,用于保存数据,执行数据相关的操作(CRUD,Aggregation);
- 启动容器
sudo docker run -e ES_JAVA_OPTS="-Xms256m -Xmx256m" -d -p 9202:9202 -p 9302:9302 -v /opt/ES/config/es3.yml:/usr/share/elasticsearch/config/elasticsearch.yml -v /opt/ES/data3:/usr/share/elasticsearch/data --name ES03 elasticsearch:5.6.8
sudo docker run -e ES_JAVA_OPTS="-Xms256m -Xmx256m" -d -p 9201:9201 -p 9301:9301 -v /opt/ES/config/es2.yml:/usr/share/elasticsearch/config/elasticsearch.yml -v /opt/ES/data2:/usr/share/elasticsearch/data --name ES02 elasticsearch:5.6.8
sudo docker run -e ES_JAVA_OPTS="-Xms256m -Xmx256m" -d -p 9200:9200 -p 9300:9300 -v /opt/ES/config/es1.yml:/usr/share/elasticsearch/config/elasticsearch.yml -v /opt/ES/data1:/usr/share/elasticsearch/data --name ES01 elasticsearch:5.6.8
- 验证是否搭建成功
在浏览器输入地址验证
http://localhost:9200/_cat/nodes?pretty
网友评论