最新ELK(Elasticsearch、Kibana、Logstash )账号密码版(及各种踩坑)

前期准备
环境 :CentOS-7-x86_64-Everything-2009
内存:6G
处理器:4
elasticsearch-8.5.0-linux-x86_64.tar
logstash-8.5.0-linux-x86_64.tar
kibana-8.5.0-linux-x86_64.tar

Elasticsearch
是实时全文搜索和分析引擎,提供搜集、分析、存储数据三大功能,是一套开放REST和JAVA API等结构提供高效搜索功能,可扩展的分布式系统。它构建于Apache Lucene搜索引擎库之上。
具有分布式,零配置,自动发现,索引自动分片,索引副本机制,restful 风格接口,多数据源,自动搜索负载等特点
Logstash
它支持几乎任何类型的日志,包括系统日志、错误日志和自定义应用程序日志。
它可以从许多来源接收日志,这些来源包括 syslog、消息传递(例如 RabbitMQ)和JMX,它能够以多种方式输出数据,包括电子邮件、websockets和Elasticsearch。
Kibana
是一个基于Web的图形界面,用于搜索、分析和可视化存储在 Elasticsearch指标中的日志数据。
它利用Elasticsearch的REST接口来检索数据,不仅允许用户创建他们自己的数据的定制仪表板视图,还允许他们以特殊的方式查询和过滤数据,Kibana 可以为 Logstash 和 Elasticsearch 提供友好的日志分析 web 界面,可以帮助你汇总、分析和搜索重要数据日志。

elasticsearch安装

tar -zxvf elasticsearch-8.5.0-linux-x86_64.tar.gz
mv elasticsearch-8.5.0  elasticsearch
#修改配置
vi  config/elasticsearch.yml 
cluster.name : my-application
node.name : node-1
network.host : 0.0.0.0
http.port : 9200

#绑定可以操作的地址 0.0.0.0表示所有的ip地址都可以访问操作
network.host: 0.0.0.0
#用于访问的端口
http.port: 9200
#添加跨域配置
http.cors.enabled: true
#可以跨域的地址
http.cors.allow-origin: "*"

#数据存放路径
path.data: /mnt/ELK/elasticsearch/data
#日志存放路径
path.logs: /mnt/ELK/elasticsearch/logs
# Enable security features
xpack.security.enabled: false
# Enable encryption for HTTP API client connections, such as Kibana, Logstash, and Agents
xpack.security.http.ssl:
  enabled: false
  keystore.path: certs/http.p12

--------------------------------------------------------------------------------


[root@localhost config]# adduser esuser
[root@localhost config]# passwd esuser
更改用户 esuser 的密码 。
新的 密码:
无效的密码: 密码少于 8 个字符
重新输入新的 密码:
passwd:所有的身份验证令牌已经成功更新。


vim /etc/security/limits.conf 
最下方位置添加
#@student        -       maxlogins       4

esuser hard nofile 65536
esuser soft nofile 65536
# End of file





vim /etc/security/limits.d/20-nproc.conf
最下方位置添加
# See rhbz #432903 for reasoning.

*          soft    nproc     4096
root       soft    nproc     unlimited




vim /etc/sysctl.conf
最下方位置添加
# For more information, see sysctl.conf(5) and sysctl.d(5).

vm.max_map_count=655360

#执行
sysctl -p
[root@localhost ~]# sysctl -p
vm.max_map_count = 655360
[root@localhost ~]# 


esuser增加权限
[root@localhost elasticsearch]# pwd
/root/tools/ELK/elasticsearch 
[root@localhost elasticsearch]# chown -R esuser:esuser /root/tools/ELK/elasticsearch
[root@localhost elasticsearch]# 



启动elasticsearch
#启动前先切换用户
 
su esuser
 
# 后台启动
nohup ./bin/elasticsearch -d

# 后台启动
bin/elasticsearch -d
# 查看是否启动成功
ps -ef|grep elasticsearch
 
# 输入此命令查看是否有json字符串
curl http://ip:9200
[root@localhost ELK]# curl http://本机IP:9200
{
  "name" : "node-1",
  "cluster_name" : "my-application",
  "cluster_uuid" : "iSh2UxP3SuC7g1nD3nupYA",
  "version" : {
    "number" : "8.5.0",
    "build_flavor" : "default",
    "build_type" : "tar",
    "build_hash" : "c94b4700cda13820dad5aa74fae6db185ca5c304",
    "build_date" : "2022-10-24T16:54:16.433628434Z",
    "build_snapshot" : false,
    "lucene_version" : "9.4.1",
    "minimum_wire_compatibility_version" : "7.17.0",
    "minimum_index_compatibility_version" : "7.0.0"
  },
  "tagline" : "You Know, for Search"
}
[root@localhost ELK]# 
elasticsearch配置用户登录
关于x-pack插件

