当前位置: 首页 > news >正文

ELK集添加安全认证

一、ElasticSearch配置

1、elasticsearch集群启用SSL
编辑所有elasticsearch节点 elasticsearch/config/elasticsearch.yml 配置文件新增以下内容:

vi 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: certs/elastic-certificates.p12
xpack.security.transport.ssl.truststore.path: certs/elastic-certificates.p12

2、生成证书
注意:如果是在docker中部署的,需要进入到容器中进行操作
生成的证书默认都在 /usr/share/elasticsearch 目录下:

cd /usr/share/elasticsearch/bin
 ./elasticsearch-certutil cert -out /usr/share/elasticsearch/elastic-certificates.p12 -pass ""
 
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.bouncycastle.jcajce.provider.drbg.DRBG (file:/home/estestuser/elasticsearch-7.1.1/lib/tools/security-cli/bcprov-jdk15on-1.61.jar) to constructor sun.security.provider.Sun()
WARNING: Please consider reporting this to the maintainers of org.bouncycastle.jcajce.provider.drbg.DRBG
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
This tool assists you in the generation of X.509 certificates and certificate
signing requests for use with SSL/TLS in the Elastic stack.

The 'cert' mode generates X.509 certificate and private keys.
    * By default, this generates a single certificate and key for use
       on a single instance.
    * The '-multiple' option will prompt you to enter details for multiple
       instances and will generate a certificate and key for each one
    * The '-in' option allows for the certificate generation to be automated by describing
       the details of each instance in a YAML file

    * An instance is any piece of the Elastic Stack that requires a SSL certificate.
      Depending on your configuration, Elasticsearch, Logstash, Kibana, and Beats
      may all require a certificate and private key.
    * The minimum required value for each instance is a name. This can simply be the
      hostname, which will be used as the Common Name of the certificate. A full
      distinguished name may also be used.
    * A filename value may be required for each instance. This is necessary when the
      name would result in an invalid file or directory name. The name provided here
      is used as the directory name (within the zip) and the prefix for the key and
      certificate files. The filename is required if you are prompted and the name
      is not displayed in the prompt.
    * IP addresses and DNS names are optional. Multiple values can be specified as a
      comma separated string. If no IP addresses or DNS names are provided, you may
      disable hostname verification in your SSL configuration.

    * All certificates generated by this tool will be signed by a certificate authority (CA).
    * The tool can automatically generate a new CA for you, or you can provide your own with the
         -ca or -ca-cert command line options.

By default the 'cert' mode produces a single PKCS#12 output file which holds:
    * The instance certificate
    * The private key for the instance certificate
    * The CA certificate

If you specify any of the following options:
    * -pem (PEM formatted output)
    * -keep-ca-key (retain generated CA key)
    * -multiple (generate multiple certificates)
    * -in (generate certificates from an input file)
then the output will be be a zip file containing individual certificate/key files


Certificates written to /home/estestuser/elasticsearch-7.1.1/config/elastic-certificates.p12

This file should be properly secured as it contains the private key for 
your instance.

This file is a self contained file and can be copied and used 'as is'
For each Elastic product that you wish to configure, you should copy
this '.p12' file to the relevant configuration directory
and then follow the SSL configuration instructions in the product guide.

查看是否成功生成证书

ls -l /usr/share/elasticsearch/elastic-*                
-rw------- 1 root root 3596 May 27 05:58 /usr/share/elasticsearch/elastic-certificates.p12
-rw------- 1 root root 2672 May 27 05:53 /usr/share/elasticsearch/elastic-stack-ca.p12

把这两个证书移动到 /usr/share/elasticsearch/config/certs(elasticsearch.yml同级目录下) 目录里

mkdir /usr/share/elasticsearch/config/certs
mv /usr/share/elasticsearch/elastic-* /usr/share/elasticsearch/config/certs

另外,需要注意修改证书的权限
生成的elastic-certificates.p12文件拷贝到每个节点的/usr/share/elasticsearch/config/certs目录下
3、重启 ES 集群
 ES 集群不启动,下面的添加密码操作执行不了,所以依次重启 3 个节点。首先重启节点 1。

ps -ef|grep elasticsearch
kill -9 pid

bin/elasticsearch -d

依次重启节点 2 和节点 3。
4、创建 Elasticsearch 集群密码
在主节点 上执行如下命令,设置用户密码。设置完之后,数据会自动同步到其他节点。
bin/elasticsearch-setup-passwords interactive 设置密码
bin/elasticsearch-setup-passwords auto 自动生成密码

[root@wecity elasticsearch-7.1.1]$ bin/elasticsearch-setup-passwords interactive

Initiating the setup of passwords for reserved users elastic,apm_system,kibana,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]y


Enter password for [elastic]: 
Reenter password for [elastic]: 
Enter password for [apm_system]: 
Reenter password for [apm_system]: 
Enter password for [kibana]: 
Reenter password for [kibana]: 
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]
Changed password for user [logstash_system]
Changed password for user [beats_system]
Changed password for user [remote_monitoring_user]
Changed password for user [elastic]

在这里插入图片描述

5、访问验证

 curl http://localhost:9200
{"error":{"root_cause":[{"type":"security_exception","reason":"missing authentication credentials for REST request [/]","header":{"WWW-Authenticate":"Basic realm=\"security\" charset=\"UTF-8\""}}],"type":"security_exception","reason":"missing authentication credentials for REST request [/]","header":{"WWW-Authenticate":"Basic realm=\"security\" charset=\"UTF-8\""}},"status":401}

输入帐号:elastic,密码:password(此密码非真实密码,仅为了写博客记录),再次访问,发现成功。

