Elastic stack8.10.4搭建、启用安全认证,启用https,TLS,SSL 安全配置详解

ELK大家应该很了解了,废话不多说开始部署

kafka在其中作为消息队列解耦和让logstash高可用

kafka和zk 的安装可以参考这篇文章

深入理解Kafka3.6.0的核心概念,搭建与使用-CSDN博客

第一步、官网下载安装包

需要

elasticsearch-8.10.4

logstash-8.10.4

kibana-8.10.4

kafka_2.13-3.6.0

apache-zookeeper-3.9.1-bin.tar

filebeat-8.10.4-linux-x86_64.tar

第二步: 环境配置(每一台都做)

创建es用户
 

useradd es

配置主机名、配置IP地址、每台主机配置/etc/hosts名称解析

192.168.1.1 es1

192.168.1.2 es2

192.168.1.3 es3

将Linux系统的软硬限制最大文件数改为65536,将所有用户的最大线程数修改为65536

打开/etc/security/limits.conf文件,添加以下配置(每一台都做)

vim  /etc/security/limits.conf* soft nofile 65536
* hard nofile 65536* soft nproc 65536
* hard nproc 65536es  hard   core    unlimited  #打开生成Core文件
es  soft   core    unlimited
es  soft   memlock unlimited #允许用户锁定内存
es  hard   memlock unlimitedsoft  xxx  : 代表警告的设定,可以超过这个设定值,但是超过后会有警告。
hard  xxx  : 代表严格的设定,不允许超过这个设定的值。
nproc  : 是操作系统级别对每个用户创建的进程数的限制
nofile : 是每个进程可以打开的文件数的限制
soft nproc :单个用户可用的最大进程数量(超过会警告);
hard nproc:单个用户可用的最大进程数量(超过会报错);
soft nofile  :可打开的文件描述符的最大数(超过会警告);
hard nofile :可打开的文件描述符的最大数(超过会报错);

修改/etc/sysctl.conf文件,添加下面这行,并执行命令sysctl  -p使其生效

vim /etc/sysctl.confvm.max_map_count=262144  #限制一个进程可以拥有的VMA(虚拟内存区域)的数量,es要求最低65536
net.ipv4.tcp_retries2=5 #数据重传次数超过 tcp_retries2 会直接放弃重传,关闭 TCP 流

解压安装包,进入config文件夹,修改elasticsearch.yml 配置文件 

cluster.name: elk #集群名称
node.name: node1 #节点名称
node.roles: [ master,data ] #节点角色
node.attr.rack: r1  #机架位置,一般没啥意义这个配置
path.data: /data/esdata  
path.logs: /data/eslog
bootstrap.memory_lock: true  #允许锁定内存
network.host: 0.0.0.0 
http.max_content_length: 200mb
network.tcp.keep_alive: true
network.tcp.no_delay: true
http.port: 9200
http.cors.enabled: true #允许http跨域访问,es_head插件必须开启
http.cors.allow-origin: "*"  #允许http跨域访问,es_head插件必须开启
discovery.seed_hosts: ["ypd-dmcp-log01", "ypd-dmcp-log02"]
cluster.initial_master_nodes: ["ypd-dmcp-log01", "ypd-dmcp-log02"]
xpack.monitoring.collection.enabled: true #添加这个配置以后在kibana中才会显示联机状态,否则会显示脱机状态
xpack.security.enabled: true
#xpack.security.enrollment.enabled: true
xpack.security.http.ssl.enabled: true
xpack.security.http.ssl.keystore.path: elastic-certificates.p12  #我把文件都放在config下。所以直接写文件名,放在别处需要写路径
xpack.security.http.ssl.truststore.path: elastic-certificates.p12
xpack.security.transport.ssl.enabled: true
xpack.security.transport.ssl.verification_mode: certificate
xpack.security.transport.ssl.keystore.path: elastic-certificates.p12k
xpack.security.transport.ssl.truststore.path: elastic-certificates.p12

配置jvm内存大小 

