zabbix
官网:https://www.zabbix.com/cn
关于zabbix相关描述可以上zabbix官网查看
部署架构
仅供参考
zabbix架构
基本配置
配置主机ip
[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-ens33
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens33
UUID=416c1165-4bcb-4fb6-9a47-a97ead937b97
DEVICE=ens33
ONBOOT=yes
IPADDR=10.0.54.60
NETMASK=255.255.255.0
GATEWAY=10.0.54.2
DNS1=8.8.8.8
DNS2=114.114.114.114
[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-ens37
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
NAME=ens37
DEVICE=ens37
ONBOOT=yes
IPADDR=192.168.54.60
NETMASK=255.255.255.0
修改主机名
[root@localhost ~]# hostnamectl set-hostname zabbixzh54 && bash
关闭防火墙与selinux
[root@zabbixzh54 ~]# systemctl stop firewalld && systemctl enable firewalld
安装remi源
里面包含php的多个版本的源
https://rpms.remirepo.net/enterprise/remi-release-7.rpm
[root@zabbixzh54 ~]# rpm -ivh https://rpms.remirepo.net/enterprise/remi-release-7.9.rpm
出现如下错误,后面加--force --nodeps
warning: /var/tmp/rpm-tmp.O8ZvUZ: Header V4 DSA/SHA1 Signature, key ID 00f97f56: NOKEY
error: Failed dependencies:
epel-release = 7 is needed by remi-release-7.9-4.el7.remi.noarch
安装epel源
#配置阿里云yum源
[root@zabbixzh54 ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
#安装epel-release源
[root@zabbixzh54 ~]# yum install -y epel-release
部署LAMP架构
安装apache
[root@zabbixzh54 ~]# yum install -y httpd
安装php74
[root@zabbixzh54 ~]# yum install -y php-fpm php74-php php74-php-fpm php74-php-cli php74-php-common php74-php-devel php74-php-gd php74-php-pdo php74-php-mysql php74-php-mbstring php74-php-bcmath php74-php-xml php74-php-pecl-redis php74-php-process php74-php-intl php74-php-xmlrpc php74-php-soap php74-php-ldap php74-php-opcache
配置mariadb10.8的安装源
[root@zabbixzh54 ~]# vim /etc/yum.repos.d/mariadb.repo
# MariaDB 10.8 CentOS repository list - created 2022-12-26 07:55 UTC
# https://mariadb.org/download/
[mariadb]
name = MariaDB
baseurl = https://mirrors.aliyun.com/mariadb/yum/10.8/centos7-amd64
gpgkey=https://mirrors.aliyun.com/mariadb/yum/RPM-GPG-KEY-MariaDB
gpgcheck=1
安装mariadb
[root@zabbixzh54 ~]# yum install -y MariaDB-server Mariadb-client
启动httpd、mariadb、php-fpm
[root@zabbixzh54 ~]# systemctl start httpd mariadb php-fpm && systemctl enable httpd mariadb php-fpm
查看服务状态
[root@zabbixzh54 ~]# systemctl status httpd mariadb php-fpm
初始化mariadb数据库密码
[root@zabbixzh54 ~]# mysqladmin -uroot password 123456
修改mariadb用户root本地登录密码
[root@zabbixzh54 ~]# mysql
MariaDB [(none)]>alter user 'root'@'localhost' identified by "123456"
测试登录
[root@zabbixzh54 ~]# mysql -uroot -p123456
测试php网页
[root@zabbixzh54 ~]# echo "<?php phpinfo()?>" > /var/www/html/phpinfo.php
访问测试 http://192.168.54.60/phpinfo.php
安装部署Z;abbix Server
下载zabbix源码包
下载好上传到服务器
[root@zabbixzh54 ~]# ls
anaconda-ks.cfg zabbix-6.0.8.tar.gz
将压缩包解压
[root@zabbixzh54 ~]# tar -zxf zabbix-6.0.8.tar.gz
[root@zabbixzh54 ~]# ls
anaconda-ks.cfg zabbix-6.0.8 zabbix-6.0.8.tar.gz
创建安装目录,并将解压的文件移动到该目录
[root@zabbixzh54 ~]# mkdir /usr/local/zabbix
[root@zabbixzh54 ~]# mv -f zabbix-6.0.8/* /usr/local/zabbix/
创建zabbix系统用户和组
[root@zabbixzh54 ~]# groupadd --system zabbix
[root@zabbixzh54 ~]# useradd --system -g zabbix -d /usr/lib/zabbix -s /sbin/nologin -c "Zabbix Monitoring System" zabbix
创建zabbix数据库用户和zabbix数据库
[root@zabbixzh54 ~]# mysql -uroot -p123456
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 6
Server version: 10.8.6-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> create database zabbix character set utf8mb4 collate utf8mb4_bin;
Query OK, 1 row affected (0.000 sec)
MariaDB [(none)]> create user zabbix@localhost identified by "123456";
Query OK, 0 rows affected (0.001 sec)
配置数据库zabbix用户权限
MariaDB [(none)]> grant all privileges on zabbix.* to zabbix@localhost;
Query OK, 0 rows affected (0.001 sec)
编译安装zabbix
安装支持zabbix允许需要的软件
可以看到没有这个包libecent-devel
这里上传一个libecent-devel包进行安装
[root@zabbixzh54 ~]# yum install gcc mysql-devel libecent-devel libcurl-devel libxml2-devel libssh2-devel OpenIPMI-devel net-snmp-devel go java-devel -y
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* epel: mirror.01link.hk
* extras: mirrors.aliyun.com
* remi-safe: mirrors.tuna.tsinghua.edu.cn
* updates: mirrors.aliyun.com
Package gcc-4.8.5-44.el7.x86_64 already installed and latest version
Package MariaDB-devel-10.8.6-1.el7.centos.x86_64 already installed and latest version
No package libecent-devel available.
Package libcurl-devel-7.29.0-59.el7_9.1.x86_64 already installed and latest version
Package libxml2-devel-2.9.1-6.el7_9.6.x86_64 already installed and latest version
Package libssh2-devel-1.8.0-4.el7.x86_64 already installed and latest version
Package OpenIPMI-devel-2.0.27-1.el7.x86_64 already installed and latest version
Package 1:net-snmp-devel-5.7.2-49.el7_9.2.x86_64 already installed and latest version
Package golang-1.18.4-1.el7.x86_64 already installed and latest version
Package 1:java-1.8.0-openjdk-devel-1.8.0.352.b08-2.el7_9.x86_64 already installed and latest version
Nothing to do
[root@zabbixzh54 ~]# ls
anaconda-ks.cfg zabbix-6.0.8
libevent-devel-2.0.21-4.el7.x86_64.rpm zabbix-6.0.8.tar.gz
[root@zabbixzh54 ~]# yum install -y libevent-devel-2.0.21-4.el7.x86_64.rpm
安装zabbix
[root@zabbixzh54 zabbix]# cd /usr/local/zabbix/
[root@zabbixzh54 zabbix]# ./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2 --with-openipmi
[root@zabbixzh54 zabbix]# make install
将zabbix数据库导入到mariadb
[root@zabbixzh54 zabbix]# cd database/mysql/
[root@zabbixzh54 mysql]# ls
data.sql history_pk_prepare.sql Makefile Makefile.in
double.sql images.sql Makefile.am schema.sql
[root@zabbixzh54 mysql]# mysql -uroot -p123456 zabbix< schema.sql
[root@zabbixzh54 mysql]# mysql -uroot -p123456 zabbix< images.sql
[root@zabbixzh54 mysql]# mysql -uroot -p123456 zabbix< data.sql
修改zabbix server配置文件
[root@zabbixzh54 zabbix]# vim /usr/local/zabbix/etc/zabbix_server.conf
##修改相应的数据名称和数据库用户密码,我这里创建的数据库和用户都和配置的一样就不修改了,只修改了密码
DBPassword=123456
将zabbix门户UI复制到apache根目录
[root@zabbixzh54 mysql]# cd ../../ui
[root@zabbixzh54 ui]# cp -rf * /var/www/html/
查看是否移动成功
[root@zabbixzh54 ui]# ls /var/www/html/
actionconf.php graphs.php local
api_jsonrpc.php history.php locale
app host_discovery.php maintenance.php
assets hostgroups.php map.php
audio hostinventoriesoverview.php modules
auditacts.php hostinventories.php phpinfo.php
browserwarning.php host_prototypes.php report2.php
chart2.php httpconf.php report4.php
chart3.php httpdetails.php robots.txt
chart4.php image.php setup.php
chart6.php imgstore.php sysmap.php
chart7.php include sysmaps.php
chart.php index_http.php templates.php
composer.json index.php toptriggers.php
composer.lock index_sso.php tr_events.php
conf items.php trigger_prototypes.php
data js triggers.php
disc_prototypes.php jsLoader.php vendor
favicon.ico jsrpc.php zabbix.php
启动zabbix server服务
[root@zabbixzh54 ui]# cd ../
[root@zabbixzh54 zabbix]# ./sbin/zabbix_server
查看zabbix server相关服务是否运行
[root@zabbixzh54 zabbix]# ss -anp | grep zabbix
u_str LISTEN 0 128 /tmp/zabbix_server_rtc.sock 88764 * 0 users:(("zabbix_server",pid=61773,fd=4))
u_str ESTAB 0 0 * 88765 * 88766 users:(("zabbix_server",pid=61773,fd=6))
u_str ESTAB 0 0 * 88766 * 88765 users:(("zabbix_server",pid=61773,fd=7))
访问网页进行安装
http://192.168.54.60
出现如下错误:
解决方案:
[root@zabbixzh54 zabbix]# vim /etc/opt/remi/php74/php.ini
##修改相应的key值
post_max_size = 16M
max_execution_time = 300
max_input_time = 300
##重启php-fpm和httpd
[root@zabbixzh54 zabbix]# systemctl restart httpd php-fpm
问题解决,重新进入网页刷新
出现如下问题:
解决方案:
[root@zabbixzh54 zabbix]# cd
[root@zabbixzh54 ~]# ls
anaconda-ks.cfg libevent-devel-2.0.21-4.el7.x86_64.rpm zabbix-6.0.8 zabbix-6.0.8.tar.gz zabbix.conf.php
[root@zabbixzh54 ~]# cp zabbix.conf.php /var/www/html/conf/zabbix.conf.php
问题解决刷新页面
登录zabbix
默认用户Admin 密码zabbix
安装部署Zabbix agent
server本机部署agent
Zabbix服务器运行Zabbix agent
[root@zabbixzh54 ~]# cd /usr/local/zabbix/sbin/
[root@zabbixzh54 sbin]# ./zabbix_agentd
查看Zabbix agent服务是否启动
[root@zabbixzh54 sbin]# ss -anp | grep zabbix_agent
tcp LISTEN 0 128 *:10050 *:* users:(("zabbix_agentd",pid=74376,fd=4),("zabbix_agentd",pid=74375,fd=4),("zabbix_agentd",pid=74374,fd=4),("zabbix_agentd",pid=74373,fd=4),("zabbix_agentd",pid=74372,fd=4),("zabbix_agentd",pid=74371,fd=4))
tcp LISTEN 0 128 [::]:10050 [::]:* users:(("zabbix_agentd",pid=74376,fd=5),("zabbix_agentd",pid=74375,fd=5),("zabbix_agentd",pid=74374,fd=5),("zabbix_agentd",pid=74373,fd=5),("zabbix_agentd",pid=74372,fd=5),("zabbix_agentd",pid=74371,fd=5))
目标主机安装agent与配置
准备一个高可用集群里面包含Haproxy,keepalived,apache,mariadb服务器
安装agent过程都一样,文档记录了一台服务器的过程
在目标主机安装zabbix源
将zabbix源上传到各各服务器上
[root@hamasterzh54 ~]# ls
anaconda-ks.cfg zabbix-release-6.0-4.el7.noarch.rpm
rpm安装zabbix源
[root@hamasterzh54 ~]# rpm -ivh zabbix-release-6.0-4.el7.noarch.rpm
warning: zabbix-release-6.0-4.el7.noarch.rpm: Header V4 RSA/SHA512 Signature, key ID a14fe591: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:zabbix-release-6.0-4.el7 ################################# [100%]
将zabbix源地址替换成阿里镜像仓库地址
[root@web1 ~]# sed -i 's#repo.zabbix.com#mirrors.aliyun.com/zabbix#g' /etc/yum.repos.d/zabbix*
更新yum缓存
[root@hamasterzh54 ~]# yum makecache
Loaded plugins: fastestmirror
Determining fastest mirrors
zabbix | 2.9 kB 00:00
zabbix-agent2-plugins | 2.9 kB 00:00
zabbix-non-supported | 2.9 kB 00:00
(1/9): zabbix/x86_64/filelists_db | 31 kB 00:00
(2/9): zabbix/x86_64/primary_db | 78 kB 00:00
(3/9): zabbix-agent2-plugins/x86_64/filelists_db | 1.5 kB 00:00
(4/9): zabbix-agent2-plugins/x86_64/primary_db | 2.9 kB 00:00
(5/9): zabbix/x86_64/other_db | 191 kB 00:00
(6/9): zabbix-agent2-plugins/x86_64/other_db | 1.2 kB 00:00
(7/9): zabbix-non-supported/x86_64/primary_db | 3.7 kB 00:00
(8/9): zabbix-non-supported/x86_64/other_db | 3.3 kB 00:00
(9/9): zabbix-non-supported/x86_64/filelists_db | 1.7 kB 00:00
Metadata Cache Created
安装zabbix-agent
[root@hamasterzh54 ~]# yum install -y zabbix-agent
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Package zabbix-agent-6.0.12-release1.el7.x86_64 already installed and latest version
Nothing to do
修改zabbix-agent配置
使其连接zabbix server
[root@hamasterzh54 ~]# vim /etc/zabbix/zabbix_agentd.conf
Server=192.168.54.60 #zabbix server主机ip
ServerActive=192.168.54.60 #zabbix server主机ip
Hostname=Haproxy_keepalived_master #在zabbix server服务器web界面显示的主机名
启动zabbix-agent并设置开机自启
[root@hamasterzh54 ~]# systemctl start zabbix-agent && systemctl enable zabbix-agent
查看相应的端口是否启动成功
[root@hamasterzh54 ~]# ss -anp | grep zabbix
tcp LISTEN 0 128 *:10050 *:* users:(("zabbix_agentd",pid=16070,fd=4),("zabbix_agentd",pid=16069,fd=4),("zabbix_agentd",pid=16068,fd=4),("zabbix_agentd",pid=16067,fd=4),("zabbix_agentd",pid=16066,fd=4),("zabbix_agentd",pid=16065,fd=4))
tcp LISTEN 0 128 [::]:10050 [::]:* users:(("zabbix_agentd",pid=16070,fd=5),("zabbix_agentd",pid=16069,fd=5),("zabbix_agentd",pid=16068,fd=5),("zabbix_agentd",pid=16067,fd=5),("zabbix_agentd",pid=16066,fd=5),("zabbix_agentd",pid=16065,fd=5))
zabbix添加监控
添加主机群组
zabbix server添加主机
进入配置创建主机
根据相应的数据进行修改,然后点击添加
其他主机以此类推,这里就不截图了
可以看到有7个可用了
添加模板
添加监控80端口模板
创建监控项
创建触发器
添加图形
添加监控3306端口模板
配置监控项
添加触发器
添加图形
添加检测keepalived主节点是否异常模板
ip a show ens33 | grep 10.0.54.100 | wc -l 如果为0 则异常,1则正常
修改zabbix-agent配置文件
[root@hamasterzh54 ~]# vim /opt/vip.sh
#!bin/bash
if [ "`ip a show ens33 | grep 10.0.54.100|wc -l`" -eq "1" ]
then
echo 1
else
echo 0
fi
[root@hamasterzh54 ~]# echo "UserParameter=keepalived.status.activity,/opt/vip.sh" /etc/zabbix/zabbix_agentd.conf
[root@hamasterzh54 ~]# systemctl restart zabbix-agent
mariadb节点上的keepalived也一样添加
[root@mariadb1_zh54 ~]# vim /opt/vip.sh
#!bin/bash
if [ "`ip a show ens37 | grep 192.168.54.4|wc -l`" -eq "1" ]
then
echo 1
else
echo 0
fi
[root@mariadb1_zh54 ~]# echo "UserParameter=keepalived.status.activity,/opt/vip.sh" /etc/zabbix/zabbix_agentd.conf
[root@mariadb1_zh54 ~]# systemctl restart zabbix-agent
测试键值是否正常
[root@zabbixzh54 bin]# ./zabbix_get -s 192.168.54.1 -p 10050 -k "keepalived.status.activity"
1
[root@zabbixzh54 bin]# ./zabbix_get -s 192.168.54.31 -p 10050 -k "keepalived.status.activity"
1
在zabbix web中添加此监控模板
添加监控项
配置触发器
添加图形
将模板应用在需要监控80端口和需要监控3306端口的主机上
在web1,web2,Haproxy1,Haproxy2,mariadb1,mariadb2添加模板
这里只演示在web1上添加
选择要添加模板的主机
这里将所有的监控80端口和监控3306端口模板都添加上了
查看图形数据
将keepalived自定义模板应用在keepalived master节点上
mariadb_master节点添加这里就省略了一样的操作
查看图形数据
可以看到有数据,自定义监控成功
现将网卡关闭进行测试
可以看到检测到了失败
监控就简单弄了,有点多
配置邮箱告警
这里使用的126邮箱
开启SMTP服务
新增授权
等会需要用到此网址
CMZKTZRRCCLOVRKN
添加报警类型
测试成功
解决web乱码
可以看到会乱码
将window的字体上传到zabbix服务器
ip
[root@zabbixzh54 ~]# ls
anaconda-ks.cfg SIMKAI.TTF libevent-devel-2.0.21-4.el7.x86_64.rpm zabbix-6.0.8 zabbix-6.0.8.tar.gz zabbix.conf.php
进入字体目录
[root@zabbixzh54 fonts]# cd /var/www/html/assets/fonts
将字体移动到web页面存放字体目录
[root@zabbixzh54 fonts]# mv /root/ARIALN.TTF ./
[root@zabbixzh54 fonts]# ls
SIMKAI.TTF DejaVuSans.ttf
将原来的字体备份
[root@zabbixzh54 fonts]# mv DejaVuSans.ttf{,.bak}
重命名上传的字体
[root@zabbixzh54 fonts]# mv SIMKAI.TTF DejaVuSans.ttf
文章评论