ELK服务搭建

ELK服务搭建

创建Elasticsearch服务

  • 环境 Centos

这里是直接在服务器中创建es服务,没有使用docker部署服务是因为会出现莫名其妙的停止运行问题,应该是Java堆栈设置问题

#这里是使用的最新版,下载解压
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.11.3-linux-x86_64.tar.gz
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.11.3-linux-x86_64.tar.gz.sha512
shasum -a 512 -c elasticsearch-8.11.3-linux-x86_64.tar.gz.sha512 
tar -xzf elasticsearch-8.11.3-linux-x86_64.tar.gz
cd elasticsearch-8.11.3/ 
# 修改配置文件
cd config

elasticsearch.yml 文件配置

cluster.name: es-cluster
node.name: master
path.data: /home/elasticsearch/elasticsearch-8.11.3/data
path.logs: /home/elasticsearch/elasticsearch-8.11.3/logs
network.host: 127.0.0.1
http.host: 0.0.0.0
http.port: 9200
# 以下内容应该是自动生成
xpack.security.enabled: true
xpack.security.enrollment.enabled: true
xpack.security.http.ssl:
  enabled: true
  keystore.path: certs/http.p12
xpack.security.transport.ssl:
  enabled: true
  verification_mode: certificate
  keystore.path: certs/transport.p12
  truststore.path: certs/transport.p12
cluster.initial_master_nodes: ["master"]

在文件jvm.options最后追加

-Xms2g
-Xmx2g

进入到bin文件夹下,./elasticsearch -d后台启动,浏览器输入https://ip:9200访问,正常是需要输入账户密码代表部署成功。

重置密码

bin目录下,执行./elasticsearch-reset-password -u elastic获取密码,账户是elastic

创建Kibana

docker部署

执行docker run --name kib01 -p 5601:5601 docker.elastic.co/kibana/kibana:8.11.2,版本可以自行选择8.11.3,在启动的时候会打印出一个六个数字如:110 021需要记住。

网站修改成中文

进入Kibana容器

echo i18n.locale: zh-CN >> config/kibana.yml

重启容器

登录

服务启动后在页面中访问http://ip:5601,首次登录需要连接es服务器,这里需要填es服务器生成的token。进入到es服务中bin文件夹下执行./elasticsearch-create-enrollment-token -f kibana即可获取,具体可以看kibana页面提示,输入token后执行下一步,需要填入刚刚生成的六个数字如: 110 021,在填写账户elastic以及es中生成的密码

创建Logstash

创建需要挂载的文件

mkdir /home/logstash
cd /home/logstash
mkdir config #配置文件
mkdir logs #上传到es的文件
mkdir pipeline #管道配置,定义文件怎么传输

配置jvm.options

config文件夹中的文件是把logstash容器中config的文件挪出来的
同样修改config文件夹下的jvm.options文件,添加

-Xms512m
-Xmx512m

添加http.p12证书

该文件夹中还有一个http.p12证书文件,因为es服务开启了ssl认证,所以需要使用es服务提供的证书才能访问,该文件在es服务的elasticsearch-8.11.3/config/certs路径下

配置logstash.conf

pipeline文件夹下定义了一个文件logstash.conf内容如下

# Sample Logstash configuration for creating a simple
# Beats -> Logstash -> Elasticsearch pipeline.

input {
  file {
    path => "/usr/share/logstash/logs/*.log" #文件
    start_position => beginning #从开始除获取
    sincedb_path => "/usr/share/logstash/r_log.log" # 传输文件产生的日志信息
  }
}

output {
  elasticsearch {
    hosts => ["https://esip地址:9200"] # es地址
    index => "index_127_23" # es 索引名
    user => "elastic" # es 用户名
    password => "****************" # es 密码
    ssl_certificate_verification => true # ssl校验
    truststore => "/usr/share/logstash/config/http.p12" # 容器中的证书路径,刚刚的挂载路径
    truststore_password => "***********" # 证书密码
  }
}

证书密码获取方式,进入到es服务器bin文件夹中,执行

./elasticsearch-keystore list
./elasticsearch-keystore show xpack.security.http.ssl.keystore.secure_password

docker启动

  docker run --name logstash -dit \
  -v /home/logstash/config:/usr/share/logstash/config \
  -v /home/logstash/pipeline:/usr/share/logstash/pipeline \
  -v /home/logstash/logs:/usr/share/logstash/logs \
  docker.elastic.co/logstash/logstash:8.11.2

启动成功后在/home/logstash/logs文件夹下添加一些文件,注意要以.log结尾,为文件添加内容

kibana查看日志

