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

Filebeat、ELK安装与数据同步

环境准备

首先确保系统已安装Java(ELK栈需要Java环境)

安装OpenJDK

sudo apt update && sudo apt install openjdk-11-jdk -y  # Ubuntu/Debian

或者

sudo yum install java-11-openjdk-devel -y  # CentOS/RHEL

#验证Java安装

java -version

1. Elasticsearch 安装

wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.11.0-linux-x86_64.tar.gztar -xzf elasticsearch-8.11.0-linux-x86_64.tar.gzcd elasticsearch-8.11.0/
1.1 创建专用用户(Elasticsearch不允许root运行)
sudo useradd elastic
sudo chown -R elastic:elastic /path/to/elasticsearch-8.11.0# 切换到elastic用户
sudo su elastic# 启动Elasticsearch(前台运行)
./bin/elasticsearch# 或者后台启动
./bin/elasticsearch -d
1.2 配置Elasticsearch(编辑 config/elasticsearch.yml):
yaml配置:cluster.name: my-elasticsearch-cluster
node.name: node-1
path.data: /path/to/elasticsearch-data
path.logs: /path/to/elasticsearch-logs
network.host: 0.0.0.0
http.port: 9200
discovery.type: single-node  # 单节点模式验证安装:
curl -X GET "localhost:9200/"

2. Kibana 安装

wget https://artifacts.elastic.co/downloads/kibana/kibana-8.11.0-linux-x86_64.tar.gz# 解压
tar -xzf kibana-8.11.0-linux-x86_64.tar.gz
2.1 配置Kibana(编辑 config/kibana.yml):
cd kibana-8.11.0/yaml配置server.port: 5601
server.host: "0.0.0.0"
elasticsearch.hosts: ["http://localhost:9200"]

启动Kibana:
# 前台启动
./bin/kibana# 后台启动
nohup ./bin/kibana > kibana.log 2>&1 &

访问Kibana:http://your-server-ip:5601

3. Logstash 安装

wget https://artifacts.elastic.co/downloads/logstash/logstash-8.11.0-linux-x86_64.tar.gztar -xzf logstash-8.11.0-linux-x86_64.tar.gz
3.1创建Logstash配置文件:
cd logstash-8.11.0/# 创建配置目录
mkdir config/pipelines# 创建主配置文件
cat > config/pipelines.yml << EOF
- pipeline.id: mainpath.config: "config/conf.d/*.conf"
EOF
3.2 创建管道配置
mkdir config/conf.d
创建Logstash处理配置(config/conf.d/filebeat-to-es.conf):ruby
input {beats {port => 5044host => "0.0.0.0"}
}filter {# 如果有Grok解析需求可以在这里添加# grok {#   match => { "message" => "%{COMBINEDAPACHELOG}" }# }# 添加时间戳date {match => [ "timestamp", "ISO8601" ]}
}output {elasticsearch {hosts => ["http://localhost:9200"]index => "filebeat-logs-%{+YYYY.MM.dd}"# 如果是Elasticsearch 8.x且开启了安全功能# user => "elastic"# password => "your_password"}# 可选:同时输出到控制台用于调试stdout {codec => rubydebug}
}

启动Logstash:

# 测试配置
./bin/logstash -f config/conf.d/filebeat-to-es.conf --config.test_and_exit# 前台启动
./bin/logstash -f config/conf.d/filebeat-to-es.conf# 后台启动
nohup ./bin/logstash -f config/conf.d/filebeat-to-es.conf > logstash.log 2>&1 &

4. Filebeat 安装

wget https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-8.11.0-linux-x86_64.tar.gz# 解压
tar -xzf filebeat-8.11.0-linux-x86_64.tar.gz
4.1 配置Filebeat(编辑 filebeat.yml):

cd filebeat-8.11.0-linux-x86_64/yaml
filebeat.inputs:
- type: logenabled: truepaths:- /var/log/*.log# - /path/to/your/logs/*.log# 输出到Logstash
output.logstash:hosts: ["localhost:5044"]# 可选:直接输出到Elasticsearch(如果不需要Logstash处理)
#output.elasticsearch:
#  hosts: ["localhost:9200"]
#  index: "filebeat-%{[agent.version]}-%{+yyyy.MM.dd}"
4.2 设置Filebeat自身日志
logging.level: info
logging.to_files: true
logging.files:path: /var/log/filebeatname: filebeatkeepfiles: 7
设置和启动Filebeat:# 创建日志目录(如果监控系统日志)
sudo mkdir -p /var/log/filebeat
sudo chown $USER:$USER /var/log/filebeat# 测试配置
./filebeat test config
./filebeat test output# 安装Filebeat为系统服务(可选)
./filebeat setup --pipelines --modules system
sudo ./filebeat setup -e# 前台启动
./filebeat -e# 后台启动
nohup ./filebeat -e > filebeat.log 2>&1 &

5 验证数据流

检查服务状态
# 检查Elasticsearch
curl -X GET "localhost:9200/_cluster/health?pretty"# 检查索引
curl -X GET "localhost:9200/_cat/indices?v"# 检查Filebeat是否发送数据
tail -f filebeat.log
在Kibana中查看数据
访问 http://your-server-ip:5601进入 "Stack Management" > "Index Patterns"创建索引模式 "filebeat-logs-*"进入 "Discover" 查看日志数据
http://www.dtcms.com/a/503525.html

相关文章:

  • 嵌入式开发学习日志40——stm32之I2C协议层
  • 网站建设公司小江可以做试题的网站
  • Android 四大组件桥梁 —— Intent (意图) 详解
  • 小鱼在线网站建设网站注册步骤
  • wordpress 视频站模板wordpress和网盘结合
  • Orleans流背压控制机制深度分析
  • Java并发之队列同步器AQS原理
  • c++11可变模版参数 emplace接口 新的类功能 lambda 包装器
  • 手机代码网站有哪些问题吗制作视频特效
  • 济南正规的网站制作郑州做网站九零后网络
  • SQL入门:分页查询核心技术解析
  • 5.3 TCP (答案见原书 P252)
  • 教育房地产 网站建设中山网站建设找丁生
  • 【第十八周】自然语言处理的学习笔记03
  • 探索 Python 判断语句:逻辑与感性的交汇
  • 深圳哪家制作网站好成都近期发生的大事
  • IDEA Gradle并行编译内存溢出问题
  • 如何做电影网站赚钱瓯海住房与城乡建设局网站
  • 婚礼(一)
  • 电阻应变式传感器
  • 在开发过程中遇到问题如何解决,以及两个经典问题
  • 企业网站建设 属于什么费用个人博客网页设计
  • 网站怎么做301信息类网站 wordpress
  • MyBatis入门到精通(Mybatis学习笔记)
  • 一次渗透测试的全过程:从扫描到提权
  • 英语作文网站济南专业做公司网站的机构
  • 织梦后台做的网站怎么绑定域名做瞹视频网站
  • 网站悬浮代码做柱状图饼状图好看的网站
  • 2510d,C++与d互操作
  • 移动端漂亮网站今天出入济南最新通知