修改 jvm.options
-Xms6g #你服务器内存的一半,最高32G
-Xmx6g #你服务器内存的一半,最高32G

改好文件夹准备生成相关key

 创建ca证书,什么也不用输入,两次回车即可(会在当前目录生成名为elastic-stack-ca.p12的证书文件)

bin/elasticsearch-certutil  ca

 使用之前生成的ca证书创建节点证书,过程三次回车,会在当前目录生成一个名为elastic-certificates.p12的文件

 

bin/elasticsearch-certutil  cert --ca elastic-stack-ca.p12

 生成http证书,根据提示信息进行操作,主要是下面几步

bin/elasticsearch-certutil httpGenerate a CSR? [y/N]n
Use an existing CA? [y/N]y
CA Path: /usr/local/elasticsearch-8.10.4/config/certs/elastic-stack-ca.p12
Password for elastic-stack-ca.p12:  直接回车,不使用密码
For how long should your certificate be valid? [5y] 50y#过期时间
Generate a certificate per node? [y/N]n
Enter all the hostnames that you need, one per line. #输入es的节点 两次回车确认
When you are done, press <ENTER> once more to move on to the next step.
es1
es2
es3You entered the following hostnames.- es1- es2- es3Is this correct [Y/n]yWhen you are done, press <ENTER> once more to move on to the next step. #输入es的ip 两次回车确认192.168.1.1
192.168.1.2
192.168.1.3You entered the following IP addresses.- 192.168.1.1- 192.168.1.2- 192.168.1.3Is this correct [Y/n]yDo you wish to change any of these options? [y/N]n

接下来一直回车,然后会在当前目录生成名为:elasticsearch-ssl-http.zip的压缩文件

解压缩http证书文件到config下,证书在http文件夹里。名字是http.p12,mv出来到config下

 确保elasticsearch目录下所有文件的归属关系都是es用户

 chown -R es:es /home/es/elasticsearch-8.10.4

启动es

su - es #到es用户下
bin/elasticsearch  初次可以前台启动 没问题就放后台
bin/elasticsearch -d

复制整个es文件夹到es2,es3

只需要修改

node.name: es2 #节点名称network.host: 192.168.1.2 #节点ipnode.name: es3 #节点名称network.host: 192.168.1.3 #节点ip

 浏览器访问一下es的web ui

https://192.168.1.1:9200 

 

生成账户密码

 

bin/elasticsearch-setup-passwords interactivewarning: ignoring JAVA_HOME=/usr/local/java/jdk1.8.0_361; using bundled JDK
******************************************************************************
Note: The 'elasticsearch-setup-passwords' tool has been deprecated. This       command will be removed in a future release.
******************************************************************************Initiating the setup of passwords for reserved users elastic,apm_system,kibana,kibana_system,logstash_system,beats_system,remote_monitoring_user.
You will be prompted to enter passwords as the process progresses.
Please confirm that you would like to continue [y/N]yEnter password for [elastic]: 
Reenter password for [elastic]: 
Enter password for [apm_system]: 
Reenter password for [apm_system]: 
Enter password for [kibana_system]: 
Reenter password for [kibana_system]: 
Enter password for [logstash_system]: 
Reenter password for [logstash_system]: 
Enter password for [beats_system]: 
Reenter password for [beats_system]: 
Enter password for [remote_monitoring_user]: 
Reenter password for [remote_monitoring_user]: 
Changed password for user [apm_system]
Changed password for user [kibana_system]
Changed password for user [kibana]
Changed password for user [logstash_system]
Changed password for user [beats_system]
Changed password for user [remote_monitoring_user]
Changed password for user [elastic]这个时候就可以使用账号密码访问了

创建一个给kibana使用的用户

bin/elasticsearch-users useradd kibanauser
kibana不能用es超级用户,此处展示一下用法
bin/elasticsearch-users roles -a superuser kibanauser
加两个角色 不然没有监控权限
bin/elasticsearch-users roles -a kibana_admin kibanauser
bin/elasticsearch-users roles -a monitoring_user kibanauser

 然后配置kibana

