Zabbix官网:宏时数据-Zabbix中国
Zabbix是一个基于WEB界面的提供分布式系统监控以及网络监控功能的企业级开源监控套件
Zabbix主要功能
1:主机的性能监控
2:网络设备性能监控
3:数据库性能监控
4:多种告警方式(邮件、钉钉)
5:详细报表图表绘制
Zabbix监控对象
1:Linux、Windows等主机系统
2:路由器、交换机等网络设备
Zabbix特性
1:数据收集
2:灵活的阈值定义
3:高级告警配置
4:实时绘图
5:扩展的图形化显示
6:历史数据存储
7:网络自动发现
8:二进制守护进程
Zabbix主要组件
1:Zabbix Server(服务端)
2:服务端守护进程,能够主动/被动获取数据
3:Zabbix Agent(代理)
4:客户端守护进程,此进程收集客户端数据
5:例如cpu负载、内存、硬盘使用情况等
6:Zabbix Proxy(中继(桥接的作用))(中转站,搜集监控的服务器少可以不需要,需要收集架空的服务器很多,可以加一个中转站)
7:代理守护进程,功能类似Server
8:它只是一个中转站,需要把收集到的数据提交/被提交到Server
Zabbix4.3的版本开始要求php的版本必须是7.0的版本;
Zabbix6.4的版本开始要求php的版本必须是8.0的版本;
yum install -y --enablerepo=remi --enablerepo=remi-php74 mod_phpphp-gd* php php-opcache php-mbstring php-mysqlnd php-phpunit-PHPUnit php-pecl-xdebug php-pecl-xhprof php-fpm php-develphp-bcmath php-ldap gcc* libxml2-devel net-snmp net-snmp-devel libevent-develcurl-devel
net-snmp:简短网络管理协议,采集所在设备数据,主要针对路由器
--enablerepo=remi:指定需要安装软件包的仓库(php的仓库)
--enablerepo=remi-php74 (指定仓库中的php的软件包):如果在这里不加--enablerepo选项,需要在后面所有的php的软件包上添加74,如:php74-phpunit-PHPUnit
grant all privileges on zabbix.* tozabbix@'%' identified by 'zabbix';
%不包括localhost
--with-unixODBC:连接数据库的数据源名称为ODBC
--with-zabbix-get:zabbix为我们提供的命令行工具
安装高版本zabbix时注意事项:(zabbix.6.4的版本)
export CFLAGS="-std=gnu99"
执行./configure --enable-server --enable-agent --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2 --with-openipmi 命令前,先执行上面的命令;
zabbix工作模式:
被动模式是server端找agent端
主动模式是agent端主动找server端
一:LNMP环境的搭建(在server主机上)
1:配置yum仓库
rm -rf /etc/yum.repos.d/*
curl -o /etc/yum.repos.d/CentOS-Base.repohttps://mirrors.aliyun.com/repo/Centos-7.repo
yum -y install epel-release yum-utils
yum -y install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
2:安装php74、nginx、mariadb
systemctl stop firewalld
setenforce 0
yum install -y --enablerepo=remi --enablerepo=remi-php74 mod_phpphp-gd* php php-opcache php-mbstring php-mysqlnd php-phpunit-PHPUnit php-pecl-xdebug php-pecl-xhprof php-fpm php-develphp-bcmath php-ldap gcc* libxml2-devel net-snmp net-snmp-devel libevent-develcurl-devel
yum -y install mariadb-server mariadb-develnginx
3:配置nginx
cd /etc/nginx
cp nginx.conf nginx.conf.bak
rm -rf nginx.conf
cp nginx.conf.default nginx.conf
vim nginx.conf
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root /www;
index index.html index.htmindex.php;
}
location ~ \.php$ {
root /www;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi.conf;
}
}
4:启动服务
systemctl start nginx
systemctl enable nginx
systemctl start php-fpm
systemctl enable php-fpm
systemctl start mariadb
systemctl enable mariadb
5:设置数据库密码
[root@localhost ~]# mysqladmin -u root password 'pwd123'
6:测试LNMP环境
[root@localhost ~]# mkdir /www
[root@localhost ~]# vim /www/test.php
$link=mysqli_connect('127.0.0.1','root','pwd123');
if($link) echo "恭喜你,数据库连接成功啦!!";
mysqli_close($link);
?>
################################
二:zabbix的安装与配置(在server主机上)
1:创建zabbix数据库并导入数据
[root@localhost ~]# mysql -uroot -ppwd123
MariaDB [(none)]> create database zabbix character set utf8 collate utf8_bin;
MariaDB [(none)]> CREATE DATABASE zabbix_proxy character set utf8 collate utf8_bin;
MariaDB [(none)]> grant all privileges on zabbix.* to zabbix@'%' identified by 'zabbix';
MariaDB [(none)]> grant all privileges on zabbix.* to zabbix@'localhost' identified by 'zabbix';
MariaDB [(none)]> GRANT ALL PRIVILEGESON zabbix_proxy.* TO 'zabbix'@'localhost' IDENTIFIED BY 'zabbix';
MariaDB [(none)]> GRANT ALL PRIVILEGESON zabbix_proxy.* TO 'zabbix'@'%' IDENTIFIED BY 'zabbix';
[root@localhost ~]# tar zxvf zabbix-5.2.1.tar.gz
[root@localhost ~]# cd zabbix-5.2.1/database/mysql/
[root@localhost mysql]# mysql -uzabbix-pzabbix zabbix [root@localhost mysql]# mysql -uzabbix-pzabbix zabbix [root@localhost mysql]# mysql -uzabbix-pzabbix zabbix
2:源码安装zabbix
[root@localhost ~]# useradd -M -s /sbin/nologin zabbix
[root@localhost mysql]# cd /root/zabbix-5.2.1
[root@localhost zabbix-5.2.1]# ./configure--prefix=/usr/local/zabbix/ --enable-server --enable-agent --with-mysql--with-libcurl --with-libxml2 --with-net-snmp --with-unixODBC --with-zabbix-get
[root@localhost zabbix-5.2.1]# make
[root@localhost zabbix-5.2.1]# make install
[root@localhost zabbix-5.2.1]# ln -s /usr/local/zabbix/sbin/*/usr/local/sbin/
[root@localhost zabbix-5.2.1]# ln -s /usr/local/zabbix/bin/* /usr/local/bin
3:服务控制脚本的优化
[root@localhost zabbix-5.2.1]# cd /root/zabbix-5.2.1/misc/init.d/fedora/core
[root@localhost core]# cp zabbix_agentd /etc/init.d/
[root@localhost core]# cp zabbix_server /etc/init.d/
[root@localhost core]# cd /etc/init.d/
[root@localhost init.d]# vim zabbix_agentd
BASEDIR=/usr/local/zabbix
[root@localhost init.d]# vim zabbix_server
BASEDIR=/usr/local/zabbix
4:修改zabbix服务端参数
[root@localhost conf]# cd /usr/local/zabbix/etc
[root@localhost etc]# vim zabbix_server.conf
LogFile=/tmp/zabbix_server.log
LogFileSize=1024 # 单位M, 47
DBHost=zabbix-db # 数据库主机名,或IP地址
DBName=zabbix # 数据库中库名 94
DBUser=zabbix # 数据库用户名 110
DBPassword=zabbix # 用户密码 118
Timeout=10 ##超时时间,秒 465
CacheSize=256M # 根据内存情况尽量调大 402
HistoryCacheSize=256M # 根据内存情况尽量调大 427
TrendCacheSize=256M
ValueCacheSize=256M
StartTrappers=30
StartPollers=10 # agent端的数量
5:修改zabbix代理端参数
[root@localhost etc]# vim zabbix_agentd.conf
Server=127.0.0.1 ##113
ServerActive=127.0.0.1 ##154
Hostname=Zabbix server ##165
6:拷贝zabbix网站程序到httpd的网站根目录下
[root@localhost ~]# cd zabbix-5.2.1
[root@localhost zabbix-5.2.1]# cd ui
[root@localhost ui]# cp -rf * /www
7:修改php.ini
[root@localhost etc]# vim /etc/php.ini
max_execution_time= 300 ##388行
max_input_time =300 ##398行
date.timezone = Asia/Shanghai ##923行
post_max_size =16M ##694
bcmath.scale = 1 ##1205
8:修改php-fpm
[root@localhost ~]# vim /etc/php-fpm.d/www.conf
user = zabbix
group = zabbix
[root@localhost ~]# chown -R zabbix:zabbix/www
[root@localhost ~]# systemctl restart php-fpm
9:启动zabbix
chkconfig --add zabbix_agentd
chkconfig --add zabbix_server
chkconfig zabbix_agentd on
chkconfig zabbix_server on
systemctl start zabbix_agentd
systemctl enable zabbix_agentd
systemctl enable zabbix_server
10:登录zbbix
默认账号:Admin
默认密码:zabbix
三:安装 Zabbix Agent(在agent主机上)
[root@localhost ~]# hostnamectl set-hostname web01
[root@localhost ~]# bash
[root@web01 ~]# systemctl stop firewalld
[root@web01 ~]# setenforce 0
[root@web01 ~]# rpm -ivh zabbix-agent-5.2.1-1.el7.x86_64.rpm
[root@web01 ~]# vim /etc/zabbix/zabbix_agentd.conf
Server=192.168.10.102 #指向 Proxy 地址 ,也可以直接指向server端
ServerActive=192.168.10.102 #指向 Proxy 地址,也可以直接指向server端
Hostname=web01
#Agent 本地的名称,需要与将来在 Server 端的 Web 页面上的主机名称一致,名称自定义
[root@web01 ~]# systemctl start zabbix-agent
[root@web01 ~]# systemctl enable zabbix-agent
备注:
Server:被动模式,允许指定的服务器连接本机获取采集的数据
ServerActive:此参数为主动模式需要设置的,主动提交采集数据给指定的服务器,此处可以注释掉,如果要开启主动模式,则开启
四:在zabbix server上添加主机
1:添加agent主机
主机列表中的Availability(可用性)列包括了每个接口的主机的可用性指标,如果定义了主机的zabbix agent接口,可以通过ZBX选项了解主机的可用性。
ZBX为灰色代表未建立主机连接,未进行数据的采集
ZBX为绿色代表主机可用,zabbix agent检查成功
ZBX为红色代表主机不可用,zabbix agent检查失败
备注:
使用zabbix agent接口,需要为主机添加zabbix agent的监控模板
解决图像中文乱码:
1:查找zabbix定义字体的php文件
[root@localhost ~]# find / -namedefines.inc.php
/root/zabbix-5.2.1/ui/include/defines.inc.php
/www/include/defines.inc.php
注意:
/www是本案中zabbix的前端位置,不同的安装者,此位置可能不同
2:查看zabbix字体文件中用的字体
[root@localhost ~]# grep"ZBX_FONTPATH" /www/include/defines.inc.php
define('ZBX_FONTPATH', realpath('assets/fonts'));// where to search for font (GD > 2.0.18)
[root@localhost ~]# grep"ZBX_GRAPH_FONT_NAME" /www/include/defines.inc.php
define('ZBX_GRAPH_FONT_NAME', 'DejaVuSans');// font file name
3:查找zabbix的字体文件位置
[root@localhost ~]# find / -nameDejaVuSans.ttf
/root/zabbix-5.2.1/ui/assets/fonts/DejaVuSans.ttf
/usr/share/fonts/dejavu/DejaVuSans.ttf
/www/assets/fonts/DejaVuSans.ttf
4:在windows系统中找一个ttf或ttc格式的字体
位置在C:\Windows\Fonts
5:将选择的字体文件上传到/www/assets/fonts目录下
例如此处选择msyhl.ttc(微软雅黑)
[root@localhost fonts]# ln -snf msyhl.ttcDejaVuSans.ttf
-s --symbolic比较容易,有-s时表示创建软连接,没有-s时,表示创建硬链接
-f --force 强行删除任何已存在的目标文件
-n --no-dereference 把符号连接的目的目录视为一般文件
刷新页面观察效果
配置好需要监控的主机后:
查看监控的图形: