centos7安装配置ELK(Elasticsearch+Logstash+Kibana)

本文涉及的产品
云数据库 Tair(兼容Redis),内存型 2GB
Redis 开源版,标准版 2GB
推荐场景:
搭建游戏排行榜
检索分析服务 Elasticsearch 版,2核4GB开发者规格 1个月
简介:

1.server端安装

#安装elasticsearch

yum install java-1.8.0-openjdk ruby

yum install elasticsearch-2.1.0.rpm

vi /etc/elasticsearch/elasticsearch.yml

# cluster.name: my-application

cluster.name: wc

# network.host: 192.168.0.1

network.host: 127.0.0.1

systemctl start elasticsearch

rpm -qc elasticsearch

curl -X GET http://localhost:9200/

vi /etc/nginx/conf.d/elasticsearch.conf

server {

    listen 80;

    server_name 110.110.110.110;:

    location / {

        proxy_pass http://110.110.110.110:9200;

        proxy_redirect  off;

        proxy_set_header Host $host;

        proxy_set_header X-Real-IP $remote_addr;

        proxy_set_header X-Forwarded-Proto https;

        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

        }

}

浏览器输入http://110.110.110.110:9200/


#安装redis

yum install redis

mkdir -p /opt/redis

cd /opt/redis

mkdir {db,log,etc}

redis-server /etc/redis.conf &   启动默认的redis配置文件


#安装kibana

tar -zxvf kibana-5.0.0-snapshot-linux-x64.tar.gz

mv kibana-5.0.0-snapshot-linux-x64 kibana

cp -R kibana /opt/

vi /etc/systemd/system/kibana.service

[Service]

ExecStart=/opt/kibana/bin/kibana

[Install]

WantedBy=multi-user.target

systemctl start kibana

systemctl enable kibana

systemctl status kibana

http://IP:5601

报错1:Unable to connect to Elasticsearch at http://localhost:9200. Retrying in 2.5 seconds

解决1:

vi /etc/elasticsearch/elasticsearch.yml

network.host: 127.0.0.1

报错2:No existing Kibana index found

解决2:

报错3:Warning No default index pattern. You must select or create one to continue.

解决3:


#安装logstash

yum install logstash-2.1.0-1.noarch.rpm

cd /etc/pki/tls

openssl req -config /etc/pki/tls/openssl.cnf -x509 -days 3650 -batch -nodes -newkey rsa:2048 -keyout private/logstash-forwarder.key -out certs/logstash-forwarder.crt

vi /etc/logstash/conf.d/logstasg-hello.conf

input {

  lumberjack {

    # The port to listen on

    port => 5000

    # The paths to your ssl cert and key

    ssl_certificate => "/etc/pki/tls/certs/logstash-forwarder.crt"

    ssl_key => "/etc/pki/tls/private/logstash-forwarder.key"

    type => "this forwarder's file have no type!"

  }

}


filter {

  if [type] == "syslog" {

    grok {

      match => { "message" => "%{SYSLOGTIMESTAMP:syslog_timestamp} %{SYSLOGHOST:syslog_hostname} %{DATA:syslog_program}(?:\[%{POSINT:syslog_pid}\])?: %{GREEDYDATA:syslog_message}" }

      add_field => [ "received_at", "%{@timestamp}" ]

      add_field => [ "received_from", "%{host}" ]

    }

    syslog_pri { }

    date {

      match => [ "syslog_timestamp", "MMM  d HH:mm:ss", "MMM dd HH:mm:ss" ]

    }

  }

}


output {

  elasticsearch { host => localhost }

  stdout { codec => rubydebug }

}

/opt/logstash/bin/logstash -f /etc/logstash/conf.d/logstash-hello.conf


#安装lnmp环境

yum install nginx php

vi /etc/nginx/conf.d/logstash.conf

server {

     listen       80;

     server_name   IP;

     location / {

     proxy_pass  http://localhost:5601;

     proxy_redirect  off;

     proxy_set_header Host $host;

     proxy_set_header X-Real-IP $remote_addr;

     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

     client_max_body_size 10m;

     client_body_buffer_size 128k;

     proxy_connect_timeout 90;

     proxy_send_timeout 90;

     proxy_read_timeout 90;

     proxy_buffer_size 4k;

     proxy_buffers 4 32k;

     proxy_busy_buffers_size 64k;

     proxy_temp_file_write_size 64k;

     }

}

systemctl start nginx


2.client端安装


3.elasticsearch配置文件详解

cat /etc/elasticsearch里的logging.yml用默认配置,elasticsearch.yml配置如下:


cluster.name: elasticsearch

配置es的集群名称,默认是elasticsearch,es会自动发现在同一网段下的es,如果在同一网段下有多个集群,就可以用这个属性来区分不同的集群。


node.name: "Franz Kafka"

节点名,默认随机指定一个name列表中名字,该列表在es的jar包中config文件夹里name.txt文件中,其中有很多作者添加的有趣名字。


node.master: true

指定该节点是否有资格被选举成为node,默认是true,es是默认集群中的第一台机器为master,如果这台机挂了就会重新选举master。


