ELK-日志服务【redis-配置使用】

目录

环境

【1】redis配置

【2】filebeat配置

【3】对接logstash配置

【4】验证

【5】安全配置:第一种:kibana-nginx访问控制

【6】第二种:在ES-主节点-配置TLS

【7】kibana配置密码

【8】logstash添加用户密码


环境

es-01,kibana

10.0.0.21

es-02

10.0.0.22

es-03

10.0.0.23

filebeat,nginx

10.0.0.25

logstash

10.0.0.26

redis

10.0.0.27

【1】redis配置

[root@redis ~]# vim /etc/redis.conf 
.....
bind 0.0.0.0
.....
requirepass 111
.....

【2】filebeat配置

[root@filebeat ~]# vim /etc/filebeat/filebeat.yml
filebeat.inputs:
- type: logenabled: truepaths:- /var/log/nginx/access.logtags: ["access"]- type: logenabled: truepaths:- /var/log/nginx/error.logtags: ["error"]output.redis:hosts: ["10.0.0.27:6379"]password: "111"db: 0timeout: 5keys:- key: "filebeat-nginx-access"when.contains:tags: "access"- key: "filebeat-nginx-error"when.contains:tags: "error"[root@filebeat ~]# systemctl restart filebeat.service## 验证redis是否有数据写入,查看key的长度
[root@redis ~]# redis-cli
127.0.0.1:6379> auth 111
OK
127.0.0.1:6379> keys *
1) "filebeat-nginx-access"
2) "filebeat-nginx-error"
127.0.0.1:6379> select 0
OK
127.0.0.1:6379> LLEN filebeat-access
(integer) 19
127.0.0.1:6379> LLEN filebeat-error
(integer) 15
127.0.0.1:6379>

【3】对接logstash配置

