Basics of using a container to run zabbix to monitor another virtual machine

Table of contents

Install docker

mysql database deployment

Pull mysql image

 Run mysql server

 Create zabbix user and database

Enter the docker container login database

 Create zabbix database Create zabbix user

 zabbix user authorization

Copy the mysql initialization database file to the container

 Import zabbix initialization data

zabbix server deployment

Pull image

Run container

Effect verification


Install docker

#永久关闭selinux,需要重启
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
setenforce 0

#关闭防火墙并设为开机不自启,然后显示状态
systemctl stop firewalld.service &> /dev/null
systemctl disable firewalld.service &> /dev/null

#配置yum源安装需要的组件
yum install -y yum-utils device-mapper-persistent-data  lvm2
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

#查看docker版本
yum list docker-ce --showduplicates

#安装最新的稳定版本
yum install 3:docker-ce-20.10.17-3.el7.x86_64 -y

#配置镜像加速、镜像仓库、docker数据存储路径
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://7w5yqlyj.mirror.aliyuncs.com"],
  "insecure-registries": ["http://docker.hanweb.com"],
  "graph": "/data/dockerdata/docker"  
}
EOF

#启动docker
sudo systemctl daemon-reload
sudo systemctl start docker
systemctl enable docker

mysql database deployment

Before deploying the zabbix server, you need to deploy the mysql server in advance and create the zabbix database and user

Pull mysql image

docker pull mysql

 

 Run mysql server

docker run -itd --name zabbix-database -p 3306:3306 -e MYSQL_ROOT_PASSWORD=password mysql

创建一个名为zabbix-database,并且把3306端口映射到docker主机的3306,设置mysql的root用户密码为password

 Create zabbix user and database

Enter the docker container login database

docker exec -it  zabbix-database /bin/bash
mysql -ppassword

 Create zabbix database Create zabbix user

create database zabbix character set utf8 collate utf8_bin;
create user 'zabbix'@'localhost' identified WITH mysql_native_password by 'password';
create user 'zabbix'@'%' identified WITH mysql_native_password by 'password';

 zabbix user authorization

 grant all privileges on zabbix.* to 'zabbix'@'localhost';
 grant all privileges on zabbix.* to 'zabbix'@'%';
 FLUSH PRIVILEGES;

Copy the mysql initialization database file to the container

docker cp schema.sql zabbix-database:/tmp
docker cp images.sql zabbix-database:/tmp
docker cp data.sql zabbix-database:/tmp

 Import zabbix initialization data

docker exec -it zabbix--database
mysql -ppassword
show databases;
use zabbix
source /tmp/schema.sql
source /tmp/images.sql
source /tmp/data.sql

zabbix server deployment

Pull image

docker pull zabbix/zabbix-server-mysql:centos-6.2.6
docker pull zabbix/zabbix-web-nginx-mysql:centos-6.2.6

Run container

docker run --name zabbix-server -e DB_SERVER_HOST="172.17.0.2" -e MYSQL_USER="zabbix" -e MYSQL_PASSWORD="password" -d zabbix/zabbix-server-mysql:centos-6.2.6

docker run --name zabbix-web -p 8080:8080 --link zabbix-database:zabbix-database --link zabbix-server:zabbix-server -e DB_SERVER_HOST="zabbix-database" -e MYSQL_USER="zabbix" -e MYSQL_PASSWORD="password" -e ZBX_SERVER_HOST="zabbix-server" -e PHP_TZ="Asia/Shanghai" -d zabbix/zabbix-web-nginx-mysql:centos-6.2.6

Effect verification

 

 

 

Supongo que te gusta

Origin blog.csdn.net/weixin_71429844/article/details/128609445
Recomendado
Clasificación