在现代IT运维和DevOps实践中,RockyLinux数据采集系统扮演着至关重要的角色。无论是监控服务器性能、分析应用日志,还是进行安全审计,一个稳定可靠的数据采集平台都是不可或缺的。本教程将面向零基础用户,详细讲解如何在RockyLinux上配置一套完整的数据采集配置教程,让你轻松掌握日志与指标的自动化收集。
首先,确保你的RockyLinux系统是最新的,并安装一些基础工具:
sudo dnf update -ysudo dnf install -y wget curl vim git 对于初学者,推荐使用 Filebeat + Prometheus + Grafana 的组合:
1. 添加Elastic官方仓库:
sudo rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearchcat <<EOF | sudo tee /etc/yum.repos.d/elastic.repo[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 2. 安装Filebeat:
sudo dnf install filebeat -y 3. 启用系统日志模块(自动配置常见日志路径):
sudo filebeat modules enable system 4. 配置输出目标(这里以本地Elasticsearch为例,你也可以输出到Logstash或Kafka):
# 编辑配置文件sudo vim /etc/filebeat/filebeat.yml# 找到 output.elasticsearch 部分,取消注释并修改为:output.elasticsearch: hosts: ["localhost:9200"] # 如果有账号密码,请取消下面两行注释 # username: "elastic" # password: "your_password" 5. 启动并设置开机自启:
sudo filebeat setupsudo systemctl enable filebeat --now 1. 创建专用用户:
sudo useradd --no-create-home --shell /bin/false prometheus 2. 下载并解压Prometheus:
cd /tmpwget https://github.com/prometheus/prometheus/releases/download/v2.45.0/prometheus-2.45.0.linux-amd64.tar.gztar xvfz prometheus-*.tar.gzsudo cp prometheus-2.45.0.linux-amd64/prometheus /usr/local/bin/sudo cp prometheus-2.45.0.linux-amd64/promtool /usr/local/bin/ 3. 创建配置目录并写入基础配置:
sudo mkdir /etc/prometheus /var/lib/prometheussudo chown prometheus:prometheus /var/lib/prometheus# 创建简单配置文件sudo cat <<EOF | sudo tee /etc/prometheus/prometheus.ymlglobal: scrape_interval: 15sscrape_configs: - job_name: 'prometheus' static_configs: - targets: ['localhost:9090'] - job_name: 'node_exporter' static_configs: - targets: ['localhost:9100']EOF 4. 安装Node Exporter(用于采集主机指标):
wget https://github.com/prometheus/node_exporter/releases/download/v1.6.1/node_exporter-1.6.1.linux-amd64.tar.gztar xvfz node_exporter-*.tar.gzsudo cp node_exporter-1.6.1.linux-amd64/node_exporter /usr/local/bin/ 5. 创建systemd服务并启动:
# Prometheus 服务sudo cat <<EOF | sudo tee /etc/systemd/system/prometheus.service[Unit]Description=PrometheusWants=network-online.targetAfter=network-online.target[Service]User=prometheusGroup=prometheusType=simpleExecStart=/usr/local/bin/prometheus \ --config.file /etc/prometheus/prometheus.yml \ --storage.tsdb.path /var/lib/prometheus/ \ --web.console.templates=/etc/prometheus/consoles \ --web.console.libraries=/etc/prometheus/console_libraries[Install]WantedBy=multi-user.targetEOF# Node Exporter 服务sudo cat <<EOF | sudo tee /etc/systemd/system/node_exporter.service[Unit]Description=Node ExporterWants=network-online.targetAfter=network-online.target[Service]User=prometheusExecStart=/usr/local/bin/node_exporter[Install]WantedBy=default.targetEOF# 启动服务sudo systemctl daemon-reloadsudo systemctl enable --now prometheus node_exporter 1. 添加Grafana仓库并安装:
sudo dnf install -y https://dl.grafana.com/oss/release/grafana-10.0.3-1.x86_64.rpm 2. 启动Grafana:
sudo systemctl enable grafana-server --now 3. 访问 http://你的服务器IP:3000,默认账号密码为 admin/admin,首次登录会提示修改密码。
现在你已经搭建了一个基础的RockyLinux监控工具体系:
你可以进一步:
通过本教程,你已成功构建了一套完整的日志收集系统。这套系统不仅适用于个人学习,也能满足中小企业的生产环境需求。随着经验积累,你可以逐步扩展其功能,打造更强大的数据采集与分析平台。
祝你在RockyLinux数据采集之旅中收获满满!
本文由主机测评网于2025-12-04发表在主机测评网_免费VPS_免费云服务器_免费独立服务器,如有疑问,请联系我们。
本文链接:https://www.vpshk.cn/2025122812.html