在现代IT运维和DevOps实践中,Centos数据采集系统是实现系统监控、故障排查和性能优化的核心基础设施。无论你是刚接触Linux的新手,还是有一定经验的运维工程师,掌握如何在CentOS上部署一套稳定、高效的开源数据采集平台都至关重要。
在CentOS服务器运行过程中,会产生大量有价值的数据,例如:
通过Linux日志采集和指标收集,我们可以将这些分散的数据集中管理,用于实时告警、趋势分析和历史回溯。
本教程基于 CentOS 7 或 CentOS 8 系统。请确保你有 root 权限或 sudo 权限。
首先,更新系统并安装必要工具:
sudo yum update -ysudo yum install -y wget curl vim net-tools 我们将使用两个主流的Centos监控工具:
# 添加 Elastic 官方仓库sudo rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearchcat > /etc/yum.repos.d/elastic.repo <<EOF[elastic-8.x]name=Elastic repository for 8.x packagesbaseurl=https://artifacts.elastic.co/packages/8.x/yumgpgcheck=1gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearchenabled=1autorefresh=1type=rpm-mdEOF# 安装 Filebeatsudo yum install -y filebeat 编辑配置文件:
sudo vim /etc/filebeat/filebeat.yml 修改以下关键部分(以输出到本地文件为例,便于测试):
filebeat.inputs:- type: filestream enabled: true paths: - /var/log/messages - /var/log/secureoutput.file: path: "/tmp/filebeat" filename: "collected-logs.txt"# 关闭 Elasticsearch 输出(因为我们暂时不连接 ES)# output.elasticsearch:# hosts: ["localhost:9200"] 启动并设置开机自启:
sudo filebeat setupsudo systemctl enable filebeatsudo systemctl start filebeat # 下载最新版(请根据官网替换版本号)wget https://github.com/prometheus/node_exporter/releases/download/v1.7.0/node_exporter-1.7.0.linux-amd64.tar.gztar xvfz node_exporter-*.linux-amd64.tar.gzsudo cp node_exporter-1.7.0.linux-amd64/node_exporter /usr/local/bin/# 创建 systemd 服务sudo tee /etc/systemd/system/node_exporter.service <<EOF[Unit]Description=Node ExporterWants=network-online.targetAfter=network-online.target[Service]User=node_exporterGroup=node_exporterType=simpleExecStart=/usr/local/bin/node_exporter[Install]WantedBy=multi-user.targetEOF# 创建用户sudo useradd -rs /bin/false node_exporter# 启动服务sudo systemctl daemon-reloadsudo systemctl enable node_exportersudo systemctl start node_exporter 现在,你可以通过访问 http://你的服务器IP:9100/metrics 查看采集到的系统指标。
检查 Filebeat 是否写入日志:
tail -f /tmp/filebeat/collected-logs.txt 检查 Node Exporter 指标:
curl http://localhost:9100/metrics | head -20 你现在已成功搭建了一个基础的Centos数据采集系统!下一步可以考虑:
通过这套方案,即使是Linux小白也能快速上手,构建企业级的开源数据采集体系。
本文由主机测评网于2025-12-13发表在主机测评网_免费VPS_免费云服务器_免费独立服务器,如有疑问,请联系我们。
本文链接:https://www.vpshk.cn/2025127300.html