选择
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
最后:有使用kibana中提供的连接器的方式提取数据,但是没有成功,配置的步骤都是按照官方文档进行,连接器无报错,但是在Kibana中无法连接

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
开源实时日志分析ELK平台能够完美的解决我们上述的问题,ELKElasticSearch、Logstash和Kiabana三个开源工具组成。 官方网站:https://www.elastic.co/products Elasticsearch是个开源分布式搜索引擎,它的特点有:分布式,零配置,自动发现,索引自动分片,索引副本机制,restful风格接口,多数据源,自动搜索负载等。 Logstash是一个完全开源的工具,他可以对你的日志进行收集、过滤,并将其存储供以后使用(如,搜索)。 Kibana 也是一个开源和免费的工具,它Kibana可以为 Logstash 和 ElasticSearch 提供的日志分析友好的 Web 界面,可以帮助您汇总、分析和搜索重要数据日志。 ELK下载:https://www.elastic.co/downloads/ ELK工作原理: ElasticSearch 配置ElasticSearch: 1 2 unzip elasticsearch-6.2.4.zip cd elasticsearch-6.2.4 然后编辑ES的配置文件: 1 vi config/elasticsearch.yml 修改以下配置项: 1 2 3 4 5 6 7 cluster.name=es_cluster node.name=node0 path.data=/tmp/elasticsearch/data path.logs=/tmp/elasticsearch/logs #当前hostname或IP,我这里是node1 network.host=node1 network.port=9200 其他的选项保持默认,然后启动ES: 1 nohup sh elasticsearch > nohup.log & 注意: 1.需要添加用户elk,ES不能以root用户进行启动 2.可能出现的错误: max file descriptors [4096] for elasticsearch process likely too low, increase to at least [65536] 1 2 3 vi /etc/security/limits.conf elk soft nofile 819200 elk hard nofile 819200 max number of threads [1024] for user [work] likely too low, increase to at least [2048] 1 2 3 4 vi /etc/security/limits.d/90-nproc.conf * soft nproc 1024 #修改为: * soft nproc 2048 max virtual memory areas vm.max_map_count [65530] likely too low, increase to at least [262144] 1 2 3 4 5 vi /etc/sysctl.conf #增加改行配置: vm.max_map_count=655360 #保存退出后,执行: sysctl -p 另外再配置ES的时候,threadpool.bulk.queue_size 已经变成了thread_pool.bulk.queue_size ,ES_HEAP_SIZE,ES_MAX_MEM等配置都变为ES_JAVA_OPTS这一配置项,如限制内存最大最小为1G: 1 export ES_JAVA_OPTS="-Xms1g -Xmx1g" 然后可以打开页面http://node1:9200/,将会看到以下内容:(我是通过外部访问虚拟机,因此为了简单没有配置host文件,直接用ip访问) Logstash 配置Logstash: 1 2 tar -zxvf logstash-6.2.4.tar.gz cd logstash-6.2.4 编写配置文件(名字和位置可以随意,这里我放在config目录下,取名为log_app.conf): 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 vi config/log_app.config #以下为内容 input { file { path => "/usr/local/software/elk/app.log" start_position => "beginning" #从文件开始处读写 } # stdin {} #可以从标准输入读数据 } filter { #Only matched data are send to output. } output { # For detail config for elasticsearch as output, # See: https://www.elastic.co/guide/en/logstash/current/plugins-outputs-elasticsearch.html elasticsearch { action => "index" #The operation on ES hosts => "node1:9200" #ElasticSearch host, can be array. index => "applog" #The index to write data to. } } 其他的选项保持默认,然后启动Logstash: 1 2 # -f为指定配置文件 nohup sh ./bin/logstash -f ../config/log_app.config > nohup.log & 日志: Kibana 配置Kibana: 1 2 tar -zxvf kibana-6.2.4-linux-x86_64.tar.gz cd kibana-6.2.4-linux-x86_64 修改以下几项(由于是单机版的,因此host的值也可以使用localhost来代替,这里仅仅作为演示): 1 2 3 4 server.port: 5601 server.host: “node1” elasticsearch.url: http://node1:9200 kibana.index: “.kibana” 启动kibana: 1 nohup sh ./bin/kibana > nohup.log & 启动后界面: 然后需要创建index,步骤如下: ①点击左边iscover出现以下界面 ②按照注释配置,然后点击Next step,在第二页 选择@timestamp点击create创建 ③创建完成之后,可以看到以下一个界面,红框内是 自动生成的域,也可以理解为 跟数据库中的字段类似,其中有一个message字段,就是我们想要的日志信息。 ④再次点击Discover出现以下界面,可以看到默认搜索的是最后15分钟的日志,可以通过点击设置搜索的时间范围. ⑤可以点击右侧域的add设置需要显示的字段 添加完成之后,日志显示如下:

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值