美文网首页
1、搭建ES7.10.0集群

1、搭建ES7.10.0集群

作者: 阿fong | 来源:发表于2020-12-07 21:59 被阅读0次

    一、规划
    注:实际生产环境中,角色最好分开,单独的两个master和两个client,配置不用很高,不用存储,kibana也单独部署

    1. es01
      master data
      192.168.18.11
      2 12G 100G

    2. es02
      master data
      192.168.18.12
      2 12G 100G

    3. es03(kibana)
      client
      192.168.18.13
      2 8G 30G

    二、部署(centos7)
    注意修改脚本个性化的配置
    1、部署jdk,推荐jdk11
    1.1、将jdk上传至/usr/local/目录下
    1.2、使用root用户复制执行以下脚本
    --自动部署脚本--

    #!/bin/bash
    #要安装的jdk路径
    jdkpath=/usr/local/java/
    #jdk压缩包所在的路径
    jdkfile=/usr/local/
    #jdk压缩包的名字
    jdkname=openjdk-11.0.2_linux-x64_bin.tar.gz
    
    mkdir $jdkpath
    cp $jdkfile/$jdkname $jdkpath
    cd $jdkpath
    tar -xzvf $jdkname
    rm $jdkname
    echo `ls`
    dirname=`ls`
    echo "#java" >> /etc/bashrc
    echo "export JAVA_HOME=$jdkpath/$dirname" >>   /etc/bashrc
    echo "export PATH=\$PATH:\$JAVA_HOME/bin:\$JAVA_HOME/jre/bin" >>  /etc/bashrc
    echo "export CLASSPATH=.:\$JAVA_HOME/lib:\$JAVA_HOME/jre/lib" >>  /etc/bashrc
    
     ln -s /usr/local/java/jdk-11.0.2/bin/java /usr/bin/java
    

    1.3、执行命令

    source /etc/bashrc & java -version
    

    2、es01
    1.1、上传安装包至/usr/local/
    下载地址
    https://www.elastic.co/cn/downloads/elasticsearch

    1.2、部署脚本
    --生产环境建议单独磁盘,单独建立分区逻辑卷挂载目录--

    #!/bin/bash
    #安装es
    echo  "安装ES"
    cd /usr/local/
    rpm -ivh elasticsearch-7.10.0-x86_64.rpm
    
    #准备数据目录
    echo "创建es目录"
    mkdir -p /es_data/{data,log}
    ls -l / | grep es_data
    ls -l /es_data/
    echo  "配置目录所属"
    chown elasticsearch:elasticsearch /es_data/ -R
    ls -l / | grep es_data
    ls -l /es_data/
    
    
    
    #jvm优化
    echo  "修改JVM参数"
    cp /etc/elasticsearch/jvm.options{,.bak}
    #设置堆内存6g=总内存*50%
    sed -i "s/^-Xms1g/-Xms6g/" /etc/elasticsearch/jvm.options && sed -i "s/^-Xmx1g/-Xmx6g/" /etc/elasticsearch/jvm.options
    echo "JVM"
    cat /etc/elasticsearch/jvm.options | grep "^-Xm"
    #减少新生代晋升到老年代时停顿,会使得启动慢上一点,但后面访问时会更流畅
    sed -i "s/^## GC configuration/## GC configuration\n8-13:-XX:+AlwaysPreTouch/" /etc/elasticsearch/jvm.options
    
    #系统优化
    echo "关闭swap交换分区"
    cp /etc/fstab{,.bak}
    sed -i "s/^\/dev\/mapper\/centos-swap/#\/dev\/mapper\/centos-swap/" /etc/fstab
    cat /etc/fstab | grep "swap"
    echo vm.swappiness=1 >> /etc/sysctl.conf
    echo "设置系统最大打开文件描述符数为655360"
    echo "fs.file-max=655360" >> /etc/sysctl.conf
    echo "限制一个进程可以用于VM(虚拟内存区域大小)为262144"
    echo "vm.max_map_count=262144" >> /etc/sysctl.conf
    echo "--/etc/sysctl.conf--"
    cat  /etc/sysctl.conf |grep "^[a-z]"
    
    echo "优化批量请求"
    echo '* soft nproc 32000' >> /etc/security/limits.conf
    echo '* hard nproc 32000' >> /etc/security/limits.conf
    echo '* soft nofile 65536' >> /etc/security/limits.conf
    echo '* hard nofile 65536' >> /etc/security/limits.conf
    echo '* soft memlock unlimited' >> /etc/security/limits.conf
    echo '* hard memlock unlimited' >> /etc/security/limits.conf
    echo "--/etc/security/limits.conf--"
    cat /etc/security/limits.conf | grep "^\*"
    
    echo "DefaultLimitNOFILE=65536" >>  /etc/systemd/system.conf
    echo "DefaultLimitNPROC=32000" >>  /etc/systemd/system.conf
    echo "DefaultLimitMEMLOCK=infinity" >>  /etc/systemd/system.conf
    cat /etc/systemd/system.conf | grep "^[A-Z]"
    
    #配置es
    cp /etc/elasticsearch/elasticsearch.yml{,.bak}
    echo "修改elasticsearch.yml"
    #基本配置
    clusterName="es_cluster"
    nodeName="es01"
    #是否竞选master
    master=true
    #是否存储索引数据
    data=true
    #如果都不做,会变成client节点
    #本机ip和端口
    localIp=192.168.18.11
    localPort=9200
    #初始竞选master的节点
    masters="[\"es01\", \"es02\"]"
    #发现其他节点的列表
    discovery="[\"192.168.18.11:9300\", \"192.168.18.12:9300\", \"192.168.18.13:9300\"]"
    
    echo "cluster.name: $clusterName" >> /etc/elasticsearch/elasticsearch.yml
    echo "node.name: $nodeName" >> /etc/elasticsearch/elasticsearch.yml
    sed -i "s/^path.data: \/var\/lib\/elasticsearch/path.data: \/es_data\/data/" /etc/elasticsearch/elasticsearch.yml
    sed -i "s/^path.logs: \/var\/log\/elasticsearch/path.logs: \/es_data\/log/" /etc/elasticsearch/elasticsearch.yml
    echo "node.master: $master" >> /etc/elasticsearch/elasticsearch.yml
    echo "node.data: $data" >> /etc/elasticsearch/elasticsearch.yml
    echo "network.host: $localIp" >> /etc/elasticsearch/elasticsearch.yml
    echo "http.port: $localPort" >> /etc/elasticsearch/elasticsearch.yml
    echo "discovery.seed_hosts: $discovery" >> /etc/elasticsearch/elasticsearch.yml
    echo "cluster.initial_master_nodes: $masters" >> /etc/elasticsearch/elasticsearch.yml
    #锁住物理内存,避免使用swap交换分区
    echo "bootstrap.memory_lock: true" >> /etc/elasticsearch/elasticsearch.yml
    echo "es配置完毕"
    cat /etc/elasticsearch/elasticsearch.yml | grep "^[a-z]"
    
    chkconfig --add elasticsearch
    chkconfig elasticsearch on
    
    echo "重启系统"
    reboot
    
    


    1、用rpm安装es,会自动创建elasticsearch用户和用户组
    2、最好重启一下,应用这些参数,重启后会自动开启es
    3、在浏览器输入http:<ip>:9200即可查看是否安装成功

    相关文章

      网友评论

          本文标题:1、搭建ES7.10.0集群

          本文链接:https://www.haomeiwen.com/subject/kslowktx.html