Zabbix部署过程

Zabbix学习笔记

一、安装

安装分为两个部分,服务器和监控机,安装必须关闭防火墙和SeLinux否则会出现问题。

Zabbix版本为 4.0.2 LTS版 适用于 CentOS7的安装,如果为CentOs6需要将systemctl替换为service指令

rpm包也要换为https://repo.zabbix.com/zabbix/4.0/rhel/6/x86_64/zabbix-release-4.0-1.el6.noarch.rpm

注意:需要关闭Selinux

sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
reboot

1、zabbix-server的安装

1.1、安装仓库rpm包

#注意,如果之前安装过更高版本的需要清理缓存
yum clean all && yum makecache
#安装rpm包
rpm -ivh https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm

1.2、安装 zabbix-server-mysql、zabbix-web-mysql 及zabbix-agent

这里一般服务器都需要监控,所以也在服务器上安装zabbix-agent

yum install -y zabbix-server-mysql zabbix-web-mysql zabbix-agent

1.3、安装mysql及相应用户与数据库配置

安装Mysql不在赘述,下面说明需要创建的数据库以及用户。

 --创建zabbix数据库,用于服务器使用
 create database zabbix character set utf8 collate utf8_bin;
 --创建zabbix用户,给予zabbix数据库的全部权限
 create user 'zabbix'@'localhost' identified by 'Zabbix_123';
 grant all privileges on zabbix.* to 'zabbix'@'localhost';
 flush privileges;

1.4、修改相关配置

sed -i.bak '/^DBUser/a DBPassword=Zabbix_123' /etc/zabbix/zabbix_server.conf

1.5 、数据初始化

zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p zabbix
输入密码:Zabbix_123
--查看是否成功
use zabbix;
show tables;
--如果有144rows就证明成功

1.6 、修改时区

sed -i.bak '/Europe\/Riga/a \\tphp_value date.timezone Asia/Shanghai' /etc/httpd/conf.d/zabbix.conf

1.7、完成设置,重启服务器

#如果有firewalld防火墙需要关闭
systemctl stop firewalld
systemctl disable firewalld
#启动httpd服务器
systemctl start httpd
#开机启动
systemctl enable httpd
#重启zabbix
systemctl restart zabbix-server zabbix-agent
#添加到开机启动
systemctl enable zabbix-server zabbix-agent

2、zabbix-agent的安装

在host机上安装zabbix-agent。需要安装rpm包,使用和zabbix-server相同的rpm包

#安装zabbix-agent
yum -y install zabbix-agent
#文件配置 需要将ServerIp替换为zabbix-server所在的服务器
sed -i.bak 's/Server=127.0.0.1/Server=ServerIp/g' /etc/zabbix/zabbix_agentd.conf
#启动并加入到开机
systemctl start zabbix-agent
systemctl enable zabbix-agent

二、agent配置

新模板的配置文件都在/etc/zabbix/zabbix_agentd.d下的userparameter_xxx.conf

每次修改都要重启agent服务

1、监听Mysql

1.1、创建客户端账户密码

#在/var/lib/zabbix 下 新建 .my.cnf 内容如下
[client]
user=zabbix
host=127.0.0.1
password=Zabbix_123

1.2、添加模板

在网页上,配置中主机模板处,选择mysql的模板,等待几分钟后,就有数据了

2、监听Redis

1.1、创建userparameter_redis.conf

#redis-cli 和 redis-server的目录需要根据具体而定
UserParameter=redis[*],/usr/local/redis-4.0.2/bin/redis-cli  info | grep $1":" | cut -d ':' -f 2
UserParameter=redis-ping,/usr/local/redis-4.0.2/bin/redis-cli  ping | grep -c PONG
UserParameter=redis.version,/usr/local/redis-4.0.2/bin/redis-server --version | cut -d " " -f 3 | cut -d "=" -f 2

1.2、导入模板

下载的Template App Redis模板,导入即可使用

posted @ 2020-11-09 22:09  北辰hpy  阅读(195)  评论(0)    收藏  举报