[root@logstash ~]# cat /etc/logstash/conf.d/file-redis-log.conf 
input {redis {host => "10.0.0.27"password => "111"db => "0"data_type => "list"key => "filebeat-access"}redis {host => "10.0.0.27"password => "111"db => "0"data_type => "list"key => "filebeat-error"}
}filter {if "access" in [tags][0] {grok {match => { "message" => "%{COMBINEDAPACHELOG}"}}geoip {source => "clientip"}date {match => ["timestamp","dd/MMM/yyyy:HH:mm:ss Z"]target => "@timestamp"timezone => "Asia/Shanghai"}useragent {source => "agent"target => "useragent"}mutate {convert => ["bytes","integer"]convert => ["response_time", "float"]convert => ["upstream_response_time", "float"]remove_field => ["message"]add_field => { "target_index" => "app-logstash-nginx-access-%{+YYYY.MM.dd}" }	   }# 提取 referrer 具体的域名 /^"http/if [referrer] =~ /^"http/ {grok {match => { "referrer" => '%{URIPROTO}://%{URIHOST:referrer_host}' }}}# 提取用户请求资源类型以及资源 ID 编号if "test.com" in [referrer_host] {grok {match => { "referrer" => '%{URIPROTO}://%{URIHOST}/(%{NOTSPACE:test_type}/%{NOTSPACE:test_res_id})?' }}}}else if "error" in [tags][0] {date {match => ["timestamp","dd/MMM/yyyy:HH:mm:ss Z"]target => "@timestamp"timezone => "Asia/Shanghai"}mutate {add_field => { "target_index" => "app-logstash-nginx-error-%{+YYYY.MM.dd}" }}}
}output {elasticsearch {hosts => ["10.0.0.21:9200","10.0.0.22:9200","10.0.0.23:9200"]index => "%{[target_index]}"template_overwrite => true}
}[root@logstash ~]# /usr/share/logstash/bin/logstash -f /etc/logstash/conf.d/file-redis-log.conf -r

【4】验证

【5】安全配置:第一种:kibana-nginx访问控制

[root@es-01 ~]# yum -y install httpd-tools.x86_64
[root@es-01 ~]# htpasswd -c -b /etc/nginx/basic_passwd kibana 123123
Adding password for user kibana
[root@es-01 ~]# cat /etc/nginx/basic_passwd 
kibana:$apr1$SASZLDcF$mHc2stQeQOCYXeapYhMj7/[root@es-01 ~]# vim /etc/nginx/conf.d/kibana.conf
server {listen 80;server_name nginx.kibana.org;location / {proxy_pass http://127.0.0.1:5601$request_uri;auth_basic "请输入用户名、密码";auth_basic_user_file /etc/nginx/basic_passwd; }
}[root@es-01 ~]# systemctl start nginx

【6】第二种:在ES-主节点-配置TLS

## 在主节点配置TLS
[root@es-01 ~]# /usr/share/elasticsearch/bin/elasticsearch-certutil \    
> cert -out /etc/elasticsearch/elasticsearch-certificates.p12 -pass ""[root@es-01 ~]# chmod 660 /etc/elasticsearch/elasticsearch-certificates.p12 ## 编辑配置文件,添加以下内容,所有节点都需要添加
[root@es-01 ~]# vim /etc/elasticsearch/elasticsearch.yml
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true
xpack.security.transport.ssl.verification_mode: certificate
xpack.security.transport.ssl.keystore.path: elasticsearch-certificates.p12
xpack.security.transport.ssl.truststore.path: elasticsearch-certificates.p12[root@es-02 ~]# vim /etc/elasticsearch/elasticsearch.yml
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true
xpack.security.transport.ssl.verification_mode: certificate
xpack.security.transport.ssl.keystore.path: elasticsearch-certificates.p12
xpack.security.transport.ssl.truststore.path: elasticsearch-certificates.p12[root@es-03 ~]# vim /etc/elasticsearch/elasticsearch.yml
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true
xpack.security.transport.ssl.verification_mode: certificate
xpack.security.transport.ssl.keystore.path: elasticsearch-certificates.p12
xpack.security.transport.ssl.truststore.path: elasticsearch-certificates.p12## 将TLS证书拷贝到所有节点
[root@es-01 ~]# scp -rp /etc/elasticsearch/elasticsearch-certificates.p12 root@10.0.0.22:/etc/elasticsearch/
[root@es-01 ~]# scp -rp /etc/elasticsearch/elasticsearch-certificates.p12 root@10.0.0.23:/etc/elasticsearch/## 重新启动所有节点
[root@es-01 ~]# systemctl restart elasticsearch## 主节点运行后,集群配置密码,auto随机密码,interactive手动
[root@es-01 ~]# /usr/share/elasticsearch/bin/elasticsearch-setup-passwords auto
Initiating the setup of passwords for reserved users elastic,apm_system,kibana,logstash_system,beats_system,remote_monitoring_user.
The passwords will be randomly generated and printed to the console.
Please confirm that you would like to continue [y/N]yChanged password for user apm_system
PASSWORD apm_system = IFYVDU9pa0BaYqn8bFdiChanged password for user kibana
PASSWORD kibana = 3S32IGJTj9bpgIy8q4bPChanged password for user logstash_system
PASSWORD logstash_system = EbaDFZhIMqNMgtMWaBFYChanged password for user beats_system
PASSWORD beats_system = hFivaRmv8BUGxr11vkRMChanged password for user remote_monitoring_user
PASSWORD remote_monitoring_user = 68xmYgepf2L40Zr5HPLIChanged password for user elastic
PASSWORD elastic = PpCC9KV8FnoDepE7DYZU[root@es-01 ~]# 

【7】kibana配置密码

[root@es-01 ~]# vim /etc/kibana/kibana.yml
......
elasticsearch.username: "kibana"
elasticsearch.password: "vERKRjujB5kfukYCT77w"[root@es-01 ~]# systemctl restart kibana

【8】logstash添加用户密码

 

[root@logstash ~]# cat /etc/logstash/conf.d/file-redis-log.conf 
input {redis {host => "10.0.0.27"password => "111"db => "0"data_type => "list"key => "filebeat-access"}redis {host => "10.0.0.27"password => "111"db => "0"data_type => "list"key => "filebeat-error"}
}filter {if "access" in [tags][0] {grok {match => { "message" => "%{COMBINEDAPACHELOG}"}}geoip {source => "clientip"}date {match => ["timestamp","dd/MMM/yyyy:HH:mm:ss Z"]target => "@timestamp"timezone => "Asia/Shanghai"}useragent {source => "useragent"target => "useragent"}mutate {convert => ["bytes","integer"]convert => ["response_time", "float"]convert => ["upstream_response_time", "float"]remove_field => ["message"]add_field => { "target_index" => "app-logstash-nginx-access-%{+YYYY.MM.dd}" }	   }# 提取 referrer 具体的域名 /^"http/if [referrer] =~ /^"http/ {grok {match => { "referrer" => '%{URIPROTO}://%{URIHOST:referrer_host}' }}}# 提取用户请求资源类型以及资源 ID 编号if "test.com" in [referrer_host] {grok {match => { "referrer" => '%{URIPROTO}://%{URIHOST}/(%{NOTSPACE:test_type}/%{NOTSPACE:test_res_id})?' }}}}else if "error" in [tags][0] {date {match => ["timestamp","dd/MMM/yyyy:HH:mm:ss Z"]target => "@timestamp"timezone => "Asia/Shanghai"}mutate {add_field => { "target_index" => "app-logstash-nginx-error-%{+YYYY.MM.dd}" }}}
}output {elasticsearch {hosts => ["10.0.0.21:9200","10.0.0.22:9200","10.0.0.23:9200"]user => "logstash_push_es"password => "111111"index => "%{[target_index]}"template_overwrite => true}stdout {codec => rubydebug}
}

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/28306.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

ChatGPT 最佳实践指南之:系统地测试变化

Test changes systematically 系统地测试变化 Improving performance is easier if you can measure it. In some cases a modification to a prompt will achieve better performance on a few isolated examples but lead to worse overall performance on a more representa…

C++类和对象——类的基础

目录 类的引入类的定义类的访问限定符和封装对象的实例化类对象的大小this指针 类的引入 在C语言中,结构体中只能定义变量 但是在C中,结构体不仅可以定义变量,还可以定义函数 下面就是C中的一个结构体: struct Stack {void init(…

《Linux0.11源码解读》理解(五) head之开启分页

先回顾一下地址长度以及组合的演变:16位cpu意味着其数据总线/寄存器也是16位,但是地址总线(寻址能力)与此无关,可能是20位。可以参考:cpu的位宽、操作系统的位宽和寻址能力的关系_cpu位宽_brahmsjiang的博客…

Android TextView 在最后一行末尾加图标

当前有个需求.显示一段文本,文本最多显示两行,点击展开后才显示完全。当没有显示完全的时候,需要在文本的第二行末尾显示图标,点击图标和文本,文本展开。难点在于图标需要和第二行文本显示在同一行,高度和文…

oracle 如何连同空表一起导出成dmp的方法

1、oracle导出dmp文件的时候,经常会出现一些空表,没有一并被导出的情况。 执行sql select alter table ||table_name|| allocate extent; from user_tables where num_rows0 or num_rows is null; 新建一个sql窗口,把查询结果的sql&#…

Pytorch自动求导机制详解

目录 1. 自动求导 1.1 梯度计算 1.1.1 一阶导数 1.1.2 二阶导数 1.1.3 向量 1.2 线性回归实战 1. 自动求导 在深度学习中,我们通常需要训练一个模型来最小化损失函数。这个过程可以通过梯度下降等优化算法来实现。梯度是函数在某一点上的变化率,可以告…

[黑苹果EFI]Lenovo ThinkPad T490电脑 Hackintosh 黑苹果引导文件

原文来源于黑果魏叔官网,转载需注明出处。(下载请直接百度黑果魏叔) 硬件型号驱动情况 主板Lenovo ThinkPad T490 处理器Intel Intel Core i5 8265U (Quad Core)已驱动 内存16 GB:8 GB Samsung DDR 4 2666 Mhz *2已驱动 硬盘PC SN520 NVM…

CentOS7中安装docker并配置阿里云加速器

文章目录 一、docker的安装二、docker的卸载三、配置加速器四、docker-compose安装五、docker-compose卸载六、docker-compose相关命令七、常用shell组合 一、docker的安装 参考:https://docs.docker.com/engine/install/centos 本文内容是基于:CentOS L…

文件IO 文件属性获取,目录操作

文件属性获取 int stat(const char *path, struct stat *buf); 功能:获取文件属性参数: path:文件路径名 buf:保存文件属性信息的结构体返回值: 成功:0 失败:-1struct stat {ino_t st_ino;…

批发小程序怎么做

批发订货小程序功能介绍 我们的批发订货小程序是一个集订货浏览权限、一客一价、业务员端口、代客下单、订单汇总和订单打印等功能于一体的专业平台。以下是对这些功能的详细描述: 1. 订货浏览权限:我们的小程序可以为不同用户分配不同的订货浏览权限。…

在LLM的支持下使游戏NPC具有记忆化的方法

问题 使用GPT这样的LLM去处理游戏中的NPC和玩家的对话是个很好的点子,那么如何处理记忆化的问题呢。 因为LLM的输入tokens是有限制的,所以伴随着问题的记忆context是有窗口大小限制的,将所有的记忆输入LLM并不现实。 所以这里看到了stanfo…

TOWE智能PDU是如何帮助机房安然度夏的?

最近,全国各地纷纷进入高温“火炉”模式,炎炎夏日,数据中心的工作温度不应该超过一定的限度。数据中心机房不仅要确保在高温多雨天气下安全、稳定的运维,还要承受降低企业总体运营成本的压力。这种需求下,相较于传统基…