zabbix中文文档 zabbix_web_service
一、Docker 安装配置
1、安装所需的软件包
yum install -y yum-utils device-mapper-persistent-data lvm2
2、配置阿里源
yum-config-manager \
--add-repo \
http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
3、更新仓库yum缓存
yum clean all && yum makecache
4、安装docker
yum install docker-ce docker-ce-cli containerd.io
5、启动服务并设置开机自启
systemctl start docker && systemctl enable docker
二、zabbix安装配置
该示例示范了如何运行 MySQL 数据库支持的 Zabbix Server
基于 Nginx Web 服务器的 Zabbix Web 界面和 Zabbix Java 网关。
创建专用于 Zabbix 组件容器的网络:
docker network create -d bridge zabbix_net
创建后,可以查看是否创建成功
创建数据目录
mkdir -p /data/mysql/conf
1、启动MySQL 服务实例:
首先将配置文件挂载出来
cat /data/mysql/conf/my.cnf
[mysqld]
user=mysql
character-set-server=utf8
default_authentication_plugin=mysql_native_password
secure_file_priv=/var/lib/mysql
expire_logs_days=7
innodb_flush_log_at_trx_commit=0 //增大导入数据速度
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
max_connections=1000
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
2、启动MySQL
docker run --privileged=true \
--restart always \
--name zabbix-mysql \
--network zabbix_net \
-v /data/mysql/conf/my.cnf:/etc/mysql/my.cnf \
-v /data/mysql/log:/var/log \
-v /data/mysql/data:/var/lib/mysql \
-v /data/mysql/conf.d:/etc/mysql/conf.d \
-e MYSQL_DATABASE="zabbix" \
-e MYSQL_USER="zabbix" \
-e MYSQL_PASSWORD="zabbix123" \
-e MYSQL_ROOT_PASSWORD="root123" \
-d mysql:5.7
下面2行参数可以忽略,前面配置文件已经包含
#--character-set-server=utf8 \
#--collation-server=utf8_bin
- MYSQL_DATABASE="zabbix" 在msql中创建的数据库的名
- MYSQL_USER="zabbix" 创建msql的登录账户名
- MYSQL_PASSWORD="zabbix123" 设置创建msql的登录账户的密码
- MYSQL_ROOT_PASSWORD="root123" 设置msql数据库root 的密码
- 启动 Zabbix Java 网关实例:
docker run --restart always \
--name zabbix-java-gateway -t \
--network=zabbix_net \
--restart unless-stopped \
-d zabbix/zabbix-java-gateway:alpine-5.4-latest
- 启动 Zabbix server 实例,并将其关联到已创建的 MySQL server 实例:
Zabbix server 实例将 10051/TCP 端口(Zabbix trapper)暴露给主机
首先创建数据卷zabbix-server-vol,通过命令
docker volume create zabbix-server
zabbix-server镜像分两种:
支持MySQL数据库zabbix-server-mysql
支持支持PostgreSQL数据库zabbix/zabbix-server-pgsql
下面安装的是支持MySQL数据库的Server镜像
docker run -p 10051:10051 \
--restart always \
--restart unless-stopped \
--name zabbix-server-mysql -t \
--mount source=zabbix-server,target=/etc/zabbix \
-v /etc/localtime:/etc/localtime \
-v /data/zabbix/alertscripts:/usr/lib/zabbix/alertscripts \
-e DB_SERVER_HOST="zabbix-mysql" \
-e MYSQL_DATABASE="zabbix" \
-e MYSQL_USER="zabbix" \
-e MYSQL_PASSWORD="zabbix123" \
-e MYSQL_ROOT_PASSWORD="root123" \
-e ZBX_JAVAGATEWAY="zabbix-java-gateway" \
--network=zabbix_net \
-d zabbix/zabbix-server-mysql:alpine-5.4-latest
- 启动 Zabbix Web 界面,并将其关联到已创建的 MySQL server 和 Zabbix server 实例:
Zabbix web 界面实例将 80/TCP 端口(HTTP)暴露给主机
docker run --name zabbix-web-nginx-mysql -t \
-e ZBX_SERVER_HOST="zabbix-server-mysql" \
-e DB_SERVER_HOST="zabbix-mysql" \
-e MYSQL_DATABASE="zabbix" \
-e MYSQL_USER="zabbix" \
-e MYSQL_PASSWORD="zabbix123" \
-e MYSQL_ROOT_PASSWORD="root123" \
--network=zabbix_net \
-p 80:8080 \
--restart unless-stopped \
-d zabbix/zabbix-web-nginx-mysql:alpine-5.4-latest
- 访问测试:http://IP/zabbix
打开zabbix首页,其中用户名密码分别是admin/zabbix。
三、通过docker-compose 部署zabbix
安装docker-compose
curl -sL https://github.com/docker/compose/releases/download/v2.7.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
curl -sL https://get.daocloud.io/docker/compose/releases/download/v2.7.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
zabbix-docker-compose.yml 文件
version: '3'
services:
zabbix_mysql:
container_name: "zabbix_mysql"
restart: "always"
image: mysql:5.7
ports:
- "3306:3306"
volumes:
- /data/docker/mysql-data:/var/lib/mysql
- /data/mysql/conf/my.cnf:/etc/mysql/my.cnf
environment:
MYSQL_ROOT_PASSWORD: "mysqlpss123"
MYSQL_USER: "zabbix"
MYSQL_PASSWORD: "mysqlpss123"
MYSQL_DATABASE: "zabbix"
zabbix_java_gateway:
container_name: "zabbix_java_gateway"
restart: "always"
image: zabbix/zabbix-java-gateway:alpine-5.4-latest
zabbix_server:
container_name: "zabbix_server"
restart: "always"
image: zabbix/zabbix-server-mysql:alpine-5.4-latest
ports:
- "10051:10051"
volumes:
- /etc/localtime:/etc/localtime:ro
- /data/docker/zabbix:/usr/lib/zabbix
depends_on:
- zabbix_mysql
links:
- zabbix_mysql:mysql
environment:
DB_SERVER_HOST: "mysql"
MYSQL_USER: "zabbix"
MYSQL_DATABASE: "zabbix"
MYSQL_PASSWORD: "mysqlpss123"
ZBX_JAVAGATEWAY: "zabbix_java_gateway"
zabbix_nginx_web:
container_name: "zabbix_nginx_web"
restart: "always"
image: zabbix/zabbix-web-nginx-mysql:alpine-5.4-latest
ports:
- "8443:443"
- "80:8080"
depends_on:
- zabbix_mysql
- zabbix_server
links:
- zabbix_mysql:mysql
- zabbix_server:zabbix_server
environment:
DB_SERVER_HOST: "mysql"
MYSQL_USER: "zabbix"
MYSQL_PASSWORD: "mysqlpss123"
MYSQL_DATABASE: "zabbix"
ZBX_SERVER_HOST: "zabbix_server"
PHP_TZ: "Asia/Shanghai"
zabbix_agent_a:
image: zabbix/zabbix-agent:alpine-5.4-latest
links:
- zabbix_server:zabbix_server
container_name: zabbix_agent_a
restart: always
depends_on:
- zabbix_server
environment:
- ZBX_HOSTNAME=zabbix_agent_a
- ZBX_SERVER_HOST=zabbix_server