文章目录
- 一:环境准备:
- 二:zabbix概述
- 三:基于LNMP搭建zabbix
- 3.1 创建nginx的repo
- 3.2 yum 安装nginx
- 3.3 安装mariadb
- 3.4 安装php
- 3.5 配置php配置文件以使nginx支持php
- 3.6 配置nginx.conf,使nginx能识别php
- 3.7 配置php.ini
- 3.8 重启一下nginx服务
- 3.9 创建站点
- 3.10 测试php连接数据库
- 3.11 创建数据库的zabbix用户
- 3.12 修改php的测试页,测试zabbix用户连接mysql
- 3.13 出现报错,本地直接测试
- 3.14 登录数据库,删除空用户
- 3.15 再次测试
- 3.16 开始部署zabbix server
- 3.17 出现报错,提示再次尝试,再次安装
- 3.18 导入数据库脚本
- 3.19 修改服务端server配置文件
- 3.20 修改zabbix字体
- 3.21 给zabbix相关权限
- 3.22 开启zabbix服务
- 3.23 查看端口号
- 3.24 重启之前的服务,php-fpm、nginx
- 3.25 访问192.168.247.142/zabbix/
- 3.26 修改nginx配置文件
- 3.27 网页在线安装zabbix
- 3. 28 进入登录界面
- 3.29 设置语言环境
- 四:配置代理端,即被监控服务端
- 五:增加被监控主机
- 六:添加模板
- 七:查看client的服务
- 八:测试zabbix监控
前言:
服务器:
192.168.247.160 client 安装zabbix-agent,被监控
192.168.247.142 server 安装zabbix-server提供监控服务,也可以安装agent监控自己
zabbix是一个高度集成的网络监控套件,通过一个软件包即可提供如下特性
- 数据收集:
1.可用性及性能检测
2.支持SNMP(trapping及polling)、IPMI、JMX监控
3.自定义检测
4.自定义间隔收集数据
5.server/proxy/agents - 灵活的阈值定义
允许灵活的自定义阈值,在zabbix种被称为触发器(trigger),存储在后端数据库中 - 高级告警配置
1.可以自定义告警升级(escalation)、接收者及告警方式
2.告警信息可以配置并允许使用宏(macro)变量
3.通过远程命令实行自动化动作(action) - 实时绘图
通过内置的绘图方法实现监控数据实时绘图 - 扩展的图形化显示
1.允许自定义创建多监控项视图
2.生成网络拓扑(network maps)
3.自定义的面板(screen)和slide shows,并允许在dashboard页面显示
4.生成监控报告 - 历史数据存储
1.数据存储在数据库中
2.历史数据可配置
3.内置数据清理机制 - 配置简单
1.被监控主机通过监控设备方式添加
2.一次配置,终生监控——除非调整或删除
3.监控设备允许使用模板来添加监控 - 模板使用
1.模板中可以添加组监控
2.模板允许集成 - 网络自动发现
1.自动发现网络设备
2.agent自动注册
3.自动发现文件系统、网卡设备、SNMP OID等 - 快速的web接口
1.web前端采用php编写
2.访问无障碍 - zabbix API
zabbix API 提供程序级别的访问接口,第三方程序可以很快接入 - 权限系统
1.安全的权限认证
2.用户可以限制允许维护的列表 - 全特性、agent易扩展
1.在监控目标上部署
2.支持Linux及windows - 二进制守护进程
1.C开发,高性能,低内存消耗
2.易移植 - 具备应对复杂环境情况
通过zabbix proxy 可以非常容易地创建远程监控
①zabbix server
- zabbix server是zabbix 服务端守护进程。zabbix_agentd、zabbix_proxy的数据最终都是提交到server
- 当然并不是所有数据都主动提交给zabbix_server,也有的是server主动去拿数据
②zabbix agent - zabbix_agentd是客户端守护进程,此进程主要用户收集客户端数据,例如CPU负载、内存、硬盘使用情况等
③zabbix proxy - zabbix_proxy是zabbix代理守护进程,功能类似server。不同的是,zabbix_proxy只是一个中转站,他需要把收集到的数据提交或者被提交到Server
proxy也需要数据库,用于分布式监控,zabbix最大监控节点一般为300左右,面对上千级别的集群时,就需要proxy
一:环境准备:
关闭网络管理器
[root@localhost ~]# hostnamectl set-hostname server
[root@localhost ~]# su
[root@server ~]#
[root@server ~]# systemctl stop NetworkManager
[root@server ~]# systemctl disable NetworkManager
Removed symlink /etc/systemd/system/multi-user.target.wants/NetworkManager.service.
Removed symlink /etc/systemd/system/dbus-org.freedesktop.NetworkManager.service.
Removed symlink /etc/systemd/system/dbus-org.freedesktop.nm-dispatcher.service.
[root@server ~]# setenforce 0
setenforce: SELinux is disabled
[root@server ~]# sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config
[root@server ~]# iptables -F
[root@nginx ~]# hostnamectl set-hostname client
[root@nginx ~]# su
[root@client ~]# systemctl stop NetworkManager
[root@client ~]# systemctl disable NetworkManager
Removed symlink /etc/systemd/system/multi-user.target.wants/NetworkManager.service.
Removed symlink /etc/systemd/system/dbus-org.freedesktop.NetworkManager.service.
Removed symlink /etc/systemd/system/dbus-org.freedesktop.nm-dispatcher.service.
[root@client ~]# setenforce 0
[root@client ~]# sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config
[root@client ~]# iptables -F
[root@client ~]#
二:zabbix概述
2.1 查看官网
-
选择中文,确认
-
右上角下载
-
会出现选项,按照选择选好之后,下面就是安装步骤介绍
具体的接下来会做演示
2.2 zabbix与nagios
早几年前流行的监控是nagios
Nagios是一款开源的免费网络监视工具,能有效监控Windows、Linux和Unix的主机状态,交换机路由器等网络设备,打印机等。在系统或服务状态异常时发出邮件或短信报警第一时间通知网站运维人员,在状态恢复后发出正常的邮件或短信通知。
nagios的插件特别多,所以有的工程师会用cacti
Cacti是一套基于PHP,MySQL,SNMP及RRDTool开发的网络流量监测图形分析工具。
cacti的视觉感会更好一点
nagios的功能性会比较全,但是组件很多,麻烦
但自从zabbix的出现,就取代了nagios和cacti
2.3 zzbbix介绍
zabbix是一个基于WEB界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案。
zabbix能监视各种网络参数,保证服务器系统的安全运营;并提供灵活的通知机制以让系统管理员快速定位/解决存在的各种问题。
zabbix由2部分构成,zabbix server与可选组件zabbix agent。
zabbix server可以通过SNMP,zabbix agent,ping,端口监视等方法提供对远程服务器/网络状态的监视,数据收集等功能,它可以运行在Linux,Solaris,HP-UX,AIX,Free BSD,Open BSD,OS X等平台上。
zabbix可以做分布式监控,依赖于proxy
要借助proxy去做分布式
zabbix监控的服务器有一个上限值,300-500,一般做300左右,
zabbix由两个部分构成,zabbix server与可选组件zabbix agent
zabbix agent 用来安装在被监控端
像普罗米修斯监控用来管理K8S
zabbix可以自动发现服务机制
- zabbix可以监控的方向有很多
也可以监控网络设备,防火墙
2.4 zabbix软件包
4.0是用的最稳定版本
5.0 2020年才推出
lts指的是测试
4.4跟4.0没有区别
阿里云平台可以选择postgreSQL
5.0可以支持nginx
4.0其实也可以安装在nginx
这种浏览模式用到的是异步刷新,ajax,把下面的做了一个div块,是前端的一个技术
三:基于LNMP搭建zabbix
php72w-mysql是驱动,让php可以去找mysql进行增删改查
中间也会加一个中间件redis,在与其他组件进行交互时,会增加一个kafka,rabbitmq
client作为被监控端
3.1 创建nginx的repo
[root@server ~]# yum install wget -y
[root@server ~]# wget http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
--2020-05-21 20:43:23-- http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
Resolving nginx.org (nginx.org)... 62.210.92.35, 95.211.80.227, 2001:1af8:4060:a004:21::e3
Connecting to nginx.org (nginx.org)|62.210.92.35|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 4680 (4.6K) [application/x-redhat-package-manager]
Saving to: ‘nginx-release-centos-7-0.el7.ngx.noarch.rpm’
100%[===============================================================================================>] 4,680 2.63KB/s in 1.7s
2020-05-21 20:43:25 (2.63 KB/s) - ‘nginx-release-centos-7-0.el7.ngx.noarch.rpm’ saved [4680/4680]
[root@server ~]# ls
anaconda-ks.cfg nginx-release-centos-7-0.el7.ngx.noarch.rpm
[root@server ~]# vim /etc/yum.conf
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=1
[root@server ~]# cd /var/cache/yum/$basearch/$releasever
[root@server yum]# ls
x86_64
[root@server yum]# cd x86_64/
[root@server x86_64]# ls
7
[root@server x86_64]# cd 7/
[root@server 7]# ls
base docker-ce-stable extras timedhosts timedhosts.txt updates
[root@server 7]# pwd
/var/cache/yum/x86_64/7
手动创建nginx yum安装源
[root@server 7]# vim /etc/yum.repos.d/nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1
[root@server 7]# yum list
3.2 yum 安装nginx
[root@server 7]# yum install nginx -y
Installed:
nginx.x86_64 1:1.18.0-1.el7.ngx
Complete!
[root@server 7]# systemctl start ngginx
Failed to start ngginx.service: Unit not found.
[root@server 7]# systemctl start nginx
[root@server 7]# systemctl enable nginx
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
[root@server 7]# netstat -natp | grep nginx
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 125691/nginx: maste
3.3 安装mariadb
[root@server 7]# yum install mariadb mariadb-server -y
[root@server 7]# systemctl enable mariadb
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
[root@server 7]# systemctl start mariadb
[root@server 7]# netstat -natp | grep 3306
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 128096/mysqld
初始化数据库
[root@server 7]# mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
Enter current password for root (enter for none): //回车
OK, successfully used password, moving on...
Set root password? [Y/n] y
New password: 123123
Re-enter new password: 123132
Password updated successfully!
Reloading privilege tables..
... Success!
Remove anonymous users? [Y/n] n
... skipping.
Disallow root login remotely? [Y/n] n
... skipping.
Remove test database and access to it? [Y/n] n
... skipping.
Reload privilege tables now? [Y/n] y
... Success!
Cleaning up...
Thanks for using MariaDB!
本地验证登录数据库
[root@server 7]# mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 6
Server version: 5.5.65-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)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)
MariaDB [(none)]> quit
Bye
3.4 安装php
[root@server ~]# rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
#或者yum install epel-release -y
Retrieving https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
warning: /var/tmp/rpm-tmp.ooODVn: Header V3 RSA/SHA256 Signature, key ID 352c64e5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:epel-release-7-12 ################################# [100%]
[root@server ~]# ll /etc/yum.repos.d/ #此时增加epel*.repo
-rw-r--r-- 1 root root 1050 Sep 18 2019 epel.repo
-rw-r--r-- 1 root root 1149 Sep 18 2019 epel-testing.repo
[root@server ~]# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
Retrieving https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
warning: /var/tmp/rpm-tmp.CrKvHr: Header V4 RSA/SHA1 Signature, key ID 62e74ca5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:webtatic-release-7-3 ################################# [100%]
[root@server ~]# ll /etc/yum.repos.d/ #增加webtatic*.rpeo
-rw-r--r-- 1 root root 963 Oct 9 2014 webtatic-archive.repo
-rw-r--r-- 1 root root 865 Oct 9 2014 webtatic.repo
-rw-r--r-- 1 root root 963 Oct 9 2014 webtatic-testing.repo
php72w php
php72w-devel php的开发工具包
php72w-fpm php的fpm接收动态模块
php72w-gd php的处理图片的扩展库
php72w-mbstring php的扩展多字节
php72w-mysql php连接mysql的组件
[root@server ~]# yum install -y php72w php72w-devel php72w-fpm php72w-gd php72w-mbstring php72w-mysql
查看php版本
[root@server ~]# php -v
PHP 7.2.27 (cli) (built: Jan 26 2020 15:49:49) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
3.5 配置php配置文件以使nginx支持php
[root@server ~]# vim /etc/php-fpm.d/www.conf
8 user = nginx
10 group = nginx
3.6 配置nginx.conf,使nginx能识别php
[root@server ~]# vim /etc/nginx/conf.d/default.conf
8 location / {
9 root /usr/share/nginx/html;
10 index index.html index.htm index.php;
11 }
- 配置php请求被传送到后端的php-fpm模块
默认情况下php模块是被注释的
[root@server ~]# vim /etc/nginx/conf.d/default.conf
30 location ~ \.php$ {
31 root /nginx/html;
32 fastcgi_pass 127.0.0.1:9000;
33 fastcgi_index index.php;
34 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
35 include fastcgi_params;
36 }
#把fastcgi_param种的/scripts改为$document_root
#root 是配置php程序放置服务的根目录站点
3.7 配置php.ini
执行时间是在一个程序执行过程中能等待的多长时间
从zabbix检测到这个服务掉线时,到发送数据给工程师,让工程师知晓,如果时间太短,会在时间结束后,直接把这个进程断掉,防止进程卡死,如果生产环境中的业务很多,占用很多流程,可以适当放宽
接收数据等待时间要一致
[root@server ~]# vim /etc/php.ini
202 short_open_tag = On #支持php短标签
359 expose_php = off #隐藏php版本
####———————以下为zabbix配置要求,优化配置———————
368 max_execution_time = 300 #执行时间
378 max_input_time = 300 #接收数据等待时间
389 memory_limit = 128M #每个脚本占用内存
656 post_max_size = 16M #post数据大小,post 提交数据安全,get提交不安全,get会把数据卸载url上,post可以适当放宽
799 upload_max_filesize = 2M #下载文件大小
800 always_populate_raw_post_data = -1 #这一行添加进去
#可以用$HTTP_RAW_POST_DATA接收post raw data(原始未处理数据)
877 date.timezone = Asia/Shanghai #时区
[root@server ~]# systemctl start php-fpm
[root@server ~]# systemctl enable php-fpm
Created symlink from /etc/systemd/system/multi-user.target.wants/php-fpm.service to /usr/lib/systemd/system/php-fpm.service.
3.8 重启一下nginx服务
[root@server ~]# systemctl restart nginx
3.9 创建站点
[root@server ~]# mkdir -p /nginx/html
[root@server ~]# vim /nginx/html/index.php
<?
phpinfo();
?>
[root@server ~]# netstat -natp | grep fpm
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 48176/php-fpm: mast
如果配置文件中语法有问题,服务时开不了的
3.10 测试php连接数据库
[root@server ~]# vim /nginx/html/index.php
<?php
$link=mysqli_connect('127.0.0.1','root','123123');
if ($link) echo "lianjiechenggong";
else echo "lianjieshibai";
?>
备注:mysql_connect扩展自PHP 5.5.0 起已废弃,改用mysqli或pdo_mysql
connect 是php的函数
刷新一下
3.11 创建数据库的zabbix用户
进入数据库,给zabbix用户权限
为zabbix创建数据库
- collate的作用
对于mysql种那些字符类型的列,如VARCHAR、CHAR、TEXT类型的列,都需要有一个collate类型来告知mysql如何对该列进行排序和比较。collate会影响到order by的语句顺序,会影响到where条件中大于小于号筛选出来的结果
[root@server ~]# mysql -uroot -p
Enter password: 123123
MariaDB [(none)]> create database zabbix character set utf8 collate utf8_bin;
Query OK, 1 row affected (0.01 sec)
MariaDB [(none)]> grant all privileges on *.* to 'zabbix'@'%' identified by 'zabbix123';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
| zabbix |
+--------------------+
5 rows in set (0.00 sec)
3.12 修改php的测试页,测试zabbix用户连接mysql
[root@server ~]# vim /nginx/html/index.php
<?php
$link=mysqli_connect('127.0.0.1','zabbix','zabbix123');
if ($link) echo "lianjiechenggong";
else echo "lianjieshibai";
?>
清空下历史记录
3.13 出现报错,本地直接测试
[root@server ~]# mysql -uzabbix -p
Enter password:
ERROR 1045 (28000): Access denied for user 'zabbix'@'localhost' (using password: YES)
3.14 登录数据库,删除空用户
[root@server ~]# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
MariaDB [(none)]> select user,host from mysql.user
-> ;
+--------+-----------+
| user | host |
+--------+-----------+
| zabbix | % |
| root | 127.0.0.1 |
| root | ::1 |
| | localhost |
| root | localhost |
| | server |
| root | server |
+--------+-----------+
7 rows in set (0.00 sec)
MariaDB [(none)]> drop user ''@localhost
-> ;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> drop user ''@server;
Query OK, 0 rows affected (0.00 sec)
flush privileges;
3.15 再次测试
[root@server ~]# mysql -u zabbix -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 13
Server version: 5.5.65-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)]>
MariaDB [(none)]> use zabbix;
Database changed
MariaDB [zabbix]> show tables
-> ;
Empty set (0.01 sec)
3.16 开始部署zabbix server
[root@server ~]# rpm -Uvh https://repo.zabbix.com/zabbix/4.4/rhel/7/x86_64/zabbix-release-4.4-1.el7.noarch.rpm
Retrieving https://repo.zabbix.com/zabbix/4.4/rhel/7/x86_64/zabbix-release-4.4-1.el7.noarch.rpm
warning: /var/tmp/rpm-tmp.pPAy7B: Header V4 RSA/SHA512 Signature, key ID a14fe591: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:zabbix-release-4.4-1.el7 ################################# [100%]
[root@server ~]# yum list #不适用yum clean all ,因为开启了yum缓存
[root@server ~]# yum install zabbix-server-mysql zabbix-agent zabbix-web-mysql -y
#zabbix-web-mysql在4.4的nginx版本没有提示安装,4.0的zabbix需要安装
Error downloading packages:
zabbix-web-4.4.8-1.el7.noarch: [Errno 256] No more mirrors to try.
zabbix-server-mysql-4.4.8-1.el7.x86_64: [Errno 256] No more mirrors to try.
zabbix-agent-4.4.8-1.el7.x86_64: [Errno 256] No more mirrors to try.
3.17 出现报错,提示再次尝试,再次安装
[root@server ~]# yum install zabbix-server-mysql zabbix-agent zabbix-web-mysql -y
尝试到第二次,只差两个没有安装了
Error downloading packages:
zabbix-web-4.4.8-1.el7.noarch: [Errno 256] No more mirrors to try.
zabbix-server-mysql-4.4.8-1.el7.x86_64: [Errno 256] No more mirrors to try.
#继续重复执行下载任务
Installed:
zabbix-agent.x86_64 0:4.4.8-1.el7 zabbix-server-mysql.x86_64 0:4.4.8-1.el7
zabbix-web-mysql.noarch 0:4.4.8-1.el7
Dependency Installed:
OpenIPMI.x86_64 0:2.0.27-1.el7 OpenIPMI-libs.x86_64 0:2.0.27-1.el7
OpenIPMI-modalias.x86_64 0:2.0.27-1.el7 apr.x86_64 0:1.4.8-5.el7
apr-util.x86_64 0:1.5.2-6.el7 dejavu-fonts-common.noarch 0:2.33-6.el7
dejavu-sans-fonts.noarch 0:2.33-6.el7 fontpackages-filesystem.noarch 0:1.44-8.el7
fping.x86_64 0:3.10-4.el7 httpd.x86_64 0:2.4.6-93.el7.centos
httpd-tools.x86_64 0:2.4.6-93.el7.centos libevent.x86_64 0:2.0.21-4.el7
mailcap.noarch 0:2.1.41-2.el7 net-snmp-libs.x86_64 1:5.7.2-48.el7_8
php72w-bcmath.x86_64 0:7.2.27-1.w7 php72w-ldap.x86_64 0:7.2.27-1.w7
php72w-xml.x86_64 0:7.2.27-1.w7 unixODBC.x86_64 0:2.3.1-14.el7
zabbix-web.noarch 0:4.4.8-1.el7
Complete!
[root@server ~]#
重试了十几次,下载成功
- 下面的是一个安装脚本,仅供参考
#!/bin/bash
#这个是阿里云的源
echo -e "请给出要安装的zabbix版本号,建议使用4.x的版本 \033[31musage:./zabbix_aliyun.sh 4.0|4.4|4.5 \033[0m"
echo "例如要安装4.4版本,在命令行写上 ./zabbix_aliyun.sh 4.4"
if [ -z $1 ];then
exit
fi
VERSION=$1
if [ -f /etc/yum.repos.d/zabbix.repo ];then
rm -rf /etc/repos.d/zabbix.repo
fi
rpm -qa | grep zabbix-release && rpm -e zabbix-release
rpm -Uvh https://mirrors.aliyun.com/zabbix/zabbix/$VERSION/rhel/7/x86_64/zabbix-release-$VERSION-1.el7.noarch.rpm
sed -i "s@zabbix/.*/rhel@zabbix/$VERSION/rhel@g" /etc/yum.repos.d/zabbix.repo
sed -i 's@repo.zabbix.com@mirrors.aliyun.com/zabbix@g' /etc/yum.repos.d/zabbix.repo
[ $? -eq 0 ] && echo "阿里云的zabbix源替换成功" || exit 1
yum clean all
yum makecache fast
下面的源是阿里云的zabbix源
baseurl=https://mirrors.aliyun.com/zabbix/zabbix/4.0/rhel/7/$basearch/
baseurl=https://mirrors.aliyun.com/zabbix/non-supported/rhel/7/$basearch/
3.18 导入数据库脚本
[root@server ~]# cd /etc/zabbix/
[root@server zabbix]# tree .
.
├── web
│ └── maintenance.inc.php
├── zabbix_agentd.conf
├── zabbix_agentd.d
└── zabbix_server.conf
2 directories, 3 files
[root@server zabbix]# zcat /usr/share/doc/zabbix-server-mysql-4.4.8/
AUTHORS ChangeLog COPYING create.sql.gz NEWS README
[root@server zabbix]# zcat /usr/share/doc/zabbix-server-mysql-4.4.8/create.sql.gz | mysql -uzabbix -p zabbix
Enter password:
zact代表不执行解压,直接看
这样就可以解压到内存当中,不占用空间
- 到数据库内查看
[root@server zabbix]# mysql -uzabbix -pzabbix123
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 17
Server version: 5.5.65-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)]> use zabbix;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
MariaDB [zabbix]> show tables
-> ;
+----------------------------+
| Tables_in_zabbix |
+----------------------------+
| acknowledges |
······························
退出数据库
3.19 修改服务端server配置文件
[root@server zabbix]# vim /etc/zabbix/zabbix_server.conf
38 LogFile=/var/log/zabbix/zabbix_server.log
49 LogFileSize=0 #日志容量没有上限
72 PidFile=/var/run/zabbix/zabbix_server.pid
82 SocketDir=/var/run/zabbix
91 DBHost=localhost #开启
100 DBName=zabbix
116 DBUser=zabbix
124 DBPassword=zabbix123 #修改本行
356 SNMPTrapperFile=/var/log/snmptrap/snmptrap.log
473 Timeout=4
516 AlertScriptsPath=/usr/lib/zabbix/alertscripts
527 ExternalScripts=/usr/lib/zabbix/externalscripts
563 LogSlowQueries=3000 #慢日志
慢日志,漫长操作的动作,会被记录到慢日志,记录了执行速度特别慢的SQL语句
3.20 修改zabbix字体
[root@server zabbix]# vim /usr/share/zabbix/include/defines.inc.php
#使用末行模式
:% s /graphfont/kaiti/g
[root@server zabbix]# mkdir fonts
[root@server zabbix]# ll
total 36
drwxr-xr-x 2 root root 6 May 21 23:01 fonts
drwxr-x--- 2 apache apache 33 May 21 22:48 web
-rw-r--r-- 1 root root 13936 Apr 27 18:23 zabbix_agentd.conf
drwxr-xr-x 2 root root 6 Apr 27 18:22 zabbix_agentd.d
-rw-r----- 1 root zabbix 19778 May 21 23:00 zabbix_server.conf
[root@server zabbix]# cd fonts/
[root@server fonts]# ll
total 12440
-rw-r--r-- 1 root root 12736196 May 21 23:04 STKAITI.TTF
[root@server fonts]# pwd
/etc/zabbix/fonts
[root@server fonts]# pwd
/nginx/html/zabbix/fonts
[root@server fonts]# cp /etc/zabbix/fonts/STKAITI.TTF .
3.21 给zabbix相关权限
[root@server fonts]# cp -r /usr/share/zabbix /nginx/html/
[root@server fonts]# chown -R zabbix:zabbix /etc/zabbix/
[root@server fonts]# chown -R zabbix:zabbix /usr/share/nginx/
[root@server fonts]# chown -R zabbix:zabbix /usr/lib/zabbix/
[root@server fonts]# chmod -R 755 /etc/zabbix/web/
[root@server fonts]# chmod -R 777 /var/lib/php/session/
[root@server nginx]# chown -R zabbix:zabbix /nginx/
[root@server ~]# chown -R zabbix:zabbix /nginx/
3.22 开启zabbix服务
[root@server fonts]# systemctl start zabbix-server
[root@server fonts]# systemctl enable zabbix-server
Created symlink from /etc/systemd/system/multi-user.target.wants/zabbix-server.service to /usr/lib/systemd/system/zabbix-server.service.
[root@server fonts]# systemctl start zabbix-agent
[root@server fonts]# systemctl enable zabbix-agent
Created symlink from /etc/systemd/system/multi-user.target.wants/zabbix-agent.service to /usr/lib/systemd/system/zabbix-agent.service.
3.23 查看端口号
[root@server fonts]# netstat -natp | grep zabbix
tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 6048/zabbix_agentd
tcp 0 0 0.0.0.0:10051 0.0.0.0:* LISTEN 5671/zabbix_server
tcp6 0 0 :::10050 :::* LISTEN 6048/zabbix_agentd
tcp6 0 0 :::10051 :::* LISTEN 5671/zabbix_server
3.24 重启之前的服务,php-fpm、nginx
[root@server fonts]# systemctl restart php-fpm
[root@server fonts]# systemctl restart nginx
3.25 访问192.168.247.142/zabbix/
访问结果发现404报错
3.26 修改nginx配置文件
8 location / {
9 root /nginx/html; #修改站点为/nginx/html
10 index index.html index.htm index.php;
11 }
然后重启,
[root@server ~]# systemctl restart nginx
可以了
备注:业务站点为了稳定,可以不用修改站点目录,以免混淆
3.27 网页在线安装zabbix
-
下一步
-
下一步
-
数据库密码,zabbix用户的密码
-
下一步,名字改为gsy
- 下一步
-
出现报错
-
说少一个文件
- 点击下载,将这个文件导入到指定路径
Download the configuration file
Save it as "/etc/zabbix/web/zabbix.conf.php"
- 点击完成finsh
备注:给这个/etc/zabbix/web/zabbix.conf.php文件一个zabbix的权限
[root@server web]# chown zabbix.zabbix zabbix.conf.php
可以重新启动一下zabbix-server
systemctl restart zabbix-server
3. 28 进入登录界面
用户默认:Admin
密码默认:zabbix
3.29 设置语言环境
- 点击更新
四:配置代理端,即被监控服务端
被监控的服务端都需要安装zabbix-agent
宏函数官方文档:
https://www.zabbix.com/documentation/4.0/zh/manual/config/macros/macro_functions
用户宏变量官方文档:
https://www.zabbix.com/documentation/4.0/zh/manual/config/macros/usermacros
自动发现宏(LLD)
https://www.zabbix.com/documentation/4.0/zh/manual/config/macros/lld_macros
4.1 下载zabbix-agent
[root@client ~]# rpm -Uvh https://repo.zabbix.com/zabbix/4.4/rhel/7/x86_64/zabbix-release-4.4-1.el7.noarch.rpm
Retrieving https://repo.zabbix.com/zabbix/4.4/rhel/7/x86_64/zabbix-release-4.4-1.el7.noarch.rpm
warning: /var/tmp/rpm-tmp.QTmVVB: Header V4 RSA/SHA512 Signature, key ID a14fe591: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:zabbix-release-4.4-1.el7 ################################# [100%]
[root@client ~]# yum list
[root@client ~]# yum install -y zabbix-agent
4.2 修改agent配置文件
[root@client ~]# vim /etc/zabbix/zabbix_agentd.conf
13 PidFile=/var/run/zabbix/zabbix_agentd.pid
32 LogFile=/var/log/zabbix/zabbix_agentd.log
43 LogFileSize=0
98 Server=192.168.247.142 #指向zabbix-server服务端
139 ServerActive=192.168.247.142 #指向zabbix-server服务端
150 Hostname=client1 #zabbix-agent名称
290 Include=/etc/zabbix/zabbix_agentd.d/*.conf
[root@client ~]# setenforce 0
[root@client ~]# sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config
[root@client ~]# systemctl stop NetworkManager
[root@client ~]# systemctl disable NetworkManager
[root@client ~]# iptables -F
[root@client ~]# systemctl start zabbix-agent.service
[root@client ~]# systemctl enable zabbix-agent.service
Created symlink from /etc/systemd/system/multi-user.target.wants/zabbix-agent.service to /usr/lib/systemd/system/zabbix-agent.service.
[root@client ~]# netstat -natp | grep zabbix
tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 48909/zabbix_agentd
tcp6 0 0 :::10050 :::* LISTEN 48909/zabbix_agentd
五:增加被监控主机
配置——主机——创建主机
添加主机
可以手动添加,也可以做一个自动发现机制
-
创建主机
-
点击添加
六:添加模板
点击下面主机
选择监听服务,http 和ssh
点击更新
七:查看client的服务
[root@client ~]# systemctl status sshd
● sshd.service - OpenSSH server daemon
Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2020-05-21 15:41:55 CST; 17h ago
Docs: man:sshd(8)
man:sshd_config(5)
Main PID: 985 (sshd)
CGroup: /system.slice/sshd.service
└─985 /usr/sbin/sshd -D
May 21 15:41:55 nginx systemd[1]: Starting OpenSSH server daemon...
May 21 15:41:55 nginx sshd[985]: Server listening on 0.0.0.0 port 22.
May 21 15:41:55 nginx sshd[985]: Server listening on :: port 22.
May 21 15:41:55 nginx systemd[1]: Started OpenSSH server daemon.
May 21 15:51:16 nginx sshd[2480]: Accepted password for root from 192.168.247.1 port 64983 ssh2
May 21 20:19:03 client sshd[128870]: Accepted password for root from 192.168.247.1 port 50651 ssh2
May 22 08:26:39 client sshd[112471]: Accepted password for root from 192.168.247.1 port 59045 ssh2
Hint: Some lines were ellipsized, use -l to show in full.
[root@client ~]# systemctl status httpd
Unit httpd.service could not be found.
八:测试zabbix监控
8.1 回到首页,查看监控项目
一般是隔300S监控一次
8.2 出现报警,把sshd也停掉测试
[root@client ~]# systemctl stop sshd
等一会
8.3 此时点击client01
8.4 可以使用PING、traceroute去测试网络状态
zabbix-server缺少traceroute工具
[root@server ~]# yum install traceroute -y
8.5 此时ssh服务检测到
8.6 开启sshd服务
[root@client ~]# systemctl start sshd
[root@client ~]# systemctl status sshd
● sshd.service - OpenSSH server daemon
Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2020-05-22 09:48:46 CST; 4s ago
Docs: man:sshd(8)
man:sshd_config(5)
Main PID: 75812 (sshd)
CGroup: /system.slice/sshd.service
└─75812 /usr/sbin/sshd -D
May 22 09:48:46 client systemd[1]: Starting OpenSSH server daemon...
May 22 09:48:46 client sshd[75812]: Server listening on 0.0.0.0 port 22.
May 22 09:48:46 client sshd[75812]: Server listening on :: port 22.
May 22 09:48:46 client systemd[1]: Started OpenSSH server daemon.