搭建【es-cluster in CentOS7.x】

前置条件

下载
# 下载,通过测试wget比curl下载速度更快
[root@es es]# wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.1.0-linux-x86_64.tar.gz
[root@es es]# ll
总用量 338668
-rw-r--r--. 1 root root 346793931 520 2019 elasticsearch-7.1.0-linux-x86_64.tar.gz
# 解压
[root@es es]# tar -xf elasticsearch-7.1.0-linux-x86_64.tar.gz 
[root@es es]# ll
总用量 338668
drwxr-xr-x. 9 root root       154 516 2019 elasticsearch-7.1.0
-rw-r--r--. 1 root root 346793931 520 2019 elasticsearch-7.1.0-linux-x86_64.tar.gz
# 安装目录
[root@es es]# mv elasticsearch-7.1.0 ../
[root@es local]# cd elasticsearch-7.1.0/ && ll
总用量 480
drwxr-xr-x.  2 root root   4096 516 2019 bin
drwxr-xr-x.  2 root root    148 516 2019 config
drwxr-xr-x.  8 root root     96 516 2019 jdk
drwxr-xr-x.  3 root root   4096 516 2019 lib
-rw-r--r--.  1 root root  13675 516 2019 LICENSE.txt
drwxr-xr-x.  2 root root      6 516 2019 logs
drwxr-xr-x. 29 root root   4096 516 2019 modules
-rw-r--r--.  1 root root 447478 516 2019 NOTICE.txt
drwxr-xr-x.  2 root root      6 516 2019 plugins
-rw-r--r--.  1 root root   8478 516 2019 README.textile

服务配置

  • es无法以root用户启动,需要新增elasticsearch用户并修改目录权限为elasticsearch
添加账户
# 添加elasticsearch系统用户(不会生成home目录)
[root@es elasticsearch-7.1.0]# useradd -r elasticsearch
[root@es elasticsearch-7.1.0]# id elasticsearch
uid=997(elasticsearch) gid=995(elasticsearch)=995(elasticsearch)
# 修改权限
[root@es local]# chown -R elasticsearch ./elasticsearch-7.1.0/
[root@es local]# ll
总用量 0
drwxr-xr-x.  2 root          root   6 411 2018 bin
drwxr-xr-x. 10 elasticsearch root 166 54 22:32 elasticsearch-7.1.0
drwxr-xr-x.  2 root          root   6 411 2018 etc
drwxr-xr-x.  2 root          root   6 411 2018 games
drwxr-xr-x.  2 root          root   6 411 2018 include
drwxr-xr-x.  2 root          root   6 411 2018 lib
drwxr-xr-x.  2 root          root   6 411 2018 lib64
drwxr-xr-x.  2 root          root   6 411 2018 libexec
drwxr-xr-x.  2 root          root   6 411 2018 sbin
drwxr-xr-x.  5 root          root  49 1211 12:16 share
drwxr-xr-x.  2 root          root   6 411 2018 src
修改配置
  • 保证防火墙开启9200、9300端口
# 增加jvm的线程限制
[root@es es]# vi /etc/sysctl.conf
vm.max_map_count=262144
# 增加elasticsearch资源限制
[root@es es]# vi /etc/security/limits.conf
* - nofile 65536
* - nproc 4096
# 修改elasticsearch配置文件
[root@node01 elasticsearch-7.1.0]# vi config/elasticsearch.yml
# 集群名称
cluster.name: zangh-es-cluster
# 当前节点
node.name: node01
network.host: 172.16.4.101
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: ["172.16.4.101:9300","172.16.4.102:9300","172.16.4.103:9300"]
discovery.zen.minimum_master_nodes: 2
启动服务
# 以elasticsearch用户执行启动命令,-d以守护进程方式启动
[root@es elasticsearch-7.1.0]# sudo -u elasticsearch /usr/local/elasticsearch-7.1.0/bin/elasticsearch -d
# 另外两台采用相同的方式
# [root@es elasticsearch-7.1.0]# scp -r elasticsearch-7.1.0/ root@172.16.4.103:/usr/local/elasticsearch-7.1.0/
# 查看集群的运行状态
[root@es elasticsearch-7.1.0]$ curl -X GET '172.16.4.101:9200/_cat/health?v'
epoch      timestamp cluster          status node.total node.data shards pri relo init unassign pending_tasks max_task_wait_time active_shards_percent
1653646432 10:13:52  zangh-es-cluster green           3         3      0   0    0    0        0             0                  -                100.0%
# 查看集群的节点状态
[root@es elasticsearch-7.1.0]$ curl -X GET '172.16.4.101:9200/_cat/nodes?v'
ip           heap.percent ram.percent cpu load_1m load_5m load_15m node.role master name
172.16.4.103           11          93   0    0.00    0.06     0.14 mdi       *      node03
172.16.4.102            8          92   0    0.00    0.06     0.10 mdi       -      node02
172.16.4.101            8          93   3    0.00    0.07     0.11 mdi       -      node01

启动成功截图

  • 默认集群名称为elasticsearch,使用单播网络发现算法
    集群状态截图
  • 服务脚本
    • start.sh
      #!/bin/bash
      sudo -u elasticsearch /usr/local/elasticsearch-7.1.0/bin/elasticsearch -d -p pid
      
    • stop.sh
      #!/bin/bash
      pkill -F pid
      
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值