Zabbix 是一个企业级分布式开源监控解决方案,能够监控各种网络设备、服务器、中间件和应用程序等等。Zabbix 支持主动轮询(polling)和被动捕获(trapping)两种方式获取数据。Zabbix 所有的报表、统计数据和配置参数都可以通过基于 Web 的前端页面进行访问,并且提供了完善的 API 接口便于二次开发。
Zabbix 有以下几个主要组件:
Zabbix Server:是 Zabbix 软件的核心组件,Zabbix Agent 向其报告可用性、系统完整性信息和统计信息。
Zabbix Web:通过 Apache HTTP 运行,提供前端的访问页面。
Zabbix Proxy(可选):Zabbix Proxy 可以代替 Zabbix Server 收集客户端的数据,然后把数据汇报给 Zabbix Server,以减轻 Zabbix Server 的负担,本文中没有安装 Zabbix Proxy。
Zabbix Agent:部署在需要监控的服务器上,主动监控本地资源和应用程序,并将收集到的数据上报给 Zabbix Server(或 Zabbix Proxy)。
数据库存储:存储所有的配置信息以及 Zabbix 收集到的数据。数据库使用外部已经部署好的 MySQL 高可用集群。
目前 Zabbix 最新的稳定版本是 5.4,然而官方 yum 源只支持在 Centos8 上安装 Zabbix 5.4 版本,想要在 Centos7 上安装 Zabbix 5.4 版本上只能通过源码编译的方式安装。本文将会介绍在 Centos7 上通过源码编译安装的方式部署一套 Zabbix 高可用集群。
部署架构图
机器规划
准备工作
安装 PHP
Zabbix 5.4 版本要求 PHP 版本在 7.2 以上。
卸载旧版本 PHP:
安装 7.2 版本 PHP:
rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
yum install -y php72w php72w-opcache php72w-xml php72w-gd php72w-devel php72w-mysqlnd php72w-intl php72w-mbstring php72w-pear php72w-pdo php72w-fpm php72w-bcmath
复制代码
安装 Golang
Zabbix 前端服务依赖 Golang。
rpm --import https://mirror.go-repo.io/centos/RPM-GPG-KEY-GO-REPO
curl -s https://mirror.go-repo.io/centos/go-repo.repo | tee /etc/yum.repos.d/go-repo.repo
yum install golang
go env -w GOPROXY=https://goproxy.cn
复制代码
安装依赖
yum install -y gcc mysql-devel net-snmp-devel pcre*\
curl-devel libxml2 libxml2-devel \
automake libssh2-devel libevent-devel httpd libcurl-devel.x86_64 \
kernel-devel openssl-devel popt-devel
复制代码
部署 MySQL
MySQL 安装可以参考 MySQL + Keepalived 双主热备搭建。
注意 Zabbix 要求数据库版本在 5.7.35 以上,并且 database 字符集要求是 utf8,校验集为 utf8_bin。
创建 database 指定字符集。
CREATE DATABASE `acpzabbixdb` DEFAULT CHARACTER SET utf8 COLLATE utf8_bin
复制代码
源码编译部署 Zabbix
下载并解压源码包
wget https://cdn.zabbix.com/zabbix/sources/stable/5.4/zabbix-5.4.4.tar.gz
tar -xzvf zabbix-5.4.4.tar.gz
cd zabbix-5.4.4
复制代码
编译安装
./configure --prefix=/usr/local/zabbix \
--enable-server \
--enable-agent \
--with-mysql \
--with-libcurl \
--with-net-snmp \
--with-libxml2 \
--with-ssh2 \
--enable-webservice
make install
复制代码
部署 Zabbix Server
创建用户和相关目录
useradd zabbix
mkdir /usr/local/zabbix/logs
mkdir /usr/local/zabbix/trap
chown -R zabbix.zabbix /usr/local/zabbix/
复制代码
Zabbix Server 配置文件
编辑 /usr/local/zabbix/etc/zabbix_server.conf 文件:
#Zabbix Server 地址
SourceIP=11.8.38.70
#日志文件目录
LogFile=/usr/local/zabbix/logs/zabbix_server.log
#Pid 文件目录
PidFile=/usr/local/zabbix/zabbix_server.pid
#Socket 文件目录
SocketDir=/usr/local/zabbix
#数据库连接信息
DBHost=11.17.6.81
DBPort=4442
DBName=acpzabbixdb
DBUser=acpzabbixdb
DBPassword=yourpassword
Timeout=4
LogSlowQueries=3000
#允许所有地址访问
StatsAllowedIP=0.0.0.0
#配置缓存
CacheSize=1G
#snmp trap 目录
SNMPTrapperFile=/usr/local/zabbix/trap/zabbix_traps
#开启 snmp trap
StartSNMPTrapper=1
#拉取 snmp 信息的线程数
StartProxyPollers=20
复制代码
Zabbix Server 备机配置和主机除了 SourceIP 以外,其余配置一样。
初始化数据库
SQL 文件在源码解压后的目录 zabbix-5.4.4/database/ 中,执行以下命令初始化数据库。初始化数据库只需要做一次,Zabbix Server 备机和主机共用一个 MySQL 数据库。
mysql -h 11.17.6.81 -P 4442 -uacpzabbixdb -pyourpassword acpzabbixdb < schema.sql
mysql -h 11.17.6.81 -P 4442 -uacpzabbixdb -pyourpassword acpzabbixdb < images.sql
mysql -h 11.17.6.81 -P 4442 -uacpzabbixdb -pyourpassword acpzabbixdb < data.sql
复制代码
配置 Zabbix Server 系统服务
编辑 /usr/lib/systemd/system/zabbix-server.service 文件:
[Unit]
Description=Zabbix Server
After=network.target
[Service]
User=zabbix
Environment="CONFFILE=/usr/local/zabbix/etc/zabbix_server.conf"
Type=forking
Restart=on-failure
PIDFile=/usr/local/zabbix/zabbix_server.pid
KillMode=control-group
ExecStart=/usr/local/zabbix/sbin/zabbix_server -c $CONFFILE
ExecStop=/bin/kill -SIGTERM $MAINPID
RestartSec=10s
TimeoutSec=0
[Install]
WantedBy=multi-user.target
复制代码
启动 Zabbix Server,并设置开机自动启动。
systemctl enable zabbix-server.service
systemctl start zabbix-server.service
复制代码
查看 Zabbix Server 状态,Running 表示正常运行:
root@ydt-net-zabbix1:/root/zabbix-5.4.4/database #systemctl status zabbix-server
● zabbix-server.service - Zabbix Server
Loaded: loaded (/usr/lib/systemd/system/zabbix-server.service; enabled; vendor preset: disabled)
Active: active (running) since Mon 2021-09-13 11:27:14 CST; 3min 23s ago
Process: 18685 ExecStop=/bin/kill -SIGTERM $MAINPID (code=exited, status=0/SUCCESS)
Process: 18688 ExecStart=/usr/local/zabbix/sbin/zabbix_server -c $CONFFILE (code=exited, status=0/SUCCESS)
Main PID: 18690 (zabbix_server)
CGroup: /system.slice/zabbix-server.service
├─18690 /usr/local/zabbix/sbin/zabbix_server -c /usr/local/zabbix/etc/zabbix_server.conf
├─18692 /usr/local/zabbix/sbin/zabbix_server: configuration syncer [synced configuration in 0.055682 sec, idle 60 sec]
├─18693 /usr/local/zabbix/sbin/zabbix_server: alert manager #1 [sent 0, failed 0 alerts, idle 5.006520 sec during 5.006634 sec]
├─18694 /usr/local/zabbix/sbin/zabbix_server: alerter #1 started
├─18695 /usr/local/zabbix/sbin/zabbix_server: alerter #2 started
├─18696 /usr/local/zabbix/sbin/zabbix_server: alerter #3 started
├─18697 /usr/local/zabbix/sbin/zabbix_server: preprocessing manager #1 [queued 0, processed 2 values, idle 5.000761 sec during 5.000817 sec]
├─18698 /usr/local/zabbix/sbin/zabbix_server: preprocessing worker #1 started
├─18699 /usr/local/zabbix/sbin/zabbix_server: preprocessing worker #2 started
├─18700 /usr/local/zabbix/sbin/zabbix_server: preprocessing worker #3 started
├─18701 /usr/local/zabbix/sbin/zabbix_server: lld manager #1 [processed 0 LLD rules, idle 5.954542sec during 5.954592 sec]
├─18702 /usr/local/zabbix/sbin/zabbix_server: lld worker #1 started
├─18703 /usr/local/zabbix/sbin/zabbix_server: lld worker #2 started
├─18704 /usr/local/zabbix/sbin/zabbix_server: housekeeper [startup idle for 30 minutes]
├─18705 /usr/local/zabbix/sbin/zabbix_server: timer #1 [updated 0 hosts, suppressed 0 events in 0.001053 sec, idle 59 sec]
├─18706 /usr/local/zabbix/sbin/zabbix_server: http poller #1 [got 0 values in 0.000933 sec, idle 5 sec]
├─18707 /usr/local/zabbix/sbin/zabbix_server: discoverer #1 [processed 0 rules in 0.000936 sec, idle 60 sec]
├─18708 /usr/local/zabbix/sbin/zabbix_server: history syncer #1 [processed 0 values, 0 triggers in 0.000021 sec, idle 1 sec]
├─18709 /usr/local/zabbix/sbin/zabbix_server: history syncer #2 [processed 2 values, 2 triggers in 0.002352 sec, idle 1 sec]
├─18710 /usr/local/zabbix/sbin/zabbix_server: history syncer #3 [processed 0 values, 0 triggers in 0.000012 sec, idle 1 sec]
├─18711 /usr/local/zabbix/sbin/zabbix_server: history syncer #4 [processed 0 values, 0 triggers in 0.000022 sec, idle 1 sec]
├─18712 /usr/local/zabbix/sbin/zabbix_server: escalator #1 [processed 0 escalations in 0.001885 sec, idle 3 sec]
├─18713 /usr/local/zabbix/sbin/zabbix_server: proxy poller #1 [exchanged data with 0 proxies in 0.000037 sec, idle 5 sec]
├─18714 /usr/local/zabbix/sbin/zabbix_server: self-monitoring [processed data in 0.000017 sec, idle 1 sec]
├─18715 /usr/local/zabbix/sbin/zabbix_server: task manager [processed 0 task(s) in 0.003206 sec, idle 5 sec]
├─18716 /usr/local/zabbix/sbin/zabbix_server: poller #1 [got 0 values in 0.000026 sec, idle 5 sec]
├─18717 /usr/local/zabbix/sbin/zabbix_server: poller #2 [got 0 values in 0.000054 sec, idle 5 sec]
├─18718 /usr/local/zabbix/sbin/zabbix_server: poller #3 [got 0 values in 0.000018 sec, idle 5 sec]
├─18719 /usr/local/zabbix/sbin/zabbix_server: poller #4 [got 0 values in 0.000014 sec, idle 5 sec]
├─18720 /usr/local/zabbix/sbin/zabbix_server: poller #5 [got 0 values in 0.000067 sec, idle 5 sec]
├─18721 /usr/local/zabbix/sbin/zabbix_server: unreachable poller #1 [got 0 values in 0.000040 sec, idle 5 sec]
├─18722 /usr/local/zabbix/sbin/zabbix_server: trapper #1 [processed data in 0.000706 sec, waiting for connection]
├─18723 /usr/local/zabbix/sbin/zabbix_server: trapper #2 [processed data in 0.000486 sec, waiting for connection]
├─18724 /usr/local/zabbix/sbin/zabbix_server: trapper #3 [processed data in 0.000538 sec, waiting for connection]
├─18725 /usr/local/zabbix/sbin/zabbix_server: trapper #4 [processed data in 0.000475 sec, waiting for connection]
├─18726 /usr/local/zabbix/sbin/zabbix_server: trapper #5 [processed data in 0.000536 sec, waiting for connection]
├─18727 /usr/local/zabbix/sbin/zabbix_server: icmp pinger #1 [got 0 values in 0.000017 sec, idle 5 sec]
├─18728 /usr/local/zabbix/sbin/zabbix_server: alert syncer [queued 0 alerts(s), flushed 0 result(s) in 0.001174 sec, idle 1 sec]
├─18729 /usr/local/zabbix/sbin/zabbix_server: history poller #1 [got 0 values in 0.000039 sec, idle 1 sec]
├─18730 /usr/local/zabbix/sbin/zabbix_server: history poller #2 [got 1 values in 0.000109 sec, idle 1 sec]
├─18731 /usr/local/zabbix/sbin/zabbix_server: history poller #3 [got 1 values in 0.000163 sec, idle 1 sec]
├─18732 /usr/local/zabbix/sbin/zabbix_server: history poller #4 [got 0 values in 0.000140 sec, idle 1 sec]
├─18733 /usr/local/zabbix/sbin/zabbix_server: history poller #5 [got 0 values in 0.000150 sec, idle 1 sec]
└─18734 /usr/local/zabbix/sbin/zabbix_server: availability manager #1 [queued 0, processed 0 values, idle 5.005236 sec during 5.005267 sec]
复制代码
部署 Zabbix Web
拷贝前端文件
Zabbix 前端是 PHP 编写的,所以必须运行在支持 PHP 的 Web 服务器上,使用 Apache HTTP 作为 Web 服务器。
建议使用子目录替代 HTML 根目录。可以使用下列命令,以创建一个子目录并复制 Zabbix 的前端文件到这个目录下。
mkdir -p /var/www/html/zabbix
cp -a zabbix-5.4.4/ui/* /var/www/html/zabbix/
复制代码
配置 PHP 文件
编辑 /var/www/html/zabbix/conf/zabbix.conf.php 文件:
<?php
//MySQL 连接信息
$DB['TYPE'] = 'MYSQL';
$DB['SERVER'] = '11.17.6.81';
$DB['PORT'] = '4442';
$DB['DATABASE'] = 'acpzabbixdb';
$DB['USER'] = 'acpzabbixdb';
$DB['PASSWORD'] = 'yourpassword';
// Schema name. Used for PostgreSQL.
$DB['SCHEMA'] = '';
// Used for TLS connection.
$DB['ENCRYPTION'] = false;
$DB['KEY_FILE'] = '';
$DB['CERT_FILE'] = '';
$DB['CA_FILE'] = '';
$DB['VERIFY_HOST'] = false;
$DB['CIPHER_LIST'] = '';
// Vault configuration. Used if database credentials are stored in Vault secrets manager.
$DB['VAULT_URL'] = '';
$DB['VAULT_DB_PATH'] = '';
$DB['VAULT_TOKEN'] = '';
// Use IEEE754 compatible value range for 64-bit Numeric (float) history values.
// This option is enabled by default for new Zabbix installations.
// For upgraded installations, please read database upgrade notes before enabling this option.
$DB['DOUBLE_IEEE754'] = true;
#Zabbix Server 信息
$ZBX_SERVER = 'localhost';
$ZBX_SERVER_PORT = '10051';
$ZBX_SERVER_NAME = 'ACP-ZABBIX-SERVER-1';
$IMAGE_FORMAT_DEFAULT = IMAGE_FORMAT_PNG;
复制代码
Zabbix Web 备机部署的配置以及步骤和主机的一样,只是修改 /var/www/html/zabbix/conf/zabbix.conf.php 为
$ZBX_SERVER_NAME = 'ACP-ZABBIX-SERVER-2';
复制代码
便于我们识别主机和备机。
启动 Apache HTTP 服务,设置开机自动启动
systemctl start httpd
systemctl enable httpd
复制代码
查看 HTTP 服务状态,running 表示正常运行:
root@ydt-net-zabbix1:/usr/local/zabbix/sbin #systemctl status httpd
● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
Active: active (running) since Mon 2021-09-13 11:05:30 CST; 39min ago
Docs: man:httpd(8)
man:apachectl(8)
Main PID: 16648 (httpd)
Status: "Total requests: 781; Current requests/sec: 0.3; Current traffic: 716 B/sec"
CGroup: /system.slice/httpd.service
├─16648 /usr/sbin/httpd -DFOREGROUND
├─16649 /usr/sbin/httpd -DFOREGROUND
├─16651 /usr/sbin/httpd -DFOREGROUND
├─16741 /usr/sbin/httpd -DFOREGROUND
├─16749 /usr/sbin/httpd -DFOREGROUND
├─16751 /usr/sbin/httpd -DFOREGROUND
├─16752 /usr/sbin/httpd -DFOREGROUND
├─16879 /usr/sbin/httpd -DFOREGROUND
├─17012 /usr/sbin/httpd -DFOREGROUND
├─17209 /usr/sbin/httpd -DFOREGROUND
└─18772 /usr/sbin/httpd -DFOREGROUND
复制代码
浏览器输入 http://11.8.38.70/zabbix 访问 Zabbix Web 界面。默认用户名 Admin,密码 zabbix 。
部署 Keepalived
下载并解压安装包
wget https://www.keepalived.org/software/keepalived-2.2.4.tar.gz
tar -xzvf keepalived-2.2.4.tar.gz
复制代码
安装 Keepalived
mkdir /usr/local/keepalived
mkdir /etc/keepalived
cd keepalived-2.2.4
./configure --prefix=/usr/local/keepalived
make && make install
复制代码
Keepalived 配置文件
主 Zabbix Keepalived 配置
编辑 /etc/keepalived/keepalived.conf 文件:
global_defs {
router_id acp_zabbix_server # 负载均衡标识,在局域网内应该是唯一的
}
vrrp_script check_zabbix { # 配置虚拟脚本
script "/etc/keepalived/check_zabbix.sh" # 执行脚本,检查 zabbix 服务是否存活
interval 3 # 脚本执行间隔:秒
}
# vrrp_instance
vrrp_instance v_zabbix {
state MASTER # 指定该 keepalived 节点的初始状态(MASTER|BACKUP)
interface eth0 # VRRP 实例绑定的网口,用于发送 VRRP 包
virtual_router_id 200 # 路由 ID,范围是 0-255,主备都一样
priority 100 # 指定优先级,优先级高的将成为 MASTER
advert_int 1 # 指定发送 VRRP 广播的间隔。单位是秒
authentication { # 身份验证
auth_type PASS # 指定认证方式
auth_pass 123456 # 指定认证所使用的密码 ,主备都一样
}
track_script { # 调用"vrrp_script"的脚本
check_zabbix # 增加一个跟踪脚本到网口上
}
virtual_ipaddress { # 虚拟 IP
11.8.38.208/24
}
}
复制代码
编辑 /etc/keepalived/check_zabbix.sh,设置主 Zabbix 健康检查脚本,当主 Zabbix 服务状态异常时,切换虚拟 IP 到备 Zabbix 上。
#!/bin/bash
#检查 Zabbix Server 服务
systemctl status zabbix-server &>/dev/null
if [ $? -ne 0 ];then
echo -e "`date "+%F %H:%M:%S"` 主机名: `hostname` Zabbix Server 服务异常,keepalived 切换" >> /usr/local/zabbix/logs/check_zabbix.log
exit 1
else
#检查 Zabbix Web 服务
systemctl status httpd &>/dev/null
if [ $? -ne 0 ];then
echo -e "`date "+%F %H:%M:%S"` 主机名: `hostname` Zabbix Web 服务异常,keepalived 切换" >> /usr/local/zabbix/logs/check_zabbix.log
exit 1
else
exit 0
fi
exit 0
fi
复制代码
为脚本赋予可执行权限:
chmod +x /etc/keepalived/check_zabbix.sh
复制代码
备 Zabbix Keepalived 配置
编辑 /etc/keepalived/keepalived.conf 文件:
global_defs {
router_id acp_zabbix_server # 负载均衡标识,在局域网内应该是唯一的
}
# vrrp_instance
vrrp_instance v_zabbix {
state BACKUP # 指定该 keepalived 节点的初始状态(MASTER|BACKUP)
interface eth0 # VRRP 实例绑定的网口,用于发送 VRRP 包
virtual_router_id 200 # 路由ID,范围是0-255,主备都一样
priority 90 # 指定优先级,优先级高的将成为 MASTER
advert_int 1 # 指定发送VRRP广播的间隔。单位是秒
authentication { # 身份验证
auth_type PASS # 指定认证方式
auth_pass 123456 # 指定认证所使用的密码 ,主备都一样
}
notify_master /etc/keepalived/notify_zabbix.sh # 转换成 master 时,执行的脚本
virtual_ipaddress {
11.8.38.208/24
}
}
复制代码
编辑 /etc/keepalived/notify_zabbix.sh,当 Zabbix 发送主备切换时,发送告警通知。
#!/bin/bash
echo -e "`date "+%F %H:%M:%S"` Zabbix 发生主备切换" >> /usr/local/zabbix/logs/notify_zabbix.log
复制代码
为脚本赋予可执行权限:
chmod +x /etc/keepalived/notify_zabbix.sh
复制代码
启动 Keepalived,并设置开机自动启动。
systemctl enable keepalived
systemctl start keepalived
复制代码
高可用验证
浏览器访问 Zabbix Web,可以看到此时访问的是 ACP-ZABBIX-SERVER-1。
现在 keepalived 虚拟 IP 在 ydt-net-zabbix1 服务器上。
root@ydt-net-zabbix1:/etc/keepalived #ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000
link/ether 28:6e:d4:88:e3:33 brd ff:ff:ff:ff:ff:ff
inet 11.8.38.70/24 brd 11.8.38.255 scope global eth0
valid_lft forever preferred_lft forever
#虚拟 IP
inet 11.8.38.208/24 scope global secondary eth0
valid_lft forever preferred_lft forever
inet6 fe80::2a6e:d4ff:fe88:e333/64 scope link
valid_lft forever preferred_lft forever
复制代码
停止 ydt-net-zabbix1 上的 Zabbix Server 服务,模拟故障:
systemctl stop zabbix-server
复制代码
查看 keepalived 状态,显示已经移除了本机的虚拟 IP。
root@ydt-net-zabbix1:/etc/keepalived #systemctl status keepalived.service
● keepalived.service - LVS and VRRP High Availability Monitor
Loaded: loaded (/usr/lib/systemd/system/keepalived.service; enabled; vendor preset: disabled)
Active: active (running) since Mon 2021-09-13 14:17:29 CST; 1min 47s ago
Docs: man:keepalived(8)
man:keepalived.conf(5)
man:genhash(1)
https://keepalived.org
Process: 52720 ExecStart=/usr/local/keepalived/sbin/keepalived $KEEPALIVED_OPTIONS (code=exited, status=0/SUCCESS)
Main PID: 52721 (keepalived)
CGroup: /system.slice/keepalived.service
├─52721 /usr/local/keepalived/sbin/keepalived -D
└─52722 /usr/local/keepalived/sbin/keepalived -D
Sep 13 14:17:38 ydt-net-zabbix1 Keepalived_vrrp[52722]: Sending gratuitous ARP on eth0 for 11.8.38.208
Sep 13 14:17:38 ydt-net-zabbix1 Keepalived_vrrp[52722]: Sending gratuitous ARP on eth0 for 11.8.38.208
Sep 13 14:17:38 ydt-net-zabbix1 Keepalived_vrrp[52722]: Sending gratuitous ARP on eth0 for 11.8.38.208
Sep 13 14:17:38 ydt-net-zabbix1 Keepalived_vrrp[52722]: Sending gratuitous ARP on eth0 for 11.8.38.208
Sep 13 14:17:38 ydt-net-zabbix1 Keepalived_vrrp[52722]: Sending gratuitous ARP on eth0 for 11.8.38.208
Sep 13 14:19:08 ydt-net-zabbix1 Keepalived_vrrp[52722]: Script `check_zabbix` now returning 1
Sep 13 14:19:08 ydt-net-zabbix1 Keepalived_vrrp[52722]: VRRP_Script(check_zabbix) failed (exited with status 1)
Sep 13 14:19:08 ydt-net-zabbix1 Keepalived_vrrp[52722]: (v_zabbix) Entering FAULT STATE
Sep 13 14:19:08 ydt-net-zabbix1 Keepalived_vrrp[52722]: (v_zabbix) sent 0 priority
Sep 13 14:19:08 ydt-net-zabbix1 Keepalived_vrrp[52722]: (v_zabbix) removing VIPs.
复制代码
此时虚拟 IP 已经偏移到 ydt-net-zabbix2 上了。
root@ydt-net-zabbix2:/etc/keepalived #ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000
link/ether 28:6e:d4:88:e3:34 brd ff:ff:ff:ff:ff:ff
inet 11.8.38.100/24 brd 11.8.38.255 scope global eth0
valid_lft forever preferred_lft forever
inet 11.8.38.208/24 scope global secondary eth0
valid_lft forever preferred_lft forever
inet6 fe80::2a6e:d4ff:fe88:e334/64 scope link
valid_lft forever preferred_lft forever
复制代码
浏览器刷新页面,可以看到此时访问的是 ACP-ZABBIX-SERVER-2。
部署 Zabbix Agent
Zabbix Agent 用于收集服务器的监控数据(CPU,内存等等)发送给 Zabbix Server,在部署 Zabbix Server 的服务器上部署 Zabbix Agent 监控自己。
Zabbix Agent 配置文件
编辑 /usr/local/zabbix/etc/zabbix_agentd.conf 文件:
#Pid 文件目录
PidFile=/usr/local/zabbix/zabbix_agentd.pid
#Zabbix Agent 日志目录
LogFile=/usr/local/zabbix/logs/zabbix_agentd.log
#允许所有地址访问
Server=0.0.0.0/0
#Zabbix Server 地址,由于Zabbix Server 服务器和 Zabbix Agent 在一台机器上,因此用 127.0.0.1 通信即可
ServerActive=127.0.0.1
Hostname=Zabbix server
复制代码
配置 Zabbix Agent 系统服务
编辑 /usr/lib/systemd/system/zabbix-agentd.service 文件:
[Unit]
Description=Zabbix Agent
After=syslog.target
After=network.target
[Service]
User=zabbix
Environment="CONFFILE=/usr/local/zabbix/etc/zabbix_agentd.conf"
EnvironmentFile=-/etc/sysconfig/zabbix-agent
Type=forking
Restart=on-failure
PIDFile=zabbix_agentd.pid
KillMode=control-group
ExecStart=/usr/local/zabbix/sbin/zabbix_agentd -c $CONFFILE
ExecStop=/bin/kill -SIGTERM $MAINPID
RestartSec=10s
[Install]
WantedBy=multi-user.target
复制代码
启动 Zabbix Server,并设置开机自动启动。
systemctl enable zabbix-agentd.service
systemctl start zabbix-agentd.service
复制代码
查看 Zabbix Agent 主机信息:
参考资料
欢迎关注
评论