node.data: true

指定该节点是否存储索引数据,默认为true。


index.number_of_shards: 5

设置默认索引分片个数,默认为5片。


index.number_of_replicas: 1

设置默认索引副本个数,默认为1个副本。


path.conf: /path/to/conf

设置配置文件的存储路径,默认是es根目录下的config文件夹。


path.data: /path/to/data

设置索引数据的存储路径,默认是es根目录下的data文件夹,可以设置多个存储路径,用逗号隔开,例:

path.data: /path/to/data1,/path/to/data2


path.work: /path/to/work

设置临时文件的存储路径,默认是es根目录下的work文件夹。


path.logs: /path/to/logs

设置日志文件的存储路径,默认是es根目录下的logs文件夹


path.plugins: /path/to/plugins

设置插件的存放路径,默认是es根目录下的plugins文件夹


bootstrap.mlockall: true

设置为true来锁住内存。因为当jvm开始swapping时es的效率 会降低,所以要保证它不swap,可以把ES_MIN_MEM和ES_MAX_MEM两个环境变量设置成同一个值,并且保证机器有足够的内存分配给es。 同时也要允许elasticsearch的进程可以锁住内存,linux下可以通过`ulimit -l unlimited`命令。


network.bind_host: 192.168.0.1

设置绑定的ip地址,可以是ipv4或ipv6的,默认为0.0.0.0。


network.publish_host: 192.168.0.1

设置其它节点和该节点交互的ip地址,如果不设置它会自动判断,值必须是个真实的ip地址。


network.host: 192.168.0.1

这个参数是用来同时设置bind_host和publish_host上面两个参数。


transport.tcp.port: 9300

设置节点间交互的tcp端口,默认是9300。


transport.tcp.compress: true

设置是否压缩tcp传输时的数据,默认为false,不压缩。


http.port: 9200

设置对外服务的http端口,默认为9200。


http.max_content_length: 100mb

设置内容的最大容量,默认100mb


http.enabled: false

是否使用http协议对外提供服务,默认为true,开启。


gateway.type: local

gateway的类型,默认为local即为本地文件系统,可以设置为本地文件系统,分布式文件系统,hadoop的HDFS,和amazon的s3服务器,其它文件系统的设置方法下次再详细说。


gateway.recover_after_nodes: 1

设置集群中N个节点启动时进行数据恢复,默认为1。


gateway.recover_after_time: 5m

设置初始化数据恢复进程的超时时间,默认是5分钟。


gateway.expected_nodes: 2

设置这个集群中节点的数量,默认为2,一旦这N个节点启动,就会立即进行数据恢复。


cluster.routing.allocation.node_initial_primaries_recoveries: 4

初始化数据恢复时,并发恢复线程的个数,默认为4。


cluster.routing.allocation.node_concurrent_recoveries: 2

添加删除节点或负载均衡时并发恢复线程的个数,默认为4。


indices.recovery.max_size_per_sec: 0

设置数据恢复时限制的带宽,如入100mb,默认为0,即无限制。


indices.recovery.concurrent_streams: 5

设置这个参数来限制从其它分片恢复数据时最大同时打开并发流的个数,默认为5。


discovery.zen.minimum_master_nodes: 1

设置这个参数来保证集群中的节点可以知道其它N个有master资格的节点。默认为1,对于大的集群来说,可以设置大一点的值(2-4)


discovery.zen.ping.timeout: 3s

设置集群中自动发现其它节点时ping连接超时时间,默认为3秒,对于比较差的网络环境可以高点的值来防止自动发现时出错。


discovery.zen.ping.multicast.enabled: false

设置是否打开多播发现节点,默认是true。


discovery.zen.ping.unicast.hosts: ["host1", "host2:port", "host3[portX-portY]"]

设置集群中master节点的初始列表,可以通过这些节点来自动发现新加入集群的节点。


下面是一些查询时的慢日志参数设置

index.search.slowlog.level: TRACE

index.search.slowlog.threshold.query.warn: 10s

index.search.slowlog.threshold.query.info: 5s

index.search.slowlog.threshold.query.debug: 2s

index.search.slowlog.threshold.query.trace: 500ms


index.search.slowlog.threshold.fetch.warn: 1s

index.search.slowlog.threshold.fetch.info: 800ms

index.search.slowlog.threshold.fetch.debug:500ms

index.search.slowlog.threshold.fetch.trace: 200ms


本文转自 guowang327 51CTO博客,原文链接:http://blog.51cto.com/guowang327/1718601,如需转载请自行联系原作者

