1.简介
Zabbix 是一个基于 WEB 界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案。它能监视各种网络参数,保证服务器系统的安全运营;并提供灵活的通知机制以让系统管理员快速定位/解决存在的各种问题。 zabbix 软件组成 ➢ zabbix-server: 服务端 ➢ zabbix-agent: 客户端 ➢ zabbix-web: 网站服务 ➢ php: 处理动态请求 ➢ mysql: 数据库存储数据 ➢ zabbix: 负责收集 agent 信息汇总告知 zabbix-server 官网:https://www.zabbix.com/cn/
2.部署容器
docker run -d --name jemzabbix5 -h jemzabbix5 \ -p 225:22 -p 23306:3306 -p 280:80 -p 20051:10051 \ -v /sys/fs/cgroup:/sys/fs/cgroup \ --privileged=true \ centos:centos7.6.1810 /usr/sbin/init
3.添加yum源
cat > /zabbix_aliyun.sh <<"EOF" #!/bin/bash echo -e "请给出要安装的 zabbix 版本号 \033[31musage:./zabbix_aliyun.sh 4.0|4.4|4.5|5.0 \033[0m" echo "例如要安装 5.0 版本,则使用命令: sh zabbix_aliyun.sh 5.0" 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 EOF
chmod +x /zabbix_aliyun.sh sh /zabbix_aliyun.sh 5.0
4.安装组件
yum -y install zabbix-server-mysql zabbix-agent ##centos扩展包 yum -y install centos-release-scl yum-config-manager --enable zabbix-frontend yum install -y zabbix-web-mysql-scl zabbix-apache-conf-scl
5.修改配置文件
##修改数据库密码为 jem sed -ri.bak '/# DBPassword=/cDBPassword=jem' /etc/zabbix/zabbix_server.conf ##修改时区为国内 sed -ri.bak 's/^.*date.timezone.*$/php_value[date.timezone] = Asia\/Shanghai/' /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf
6.配置数据库服务
[root@jemzabbix5 ~]# mkdir /soft [root@jeames soft]# docker cp mysql-5.7.30-1.el7.x86_64.rpm-bundle.tar jemzabbix5:/soft [root@jemzabbix5 ~]# cd /soft/ [root@jemzabbix5 soft]# tar -xvf mysql-5.7.30-1.el7.x86_64.rpm-bundle.tar yum localinstall -y mysql-community-*.rpm systemctl start mysqld grep 'temporary password' /var/log/mysqld.log mysql -uroot -p alter user root@'localhost' identified by 'Jem@jem123'; uninstall plugin validate_password; grant all on *.* to root@'%' identified by 'root'; grant all on *.* to root@'localhost' identified by 'root'; create database zabbix character set utf8 collate utf8_bin; grant all on zabbix.* to zabbix@localhost identified by 'jem'; grant all on zabbix.* to zabbix@'%' identified by 'jem'; flush privileges; mysql> select Host,User from mysql.user; # 上传 create.sql.gz 文件 docker cp create.sql.gz jemzabbix5:/soft zcat create.sql.gz | mysql -uroot -proot zabbix -- 修改参数/etc/my.cnf default-time-zone = '+8:00' log_timestamps = SYSTEM character_set_server=utf8mb4
7.启动资源
systemctl enable zabbix-server zabbix-agent httpd rh-php72-php-fpm systemctl restart zabbix-server zabbix-agent httpd rh-php72-php-fpm systemctl status zabbix-server zabbix-agent httpd rh-php72-php-fpm systemctl status zabbix-server zabbix-agent httpd rh-php72-php-fpm mariadb mysqld | grep Active -B 3 http://192.168.1.54:280/zabbix 默认用户名密码:Admin/zabbix