昨天推荐了网络监控工具,今天介绍下几款开源监控工具的安装方法
开源网络监控工具有很多,常见的有 Nagios、Zabbix、Prometheus+Grafana 等。以下是一些流行的开源网络监控工具的部署和安装步骤:
1. Nagios
Nagios 是一个功能强大的开源网络监控工具,适用于监控各种网络设备、服务器和服务。
安装步骤(以 Ubuntu 为例):
-
更新包列表并安装必要的依赖:
sudo apt update sudo apt install -y autoconf gcc libc6 make wget unzip apache2 php libapache2-mod-php7.4 libgd-dev
-
创建 Nagios 用户和组:
sudo useradd nagios sudo groupadd nagcmd sudo usermod -a -G nagcmd nagios sudo usermod -a -G nagcmd www-data
-
下载并解压 Nagios:
cd /tmp wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.4.6.tar.gz tar zxvf nagios-4.4.6.tar.gz cd nagios-4.4.6
-
编译和安装 Nagios:
./configure --with-command-group=nagcmd make all sudo make install sudo make install-commandmode sudo make install-init sudo make install-config sudo make install-webconf
-
设置 Nagios Web 界面的基本身份验证:
sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
-
启动 Apache 和 Nagios 服务:
sudo systemctl restart apache2 sudo systemctl start nagios sudo systemctl enable nagios
-
访问 Nagios Web 界面:
打开浏览器,访问
http://<server-ip>/nagios
,使用刚才创建的nagiosadmin
用户登录。
2. Zabbix
Zabbix 是一个企业级的开源监控工具,支持监控各种 IT 组件,包括网络设备、服务器、虚拟机和云资源。
安装步骤(以 Ubuntu 为例):
-
安装 Zabbix 仓库:
wget https://repo.zabbix.com/zabbix/5.0/ubuntu/pool/main/z/zabbix-release/zabbix-release_5.0-1+ubuntu18.04_all.deb sudo dpkg -i zabbix-release_5.0-1+ubuntu18.04_all.deb sudo apt update
-
安装 Zabbix 服务器、前端和代理:
sudo apt install zabbix-server-mysql zabbix-frontend-php zabbix-agent
-
创建初始数据库:
sudo apt install mysql-server sudo mysql_secure_installation mysql -uroot -p create database zabbix character set utf8 collate utf8_bin; create user zabbix@localhost identified by 'password'; grant all privileges on zabbix.* to zabbix@localhost; quit;
-
导入初始架构和数据:
zcat /usr/share/doc/zabbix-server-mysql/create.sql.gz | mysql -uzabbix -p zabbix
-
配置数据库连接:
编辑
/etc/zabbix/zabbix_server.conf
文件,并设置数据库密码:DBPassword=password
-
配置 PHP 前端:
编辑
/etc/zabbix/apache.conf
文件,并设置时区:php_value date.timezone Europe/Riga
-
启动 Zabbix 服务器和代理进程:
sudo systemctl restart zabbix-server zabbix-agent apache2 sudo systemctl enable zabbix-server zabbix-agent apache2
-
访问 Zabbix 前端:
打开浏览器,访问
http://<server-ip>/zabbix
,并按照向导完成配置。
3. Prometheus + Grafana
Prometheus 是一个开源的系统监控和报警工具,Grafana 是一个开源的数据可视化工具。两者常常结合使用,用于监控和可视化数据。
安装步骤(以 Ubuntu 为例):
安装 Prometheus:
-
创建 Prometheus 用户:
sudo useradd --no-create-home --shell /bin/false prometheus
-
下载并安装 Prometheus:
wget https://github.com/prometheus/prometheus/releases/download/v2.31.1/prometheus-2.31.1.linux-amd64.tar.gz tar -xvf prometheus-2.31.1.linux-amd64.tar.gz sudo mv prometheus-2.31.1.linux-amd64 /usr/local/prometheus sudo chown -R prometheus:prometheus /usr/local/prometheus
-
创建 Prometheus 配置文件:
创建
/etc/prometheus/prometheus.yml
文件:global: scrape_interval: 15s scrape_configs: - job_name: 'prometheus' static_configs: - targets: ['localhost:9090']
-
创建 Systemd 服务文件:
创建
/etc/systemd/system/prometheus.service
文件:[Unit] Description=Prometheus Wants=network-online.target After=network-online.target [Service] User=prometheus Group=prometheus Type=simple ExecStart=/usr/local/prometheus/prometheus --config.file=/etc/prometheus/prometheus.yml --storage.tsdb.path=/usr/local/prometheus/data [Install] WantedBy=multi-user.target
-
启动 Prometheus:
sudo systemctl daemon-reload sudo systemctl start prometheus sudo systemctl enable prometheus
安装 Grafana:
-
添加 Grafana 仓库:
sudo apt-get install -y software-properties-common sudo add-apt-repository "deb https://packages.grafana.com/oss/deb stable main" wget -q -O - https://packages.grafana.com/gpg.key | sudo apt-key add -
-
安装 Grafana:
sudo apt-get update sudo apt-get install grafana
-
启动 Grafana:
sudo systemctl start grafana-server sudo systemctl enable grafana-server
-
访问 Grafana:
打开浏览器,访问
http://<server-ip>:3000
,默认用户名和密码是admin
。 -
配置数据源:
在 Grafana 中添加 Prometheus 作为数据源,地址为
http://localhost:9090
。 -
创建仪表盘:
使用 Grafana 创建新的仪表盘,并添加相关的图表和指标。
总结
以上介绍了三款流行的开源网络监控工具:Nagios、Zabbix 和 Prometheus+Grafana 的安装和基本配置步骤。选择适合你的工具取决于具体的监控需求、环境规模和技术背景。