• ELK 学习记录


    ELK 学习记录 - 环境搭建 - 手动安装

    准备工作

    1、下载安装包 

    2、解压到安装目录

    tar -zxvf elasticsearch-7.8.1-linux-x86_64.tar.gz
    
    tar -zxvf kibana-7.8.1-linux-x86_64.tar.gz
    
    tar -zxvf logstash-7.8.1.tar.gz

    一、elasticsearch 安装

    1、配置

    [root@ecs-aece elk]# cd elasticsearch-7.8.1/
    [root@ecs-aece elasticsearch-7.8.1]# ls
    bin  config  jdk  lib  LICENSE.txt  logs  modules  NOTICE.txt  plugins  README.asciidoc
    [root@ecs-aece elasticsearch-7.8.1]# cd config
    [root@ecs-aece config]# ls
    elasticsearch.yml  jvm.options  jvm.options.d  log4j2.properties  role_mapping.yml  roles.yml  users  users_roles
    [root@ecs-aece config]# vim elasticsearch.yml 

    正确配置示例

    node.name: node-1
    cluster.initial_master_nodes: ["node-1"]
    network.host: 0.0.0.0
    http.port: 9200
    http.cors.enabled: true
    http.cors.allow-origin: "*"

    2、启动

    #添加用户组
    [root@ecs-aece config]# groupadd elsearch
    #添加用户
    [root@ecs-aece config]# useradd elsearch -g elsearch
    
    #修改 es 文件夹及内部文件的所属用户及组为elsearch:elsearch 
    [root@ecs-aece elk]# pwd
    /usr/local/elk
    [root@ecs-aece elk]# ls
    elasticsearch-7.8.1  elasticsearch-7.8.1-linux-x86_64.tar.gz  kibana-7.8.1-linux-x86_64  kibana-7.8.1-linux-x86_64.tar.gz  logstash-7.8.1  logstash-7.8.1.tar.gz
    [root@ecs-aece elk]# 
    [root@ecs-aece elk]# chown -R elsearch:elsearch elasticsearch-7.8.1
    [root@ecs-aece elk]# 
    
    #切换用户
    [root@ecs-aece elk]# su elsearch
    #进去bin目录
    [elsearch@ecs-aece elk]$ cd elasticsearch-7.8.1/bin
    #启动
    sh elasticsearch &

    3、验证

    在浏览器中输入:http://xxxxxxxxxxxxxxxxxxxx:9200

    {
      "name" : "node-1",
      "cluster_name" : "elasticsearch",
      "cluster_uuid" : "stnvKTWXSImMTMK_Fnropg",
      "version" : {
        "number" : "7.8.1",
        "build_flavor" : "default",
        "build_type" : "tar",
        "build_hash" : "b5ca9c58fb664ca8bf9e4057fc229b3396bf3a89",
        "build_date" : "2020-07-21T16:40:44.668009Z",
        "build_snapshot" : false,
        "lucene_version" : "8.5.1",
        "minimum_wire_compatibility_version" : "6.8.0",
        "minimum_index_compatibility_version" : "6.0.0-beta1"
      },
      "tagline" : "You Know, for Search"
    }

    其他配置说明

    elasticsearch配置文件中 http.cors.x 字段有哪些用途和用法

    http.cors.enabled   是否支持跨域,默认为false
    http.cors.allow-origin  当设置允许跨域,默认为*,表示支持所有域名,如果我们只是允许某些网站能访问,那么可以使用正则表达式。比如只允许本地地址。 /https?://localhost(:[0-9]+)?/
    http.cors.max-age   浏览器发送一个“预检”OPTIONS请求,以确定CORS设置。最大年龄定义多久的结果应该缓存。默认为1728000(20天)
    http.cors.allow-methods 允许跨域的请求方式,默认OPTIONS,HEAD,GET,POST,PUT,DELETE
    http.cors.allow-headers 跨域允许设置的头信息,默认为X-Requested-With,Content-Type,Content-Length
    http.cors.allow-credentials 是否返回设置的跨域Access-Control-Allow-Credentials头,如果设置为true,那么会返回给客户端。

    UI 插件 elasticsearch-head 安装

    git clone git://github.com/mobz/elasticsearch-head.git
    cd elasticsearch-head
    npm install
    npm run start
    open http://localhost:9100/

    注意:安装过程中可能出现部分软件下载不下来,那么手动下载 上传到 指定的位置即可。

    如:phantomjs-2.1.1-linux-x86_64.tar.bz2

    遇到的问题

    问题一(es):

    WARNING: IPv4 forwarding is disabled. Networking will not work.

    原因:因为linux内核转发的问题

    解决方案:

    1、修改sysctl.conf或者00-system.conf文件

    vim /etc/sysctl.conf
    或者
    vim /usr/lib/sysctl.d/00-system.conf

    2、在sysctl.conf或者00-system.conf文件添加以下代码

    net.ipv4.ip_forward=1

    3、重启network服务

    systemctl restart network

    4、查看是否修改成功

    sysctl net.ipv4.ip_forward

    问题二(es):

    elasticsearch-env: line 122: syntax error near unexpected token `<

    原因:版本问题

    解决方案:修改elasticsearch-env文件的第122行:

    done < <(env)
    【<改成三连,括号改成单引号】
    done <<<'env'

    问题三(es):

    ERROR: [1] bootstrap checks failed
    [1]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

    原因:vm.max_map_count 数量太低

    解决方案:vim /etc/sysctl.conf ,追加如下配置

    vm.max_map_count=262144

     然后执行如下命令:

    sysctl -p #从指定的文件加载系统参数,如不指定即从/etc/sysctl.conf中加载

    问题四(es):

    java.lang.RuntimeException: can not run elasticsearch as root

    原因:不可以用 root 用户启动es

    解决方案:切换成 elsearch 用户 (或其他指定用户)

    问题五(es):

    ERROR: [1] bootstrap checks failed
    [1]: the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured

    原因:没有修改 host1,host2 等

    在elasticsearch的config目录下,修改elasticsearch.yml配置文件,将下面的配置加入到该配置文件中

    ip替换host1等,多节点请添加多个ip地址,单节点可写按默认来
    #配置以下三者,最少其一
    #[discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes]
    cluster.initial_master_nodes: ["node-1"] #这里的node-1为node-name配置的值

    二、kibana 安装

    1、使用 root 用户进去到 kibana 解压后的目录

    2、配置 

    kibana.yml

    server.port: 5601
    server.host: "0.0.0.0"
    elasticsearch.hosts: ["http://localhost:9200/"]
    kibana.index: ".kibana"

    3、启动

    进去 bin 目录

    sh kibana --allow-root &  #默认不可以使用 root 启动

    4、验证

    http://xxxxxxxx:5601

    问题:

    问题一(k):

    FATAL  Error: [elasticsearch.url]: definition for this key is missing

    解决方案:

    需要用: elasticsearch.hosts, 而不是: elasticsearch.url

    server.port: 5601
    server.host: "0.0.0.0"
    server.name: tanklog
    elasticsearch.hosts: ["http://localhost:9200/"]
    # elasticsearch.url: "http://localhost:9200"

    三、logstash 安装

    本次如下操作在  logstash 下进行

    1、配置

    logstash 启动之前需 手动编写配置文件,如: logstash_nacos.conf

    内容如下:

    input {
        file {
            path => "/usr/local/nacos/logs/*.log"
            start_position => beginning
        }
    }
    filter {
     
    }
    output {
        elasticsearch {
        hosts => "localhost:9200"
        }
    }

    2、启动

    # -f 配置文件启动
    sh logstash -f logstash_nacos.conf &

    总结:logstash三种启动方式,-e sting类型启动,-f 指定配置文件启动,服务启动。

    # -e string 启动
    logstash -e 'input{ stdin{} } output{ stdout{} }'
    # 服务启动
    service logstash start

    参考资料:

    安装包下载

    ELK搭建教程(全过程)

    elasticsearch.yml 配置文件说明

    logstash配置文件详解

    logstash组件详解

    Logstash+ Kafka基于AOP 实时同步日志到es

  • 相关阅读:
    javaIO流之 字节与字符流认识
    Servlet容器理解(生命周期、servletContext作用域、servlet装载方式)
    是否改变原数组的常用方法
    时间空间复杂度的初步理解---后续补充
    java集合框架之 Set
    【原】SQLPLUS支持上下翻页
    【转】shell脚本写的俄罗斯方块游戏
    【原】Oracle 11.2.0.1 64bit for RHEL6.0 Server x86_64 静默安装
    【原】RHEL6.0企业版安装
    【原】记录一句话
  • 原文地址:https://www.cnblogs.com/wangwangfei/p/13461853.html
Copyright © 2020-2023  润新知