零基础玩转分布式日志搜集系统搭建
搭建属于自己的日志搜集系统
1、日志是用于记录系统或业务的状态
2、通过日志可以获得系统或业务的状态,并进行分析。
3、早期的日志是分散在各主机上
4、通过rsyslog实现本地日志管理,收集,轮转,集中管理
5、早期的日志分析方法:wc,grep,awk
6、集中式的日志收集、分析、展示系统
任务要求
1, 搭建ELK集群
2, 收集日志信息并展示
任务拆解
1, 认识ELK
2, 部署elasticsearch集群并了解其基本概念
3, 安装elasticsearch-head实现图形化操作
4, 安装logstash收集日志
5, 安装kibana日志展示
6, 安装file beat实现轻量级日志收集
学习目标
- 能够说出ELK的应用场景
- 能够区分ELK架构中elasticsearch,logstash,kibina三个软件各自的主要功能
- 能够单机部署elasticsearch
- 能够部署elasticsearch集群
- 理解ELK中索引的概念
- 能够部署logstash
- 能够使用logstash做日志采集
认识ELK
ELK是一套开源的日志分析系统,由elasticsearch+logstash+Kibana组成。
官网说明:https://www.elastic.co/cn/products
首先: 先一句话简单了解E,L,K这三个软件
elasticsearch: 分布式搜索引擎
logstash: 日志收集与过滤,输出给elasticsearch
Kibana: 图形化展示
elk下载地址:https://www.elastic.co/cn/downloads
环境准备:
四台机器(内存建议大于1G,比如1.5G; filebeat服务器可为1G) :
1,静态IP(要求能上公网,最好用虚拟机的NAT网络类型上网)
2,主机名及主机名绑定
10.1.1.11 vm1.cluster.com kibana
10.1.1.12 vm2.cluster.com elasticsearch
10.1.1.13 vm3.cluster.com logstash
10.1.1.14 vm4.cluster.com filebeat
3, 关闭防火墙和selinux
# systemctl stop firewalld
# systemctl disable firewalld
# iptables -F
# setenforce 0
setenforce: SELinux is disabled
4, 时间同步
* * * * * ntpdate.ntp1.aliyun.com
5, yum源(centos安装完系统后的默认yum源就OK)
elasticsearch
elasticsearch简介
Elasticsearch(简称ES)是一个开源的分布式搜索引擎,Elasticsearch还是一个分布式文档数据库。所以它提供了大量数据的存储功能,快速的搜索与分析功能。
提到搜索,大家肯定就想到了百度,谷歌,必应等。当然也有如下的搜索场景。
elasticsearch部署
第1步: 在elasticsearch服务器上(我这里为vm2),确认jdk(使用系统自带的openjdk就OK)
[root@vm2 ~]# vim /etc/profile
export JAVA_HOME=/app/tools/jdk1.8.0_271/
export PATH=${JAVA_HOME}/bin:$PATH
[root@vm2 ~]# java -version
java version "1.8.0_271"
Java(TM) SE Runtime Environment (build 1.8.0_271-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.271-b09, mixed mode)
第2步: es的安装,配置
[root@vm2 ~]# rpm -ivh elasticsearch-8.15.1-x86_64.rpm
第3步: 单机es的配置与服务启动
[root@vm2 ~]# cat /etc/elasticsearch/elasticsearch.yml |grep -v "#"
cluster.name: elk-cluster 可以自定义一个集群名称,不配置的话默认会取名为elasticsearch
path.data: /var/lib/elasticsearch
path.logs: /var/log/elasticsearch
network.host: 0.0.0.0 打开注释,并修改为监听所有
http.port: 9200 打开注释,监听端口9200
[root@vm2 ~]# systemctl start elasticsearch
[root@vm2 ~]# systemctl enable elasticsearch
启动有点慢和卡,稍等1分钟左右,查看到以下端口则表示启动OK
[root@vm2 ~]# netstat -ntlup |grep java
tcp6 0 0 :::9200 :::* LISTEN 5329/java
tcp6 0 0 :::9300 :::* LISTEN 5329/java
#9200则是数据传输端口
#9300端口是集群通信端口(我们暂时还没有配置集群,现在是单点elasticsearch)
第4步: 查看状态
#进入到安装目录
cd /usr/share/elasticsearch/bin
#使用如下指令设置密码,自动密码
./elasticsearch-reset-password -u elastic
warning: ignoring JAVA_HOME=/app/tools/jdk-17.0.12/; using bundled JDK
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: cHOjXPFFs5=RGmj6MzHY
#以交互方式设置密码
#./elasticsearch-reset-password --interactive -u elastic
warning: ignoring JAVA_HOME=/app/tools/jdk-17.0.12/; using bundled JDK
This tool will reset the password of the [elastic] user.
You will be prompted to enter the password.
Please confirm that you would like to continue [y/N]y
Enter password for [elastic]:
Re-enter password for [elastic]:
Password for the [elastic] user successfully reset.
继续访问9200
{
"name" : "localhost",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "dUsKliv9Sxm5gSRLOYJBLQ",
"version" : {
"number" : "8.13.0",
"build_flavor" : "default",
"build_type" : "rpm",
"build_hash" : "09df99393193b2c53d92899662a8b8b3c55b45cd",
"build_date" : "2024-03-22T03:35:46.757803203Z",
"build_snapshot" : false,
"lucene_version" : "9.10.0",
"minimum_wire_compatibility_version" : "7.17.0",
"minimum_index_compatibility_version" : "7.0.0"
},
"tagline" : "You Know, for Search"
}
使用curl命令或浏览器访问http://10.1.1.12:9200/_cluster/health?pretty地址(IP为ES服务器IP)
[root@vm2 ~]# curl http://192.168.3.138:9200/_cluster/health?pretty
{
"cluster_name" : "elasticsearch",
"status" : "green",
"timed_out" : false,
"number_of_nodes" : 1,
"number_of_data_nodes" : 1,
"active_primary_shards" : 1,
"active_shards" : 1,
"relocating_shards" : 0,
"initializing_shards" : 0,
"unassigned_shards" : 0,
"delayed_unassigned_shards" : 0,
"number_of_pending_tasks" : 0,
"number_of_in_flight_fetch" : 0,
"task_max_waiting_in_queue_millis" : 0,
"active_shards_percent_as_number" : 100.0
}
- 点赞
- 收藏
- 关注作者
评论(0)