相关实践学习
使用阿里云Elasticsearch体验信息检索加速
通过创建登录阿里云Elasticsearch集群,使用DataWorks将MySQL数据同步至Elasticsearch,体验多条件检索效果,简单展示数据同步和信息检索加速的过程和操作。
ElasticSearch 入门精讲
ElasticSearch是一个开源的、基于Lucene的、分布式、高扩展、高实时的搜索与数据分析引擎。根据DB-Engines的排名显示,Elasticsearch是最受欢迎的企业搜索引擎,其次是Apache Solr(也是基于Lucene)。 ElasticSearch的实现原理主要分为以下几个步骤: 用户将数据提交到Elastic Search 数据库中 通过分词控制器去将对应的语句分词,将其权重和分词结果一并存入数据 当用户搜索数据时候,再根据权重将结果排名、打分 将返回结果呈现给用户 Elasticsearch可以用于搜索各种文档。它提供可扩展的搜索,具有接近实时的搜索,并支持多租户。
相关文章
|
2月前
|
存储 JSON Java
ELK 圣经:Elasticsearch、Logstash、Kibana 从入门到精通
ELK是一套强大的日志管理和分析工具,广泛应用于日志监控、故障排查、业务分析等场景。本文档将详细介绍ELK的各个组件及其配置方法,帮助读者从零开始掌握ELK的使用。
|
2月前
|
存储 监控 安全
|
2月前
|
关系型数据库 MySQL Linux
在 CentOS 7 中通过编译源码方式安装 MySQL 数据库的详细步骤,包括准备工作、下载源码、编译安装、配置 MySQL 服务、登录设置等。
本文介绍了在 CentOS 7 中通过编译源码方式安装 MySQL 数据库的详细步骤,包括准备工作、下载源码、编译安装、配置 MySQL 服务、登录设置等。同时,文章还对比了编译源码安装与使用 RPM 包安装的优缺点,帮助读者根据需求选择最合适的方法。通过具体案例,展示了编译源码安装的灵活性和定制性。
217 2
|
3月前
|
Java jenkins 持续交付
Centos7下docker的jenkins下载并配置jdk与maven
通过上述步骤,您将成功在CentOS 7上的Docker容器中部署了Jenkins,并配置好了JDK与Maven,为持续集成和自动化构建打下了坚实基础。
156 1
|
3月前
|
存储 监控 Linux
在 CentOS 7 中如何对新硬盘进行分区、格式化、挂载及配置最佳实践
本文详细介绍了在 CentOS 7 中如何对新硬盘进行分区、格式化、挂载及配置最佳实践,包括使用 `fdisk` 创建分区、`mkfs` 格式化分区、创建挂载点、编辑 `/etc/fstab` 实现永久挂载等步骤,旨在有效管理服务器磁盘空间,提高系统稳定性和可维护性。
525 1
|
3月前
|
自然语言处理 搜索推荐 关系型数据库
elasticsearch学习六:学习 全文搜索引擎 elasticsearch的语法,使用kibana进行模拟测试(持续更新学习)
这篇文章是关于Elasticsearch全文搜索引擎的学习指南,涵盖了基本概念、命令风格、索引操作、分词器使用,以及数据的增加、修改、删除和查询等操作。
42 0
elasticsearch学习六:学习 全文搜索引擎 elasticsearch的语法,使用kibana进行模拟测试(持续更新学习)
|
3月前
|
安全 Linux 数据库连接
CentOS 7环境下DM8数据库的安装与配置
【10月更文挑战第16天】本文介绍了在 CentOS 7 环境下安装与配置达梦数据库(DM8)的详细步骤,包括安装前准备、创建安装用户、上传安装文件、解压并运行安装程序、初始化数据库实例、配置环境变量、启动数据库服务、配置数据库连接和参数、备份与恢复、以及安装后的安全设置、性能优化和定期维护等内容。通过这些步骤,可以顺利完成 DM8 的安装与配置。
482 0
|
2月前
|
存储 安全 数据管理
如何在 Rocky Linux 8 上安装和配置 Elasticsearch
本文详细介绍了在 Rocky Linux 8 上安装和配置 Elasticsearch 的步骤,包括添加仓库、安装 Elasticsearch、配置文件修改、设置内存和文件描述符、启动和验证 Elasticsearch,以及常见问题的解决方法。通过这些步骤,你可以快速搭建起这个强大的分布式搜索和分析引擎。
77 5
|
3月前
|
存储 JSON Java
elasticsearch学习一:了解 ES,版本之间的对应。安装elasticsearch,kibana,head插件、elasticsearch-ik分词器。
这篇文章是关于Elasticsearch的学习指南,包括了解Elasticsearch、版本对应、安装运行Elasticsearch和Kibana、安装head插件和elasticsearch-ik分词器的步骤。
311 0
elasticsearch学习一:了解 ES,版本之间的对应。安装elasticsearch,kibana,head插件、elasticsearch-ik分词器。
|
4月前
|
NoSQL 关系型数据库 Redis
mall在linux环境下的部署(基于Docker容器),Docker安装mysql、redis、nginx、rabbitmq、elasticsearch、logstash、kibana、mongo
mall在linux环境下的部署(基于Docker容器),docker安装mysql、redis、nginx、rabbitmq、elasticsearch、logstash、kibana、mongodb、minio详细教程,拉取镜像、运行容器
mall在linux环境下的部署(基于Docker容器),Docker安装mysql、redis、nginx、rabbitmq、elasticsearch、logstash、kibana、mongo