飞天使-linux操作的一些技巧与知识点8-zabbix6.0 容器搭建
文章目录
- 安装docker
- 安装步骤mysql
- 下载镜像
- 安装zabbix
- 使用zabbix非host模式创建
- 测试效果
安装docker
1. 配置官方 yum 源
$ sudo yum install -y yum-utils
$ sudo yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
2. 安装 Docker
$ sudo yum install docker-ce docker-ce-cli containerd.io
3. 启动 Docker
$ sudo systemctl start docker
4. 查看 Docker 版本号,确认安装正确。
$ docker version
安装步骤mysql
docker pull mysql:8.0
groupadd mysql
useradd -gmysql -s /sbin/nologin -M mysql
mkdir -p /data/mysql/{data,conf,logs,mysql-files,mysqld}
mkdir /data/mysql/conf/conf.d -p
chown -R mysql.mysql /data/mysql
cd /data/mysql
[root@ zabbix_servermysql]# cat >> my.cnf << EOF
[mysqld]
# 永久修改时区
#default-time-zone = '+08:00'
log_timestamps = SYSTEM
max_connections = 1000
max-allowed-packet = 16M
max-connect-errors = 1000
lower_case_table_names = 1
innodb-flush-method = O_DIRECT
innodb-log-files-in-group = 2
innodb-log-file-size = 64M
innodb-flush-log-at-trx-commit = 1
innodb-file-per-table = 1
innodb-buffer-pool-size = 336M
tmp-table-size = 32M
max-heap-table-size = 32M
thread-cache-size = 50
open-files-limit = 1024
# 这个变量被用于限制导入和导出的数据目录
secure-file-priv=/var/lib/mysql-files
datadir=/var/lib/mysql
socket=/var/run/mysqld/mysqld.sock
pid-file=/var/run/mysqld/mysqld.pid
#character-set-server=utf8mb3
#collation-server=utf8mb3_bin
[client]
port = 3306
bind-address = 0.0.0.0
default-character-set = utf8mb4
EOF
[root@bogon mysql]# ll /data/mysql/
总用量 4
drwxr-xr-x 2 root root 6 5月 9 17:28 conf
drwxr-xr-x 2 root root 6 5月 9 17:11 data
drwxr-xr-x 2 root root 6 5月 9 17:28 logs
-rw-r--r-- 1 root root 635 5月 9 17:28 my.cnf
docker network create --subnet 172.20.0.0/16 --ip-range 172.20.96.0/20 zabbix-net
docker run \
--restart=always \
--privileged=true \
--net host \
-v /data/mysql/data:/var/lib/mysql:rw \
-v /data/mysql/logs/:/var/log/mysql:rw \
-v /data/mysql/conf/:/etc/mysql:rw \
-v /data/mysql/my.cnf:/etc/mysql/my.cnf:rw \
-v /data/mysql/mysql-files:/var/lib/mysql-files:rw \
-v /data/mysql/mysqld:/var/run/mysqld:rw \
--name mysql8 \
-e MYSQL_DATABASE="zabbix" \
-e MYSQL_USER="zabbix" \
-e MYSQL_PASSWORD="password" \
-e MYSQL_ROOT_PASSWORD="password" \
-e ZBX_DBTLSCONNECT="required" \
-e TZ="Asia/Shanghai" \
-d mysql:8.0 \
--character-set-server=utf8mb3 --collation-server=utf8mb3_bin \
--default-authentication-plugin=mysql_native_password
下载镜像
docker pull zabbix/zabbix-server-mysql:6.0-centos-latest
docker pull zabbix/zabbix-web-nginx-mysql:6.0-centos-latest
docker pull zabbix/zabbix-agent:6.0-centos-latest
mkdir -p /data/zabbix/usr/lib/zabbix
mkdir -p /data/zabbix/var/lib/zabbix
安装zabbix
docker run --name zabbix-server-mysql -t \
-e DB_SERVER_HOST="127.0.0.1" \
-e MYSQL_DATABASE="zabbix" \
-e MYSQL_USER="zabbix" \
-e MYSQL_PASSWORD="lH0awsefesfeaf" \
-e MYSQL_ROOT_PASSWORD="lH0aw2afesfeasfsfs" \
-e ZBX_JAVAGATEWAY="zabbix-java-gateway" \
--net host \
-m=500m \
-v /data/zabbix/usr/lib/zabbix:/usr/lib/zabbix:rw \
-v /data/zabbix/var/lib/zabbix:/var/lib/zabbix:rw \
--restart unless-stopped \
-e TZ="Asia/Shanghai" \
-d zabbix/zabbix-server-mysql:6.0-centos-latest
docker run --name zabbix-web-nginx-mysql -t \
-e ZBX_SERVER_HOST="zabbix-server-mysql" \
-e DB_SERVER_HOST="127.0.0.1" \
-e MYSQL_DATABASE="zabbix" \
-e MYSQL_USER="zabbix" \
-e MYSQL_PASSWORD="lH0awsefesfeaf" \
-e MYSQL_ROOT_PASSWORD="lH0aw2afesfeasfsfs" \
--net host \
--restart unless-stopped \
-e TZ="Asia/Shanghai" \
-d zabbix/zabbix-web-nginx-mysql:6.0-centos-latest
注意容器用的是host网络还是创建的网络,命令不同
复制 zabbix_server.conf到宿主机,并做修改
docker cp zabbix-server-mysql:/etc/zabbix/zabbix_server.conf /data/zabbix
使用zabbix非host模式创建
useradd -gmysql -s /sbin/nologin -M mysql
mkdir -p /data/mysql/{data,conf,logs,mysql-files,mysqld}
mkdir /data/mysql/conf/conf.d -p
chown -R mysql.mysql /data/mysql
cd /data/mysql
vim my.cnf
docker network create --driver bridge my-network
my.cnf ,从上面拿过来
docker run \
--restart=always \
--privileged=true \
--network=my-network \
-v /data/mysql/data:/var/lib/mysql:rw \
-v /data/mysql/logs/:/var/log/mysql:rw \
-v /data/mysql/conf/:/etc/mysql:rw \
-v /data/mysql/my.cnf:/etc/mysql/my.cnf:rw \
-v /data/mysql/mysql-files:/var/lib/mysql-files:rw \
-v /data/mysql/mysqld:/var/run/mysqld:rw \
--name mysql8 \
-e MYSQL_DATABASE="zabbix" \
-e MYSQL_USER="zabbix" \
-e MYSQL_PASSWORD="lH0aw281e9a342324AdF" \
-e MYSQL_ROOT_PASSWORD="lH0aw281e9a342324AdF" \
-e ZBX_DBTLSCONNECT="required" \
-e TZ="Asia/Shanghai" \
-d mysql:8.0 \
--character-set-server=utf8mb3 --collation-server=utf8mb3_bin \
--default-authentication-plugin=mysql_native_password
docker run --name zabbix-server-mysql -t \
-e DB_SERVER_HOST="mysql8" \
-e MYSQL_DATABASE="zabbix" \
-e MYSQL_USER="zabbix" \
-e MYSQL_PASSWORD="lH0aw281e9a342324AdF" \
-e MYSQL_ROOT_PASSWORD="lH0aw281e9a342324AdF" \
-e ZBX_JAVAGATEWAY="zabbix-java-gateway" \
--network=my-network \
-m=500m \
-v /data/zabbix/usr/lib/zabbix:/usr/lib/zabbix:rw \
-v /data/zabbix/var/lib/zabbix:/var/lib/zabbix:rw \
--restart unless-stopped \
-e TZ="Asia/Shanghai" \
-p 10051:10051 \
-d zabbix/zabbix-server-mysql:6.0-centos-latest
docker run --name zabbix-web-nginx-mysql -t \
-e ZBX_SERVER_HOST="zabbix-server-mysql" \
-e DB_SERVER_HOST="mysql8" \
-e MYSQL_DATABASE="zabbix" \
-e MYSQL_USER="zabbix" \
-e MYSQL_PASSWORD="lH0aw281e9a342324AdF" \
-e MYSQL_ROOT_PASSWORD="lH0aw281e9a342324AdF" \
--network=my-network \
--restart unless-stopped \
-e TZ="Asia/Shanghai" \
-d zabbix/zabbix-web-nginx-mysql:6.0-centos-latest
测试效果
参考文档:
https://blog.csdn.net/qq_44379042/article/details/130584868