[estestuser@vm-10-201-42-9 elasticsearch-7.1.1]$ curl --user elastic:password http://localhost:9200
{
  "name" : "node-1",
  "cluster_name" : "my-application",
  "cluster_uuid" : "l-kTWdoxRCuTIm6x8ekG7w",
  "version" : {
    "number" : "7.1.1",
    "build_flavor" : "default",
    "build_type" : "tar",
    "build_hash" : "7a013de",
    "build_snapshot" : false,
    "lucene_version" : "8.0.0",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}

为集群添加用户安全认证成功。

二、Kibana配置

1、 在kibana.yml中添加配置用户名和密码

elasticsearch.username: "kibana"
elasticsearch.password: "*****"
server.publicBaseUrl: "http://10.185.1.178:5600" #默认访问地址,如果挂了域名指向,这里可以写域名地址
i18n.locale: "zh-CN" #kibana的默认语言配置,默认是英文,我这里改成了中文,英文好的同学可以忽略

2、重启Kibana

service kibana  restart

重启后,输入http://ip:5600打开登录页面,使用elastic账号登录。登录进入系统后进入管理按钮(Management),就可以看到多了一块东西,就是用户与角色权限配置,在角色和用户管理中添加用户指定 索引用于访问ES。

三、Logstash配置

1、在logstash.yml中配置用户名和密码

xpack.monitoring.enabled: true
xpack.monitoring.elasticsearch.username: logstash_system
xpack.monitoring.elasticsearch.password: *****
xpack.monitoring.elasticsearch.hosts: ["http://ip:9200"]

2、在logstash指定的conf文件中加上用户名密码
在本案例中获取nginx的日志,文件是 logstash/conf.d/nginx.conf。在这个文件的output 方法下增加user 和 password。

output {
    elasticsearch {
        hosts => ["192.168.1.240:9200"]
        index => "nginx-access-log-%{+YYYY.MM.dd}"
        user => "elastic"
        password => "******"
    }
    stdout { codec => rubydebug }
}

2、重启Logstash
启动命令 bin/logstash -f 上面配置的文件位置

bin/logstash -f nginx.conf

小知识验证logstash

bin/logstash -e 'input { stdin { } } output { stdout {} }'

相关文章:

  • 智能家居离线语音识别控制系统设计(SU-03T)
  • 商家如何玩好“种草神器”?小红书KOL达人种草这样做
  • 基于共词分析的中国近代史实体关系图构建(毕业设计:图数据渲染)
  • 猿创征文|阿里云MaxCompute存取性能测试报告
  • Spring Cloud Sleuth在分布式中进行日志跟踪
  • Jmeter分布式部署执行和常见报错
  • [ vulhub漏洞复现篇 ] JBOSS AS 4.x以下反序列化远程代码执行漏洞CVE-2017-7504
  • Python Web开发 之 学生管理系统(2)[实现筛选,搜索,分页]
  • 程序员转型?不可能,绝对不可能
  • 基于SSM的二手书店推荐系统(商城)
  • 【JavaSE】认识异常(下篇)
  • 手把手教你深度学习和实战-----循环神经网络
  • 猿创征文 |【C++】动态内存的分配与回收
  • Day1_9 Java学习之DQL语言与完整性约束
  • 离线数仓搭架_01_数仓概念与项目框架说明
  • hexo+github搭建个人博客
  • JavaScript 如何正确处理 Unicode 编码问题!
  • [iOS]Core Data浅析一 -- 启用Core Data
  • CentOS7 安装JDK
  • Docker 笔记(2):Dockerfile
  • js继承的实现方法
  • LeetCode29.两数相除 JavaScript
  • magento 货币换算
  • mockjs让前端开发独立于后端
  • mongodb--安装和初步使用教程
  • 闭包--闭包作用之保存(一)
  • 从setTimeout-setInterval看JS线程
  • 基于web的全景—— Pannellum小试
  • 解析带emoji和链接的聊天系统消息
  • 京东美团研发面经
  • 看域名解析域名安全对SEO的影响
  • 聊聊flink的BlobWriter
  • 巧用 TypeScript (一)
  • 如何打造100亿SDK累计覆盖量的大数据系统
  • 腾讯优测优分享 | 你是否体验过Android手机插入耳机后仍外放的尴尬?
  • 我是如何设计 Upload 上传组件的
  • 移动端 h5开发相关内容总结(三)
  • 怎么把视频里的音乐提取出来
  • 掌握面试——弹出框的实现(一道题中包含布局/js设计模式)
  • Python 之网络式编程
  • ​用户画像从0到100的构建思路
  • #我与Java虚拟机的故事#连载04:一本让自己没面子的书
  • ()、[]、{}、(())、[[]]等各种括号的使用
  • (1)Nginx简介和安装教程
  • (9)YOLO-Pose:使用对象关键点相似性损失增强多人姿态估计的增强版YOLO
  • (翻译)Entity Framework技巧系列之七 - Tip 26 – 28
  • (非本人原创)我们工作到底是为了什么?​——HP大中华区总裁孙振耀退休感言(r4笔记第60天)...
  • (附源码)spring boot校园拼车微信小程序 毕业设计 091617
  • (三)uboot源码分析
  • (图)IntelliTrace Tools 跟踪云端程序
  • (转贴)用VML开发工作流设计器 UCML.NET工作流管理系统
  • .Net Core 中间件验签
  • .NET 使用 ILMerge 合并多个程序集,避免引入额外的依赖
  • .net 验证控件和javaScript的冲突问题
  • .NET/C# 的字符串暂存池