x-pack是elasticsearch的一个扩展包,将安全,警告,监视,图形和报告功能捆绑在一个易于安装的软件包中,可以轻松的启用或者关闭一些功能。默认我们的elk部署后,可以直接就进入web管理界面,这样会带来极大的安全隐患。

elasticsearch的密码配置需要借助x-pack插件,若是6.3.0之前的版本需要下载插件,6.3.0以后都不需要下载,如果6.3.0之前的版本需要下载则按一下进行操作:
# 在es的目录下进行下载
./elasticsearch-plugin install x-pack
在elasticsearch的config目录下elasticsearch.yml中添加如下配置
# 开启集群中http传输,我搭建的为单机
xpack.security.transport.ssl.enabled: true
 
# 开启xpack
xpack.security.enabled: true
 
# 是否支持跨域,默认为false
http.cors.enabled: true
 
# 当设置允许跨域,默认为*,表示支持所有域名,如果我们只是允许某些网站能访问,那么可以使用正则表达式。比如只允许本地地址。 /https?:\/\/localhost(:[0-9]+)?/
http.cors.allow-origin: "*"
 
# 请求头设置,可有可无
http.cors.allow-headers: "Authorization"
[root@localhost bin]# ./elasticsearch-reset-password -u elastic
This tool will reset the password of the [elastic] user to an autogenerated value.
The password will be printed in the console.
Please confirm that you would like to continue [y/N]y


Password for the [elastic] user successfully reset.
New value: VZdXfd4shU6yIGZ7dzIr
[root@localhost bin]# 

logstash安装

tar -xvf logstash-8.5.0-linux-x86_64.tar.gz 

mv logstash-8.5.0 logstash



做好input ,filter,output三大块, 其中input是吸取logs文件下的所有log后缀的日志文件,filter是一个过滤函数,配置则可进行个性化过滤,output配置了导入到hosts为127.0.0.1:9200的elasticsearch中,每天一个索引。start_position是监听的位置,默认是end,即一个文件如果没有记录它的读取信息,则从文件的末尾开始读取,也就是说,仅仅读取新添加的内容。对于一些更新的日志类型的监听,通常直接使用end就可以了;相反,beginning就会从一个文件的头开始读取。但是如果记录过文件的读取信息,则不会从最开始读取。重启读取信息不会丢失。

[root@localhost logstash]# vim config/logstash.conf (配置文件不能有中文。别问问了自己试)

input{  \\收集的日志信息
	  file {  \\收集的方式是文件形式
	    path => "/var/log/messages"   \\日志的绝对路径
	    type => "system-log"          \\日志的类型,只是标签的含义,可以自定义名字
	    start_position => "beginning"   \\从日志文件的最开始收集日志
	  } 

	}


	output{   \\日志的输出
	   elasticsearch {   \\日志输出给elasticsearch
	     hosts => "IP:9200"     \\elasticsearch的IP和端口
	     index => "system-log_%{+YYYY.MM.dd}"  \\日志的索引和日期后缀
	   }
	}


给日志文件增加读的权限
	chmod +r /var/log/messages

input {										# input输入源配置
  tcp {										# 使用tcp输入源
    port => 9601							# 服务器监听端口9061接收日志,默认ip localhost
    codec => json_lines						# 使用json解析日志  需要安装json解析插件
  }
}

output {									# output 数据输出配置
  elasticsearch {							# 使用elasticsearch接收
    hosts => ["http://localhost:9200"]		# 集群地址 多个用,隔开
  }
  stdout {
  	codec => rubydebug						# 输出到命令窗口
  }
}

安装插件 (深坑)

由于国内无法访问默认的gem source,需要将gem source改为国内的源。

# 修改Gemfile
[root@localhost logstash]# vim Gemfile

# 将source这一行改成如下所示:
source "https://ruby.taobao.org"
[root@localhost logstash]# ./bin/logstash-plugin install logstash-codec-json_lines
Using bundled JDK: /mnt/ELK/logstash/jdk
Validating logstash-codec-json_lines
Unable to download data from https://ruby.taobao.org - hostname "ruby.taobao.org" does not match the server certificate (https://ruby.taobao.org/latest_specs.4.8.gz)
ERROR: Installation aborted, verification failed for logstash-codec-json_lines  