解压然后修改kibana.yml

server.port: 5601
server.host: "0.0.0.0"server.ssl.enabled: true
server.ssl.certificate: /data/elasticsearch-8.10.4/config/client.cer
server.ssl.key: /data/elasticsearch-8.10.4/config/client.key
elasticsearch.hosts: ["https://192.168.1.1:9200"]
elasticsearch.username: "kibanauser"
elasticsearch.password: "kibanauser"
elasticsearch.ssl.certificate: /data/elasticsearch-8.10.4/config/client.cer
elasticsearch.ssl.key: /data/elasticsearch-8.10.4/config/client.key
elasticsearch.ssl.certificateAuthorities: [ "/data/elasticsearch-8.10.4/config/client-ca.cer" ]
elasticsearch.ssl.verificationMode: certificate
i18n.locale: "zh-CN"
xpack.encryptedSavedObjects.encryptionKey: encryptedSavedObjects1234567890987654321 
xpack.security.encryptionKey: encryptionKeysecurity1234567890987654321
xpack.reporting.encryptionKey: encryptionKeyreporting1234567890987654321

启动

bin/kibana

访问 https://ip:5601 

 配置logstash

解压后在conf下创建一个配置文件,我取名logstash.conf

input {kafka {bootstrap_servers => "192.168.1.1:9092"group_id => "logstash_test"client_id => 1 #设置相同topic,设置相同groupid,设置不同clientid,实现LogStash多实例并行消费kafkatopics => ["testlog"]consumer_threads => 2 #等于 topic分区数codec => json {    #添加json插件,filebeat发过来的是json格式的数据charset => "UTF-8"}decorate_events => false #此属性会将当前topic、offset、group、partition等信息也带到message中type => "testlog" #跟topics不重合。因为output读取不了topics这个变量
}}
filter {mutate {remove_field => "@version"  #去掉一些没用的参数remove_field => "event"remove_field => "fields"}
}output {elasticsearch {cacert => "/data/elasticsearch-8.10.4/config/client-ca.cer"ssl => truessl_certificate_verification => falseuser => elasticpassword => "123456"action => "index"hosts => "https://192.168.1.1:9200"index => "%{type}-%{+YYYY.MM.dd}"
}}

修改jvm.options

-Xms6g #你服务器内存的一半,最高32G
-Xmx6g #你服务器内存的一半,最高32G

 

 启动logstash

bin/logstash -f conf/logstash.conf

最后去服务器上部署filebeat 

filebeat.inputs:
- type: filestream 跟以前的log类似。普通的日志选这个就行了id: testlog1  enabled: truepaths:- /var/log/testlog1.logfield_under_root: true #让kafka的topic: '%{[fields.log_topic]}'取到变量值fields:log_topic: testlog1  #跟id不冲突,id输出取不到变量值multiline.pattern: '^\d(4)'    # 设置多行合并匹配的规则,意思就是不以4个连续数字,比如2023开头的 视为同一条multiline.negate: true   # 如果匹配不上multiline.match: after  # 合并到后面- type: filestream id: testlog2enabled: truepaths:- /var/log/testlog2field_under_root: true fields:log_topic: testlog2multiline.pattern: '^\d(4)' multiline.negate: truemultiline.match: afterfilebeat.config.modules:path: ${path.config}/modules.d/*.yml reload.enabled: true  #开启运行时重载配置#reload.period: 10s
path.home: /data/filebeat-8.10.4/  #指明filebeat的文件夹。启动多个时需要
path.data: /data/filebeat-8.10.4/data/
path.logs: /data/filebeat-8.10.4/logs/processors:- drop_fields: #删除不需要显示的字段fields: ["agent","event","input","log","type","ecs"]output.kafka:enabled: truehosts: ["10.8.74.35:9092"]   #kafka地址,可配置多个用逗号隔开topic: '%{[fields.log_topic]}'   #根据上面添加字段发送不同topic

初步的部署这就完成了。后面的使用才是大头,路漫漫其修远兮 

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

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

相关文章

【Java 进阶篇】JQuery 案例:优雅的隔行换色

在前端的设计中&#xff0c;页面的美观性是至关重要的。而其中一个简单而实用的设计技巧就是隔行换色。通过巧妙地使用 JQuery&#xff0c;我们可以轻松地实现这一效果&#xff0c;为网页增添一份优雅。本篇博客将详细解析 JQuery 隔行换色的实现原理和应用场景&#xff0c;让我…

Android Matrix的使用详解(通过矩阵获取到图片缩放比例和角度)

网上查了好久相关的资料&#xff0c;都没有明确的答案。最终通过多次测试结果&#xff0c;结合安卓定义的矩阵含义&#xff0c;推算出来矩阵的数学含义以及相关的计算公式 1.获取Matrix矩阵&#xff1a; Matrix matrix new Matrix(); float[] matrixValues new float[9]; …

利用短视频短剧小程序系统提升品牌影响力

在当今数字化时代&#xff0c;品牌影响力的重要性日益凸显。短视频短剧小程序系统作为一种新型的内容传播和互动体验方式&#xff0c;为品牌提升影响力提供了新的机遇。本文将探讨如何利用短视频短剧小程序系统提升品牌影响力&#xff0c;以及实施过程中的挑战和策略建议。 一…

linux rsyslog日志采集格式设定二

linux rsyslog日志采集格式设定二 1.创建日志接收模板 打开/etc/rsyslog.conf文件,在GLOBAL DIRECTIVES模块下任意位置添加以下内容 命令: vim /etc/rsyslog.conf 测试:rsyslog.conf文件结尾添加以下内容 $template ztj,"%timegenerated% %hostname% %TIMESTAMP:…

C 语言实现 UDP

广播 发送广播信息&#xff0c;局域网中的客户端都可以接受该信息 #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <string.h> #include <arpa/inet.h>int main() {// 1.创建一个通信的socketint fd socket(PF_INET, …

基于单片机的线路差动保护系统设计

摘 要 随着我国微型电子技术和嵌入式系统的发展&#xff0c;目前行业内相对比较传统的线路差动保护系统无法满足客户的需求。为了改进传统线路差动保护系统在控制上得短板问题&#xff0c;在本次毕业设计中&#xff0c;将使用相对先进、快捷、智能的控制机制。该系统的控制大脑…

C-4练习题

一、单项选择题(本大题共20小题,每小题2分,共40分。在每小题给出的四个备选项中,选出一个正确的答案&#xff0c;并将所选项前的字母填写在答题纸的相应位置上。) 1. C 程序是由&#xff08;)构成的。 A.常量 B.变量 C.运算符 D. 函数 2.下列合法的标识符是() A. case …

DAY54 392.判断子序列 + 115.不同的子序列

392.判断子序列 题目要求&#xff1a;给定字符串 s 和 t &#xff0c;判断 s 是否为 t 的子序列。 字符串的一个子序列是原始字符串删除一些&#xff08;也可以不删除&#xff09;字符而不改变剩余字符相对位置形成的新字符串。&#xff08;例如&#xff0c;"ace"是…

创造者设计模式

Bike package com.jmj.pattern.builder.demo01;public class Bike {private String frame;//车架private String seat;//车座public String getFrame() {return frame;}public void setFrame(String frame) {this.frame frame;}public String getSeat() {return seat;}public…

华纳云:WordPress如何制作CMS栏目块

WordPress作为一个强大的内容管理系统(CMS)&#xff0c;允许你自定义并创建各种栏目块。你可以使用插件、主题功能或自定义开发来实现这一点。下面是一些基本方法&#xff1a; 1. 使用页面模板和自定义字段 创建自定义页面模板&#xff1a; 创建一个新的页面模板&#xff0c;例…

Windows客户端开发框架WPF简介

一、WPF简介 WPF的全称是Windows Presentation Foundation&#xff0c;WPF是 Microsoft 提供的一种用于构建桌面应用程序的 UI 框架。它包含在 .NET Framework 中&#xff0c;从 .NET 3.0 版本开始就被引入。 以下是一些关于 WPF 的关键特性&#xff1a; 1. XAML&#xff1a…

【git】解决git报错:ssh:connect to host github.com port 22: Connection timed out 亲测有效

如题&#xff0c;git使用中突然报错 ssh:connect to host github.com port 22: Connection timed out 通过查阅各种资料&#xff0c;得知原因可能是由于电脑的防火墙或者其他网络原因导致ssh连接方式 端口22被封锁。 解决方法 一&#xff1a;抛弃ssh连接方式&#xff0c;使…

深度学习实战59-NLP最核心的模型:transformer的搭建与训练过程详解,手把手搭建与跑通

大家好,我是微学AI,今天给大家介绍一下深度学习实战59-NLP最核心的模型:transformer的搭建与训练过程详解,手把手搭建与跑通。transformer是一种基于自注意力机制的深度学习模型,由Vaswani等人在2017年的论文《Attention is All You Need》中提出。它最初被设计用来处理序…

centos 6.10 编译 zstd 库

从 github 上下载最新的源码。下载链接 进入到 zstd-dev 目录下 执行下面命令 cd /build/cmake mkdir build && cd build cmake .. make我遇到了报错&#xff1a; timefn.c:(.text0x5e): undefined reference to clock_gettime原因是 centos 6.10 的 glibc 版本太老…

什么叫做一站式解决方案?

一站式解决方案&#xff08;One-stop solution&#xff09;是指为客户提供从项目起始到完成的全过程服务的经营模式。这种方案通常由某个服务提供商或公司实施&#xff0c;目的是解决客户的各种问题&#xff0c;同时省去客户寻找多个供应商合作的麻烦。一站式服务可能包括咨询、…

【luckfox】0、开发环境搭建

前言 本章简单介绍如何搭建luckfox的开发环境。 一、抓取luckfox源码 需要提前准备好ubuntu环境。 git clone https://github.com/LuckfoxTECH/luckfox-pico.git二、编译 youkaiubuntu:/home/luckfox/luckfox-pico$ ./build.sh lunchyoukaiubuntu:/home/luckfox/luckfox-p…

python数据处理作业11:建一个5*3的随机数组和一个3*2的数组,其元素为1,2,3,4,5,6,求两矩阵的积

每日小语 打碎的杯子&#xff0c;烫伤的手&#xff0c;对菩萨是堪忍&#xff0c;因为他在里面得悟甚深之法&#xff0c;心生欢喜。 可是对一般人来说&#xff0c;一生何止打破千百个杯子&#xff1f;何止烫伤过千百次手&#xff1f;他只是痛苦地忍受&#xff0c;只记得下次要…

Linux--线程概念+线程控制

1.什么是线程 相对于进程而言&#xff0c;进程是承担资源调度的实体&#xff0c;线程在进程内部运行&#xff0c;是操作系统调度的基本单位。 在一个程序里的一个执行路线就叫做线程&#xff08;thread&#xff09;。更准确的定义是&#xff1a;线程是“一个进程内部的控制序列…

【C#学习】文件操作

文章目录 常见操作拷贝文件检测文件夹是否存在并创建判断文件是否存在删除文件夹下的所有文件保留文件夹获取指定目录下的所有文件名删除 常见操作 拷贝文件 System.IO.File.Copy(sourcePath, targetPath); 检测文件夹是否存在并创建 //if directory not exit,then establis…

02-Spring中Bean的8种获取方式

Bean的获取方式 常见获取方式 虽然Spring为Bean对象的创建提供了多种实例化方式如由前期xml配置逐步演化成注解配置,但本质都是通过反射机制加载类名后创建对象,最后交给Spring管控 Spring还开放出了若干种可编程控制的bean的初始化方式&#xff0c;通过分支语句由固定的加载…