搭建elasticsearch集群

4 篇文章 0 订阅
3 篇文章 0 订阅

1、前期准备

1.1 准备三台centos机器

xx.xx.xx.11
xx.xx.xx.12
xx.xx.xx.13

1.2 安装jdk

略过

1.3 新建并切换es用户

es不能用root用户启动,新建一个专门用来启动es的用户,例如elastic

1.4 下载elasticsearch
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.5.4.tar.gz

2、配置

新建es数据目录并修改owner

sudo mkdir -p /data/elasticsearchData/data
sudo mkdir -p /data/elasticsearchData/logs
sudo chown -R elastic /data/elasticsearchData

解压文件,进入目录

tar -zxvf elasticsearch-6.5.4.tar.gz
cd elasticsearch-6.5.4

修改配置es配置文件

vim config/elasticsearch.yml

配置的文件如下,按照自己的需求修改

cluster.name: es-cluster    # 集群名称,各节点配成相同的集群名称。
node.name: es-01          # 节点名称,各节点配置不同。   [!!各节点不同]。  节点二改为es02、节点三改为es03
node.master: true         # 指示某个节点是否符合成为主节点的条件。
node.data: true           # 指示节点是否为数据节点。数据节点包含并管理索引的一部分。
path.data: /data/elasticsearchData/data    # 数据存储目录
path.logs: /data/elasticsearchData/logs    # 日志存储目录
bootstrap.memory_lock: true            # 内存锁定,是否禁用交换
bootstrap.system_call_filter: false    # 系统调用过滤器。
network.host: xx.xx.xx.11     # 绑定节点IP 、 此处修改成当前自己主机的IP
http.port: 9200           # rest api端口。
discovery.zen.ping.unicast.hosts: ["xx.xx.xx.11:9300","xx.xx.xx.12:9300","xx.xx.xx.13:9300"]    # 提供其他Elasticsearch 服务节点的单点广播发现功能
discovery.zen.minimum_master_nodes: 2    # 集群中可工作的具有Master节点资格的最小数量,官方的推荐值是(N/2)+1,其中N是具有master资格的节点的数>量。
discovery.zen.ping_timeout: 150s         # 节点在发现过程中的等待时间。
discovery.zen.fd.ping_retries: 10        # 节点发现重试次数。
client.transport.ping_timeout: 60s
http.cors.enabled: true        # 是否允许跨源 REST 请求,用于允许head插件访问ES
http.cors.allow-origin: "*"    # 允许的源地址

修改系统配置文件,增加最大进程数,

sudo vim /etc/security/limits.conf

添加内容如下,保存之后要重新登录用户

* soft nofile 65536
* hard nofile 65536
* soft memlock unlimited
* hard memlock unlimited

打开/etc/sysctl.conf添加如下内容增加最大内存映射数

vm.max_map_count=262144

测试

sudo sysctl -p

3、启动并查看状态

cd 到elasticsearch-6.5.4

nohup bin/elasticsearch &

在浏览器打开http://xx.xx.xx.11:9200/查看到如下信息就成功:

{
"name": "es-01",
"cluster_name": "es-cluster",
"cluster_uuid": "_na_",
"version": {
	"number": "6.5.4",
	"build_flavor": "default",
	"build_type": "tar",
	"build_hash": "d2ef93d",
	"build_date": "2018-12-17T21:17:40.758843Z",
	"build_snapshot": false,
	"lucene_version": "7.5.0",
	"minimum_wire_compatibility_version": "5.6.0",
	"minimum_index_compatibility_version": "5.0.0"
},
"tagline": "You Know, for Search"
}

然后按照上面的步骤依次启动其他机器
最后查看集群状态:

curl xx.xx.xx.11:9200/_cluster/health?pretty

结果

{
  "cluster_name" : "es-cluster",
  "status" : "green",
  "timed_out" : false,
  "number_of_nodes" : 3,
  "number_of_data_nodes" : 3,
  "active_primary_shards" : 0,
  "active_shards" : 0,
  "relocating_shards" : 0,
  "initializing_shards" : 0,
  "unassigned_shards" : 0,
  "delayed_unassigned_shards" : 0,
  "number_of_pending_tasks" : 0,
  "number_of_in_flight_fetch" : 0,
  "task_max_waiting_in_queue_millis" : 0,
  "active_shards_percent_as_number" : 100.0
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值