zabbix安装使用
1.常见错误
-
yum 源报错
# 修改文件 /etc/yum.repos.d/CentOS-SCLo-scl.repovim /etc/yum.repos.d/CentOS-SCLo-scl.repo# 替换[centos-sclo-sclo]name=CentOS-$releasever - SCLo sclobaseurl=https://mirrors.aliyun.com/centos/$releasever/sclo/$basearch/sclo/gpgcheck=1enabled=1gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7# GPG密钥缺失vim /etc/yum.repos.d/CentOS-SCLo-scl-rh.repo[centos-sclo-rh]name=CentOS-$releasever - SCLo rhbaseurl=https://mirrors.aliyun.com/centos/$releasever/sclo/$basearch/rh/gpgcheck=1enabled=1gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7,https://www.centos.org/keys/RPM-GPG-KEY-CentOS-SIG-SCLo# 引入GPGKEYrpm --import https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7rpm --import https://www.centos.org/keys/RPM-GPG-KEY-CentOS-SIG-SCLoyum clean allyum makecacheyum -y update -
关闭selinux模式(安全策略)
# 修改配置文件 enforcing开启 disabled关闭vim /etc/selinux/config# This file controls the state of SELinux on the system.# SELINUX= can take one of these three options:# enforcing - SELinux security policy is enforced.# permissive - SELinux prints warnings instead of enforcing.# disabled - No SELinux policy is loaded.SELINUX=disabled# getenforce 查看当前状态getenforce
2.安装配置(服务端,基于nginx+mysql)
2.1安装仓库
rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
# 换源
sed -i 's#http://repo.zabbix.com#https://mirrors.aliyun.com/zabbix#' /etc/yum.repos.d/zabbix.repo
yum clean all
yum makecache
2.2安装Zabbix server,Web前端,agent
yum install zabbix-server-mysql zabbix-agent -y
2.3安装Zabbix前端
yum install centos-release-scl -y
2.3.1编辑配置文件 /etc/yum.repos.d/zabbix.repo
[zabbix-frontend]
...
enabled=1
...
2.3.2安装 Zabbix frontend packages.
yum install zabbix-web-mysql-scl zabbix-nginx-conf-scl -y
2.4创建初始数据库
# 安装数据库
yum install -y mariadb-server
# mysql -uroot -p
password
mysql> create database zabbix character set utf8 collate utf8_bin;
mysql> create user zabbix@localhost identified by 'password';
mysql> grant all privileges on zabbix.* to zabbix@localhost;
mysql> set global log_bin_trust_function_creators = 1;
mysql> quit;
2.4.1导入初始架构和数据,系统将提示您输入新创建的密码。
zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p zabbix
2.4.2Disable log_bin_trust_function_creators option after importing database schema.
# mysql -uroot -p
password
mysql> set global log_bin_trust_function_creators = 0;
mysql> quit;
2.5为Zabbix server配置数据库
编辑配置文件 /etc/zabbix/zabbix_server.conf
vim /etc/zabbix/zabbix_server.conf
DBPassword=password
2.6为Zabbix前端配置PHP
编辑配置文件 /etc/opt/rh/rh-nginx116/nginx/conf.d/zabbix.conf uncomment and set 'listen' and 'server_name' directives.
listen 80;
server_name localhost;
编辑文件/etc/opt/rh/rh-nginx116/nginx/nginx.conf
# 注释server块
# server{
# ...
# listen 80;
# ...
# }
编辑配置文件 /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf add nginx to listen.acl_users directive.
listen.acl_users = apache,nginx
php_value[date.timezone] = Asia/Shanghai
2.7启动Zabbix server和agent进程
systemctl restart zabbix-server zabbix-agent rh-nginx116-nginx rh-php72-php-fpm
systemctl enable zabbix-server zabbix-agent rh-nginx116-nginx rh-php72-php-fpm
2.8安装字体解决图表文字有乱码的问题
# 服务端安装字体
yum install -y wqy-microhei-fonts
# 拷贝字体到特定的位置
cp /usr/share/fonts/wqy-microhei/wqy-microhei.ttc /usr/share/fonts/dejavu/DejaVuSans.ttf
3.安装配置(客户端)
- 旧版本客户端,zabbix-agent
- go语言新版,zabbix-agent2
3.1确保客户端机器时间正确
# 统一时间
yum install -y ntpdate
ntpdate -u ntp.aliyun.com
# 统一时区
mv /etc/localtime{,.bak}
ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
3.2安装客户端
rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
# 换源
sed -i 's#http://repo.zabbix.com#https://mirrors.aliyun.com/zabbix#' /etc/yum.repos.d/zabbix.repo
yum clean all
yum makecache
yum install zabbix-agent2 -y
查看配置文件
vim /etc/zabbix/zabbix_agent2.conf
cp /etc/zabbix/zabbix_agent2.conf{,.bak}
sed -i "s/^Server=127.0.0.1$/Server=172.172.1.1/" /etc/zabbix/zabbix_agent2.conf && sed -i "s/^ServerActive=127.0.0.1$/ServerActive=172.172.1.1/" /etc/zabbix/zabbix_agent2.conf && sed -i "s/^Hostname=Zabbix server$/Hostname=`hostname`/" /etc/zabbix/zabbix_agent2.conf
# 修改服务端地址
Server=服务端地址(如果是docker部署使用docker网关)
ServerActive=服务端地址(如果是docker部署使用docker网关)
# 修改客户端主机名
Hostname=客户端主机名
启动命令
ls -l /usr/sbin/zabbix_agent2
启动客户端
# 默认端口10050
systemctl enable --now zabbix-agent2
验证zabbix-agent2的连通性
# 在服务端安装 zabbix-get工具
yum install -y zabbix-get
# 测试 返回1则连接成功
zabbix_get -s '客户端ip' -p 10050 -k 'agent.ping'
# 获取主机名
zabbix_get -s '客户端ip' -p 10050 -k 'system.hostname'
4.完全卸载zabbix
-
停止服务
# nginxsystemctl stop zabbix-server zabbix-agent rh-nginx116-nginx rh-php72-php-fpm# apachesystemctl stop zabbix-server zabbix-agent rh-php72-php-fpm httpd -
删除zabbix相关包
yum -y remove `rpm -qa | grep -i zabbix` -
删除相关文件
rm -rf `find / -name zabbix` -
卸载数据库
yum -y remove `rpm -qa | grep mariadb` -
删除数据库相关文件
rm -rf `find / -name mysql` -
卸载http服务
yum -y remove `rpm -qa|grep httpd` -
卸载php服务
yum -y remove `rpm -qa|grep rh-php72-php-fpm` -
卸载nginx服务
yum -y remove `rpm -qa|grep nginx`