一、部署server端
第一步:关闭selinux、防火墙
#查看是否开启selinux。Enforcing为开启状态,Permissive为关闭
[root@localhost ~]# getenforce
Enforcing
[root@localhost ~]# setenforce 0
#修改配置文件,将SELINUX=enforcing改为SELINUX=disabled
[root@localhost ~]# vim /etc/selinux/config
SELINUX=disabled
#关闭防火墙
[root@localhost ~]# systemctl stop firewalld.service
第二步:设置主机名
[root@localhost ~]# hostnamectl set-hostname zb_server
[root@localhost ~]# exit
#配置完成之后,退出重新登录一下
[root@zb_server ~]# hostname
zb_server
#可以看到主机已经改变
第三步:配置软件仓库
清华镜像站:https://mirrors.tuna.tsinghua.edu.cn
点击使用帮助——在左侧找到"centos",直接复制tsinghua.repo仓库文件就行。epel.repo也是在网站内找到“epel”复制进来。
[root@zb_server yum.repos.d]# vim tsinghua.repo
[root@zb_server yum.repos.d]# vim epel.repo
[root@zb_server /]# rpm -ivh http://repo.zabbix.com/zabbix/4.2/rhel/7/x86_64/zabbix-release-4.2-2.el7.noarch.rpm
#清除原有的缓存
[root@zb_server yum.repos.d]# yum clean all
#新建缓存
[root@zb_server /]# yum makecache
第四步:时间同步
1.安装ntp时间同步服务和ntp客户端工具
#查看是否已安装
[root@zb_server /]# yum list installed | grep 'ntp'
fontpackages-filesystem.noarch 1.44-8.el7 @anaconda/7.4
ntp.x86_64 4.2.6p5-28.el7.centos @base
ntpdate.x86_64 4.2.6p5-28.el7.centos @base
python-ntplib.noarch 0.3.2-1.el7 @anaconda/7.4
#如果没有安装就进行安装
[root@zb_server /]# yum -y install ntp.x86_64 ntpdate.x86_64
2.先做一次同步
[root@zb_server /]# ntpdate -u 0.cn.pool.ntp.org
13 Aug 09:32:11 ntpdate[123775]: adjust time server 119.28.183.184 offset 0.001769 sec
[root@zb_server /]# date
Tue Aug 13 09:32:43 PDT 2019
#我在这个配置的时间是2019/8/14/ 0:32,所以可以看出时区不一致
3.设置时区
[root@zb_server /]# timedatectl set-timezone Asia/Shanghai
#再看一下时间已正常
[root@zb_server /]# date
Wed Aug 14 00:37:05 CST 2019
4.注释掉默认的ntp服务器配置,替换为国内的ntp服务器
[root@zb_server /]# vim /etc/ntp.conf
#server 0.centos.pool.ntp.org iburst
#server 1.centos.pool.ntp.org iburst
#server 2.centos.pool.ntp.org iburst
#server 3.centos.pool.ntp.org iburst
server 0.cn.pool.ntp.org iburst
server 1.cn.pool.ntp.org iburst
server 2.cn.pool.ntp.org iburst
server 3.cn.pool.ntp.org iburst
5.重启服务
[root@zb_server /]# systemctl restart ntpd
第五步:安装数据库、zabbbix
1.安装
[root@zb_server /]# yum install -y mariadb-server mariadb
2.重启服务、设置开机启动
[root@zb_server /]# systemctl restart mariadb
[root@zb_server /]# systemctl enable mariadb
3.建库&授权
#默认密码为空,直接回车就ok
[root@zb_server /]# mysql -u root -p
MariaDB [(none)]> create database zabbix character set utf8 collate utf8_bin;
MariaDB [(none)]> grant all privileges on zabbix.* to zabbix@localhost identified by 'password';
MariaDB [(none)]> exit
Bye
4.导入epel的gpg-key证书
[root@zb_server /]# rpm --import https://mirrors.tuna.tsinghua.edu.cn/epel/RPM-GPG-KEY-EPEL-7
5.安装zabbix
[root@zb_server /]# yum -y install zabbix-server-mysql zabbix-web-mysql zabbix-agent
# 如果发现有不能安装的,就yum -y update
6.导入数据
[root@zb_server ~]# zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -u zabbix -p zabbix
7.编辑zabbix的配置文件
[root@zb_server ~]# vim /etc/zabbix/zabbix_server.conf
添加:DBPassword=password
[root@zb_server ~]# vim /etc/httpd/conf.d/zabbix.conf
php_value date.timezone Asia/Shanghai
8.启动server&agent端,并设置开机启动
[root@zb_server ~]# systemctl restart zabbix-server zabbix-agent httpd
[root@zb_server ~]# systemctl enable zabbix-server zabbix-agent httpd
第六步:配置zabbix-web
在浏览器中输入 http:// IP地址 /zabbix 登录到web页面,完成安装向导填写
用户名:Admin
密码:zabbix
二、部署agent端
1.主动模式配置
ServerActive:当工作在主动模式时,将数据推送给哪台Server端服务器,多个逗号隔开
Hostname:当前服务器的主机名,Server通过此参数识别当前主机
#我的server和agent都在一台主机上
[root@zb_server ~]# vim /etc/zabbix/zabbix_agentd.conf
##### Active checks related
ServerActive=127.0.0.1
Hostname=zb_server
2.被动模式配置
Server:用于指定允许哪台服务器拉取当前服务器的数据
ListenPort:agentd监听端口,默认10050
ListenIP:agentd监听IP
[root@zb_server ~]# vim /etc/zabbix/zabbix_agentd.conf
##### Passive checks related
Server=127.0.0.1
ServerActive=127.0.0.1
Hostname=zb_server
3.重启服务
systemctl restart zabbix-agent