Elasticsearch冷热集群搭建

简介:传统的Elasticsearch集群中所有节点均采用相同的配置,然而Elasticsearch并没有对节点的规格一致性做要求,换而言之就是每个节点可以是任意规格,当然这样做会导致集群各节点性能不一致,影响集群稳定性。但是如果有规则的将集群的节点分成不同类型,部分是高性能的节点用于存储热点数据,部分是性能相对差些的大容量节点用于存储冷数据,却可以一方面保证热数据的性能,另一方面保证冷数据的存储,降低存储成本,这也是Elasticsearch冷热分离架构的基本思想。

  • Hot阶段
          Hot 阶段可类比为人类婴儿到青年的阶段,在这个阶段,它会不断地进行知识的输入与输出(数据读写),不断地长高长大(数据量增加)成有用的青年。
          由于该阶段需要进行大量的数据读写,因此需要高配置的节点,一般建议将节点内存与磁盘比控制在 32 左右,比如 64GB 内存搭配 2TB 的 SSD 硬盘。

  • Warm 阶段
          Warm 阶段可类比为人类青年到中年的阶段,在这个阶段,它基本不会再进行知识的输入(数据写入),主要进行知识输出(数据读取),为社会贡献价值。
          由于该阶段主要负责数据的读取,中等配置的节点即可满足需求,可以将节点内存与磁盘比提高到 64~96 之间,比如 64GB 内存搭配 4~6TB 的 HDD 磁盘。
    搭建环境:
    es版本:7.6.1
    集群架构:3个master节点,6个热数据节点,8个温数据节点
    在这里插入图片描述
    解压缩上传es文件

ansible es -m unarchive -a “src=/data/install_tools/elasticsearch-7.6.1-linux-x86_64.tar.gz dest=/home/es copy=yes mode=755”

linux系统参数修改
vi es_file_system.yml

- hosts: es
  tasks:
   -name: copy file
     copy:
	 src: '{{ item.src }}'
        dest: '{{ item.dest }}'
        owner: root
        group: root
        mode: 644
      with_items:
        - { src: '/data/install/repository-hdfs-7.6.1.zip',dest: '/home/es/repository-hdfs-7.6.1.zip' }

   - name: demo shell
     shell: {{ item }}  
     with_items:
	   ###创建es用户
	   - useradd es
	   - useradd es -g es
	   ###系统优化
       - echo "vm.max_map_count = 262144" >> /etc/sysctl.conf
       - echo "vm.swappiness = 1" >> /etc/sysctl.conf
	   - echo "* soft memlock unlimited" >> /etc/security/limits.conf
	   - echo "* hard memlock unlimited" >> /etc/security/limits.conf
	   - echo "* soft nproc unlimited" >> /etc/security/limits.conf
	   - echo "* hard nproc unlimited" >> /etc/security/limits.conf
	   - echo "* soft nofile 655360" >> /etc/security/limits.conf
	   - echo "* hard nofile 655360" >> /etc/security/limits.conf 
	   - sed -i 's/^\/dev\/mapper\/centos-swap/#/g'  /etc/fstab  ###禁用swap
	   - echo '192.1.1.3 es-master' >> /etc/hosts ###对hosts文件进行更新
	   - sysctl -p	   

执行文件

ansible-playbook es_file_system.yml

安装破解版xpack插件

ansible es -a “mv /home/es/elasticsearch-7.6.1/modules/x-pack-core/x-pack-core-7.6.1.jar /home/es/elasticsearch-7.6.1/modules/x-pack-core/x-pack-core-7.6.1.jar.bak”

本地xpack文件上传

ansible es -m copy -a “src=x-pack-core-7.6.1.jar dest=/home/es/elasticsearch-7.6.1/modules/x-pack-core/”

安装repostory-hdfs插件

ansible es -a ‘echo “y” | /home/es/elasticsearch-7.6.1/bin/elasticsearch-plugin install file:///home/es/repository-hdfs-7.6.1.zip"’

更新jdk环境

ansible es -a “sed -i ‘35a\JAVA_HOME=/home/es/elasticsearch-7.6.1/jdk’ /home/es/elasticsearch-7.6.1/bin/elasticsearch-env‘”

配置ca认证文件

