8台Elasticsearch 7在CentOS Linux 8 下分布式集群配置详情

先安装jdk,需要1.8以上的版本

修改hosts

# vi /etc/hosts

添加以下内容

192.168.1.241  p241
192.168.1.242  p242
192.168.1.243  p243
192.168.1.244  p244
192.168.1.245  p245
192.168.1.246  p246
192.168.1.247  p247
192.168.1.248  p248
192.168.1.249  p249

配置Elasticsearch的yum源

# vi /etc/yum.repos.d/elasticsearch.repo

输入下面的代码

[elasticsearch]
name=Elasticsearch repository for 7.x packages
baseurl=https://artifacts.elastic.co/packages/7.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=0
autorefresh=1
type=rpm-md 

开始安装

# dnf -y install --enablerepo=elasticsearch elasticsearch

配置服务

# systemctl enable elasticsearch
# systemctl stop elasticsearch
# systemctl start elasticsearch
# systemctl restart elasticsearch

测试访问

# curl -X GET localhost:9200

集群规划

IP主机名
centered 文本居中right-aligned 文本居右
IP主机名masterdata备注
192.168.1.241P241Elasticsearch
192.168.1.242P242
192.168.1.243P243
192.168.1.244P244
192.168.1.245P245
192.168.1.246P246
192.168.1.247P247Logstash
192.168.1.248P248Kibana

注:
分片(index.number_of_shards):默认为5,是你节点数量的1.5~3倍,3台机器分片数最多不超过9(3x3)个
副本(index.number_of_replicas):默认为1,设置为1-2个就能保证高可用了(设置为1的时候就是有2份数据了)
默认情况下,Elasticsearch假定您正在开发模式下工作。 如果未正确配置上述任何设置,则会向日志文件写入警告,但您将能够启动并运行Elasticsearch节点。
一旦配置了network.host之类的网络设置,Elasticsearch就会假定您正在转向生产并将上述警告升级为异常。 这些异常将阻止您的Elasticsearch节点启动。 这是一项重要的安全措施,可确保您不会因服务器配置错误而丢失数据。

1、master服务器配置

vi /etc/elasticsearch/elasticsearch.yml

内容如下:

cluster.name: es-bj001
node.name: p241
node.master: true
node.data: false
path.data: /data/elasticsearch
path.logs: /log/elasticsearch
network.host: 192.168.1.241
discovery.seed_hosts: ["192.168.1.241","192.168.1.242","192.168.1.243"]
cluster.initial_master_nodes: ["192.168.1.241","192.168.1.242","192.168.1.243"]

注意,每台服务器的node.name、network.host都不同

2、node服务器配置

vi /etc/elasticsearch/elasticsearch.yml

内容如下:

cluster.name: es-bj001
node.name: p24
node.master: false
node.data: true
path.data: /data/elasticsearch
path.logs: /log/elasticsearch
network.host: 192.168.1.24
discovery.seed_hosts: ["192.168.1.241","192.168.1.242","192.168.1.243"]
cluster.initial_master_nodes: ["192.168.1.241","192.168.1.242","192.168.1.243"]

注意,每台服务器的node.name、network.host都不同

3、ingest服务器配置(暂时不配置这个类型的服务器了)

vi /etc/elasticsearch/elasticsearch.yml

内容如下:

cluster.name: es-bj001
node.name: p247
node.master: false
node.data: false
node.ingest: false
path.data: /data/elasticsearch
path.logs: /log/elasticsearch
network.host: 192.168.1.24
discovery.seed_hosts: ["192.168.1.241","192.168.1.242","192.168.1.243"]
cluster.initial_master_nodes: ["192.168.1.241","192.168.1.242","192.168.1.243"]

注意,每台服务器的node.name、network.host都不同

4、修改jvm参数

vi /etc/elasticsearch/jvm.options

内容如下:

-Xms4g
-Xmx4g

这样将内存设置为4G,如果你的内存够大,可以设置为总内存的一半。

关闭SELinux:

vi /etc/selinux/config

内容修改如下:

SELINUX=disabled

查看SELinux状态

# getenforce

Disabled

# /usr/sbin/sestatus -v

SELinux status: disabled

关闭防火墙:

# systemctl disable firewalld    #停掉防火墙开机启动
# systemctl stop firewalld        #停掉防火墙服务
# systemctl status firewalld        #停掉防火墙服务
# reboot

目录相关配置:

# mkdir -p /data/elasticsearch
# mkdir -p /log/elasticsearch
# chown  -R elasticsearch:elasticsearch /data/elasticsearch
# chown  -R elasticsearch:elasticsearch  /log/elasticsearch

从241到248一台一台的启动

# systemctl stop elasticsearch
# systemctl start elasticsearch

# ps auxZ | grep -v grep | grep nginx

去掉了以下参数

#index.number_of_shards: 6     #报致命错误
#index.number_of_replicas: 2     #报致命错误
#bootstrap.memory_lock: true    #内存锁不住,服务无法启动,需要研究怎么解决
#node.ingest: false         #等服务器集群大了再用这个参数
#http.port: 9200           #除非要改变默认端口,否则没必要配置这个参数

集群测试

测试访问

# curl -X GET 192.168.1.241:9200
# curl -X GET 192.168.1.242:9200
# curl -X GET 192.168.1.243:9200
# curl -X GET 192.168.1.244:9200
# curl -X GET 192.168.1.245:9200
# curl -X GET 192.168.1.246:9200
# curl -X GET 192.168.1.247:9200
# curl -X GET 192.168.1.248:9200
  1. elasticsearch启动后查看是否启动成功:
    curl -X GET “http://192.168.1.241:9200/_cluster/health?pretty=true”

  2. 停止elasticsearch应用:
    curl -X POST “http:// 192.168.1.241:9200/_shutdown”

  3. 查看集群健康:
    curl 192.168.1.241:9200/_cluster/health?pretty

  4. 检查集群状态:
    curl 192.168.1.241:9200/_cluster/stats?pretty

  5. 节点状态:
    curl 192.168.1.241:9200/_nodes/process?pretty
    curl 192.168.1.241:9200/_nodes/p241/process?pretty

  6. 当你不知道有那些属性可以查看时:
    curl ‘192.168.1.241:9200/_cat/’ #会返回可以查看的属性

pretty指令是美化显示的意思。

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值