由于安装插件报错 启动疯狂报错 加(–enable-local-plugin-development) 启动成功
[root@localhost logstash]# ./bin/logstash -f ./config/logstash.conf &
[2] 112467
[root@localhost logstash]# Using bundled JDK: /mnt/ELK/logstash/jdk
[FATAL] 2022-11-10 09:35:33.482 [main] Logstash - Logstash was unable to start due to an unexpected Gemfile change.
If you are a user, this is a bug.
If you are a logstash developer, please try restarting logstash with the `--enable-local-plugin-development` flag set.

[2]-  退出 1                ./bin/logstash -f ./config/logstash.conf
[root@localhost logstash]# ./bin/logstash -f ./config/logstash.conf --enable-local-plugin-development &
[2] 114236
[root@localhost logstash]# Using bundled JDK: /mnt/ELK/logstash/jdk
Resolving dependencies................
Sending Logstash logs to /mnt/ELK/logstash/logs which is now configured via log4j2.properties

bin目录下启动logstash了,配置文件设置为conf/logstash.conf,加&后台启动。

cd 
./bin/logstash -f ../config/logstash.conf & 

配置多个文件:./logstash -f …/config 指定启动目录,然后启动目录下配置多个*.Conf文件。里面指定不同的logpath。

没有装插件直接粘贴启动
在logstash目录下后台启动
nohup ./bin/logstash -f ./config/logstash.conf &
 
# 检查是否成功
ps -ef|grep logstash


启动完之后,使用jps命令,可以看到进程在运行

[root@localhost logstash]# jps
11078 -- process information unavailable
113398 Logstash
11146 org.elasticsearch.bootstrap.Elasticsearch
1388 Jps

不推荐以超级用户的身份运行Logstash,将来也不允许。将’allow_superuser’设置为’false’以避免在以后的版本中出现启动错误。

[root@localhost config]# vim logstash.yml 
allow_superuser: false
[root@localhost config]# 

Kibana安装

tar xvf kibana-8.5.0-linux-x86_64.tar.gz 
mv kibana-8.5.0 kibana

修改配置文件

[root@localhost kibana]# vim ./config/kibana.yml

# 服务端口
server.port: 5601
# 服务器ip  本机
server.host: "0.0.0.0"
# Elasticsearch 服务地址
elasticsearch.hosts: ["http://localhost:9200"]
# 设置语言为中文
i18n.locale: "zh-CN"

创建用户&启动kibana

[root@localhost kibana]# useradd kibana
[root@localhost kibana]# passwd kibana
更改用户 kibana 的密码 。
新的 密码:
无效的密码: 密码少于 8 个字符
重新输入新的 密码:
passwd:所有的身份验证令牌已经成功更新。
[root@localhost kibana]# chown -R /mnt/ELK/kibana
chown: "/mnt/ELK/kibana" 后缺少操作数
Try 'chown --help' for more information.
[root@localhost kibana]# chown -R kibana:kibana /mnt/ELK/kibana
[root@localhost kibana]# 
[kibana@localhost kibana]$ nohup ./bin/kibana &
[1] 4747
[kibana@localhost kibana]$ nohup: 忽略输入并把输出追加到"nohup.out"


elasticsearch已经设置好了密码,此时如果kibana想要从elasticsearch中获取数据就必须进行账号密码配置,在kibana的config目录下进行Kibana.yml配置如下
创建“ kibana_system ”用户

在elasticsearch操作
[root@localhost ~]# cd /mnt/ELK/elasticsearch
[root@localhost elasticsearch]# ./bin/elasticsearch-reset-password -u kibana_system
This tool will reset the password of the [kibana_system] user to an autogenerated value.
The password will be printed in the console.
Please confirm that you would like to continue [y/N]y


Password for the [kibana_system] user successfully reset.
New value: =Xl_IC2x*UKcrU+VTWP4
[root@localhost elasticsearch]# 






在kibana操作
[root@localhost config]# vim kibana.yml 
[root@localhost config]# pwd
/mnt/ELK/kibana/config

kibana.yml中配置:elasticsearch.username: "elastic"会报错 已踩过坑

# is proxied through the Kibana server.
elasticsearch.username: "kibana_system"
elasticsearch.password: "=Xl_IC2x*UKcrU+VTWP4"

登录Kibana,浏览器访问:ip:5601
elastic
VZdXfd4shU6yIGZ7dzIr
Kibana的superuser的账号为:elastic 密码为前面设置好的密码。登录后,elk及搭建完成
  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

RDZ-hyd

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值