单机测试集群模拟三台机子,一个主数据节点,两个数据节点
环境Java1.8
- 从官网下下载elasticsearch 7.1版本的压缩包,kibana7.1压缩包
- 解压压缩包,并复制两份分别命名
- 依次编辑对应目录下的config/elasticsearch.yml文件
1)master目录下(主节点)
cluster.name: my-application (集群名称必须一致)
node.name: node (节点名称必须不同) node.master: true (是否为主节点)
node.attr.rack: r1
network.host: 127.0.0.1
http.port: 9200
transport.tcp.port: 9300
discovery.seed_hosts: ["127.0.0.1:9300","127.0.0.1:9302","127.0.0.1:9303"] (3个节点端口) cluster.initial_master_nodes: ["node","node-1","node-2"] (3个节点的名称)
2)node目录下
cluster.name: my-application
node.name: node-1 node.master: false
node.attr.rack: r1
node.max_local_storage_nodes: 3
bootstrap.memory_lock: false
network.host: 127.0.0.1
http.port: 9202
discovery.seed_hosts: ["127.0.0.1:9300","127.0.0.1:9302","127.0.0.1:9303"]
cluster.initial_master_nodes: ["node","node-1","node-2"]
3) windows-x86_64目录下
cluster.name: my-application
node.name: node-2 node.master: false
node.attr.rack: r1
bootstrap.memory_lock: false
network.host: 127.0.0.1
http.port: 9203
transport.tcp.port: 9303
discovery.seed_hosts: ["127.0.0.1:9300","127.0.0.1:9302","127.0.0.1:9303"]
cluster.initial_master_nodes: ["node","node-1","node-2"]
- 依次bin/elasticsearch.bat,主节点目录下的先运行
表示运行成功,再运行其他两个节点,主节点终端下会提示节点加入集群 - 解压kibana压缩包,运行bin/kibana.bat,出现下图后浏览器打开localhost:5601
打开后可查看节点信息 - 同个网段下,不同主机之间搭建集群只需要更改elasticsearch.yml对应的以下几个参数
network.host: 192.168.1.55 内网IP
discovery.seed_hosts:
kibana的kibana.yml需要更改elasticsearch.hosts:为测试主机的地址elasticsearch.hosts: ["http://192.168.1.55:9200"]
结果如下(其中一个主机程序被关闭了)