elasticsearch

基本概念

  • NRT: 准实时, 秒级

  • cluster: 集群, 无中心节点

  • index: 对应database

  • document: 对应table

  • mapping:

    • 对应表结构

    • doc -> index 时进行的分词和过滤规则

    • mapping不能被修改

  • type: doc的类型, 类型对应mapping规则

  • template: 自动生成 mapping 的模板

  • shards: 分片, 将index拆分成多个进行分布式访问

  • replicas: 副本, 提高容错性

  • recovery: 节点变化时的数据重新分配

  • river: 数据源

  • gateway: 持久化

  • discovery: 节点发现

  • transport: 节点间通信

配置

系统环境

  • file descriptors

    • /etc/security/limits.conf

    • ushare hard nofile 65536

    • ushare soft nofile 65536

    • ushare hard memlock unlimited

    • ushare soft memlock unlimited

  • virtual memory

    • /etc/sysctl.conf

    • vm.max_map_count=262144

ik 分词

运行

  • daemon

    • ./bin/elasticsearch -d

问题

  • node settings must not contain any index level settings

    • 原因: es 5.0 以上不支持配置文件中进行index配置

    • 解决: 使用 index template

logstash

日志的搜集, 处理, 传输管道(pipeline)

基本概念

  • inputs: 数据源

    • file: 文件

    • syslog: 日志

    • redis: nosql

    • jdbc: mysql

  • filters: 数据处理

    • grok: 文本结构化处理

    • mutate: 处理事件

    • drop: 数据丢弃, 如debug

    • ..

  • outputs: 数据输出

    • elasticsearch: 搜索

    • file: 文件

    • graphite: 图表

  • codecs: 编码

    • json

    • msgpack

    • plain: text

    • multiline: 事件合并

  • event: 事件, 数据变动触发事件

配置

  • input-jdbc

    • bin/logstash-plugin install logstash-input-jdbc

    • mysql-driver

      • use_column_value: boolean, 是否使用 track_column_value 变量代替 sql_last_value

        • false: 使用上次查询时间
      • track_column_value: sql_last_value 替换的字段名

运行

  • nohup

    • nohup ./logstash-6.3.2/bin/logstash > /dev/null 2>&1 &

问题解决

  • 启动慢

    • 原因: 系统熵值低, 随机数被耗尽 (/proc/sys/kernel/random/entropy_avail)

    • 影响: 依赖随机数的业务 (SSL, 加密等)

    • 解决: 安装 rngd 服务

      • sudo yum -y install rng-tools

      • sudo vim /usr/lib/systemd/system/rngd.service

        • ExecStart=/sbin/rngd -f -r /dev/urandom
      • sudo systemctl daemon-reload

      • sudo systemctl rngd restart