本文共 4462 字,大约阅读时间需要 14 分钟。
在Ubuntu 18.04.1 LTS搭建一个简单的elasticsearch集群demo,具体情况如下:
集群名称:elasticsearch-cluster-demo
主节点:1个 node-master-one 数据节点:2个 node-data-one、node-data-two 客户端节点:1个 node-client-oneelasticsearch 的安装可以点击参考文章:
拷贝几个es安装包文件夹,进行相应节点的命名,再进行后续的修改配置。
# 集群名称cluster.name: elasticsearch-cluster-demo## 节点信息node.name: node-master-onenode.master: truenode.data: false## Path to directory where to store the data (separate multiple locations by comma):# es data 存储路径path.data: /home/environment/elasticsearch-cluster/elasticsearch-master-one/data## Path to log files:# log存储路径path.logs: /home/environment/elasticsearch-cluster/elasticsearch-master-one/logs## Set the bind address to a specific IP (IPv4 or IPv6):# 网路监听network.host: 0.0.0.0http.port: 9200transport.tcp.port: 9300## Pass an initial list of hosts to perform discovery when new node is started:# The default list of hosts is ["127.0.0.1", "[::1]"]# 可以发现当前节点的主节点ip:portdiscovery.zen.ping.unicast.hosts: ["127.0.0.1:9300"]# # Prevent the "split brain" by configuring the majority of nodes (total number of master-eligible nodes / 2 + 1):# 集群最小主节点个数#discovery.zen.minimum_master_nodes: 2## 设置跨域问题,方便使用elasticsearch-head来检测集群状态http.cors.enabled: truehttp.cors.allow-origin: /.*/
# 集群名称cluster.name: elasticsearch-cluster-demo## 节点信息node.name: node-data-onenode.master: falsenode.data: true## Path to directory where to store the data (separate multiple locations by comma):# es data 存储路径path.data: /home/environment/elasticsearch-cluster/elasticsearch-data-one/data## Path to log files:# log存储路径path.logs: /home/environment/elasticsearch-cluster/elasticsearch-data-one/logs## Set the bind address to a specific IP (IPv4 or IPv6):# 网路监听network.host: 0.0.0.0http.port: 9210transport.tcp.port: 9310## Pass an initial list of hosts to perform discovery when new node is started:# The default list of hosts is ["127.0.0.1", "[::1]"]# 可以发现当前节点的主节点ip:portdiscovery.zen.ping.unicast.hosts: ["127.0.0.1:9300"]# # Prevent the "split brain" by configuring the majority of nodes (total number of master-eligible nodes / 2 + 1):# 集群最小主节点个数#discovery.zen.minimum_master_nodes: 2## 设置跨域问题,方便使用elasticsearch-head来检测集群状态http.cors.enabled: truehttp.cors.allow-origin: /.*/
# 集群名称cluster.name: elasticsearch-cluster-demo## 节点信息node.name: node-data-twonode.master: falsenode.data: true## Path to directory where to store the data (separate multiple locations by comma):# es data 存储路径path.data: /home/environment/elasticsearch-cluster/elasticsearch-data/two/data## Path to log files:# log存储路径path.logs: /home/environment/elasticsearch-cluster/elasticsearch-data-two/logs## Set the bind address to a specific IP (IPv4 or IPv6):# 网路监听network.host: 0.0.0.0http.port: 9211transport.tcp.port: 9311## Pass an initial list of hosts to perform discovery when new node is started:# The default list of hosts is ["127.0.0.1", "[::1]"]# 可以发现当前节点的主节点ip:portdiscovery.zen.ping.unicast.hosts: ["127.0.0.1:9300"]# # Prevent the "split brain" by configuring the majority of nodes (total number of master-eligible nodes / 2 + 1):# 集群最小主节点个数#discovery.zen.minimum_master_nodes: 2## 设置跨域问题,方便使用elasticsearch-head来检测集群状态http.cors.enabled: truehttp.cors.allow-origin: /.*/
# 集群名称cluster.name: elasticsearch-cluster-demo## 节点信息node.name: node-client-onenode.master: falsenode.data: false## Path to directory where to store the data (separate multiple locations by comma):# es data 存储路径path.data: /home/environment/elasticsearch-cluster/elasticsearch-client-one/data## Path to log files:# log存储路径path.logs: /home/environment/elasticsearch-cluster/elasticsearch-client-one/logs## Set the bind address to a specific IP (IPv4 or IPv6):# 网路监听network.host: 0.0.0.0http.port: 9220transport.tcp.port: 9320## Pass an initial list of hosts to perform discovery when new node is started:# The default list of hosts is ["127.0.0.1", "[::1]"]# 可以发现当前节点的主节点ip:portdiscovery.zen.ping.unicast.hosts: ["127.0.0.1:9300"]# # Prevent the "split brain" by configuring the majority of nodes (total number of master-eligible nodes / 2 + 1):# 集群最小主节点个数#discovery.zen.minimum_master_nodes: 2## 设置跨域问题,方便使用elasticsearch-head来检测集群状态http.cors.enabled: truehttp.cors.allow-origin: /.*/
当对每一个es节点的配置修改完以后,便可以启动每个节点,在主节点启动后,便可以使用elasticsearch-head来检测es的集群状态,也可以通过查看es的日志来查看节点自动加入集群的情况。
elasticsearch-head项目托管在github上,安装方式可见项目主页的README.txtile文件。项目地址如下:
安装成功后,在接入输入要连接的集群的某一个主节点的ip与端口,连接成功后即可看见该集群的状态,如下图所示: