ANALYSIS
docker 国内安装脚本:
bash <(curl -sSL https://linuxmirrors.cn/docker.sh)
Nagios
适合:
- 小规模服务器
- 内网 / 传统 IDC
- 想“看得见机器活没活”的场景
不适合:
- 云原生
- 自动扩缩容
- 指标维度特别复杂(这时候你该上 Prometheus 了)
直接部署
.更新系统 + 安装依赖
PRTCL // SHELL
# 更新系统sudo apt update
# 安装编译环境和依赖sudo apt install -y \build-essential \apache2 \php \php-gd \libgd-dev \unzip \wget \openssl \libssl-dev.创建 Nagios 用户
PRTCL // SHELL
# 创建用户和组sudo useradd nagiossudo groupadd nagcmd
# 用户加入组sudo usermod -aG nagcmd nagiossudo usermod -aG nagcmd www-data.下载并编译 NagiosCore
PRTCL // SHELL
cd /usr/local/src
# 下载最新版wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.4.14.tar.gz
tar zxvf nagios-4.4.14.tar.gzcd nagios-4.4.14
# 配置./configure \--with-command-group=nagcmd
# 编译 & 安装make allsudo make installsudo make install-initsudo make install-configsudo make install-commandmodesudo make install-webconf.安装 Nagios Plugins
PRTCL // SHELL
cd /usr/local/src
wget https://nagios-plugins.org/download/nagios-plugins-2.4.8.tar.gztar zxvf nagios-plugins-2.4.8.tar.gzcd nagios-plugins-2.4.8
./configure --with-nagios-user=nagios --with-nagios-group=nagiosmakesudo make install.配置 Web 账号登陆
PRTCL // SHELL
sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin.启动服务
PRTCL // BASH
sudo systemctl restart apache2sudo systemctl enable nagiossudo systemctl start nagiosdocker 部署
.安装 Docker
PRTCL // SHELL
sudo apt install -y docker.io docker-compose sudo systemctl enable docker sudo systemctl start docker.docker-compose.yml
PRTCL // YML
version: '3'
services: nagios: image: jasonrivers/nagios container_name: nagios ports: - "8080:80" environment: - NAGIOSADMIN_USER=nagiosadmin - NAGIOSADMIN_PASS=Nagios123 volumes: - nagios_etc:/opt/nagios/etc - nagios_var:/opt/nagios/var restart: always
volumes: nagios_etc: nagios_var:.启动
PRTCL // BASH
docker-compose up -d`访问:
PRTCL // CPP
http:// 服务器 IP:8080注意事项
.检查配置是否有问题
PRTCL // BASH
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg.开放防火墙端口
PRTCL // SHELL
sudo ufw allow 80 sudo ufw allow 8080.先监控自己(别一上来就加几十台)
PRTCL // SHELL
define host{ use linux-server host_name localhost address 127.0.0.1}Zabbix
适合:
- 中小到中大型服务器规模
- 需要图表 + 告警 + 历史数据
- 不想再自己拼 Grafana + Prometheus
- 运维要“像个人样”的那种场景
不适合:
- 只监控 1~2 台机器
- 纯云原生 ( 建议采用 Prometheus)
官方仓库安装
安装 Zabbix 官方源
PRTCL // SHELL
# 下载官方源wget https://repo.zabbix.com/zabbix/7.0/ubuntu/pool/main/z/zabbix-release/zabbix-release_7.0-1+ubuntu24.04_all.deb
# 安装sudo dpkg -i zabbix-release_7.0-1+ubuntu24.04_all.debsudo apt update安装 Zabbix Server + Web + Agent(MySQL 版)
PRTCL // SHELL
sudo apt install -y \zabbix-server-mysql \zabbix-frontend-php \zabbix-apache-conf \zabbix-sql-scripts \zabbix-agent \mysql-server初始化数据库(很多人翻车在这一步)
PRTCL // SHELL
# 进入 MySQLsudo mysql
# 创建数据库CREATE DATABASE zabbix CHARACTER SET utf8mb4 COLLATE utf8mb4_bin;
# 创建用户CREATE USER zabbix@localhost IDENTIFIED BY 'Zabbix@123';
# 授权GRANT ALL PRIVILEGES ON zabbix.* TO zabbix@localhost;FLUSH PRIVILEGES;EXIT;导入初始数据
PRTCL // SHELL
zcat /usr/share/zabbix-sql-scripts/mysql/server.sql.gz | mysql -uzabbix -p zabbix配置 Zabbix Server 数据库连接
PRTCL // SHELL
sudo vim /etc/zabbix/zabbix_server.confPRTCL // CONF
### 数据库配置DBName=zabbixDBUser=zabbixDBPassword=Zabbix@123.启动服务
PRTCL // SHELL
sudo systemctl restart zabbix-server zabbix-agent apache2sudo systemctl enable zabbix-server zabbix-agent apache2Web 初始化
访问:
PRTCL // ARDUINO
http:// 服务器 IP/zabbix默认账号:
PRTCL // PGSQL
用户名:admin密码:zabbix⚠️ 第一次登录立刻改密码,这是基本素养。
Docker 部署(体验党福音)
docker-compose.yml
PRTCL // YML
version: '3'
services: mysql: image: mysql:8.0 container_name: zabbix-mysql environment: MYSQL_ROOT_PASSWORD: root123 MYSQL_DATABASE: zabbix MYSQL_USER: zabbix MYSQL_PASSWORD: zabbix123 volumes: - mysql_data:/var/lib/mysql restart: always
zabbix-server: image: zabbix/zabbix-server-mysql:alpine-latest depends_on: - mysql environment: DB_SERVER_HOST: mysql MYSQL_DATABASE: zabbix MYSQL_USER: zabbix MYSQL_PASSWORD: zabbix123 ports: - "10051:10051" restart: always
zabbix-web: image: zabbix/zabbix-web-apache-mysql:alpine-latest depends_on: - zabbix-server environment: DB_SERVER_HOST: mysql MYSQL_DATABASE: zabbix MYSQL_USER: zabbix MYSQL_PASSWORD: zabbix123 ZBX_SERVER_HOST: zabbix-server PHP_TZ: Asia/Shanghai ports: - "8080:8080" restart: always
volumes: mysql_data:启动:
PRTCL // SHELL
docker-compose up -d访问:
PRTCL // CPP
http:// 服务器 IP:8080注意事项
.修改 Agent 配置(监控自己)
PRTCL // SHELL
sudo vim /etc/zabbix/zabbix_agentd.confPRTCL // C
Server=127.0.0.1ServerActive=127.0.0.1Hostname=ZabbixServerPRTCL // SHELL
sudo systemctl restart zabbix-agent.Web 里启用 Host
路径:
PRTCL // PGSQL
配置 → 主机 → Zabbix server → 启用套模板
常用模板:
Linux by Zabbix agent
ICMP Ping
Filesystem
调整时区
PRTCL // SHELL
sudo vim /etc/php/*/apache2/php.iniPRTCL // INI
date.timezone = Asia/ShanghaiPrometheus + Grafana
适合
- 云服务器
- K8s / Docker
- 微服务
- 想知道 CPU 为什么抖、内存为什么慢慢涨
不适合
- 只监控 1 台 VPS
- 不想折腾
- 希望“装完就自动有图 Prometheus 的核心特点:
自由,但不喂饭
原生安装
.安装 Prometheus
PRTCL // BASH
# 创建用户(安全习惯)sudo useradd --no-create-home --shell /bin/false prometheus
# 创建目录sudo mkdir /etc/prometheussudo mkdir /var/lib/prometheus
# 下载cd /tmpwget https://github.com/prometheus/prometheus/releases/download/v2.49.1/prometheus-2.49.1.linux-amd64.tar.gz
tar zxvf prometheus-2.49.1.linux-amd64.tar.gzcd prometheus-2.49.1.linux-amd64PRTCL // BASH
# 安装二进制sudo cp prometheus promtool /usr/local/bin/sudo cp -r consoles console_libraries /etc/prometheus/
# 权限sudo chown -R prometheus:prometheus /etc/prometheus /var/lib/prometheus.Prometheus 配置文件
PRTCL // BASH
sudo vim /etc/prometheus/prometheus.ymlPRTCL // YAML
global: scrape_interval: 15s # 采集间隔
scrape_configs: - job_name: "prometheus" static_configs: - targets: ["localhost:9090"].systemd 服务
PRTCL // BASH
sudo vim /etc/systemd/system/prometheus.servicePRTCL // INI
[Unit]Description=PrometheusAfter=network.target
[Service]User=prometheusExecStart=/usr/local/bin/prometheus \ --config.file=/etc/prometheus/prometheus.yml \ --storage.tsdb.path=/var/lib/prometheus
[Install]WantedBy=multi-user.targetPRTCL // BASH
sudo systemctl daemon-reloadsudo systemctl enable prometheussudo systemctl start prometheus访问:
PRTCL // PLAINTEXT
http:// 服务器 IP:9090Node Exporter(受监控客户机安装)
Prometheus 不直接监控系统,靠 Exporter 进行数据采集。
安装 Node Exporter
部署安装 Node Exporter
PRTCL // SHELL
cd /tmpwget https://github.com/prometheus/node_exporter/releases/download/v1.10.2/node_exporter-1.10.2.linux-amd64.tar.gz
tar zxvf node_exporter-1.10.2.linux-amd64.tar.gzsudo cp node_exporter-1.10.2.linux-amd64/node_exporter /usr/local/bin/使用 systemctl 进行管理
PRTCL // BASH
sudo vim /etc/systemd/system/node_exporter.serviceservice文件内容
PRTCL // INI
[Unit]Description=Node Exporter
[Service]ExecStart=/usr/local/bin/node_exporter
[Install]WantedBy=multi-user.target- 开机自启
PRTCL // BASH
sudo systemctl enable node_exportersudo systemctl start node_exporterPrometheus 配置追加:
node客户机名称ip:9100
PRTCL // YAML
- job_name: "node" static_configs: - targets: ["localhost:9100"]安装 Grafana(官方仓库)
PRTCL // BASH
sudo apt install -y apt-transport-https software-properties-common
sudo wget -q -O /usr/share/keyrings/grafana.key https://apt.grafana.com/gpg.key
echo "deb [signed-by=/usr/share/keyrings/grafana.key] https://apt.grafana.com stable main" \| sudo tee /etc/apt/sources.list.d/grafana.list
sudo apt updatesudo apt install grafanaPRTCL // BASH
sudo systemctl enable grafana-serversudo systemctl start grafana-server访问:
PRTCL // PLAINTEXT
http:// 服务器 IP:3000默认账号:
PRTCL // PLAINTEXT
admin / adminDocker 安装(最推荐)
docker-compose.yml
PRTCL // YAML
version: "3"
services: prometheus: image: prom/prometheus container_name: prometheus volumes: - ./prometheus.yml:/etc/prometheus/prometheus.yml ports: - "9090:9090"
node-exporter: image: prom/node-exporter container_name: node-exporter ports: - "9100:9100"
grafana: image: grafana/grafana container_name: grafana ports: - "3000:3000" volumes: - grafana_data:/var/lib/grafana
volumes: grafana_data:启动:
PRTCL // BASH
docker-compose up -d宝塔 & 1Panel
宝塔
- 装 Docker
- 用 Docker Compose
- 宝塔只负责 UI
👉 宝塔不适合原生 Prometheus
Panel(强烈推荐)
- 原生支持 Docker
- Prometheus / Grafana 都有模板
- 配置比宝塔干净很多
一句话:
Prometheus + 1Panel = 运维舒适区
Grafana 必做三件事(新手不做 = 白装)
1 添加数据源
PRTCL // PLAINTEXT
Settings → Data Sources → PrometheusURL:http://prometheus:9090 或 http://localhost:90902 导入 Dashboard
推荐 ID:
1860(Node Exporter Full)11074(Linux 主机)8919(Docker)
总结
Prometheus 不会照顾你,
但它会把系统的真相,
一毫秒不差地摆在你面前。
如果你愿意继续往下走,下一步才是真正的云原生监控核心区:
Prometheus + Alertmanager 告警设计
Blackbox Exporter(HTTP / TCP / ICMP)
Prometheus + Zabbix 混合架构
Loki + Grafana(日志和监控合体)
这套学完,你就是“指标驱动型运维”了。
R P
Rhine Lab Pioneer Division
Auth_Verified: 2026.04.08
Auth_Verified: 2026.04.08
