美文网首页技术杂记
Centos 7 下安装elasticsearch 7.4.2

Centos 7 下安装elasticsearch 7.4.2

作者: xilin_am | 来源:发表于2019-11-04 09:09 被阅读0次

    简单记录一下安装过程,说一下其中的坑。
    我这里是四台kvm的虚拟机 安装centos7
    192.168.122.30 node01
    192.168.122.31 node02
    192.168.122.32 node03
    192.168.122.33 kibana

    1. 首先找个yum源
    导入密钥
    rpm --import  https://artifacts.elastic.co/GPG-KEY-elasticsearch123123
    
    添加 elasticsearch.repo
    [elasticsearch-7.x]
    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=1
    autorefresh=1
    type=rpm-md
    

    yum install elasticsearch

    2. elasticsearch 配置

    目前elasticsearch最新版本为7.4.2 ,elasticsearch7.X之后的版本配置跟之前的有区别.这里直接贴一个配置出来
    /etc/elasticsearch/elasticsearch.yml

    cluster.name: myes
    #
    # ------------------------------------ Node ------------------------------------
    #
    # Use a descriptive name for the node:
    #
    node.name: node01
    #
    # Add custom attributes to the node:
    #
    #node.attr.rack: r1
    #
    # ----------------------------------- Paths ------------------------------------
    #
    # Path to directory where to store the data (separate multiple locations by comma):
    #
    path.data: /var/lib/elasticsearch
    path.logs: /var/log/elasticsearch
    #
    # ----------------------------------- Memory -----------------------------------
    #
    # Lock the memory on startup:
    #
    bootstrap.memory_lock: true
    # Set the bind address to a specific IP (IPv4 or IPv6):
    #
    network.host: 192.168.122.30
    #
    # Set a custom port for HTTP:
    #
    http.port: 9200
    #
    # For more information, consult the network module documentation.
    #
    # --------------------------------- Discovery ----------------------------------
    #
    # Pass an initial list of hosts to perform discovery when this node is started:
    # The default list of hosts is ["127.0.0.1", "[::1]"]
    #
    discovery.seed_hosts: ["192.168.122.30", "192.168.122.31", "192.168.122.32"]
    cluster.initial_master_nodes: ["192.168.122.30", "192.168.122.31", "192.168.122.32"]
    http.cors.enabled: true
    # “*” 表示支持所有域名
    http.cors.allow-origin: "*"
    action.destructive_requires_name: true
    action.auto_create_index: .security,.monitoring*,.watches,.triggered_watches,.watcher-history*
    xpack.security.enabled: false
    xpack.monitoring.enabled: true
    xpack.graph.enabled: false
    xpack.watcher.enabled: false
    xpack.ml.enabled: false
    
    discovery.zen.minimum_master_nodes: 2
    discovery.zen.fd.ping_timeout: 1m
    discovery.zen.fd.ping_retries: 5
    
    3. es 安装相关问题

    1,如果打开了bootstrap.memory_lock: true,启动失败会在日志里看到

    These can be adjusted by modifying /etc/security/limits.conf, for example:
    # allow user 'baoshan' mlockall
    elasticsearch soft memlock unlimited
    elasticsearch hard memlock unlimited
    

    elasticsearch官网建议生产环境需要设置bootstrap.memory_lock: true。因为发生系统swapping的时候ES节点的性能会非常差,也会影响节点的稳定性。所以要不惜一切代价来避免swapping。swapping会导致Java GC的周期延迟从毫秒级恶化到分钟,更严重的是会引起节点响应延迟甚至脱离集群

    关于这个提示你修改了/etc/security/limits.conf也可能不够!
    1, centos7下/etc/security/limits.d下的文件会覆盖limits.conf,所以可以将其注释,
    2,修改/etc/sysctl.conf,

    vm.max_map_count = 262144
    vm.swappiness = 0
    

    sysctl -p 生效
    3,可是有文章提到

    在Centos7系统中,使用Systemd替代了之前的SysV。/etc/security/limits.conf文件的配置作用域缩小了。/etc/security/limits.conf的配置,只适用于通过PAM认证登录用户的资源限制,它对systemd的service的资源限制不生效。因此登录用户的限制,通过/etc/security/limits.conf与/etc/security/limits.d下的文件设置即可,对于systemd service的资源设置,则需修改全局配置,全局配置文件放在/etc/systemd/system.conf
    所以加个全局设置

    vim /etc/systemd/system.conf
    ...
    DefaultLimitNOFILE=65536
    DefaultLimitNPROC=32000
    DefaultLimitMEMLOCK=infinity
    

    以上centos7下安装elasticsearch-7.4.2-x86_64 亲测有效。

    4.kibana7.4.2 安装
    可能是我虚拟机资源有限的问题,我发现在elasticsearch节点上安装kibana会导致本机节点死机 , 所以,我准备了另外一台来安装kibana.

    yum install kibana

    配置/etc/kibana/kibana.yml

    server.port: 5601
    
    server.host: "192.168.122.33"
        
    server.name: "mykb"
     
    elasticsearch.hosts: ["http://192.168.122.30:9200", "http://192.168.122.31:9200", "http://192.168.122.32:9200"]
                  
    i18n.locale: "zh-CN"
    xpack.reporting.encryptionKey: "a_random_string"
    
    
    5 .其他

    刚开始也尝试了docker部署, 单节点很快速,多节点出了点问题, 网上很多单机部署多个容器的,但实际情况是多台机器部署集群, 匆忙之下直接在系统安装, 下次还是考虑一步到位在k8s下部署es更好一点。

    相关文章

      网友评论

        本文标题:Centos 7 下安装elasticsearch 7.4.2

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