一、环境说明
1、操作系统内核版本:Centos7
2、zabbix版本:4.0.12
二、环境配置
1、zabbix-server: 192.168.2.101
2、zabbix-agent: 192.168.2.101 ~ 192.168.2.105
三、离线包并制作Zabbix YUM源
找一台Centos7_x64能上网的主机(干净的,无任何依赖包),操作命令如下:
1)安装yum
https://blog.csdn.net/qq_23160237/article/details/100679293
2)添加yum源
# base
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
# php
rpm -ivh https://mirror.webtatic.com/yum/el7/epel-release.rpm
rpm -ivh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
# mysql
rpm -ivh http://repo.mysql.com/mysql57-community-release-el7.rpm
# zabbix
rpm -ivh https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-2.el7.noarch.rpm
3)更新yum源
yum clean all; yum list update; yum makecache
4)下载rpm包
# mysql
mkdir -p /opt/data/mysql
yum install --downloadonly --downloaddir=/opt/data/mysql mysql-server libaio*
# zabbix
mkdir -p /opt/data/zabbix
yum install --downloadonly --downloaddir=/opt/data/zabbix zabbix-agent zabbix-get zabbix-sender zabbix-server-mysql zabbix-web-mysql
备注:一定是要空的完全干净的系统,不然已经安装的依赖,执行上述命令不会被下载
(zabbix依赖 php5.4+ 、 httpd 、fping 、libiksemel,注意查看是否下载)
(mysql依赖 libaio)
三、无网络服务器安装
1)安装mysql(192.168.2.101执行)
rpm -ivh /opt/data/mysql/*.rpm --force --nodeps
chown mysql:mysql -R /var/lib/mysql
systemctl start mysqld
# 查看密码
cat /var/log/mysqld.log | grep password
# 如以前装过mysql,导致新安装的mysql无法启动,务必执行以下命令删除数据
rpm -qa | grep mysql | xargs rpm -e
rm -rf /var/lib/mysql/*
rm -rf /etc/my.cnf
2)安装zabbix
# 192.168.2.101
rpm -ivh /opt/data/zabbix/*.rpm --force --nodeps
# 192.168.2.102 - 192.16.2.105
rpm -ivh /opt/data/zabbix/zabbix-agent-4.0.12-1.el7.x86_64.rpm
四、配置
1)mysql配置(192.168.2.101)
1)修改密码策略
set global validate_password_policy=0;
set global validate_password_length=4;
2)修改初始root密码
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'root';
3)远程设置
mysql> use mysql;
mysql> update user set host='%' where user='root';
4)创建zabbix数据库并授权
mysql> create database zabbix character set utf8 collate utf8_bin;
mysql> grant all on zabbix.* to 'zabbix'@'%' identified by 'zabbix';
5)刷新
mysql> FLUSH PRIVILEGES;
# 导入zabbix表结构
cd /usr/share/doc/zabbix-agent-4.0.12/
zcat create.sql.gz | mysql -uzabbix -pzabbix zabbix
2)httpd配置(192.168.2.101)
cat >>/etc/httpd/conf.d/zabbix.conf<<EOF
#
# Zabbix monitoring system php web frontend
#
Alias /zabbix /usr/share/zabbix
<Directory "/usr/share/zabbix">
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
<IfModule mod_php5.c>
php_value max_execution_time 300
php_value memory_limit 128M
php_value post_max_size 16M
php_value upload_max_filesize 2M
php_value max_input_time 300
php_value max_input_vars 10000
php_value date.timezone Asia/Shanghai
</IfModule>
</Directory>
<Directory "/usr/share/zabbix/conf">
Order deny,allow
Deny from all
<files *.php>
Order deny,allow
Deny from all
</files>
</Directory>
<Directory "/usr/share/zabbix/api">
Order deny,allow
Deny from all
<files *.php>
Order deny,allow
Deny from all
</files>
</Directory>
<Directory "/usr/share/zabbix/include">
Order deny,allow
Deny from all
<files *.php>
Order deny,allow
Deny from all
</files>
</Directory>
<Directory "/usr/share/zabbix/include/classes">
Order deny,allow
Deny from all
<files *.php>
Order deny,allow
Deny from all
</files>
</Directory>
EOF
重启httpd: systemctl restart httpd
2)zabbix-server配置(192.168.2.101)
sed "s/^DBName=.*/DBName=zabbix/g" /etc/zabbix/zabbix_server.conf -i
sed "s/^DBUser=.*/DBUser=zabbix/g" /etc/zabbix/zabbix_server.conf -i
sed "s/.*DBPassword=.*/DBPassword=zabbix/g" /etc/zabbix/zabbix_server.conf -i
cat /etc/zabbix/zabbix_server.conf |grep -E "DBHost=|DBName=|DBUser=|DBPassword="
启动zabbix-server: systemctl start zabbix-server
查看启动日志:tail -f /var/log/zabbix/zabbix_server.log
3)zabbix-agent配置(192.168.2.101——192.168.2.105)
sed "s/^Server=.*/Server=192.168.2.101,127.0.0.1/g" /etc/zabbix/zabbix_agentd.conf -i
sed "s/^ServerActive=.*/ServerActive=192.168.2.101/g" /etc/zabbix/zabbix_agentd.conf -i
sed "s/^Hostname=.*/Hostname=server1/g" /etc/zabbix/zabbix_agentd.conf -i
备注:第三条命令 Hostname 配置成 server1 ~ server5
启动zabbix-agent:systemctl start zabbix-agent
四、启动
访问: http://serverip/zabbix
默认用户名和密码: Admin/zabbix
五、页面配置
1)设置中文
2)添加主机
备注:主机名称必须与配置文件的HostName相同
3)添加监控指标
https://www.cnblogs.com/linyaonie/p/10113376.html
4)添加邮件报警通知
查看告警日志记录
5)自定义监控键值
vim /etc/zabbix/zabbix_agentd.d/userparameter_kylin.conf
UserParameter=kylin-manager[*],python kylin-manager/kylin_manager.py --host $1 --username $2 --password $3 exception-job --max-duration $4