zabbix5

发布时间 2023-05-09 09:30:43作者: 也曾滿眼愛意丶

环境准备

主机 外网ip 内网ip
server 10.0.0.101
proxy 10.0.0.102 172.16.1.102
agent01 172.16.1.103
agent02 172.16.1.104
win 192.168.45.171

配置源

# 4台服务器都配置源
使用脚本换源
vi zabbix_aliyun.sh

#!/bin/bash
echo -e "请给出要安装的zabbix版本号,建议使用4.x的版本  \033[31musage:./zabbix_aliyun.sh 4.0|4.4|4.5|5.0 \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

# 执行脚本
bash zabbix_aliyun.sh 5.0

server

# 安装server
rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
yum clean all
yum install zabbix-server-mysql zabbix-agent -y
yum install centos-release-scl -y

# 编辑repo
vi /etc/yum.repos.d/zabbix.repo
[zabbix-frontend]
...
enabled=1
...

# 安装
yum install zabbix-web-mysql-scl zabbix-apache-conf-scl -y

# 安装数据库
cd /usr/local/src/
wget http://repo.mysql.com/mysql57-community-release-el7-8.noarch.rpm 
rpm -ivh mysql57-community-release-el7-8.noarch.rpm
yum -y install mysql-server

# 启动mysql
systemctl start mysqld

# 查看密码
grep 'temporary password' /var/log/mysqld.log

# 修改密码
mysql -uroot -p

mysql> set password for root@localhost = password('Abc123!@#');

# 创建库
mysql> create database zabbix character set utf8 collate utf8_bin;
mysql> grant all privileges on zabbix.* to zabbix@localhost identified by 'Abc123!@#';
mysql> quit;

# 导入数据库
zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p'Abc123!@#' zabbix

# 若遇到报错
vim create.sql.gz
//在第一行加上
USE zabbix;

# 配置server的conf文件
grep ^[a-Z] /etc/zabbix/zabbix_server.conf 
LogFile=/var/log/zabbix/zabbix_server.log
LogFileSize=0
PidFile=/var/run/zabbix/zabbix_server.pid
SocketDir=/var/run/zabbix
DBName=zabbix
DBUser=zabbix
DBPassword=Abc123!@#
SNMPTrapperFile=/var/log/snmptrap/snmptrap.log
Timeout=4
AlertScriptsPath=/usr/lib/zabbix/alertscripts
ExternalScripts=/usr/lib/zabbix/externalscripts
LogSlowQueries=3000
StatsAllowedIP=127.0.0.1

# 配置PHP
vim /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf
...
php_value[date.timezone] = Asia/Shanghai
...

# 解决中文乱码
yum install wqy-microhei-fonts

# 替换默认字符集
cp /usr/share/fonts/wqy-microhei/wqy-microhei.ttc /usr/share/fonts/dejavu/DejaVuSans.ttf

# 启动zabbix-server和agent
systemctl restart zabbix-server zabbix-agent httpd rh-php72-php-fpm
systemctl enable zabbix-server zabbix-agent httpd rh-php72-php-fpm

# 浏览器打开
打开http:IP/zabbix  例:http://10.0.0.101/zabbix

proxy

# 安装proxy
yum install zabbix-proxy

# 安装数据库
cd /usr/local/src/
wget http://repo.mysql.com/mysql57-community-release-el7-8.noarch.rpm 
rpm -ivh mysql57-community-release-el7-8.noarch.rpm
yum -y install mysql-server

# 启动mysql
systemctl start mysqld

# 查看密码
grep 'temporary password' /var/log/mysqld.log

# 修改密码
mysql -uroot -p

mysql> set password for root@localhost = password('Abc123!@#');

# 创建库
mysql> create database zabbix_proxy character set utf8 collate utf8_bin;
mysql> grant all privileges on zabbix_proxy.* to zabbix@localhost identified by 'Abc123!@#';
mysql> quit;

# 导入
zcat /usr/share/doc/zabbix-proxy-mysql-5.0.15/schema.sql.gz |mysql -uzabbix -p'Abc123!@#' zabbix_proxy

#查看数据库
mysql -uzabbix -p'Abc123!@#'
show databases;
use zabbix_proxy;
show tables;
quit

#配置conf文件
grep ^[a-Z] /etc/zabbix/zabbix_proxy.conf 
Server=10.0.0.101
Hostname=zabbix-proxy
LogFile=/var/log/zabbix/zabbix_proxy.log
LogFileSize=0
PidFile=/var/run/zabbix/zabbix_proxy.pid
SocketDir=/var/run/zabbix
DBHost=localhost
DBName=zabbix_proxy
DBUser=zabbix
DBPassword=Abc123!@#
SNMPTrapperFile=/var/log/snmptrap/snmptrap.log
Timeout=4
ExternalScripts=/usr/lib/zabbix/externalscripts
LogSlowQueries=3000
StatsAllowedIP=127.0.0.1


#启动proxy并加入开机自启
systemctl start zabbix-proxy
systemctl enable zabbix-proxy
netstat -lntp

agent

# 安装agent
yum install zabbix-agent

#配置agent
grep ^[a-Z] /etc/zabbix/zabbix_agentd.conf 
PidFile=/var/run/zabbix/zabbix_agentd.pid
LogFile=/var/log/zabbix/zabbix_agentd.log
LogFileSize=0
Server=172.16.1.102
ServerActive=172.16.1.102
Hostname=Zabbix server
Include=/etc/zabbix/zabbix_agentd.d/*.conf

#启动agnet并加入开机自启
systemctl start zabbix-agent
systemctl enable zabbix-agent
netstat -lntp