./elasticsearch-certutil ca
./elasticsearch-certutil cert --ca /home/es/elastic-stack-ca.p12 --name es01 --ip 192.1.1.2 --dns es01
ansible es -m copy -a “src=es01.p12 dest=/home/es/elasticsearch-7.6.1/config/certs/”

修改jvm.options

ansible es -m command -a ‘mv /home/es/elasticsearch-7.6.1/config/jvm.options /home/es/elasticsearch-7.6.1/config/jvm.options."date +%Y-%m-%d"’
ansible es -m command -a ‘sed -i “36,38 s/^/#&/g” /home/es/elasticsearch-7.6.1/config/jvm.options’
ansible es -m command -a ‘sed -i “48 s/30/75/g” /home/es/elasticsearch-7.6.1/config/jvm.options’
ansible es -m command -a “sed -i ‘s/^# 10-13:-XX:-UseConcMarkSweepGC/10-13:-XX:-UseConcMarkSweepGC/g’ /home/es/elasticsearch-7.6.1/config/jvm.options”
ansible es -m command -a “sed -i ‘s/^# 10-13:-XX:-UseCMSInitiatingOccupancyOnly/10-13:-XX:-UseCMSInitiatingOccupancyOnly/g’ /home/es/elasticsearch-7.6.1/config/jvm.options”

上传本地修改好的elasticsearch-7.6.1,注意区分冷热节点,和ca认证文件以及主机名

ansible es -m command -a ‘mv /home/es/elasticsearch.yml /home/es/elasticsearch-7.6.1/config/elasticsearch.yml."date +%Y-%m-%d"’
ansible es -m command -a ‘src=/home/es/elasticsearch.yml dest=/home/es/elasticsearch-7.6.1/config/elasticsearch.yml’

更改es目录用户权限

ansible es -m command -a ‘chown -R es:es /data/es’

安装supervisor进程管理工具
解压缩上传文件

ansible es -m unarchive -a “src=/data/install_tools/meld3-1.0.2.tar.gz dest=/data copy=yes mode=755”
ansible es -m unarchive -a “src=/data/install_tools/supervisor-3.3.3.tar.gz dest=/data copy=yes mode=755”

下发安装文件

#!/bin/sh
yum -y install python-setuptools
cd /data/meld3-1.0.2/
python setup.py install
cd /data/supervisor-3.3.3
python setup.py install
echo_supervisord_conf > /etc/supervisord.conf

远程执行

ansible es -m command -a ‘sh /root/supervisor.sh’

上传本地修改好的supervisord.conf配置文件

es节点配置文件

cluster.name: ###集群名称
node.name: es-master ###节点名称
node.master: true ###定义是否为主节点
node.data: false ##定义是否为数据节点
path.data: /data/es/data  ###数据存放路径
path.logs: /data/es/logs  ###日志存放路径
bootstrap.memory_lock: true  ###这个配置,锁定物理内存地址,防止elasticsearch内存被交换出去,也就是避免es使用swap交换分区,频繁的交换,会导致IOPS变高;
network.host: 0.0.0.0 
network.publish_host: ###本机的主机名
###主节点定义,奇数个避免脑裂
discovery.seed_hosts:
   - es-master:9300
   - es-master-slave:9300
   - es-master-slave1:9300
cluster.initial_master_nodes:
   - es-master
   - es-master-slave
   - es-master-slave1
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true 
xpack.security.transport.ssl.verification_mode: full
xpack.security.transport.ssl.keystore.path: certs/es-master.p12
xpack.security.transport.ssl.keystore.password: ###ca文件用户名密码
indices.recovery.max_bytes_per_sec: 300mb  ##提升recovery速度,减少数据写入被阻塞的时长
indices.fielddata.cache.size: 40% ##制fielddata允许内存大小,达到HEAP 40% 自动清理旧cache
indices.memory.index_buffer_size: 40% ###默认值是10%,在单个结点上,所有索引的分片占用的最大内存大小,或占用JVM堆内存的百分比
thread_pool.write.queue_size: 5000 ###写入bulk提交

###冷热节点配置项
node.attr.caax: hot  

至此所有的安装步骤完成可以进行es的启动


版权声明:本文为weixin_40368523原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。