Ready to work
Two VMware virtual machine
Act as a zabbix server (installed docker) ip: 192.168.73.133
Act as a zabbix agent (installed docker) ip: 192.168.73.136
Basic environment
cat /etc/redhat-release
CentOS Linux release 7.5.1804 (Core)
dcoker installation
# Turn off the firewall:
systemctl stop firewalld
systemctl disable firewalld
# Disable selinux:
sed -i 's/enforcing/disabled/' /etc/selinux/config
setenforce 0
# Install dependencies
yum install -y yum-utils device-mapper-persistent-data lvm2
# Add Docker package source
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
# Installation Docker ce
yum install -y docker-ce
# Docker start the service and set the boot
systemctl start docker
systemctl enable docker
# View the version number
[root@localhost ~]# docker versionClient: Docker Engine - Community Version: 19.03.1
API version: 1.40
Go version: go1.12.5
Git commit: 74b1e89 Built: Thu Jul 25 21:21:07 2019 OS/Arch:
linux/amd64 Experimental: falseServer: Docker Engine - Community Engine:
Version: 19.03.1 API version: 1.40 (minimum version 1.12)
Go version: go1.12.5 Git commit: 74b1e89 Built: Thu Jul 25 21:19:36 2019
OS/Arch: linux/amd64
Experimental: false
containerd: Version: 1.2.6
GitCommit: 894b81a4b802e4eb2a91d1ce216b8817763c29fb runc:
Version: 1.0.0-rc8
GitCommit: 425e105d5a03fabd737a126ad93d62a9eeede87f
docker-init: Version: 0.18.0
GitCommit: fec3683
# Configure mirroring accelerator
curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://f1361db2.m.daocloud.io
# Reboot Mirror
systemctl restart docker
docker installed!
zabbix server side operation
It offers two different installation methods
1, using the official website of the docker zabbix mounting chapters, the image library in the official pulls the mirror mounting manner
https://www.zabbix.com/documentation/4.0/zh/manual/installation/containers
Contents of this document local directory structure in the host / home / zabbix, the container is provided for storing data, and other optional depending on the application directory, the following command to connect to external networks needs to be mirrored pull, there is no need for external network offline Download image package
1) Start mysql a separate database for storing data zabbix
1 docker run --name mysql-server -t \ 2 -e MYSQL_DATABASE="zabbix" \ 3 -e MYSQL_USER="zabbix" \ 4 -e MYSQL_PASSWORD="zabbix" \ 5 -e MYSQL_ROOT_PASSWORD="zabbix" \ 6 -v /home/zabbix/data:/var/lib/mysql \ 7 -d mysql:5.7 \ 8 --character-set-server=utf8 \ 9 --collation-server=utf8_bin \ 10 --restart=always \ 11 -p 3306:3306
Defines the database name zabbix, database user zabbix, password zabbix, in the local directory / home / zabbix / data in persistent data stored in the mysql container operation, ensure that the vessel out of operation, data is not lost, the last two of which are defined database character set is utf8, to solve the problem of Chinese mysql database saved;
2) Start zabbix server services, and services related to the above example the mysql database has been launched to ensure that the data can be saved to zabbix mysql database, mount a local directory and some other content, according to the actual situation of the production environment flexibility to decide whether to mount If the mount can be loaded directly through the container script or authentication information in the local directory, centos version mirror version to use, easy to follow to use a python script, pre-installed py environment
1 docker run --name zabbix-server-mysql -t \ 2 -e DB_SERVER_HOST="mysql-server" \ 3 -e MYSQL_DATABASE="zabbix" \ 4 -e MYSQL_USER="zabbix" \ 5 -e MYSQL_PASSWORD="zabbix" \ 6 -e MYSQL_ROOT_PASSWORD="zabbix" \ 7 --link mysql-server:mysql \ 8 -v /home/zabbix/alertscripts:/usr/lib/zabbix/alertscripts \ 9 -v /home/zabbix/externalscripts:/usr/lib/zabbix/externalscripts \ 10 -v /home/zabbix/zabbixconfig:/etc/zabbix \ 11 -v /home/zabbix/modules:/var/lib/zabbix/modules \ 12 -v /home/zabbix/enc:/var/lib/zabbix/enc \ 13 -v /home/zabbix/ssh_keys:/var/lib/zabbix/ssh_keys \ 14 -v /home/zabbix/ssl/certs:/var/lib/zabbix/ssl/certs \ 15 -v /home/zabbix/ssl/keys:/var/lib/zabbix/ssl/keys \ 16 -v /home/zabbix/ssl/ssl_ca:/var/lib/zabbix/ssl/ssl_ca \ 17 -v /home/zabbix/snmptraps:/var/lib/zabbix/snmptraps \ 18 -v /home/zabbix/mibs:/var/lib/zabbix/mibs \ 19 -p 10051:10051 \ 20 -d zabbix/zabbix-server-mysql:centos-latest \ 21 -restart=always
Mount Description:
/usr/lib/zabbix/alertscripts
The volume used to store custom alert scripts, it is AlertScriptsPath parameters zabbix_server.conf
/usr/lib/zabbix/externalscripts
External inspection (item type) using the volume, which is ExternalScripts parameter zabbix_server.conf
/usr/lib/zabbix/alertscripts
The volume for holding an end zabbix-server configuration file
/var/lib/zabbix/modules
The volume loading of other modules and allows the use of a function expansion LoadModule Zabbix server.
/var/lib/zabbix/enc
The volume TLS is used to store related files. The names of these files using a predetermined ZBX_TLSCAFILE, ZBX_TLSCRLFILE, ZBX_TLSKEY_FILE and ZBX_TLSPSKFILE variables.
/var/lib/zabbix/ssh_keys
The volume is used to check SSH public and private keys and operation positions. It is SSHKeyLocation parameters zabbix_server.conf.
/var/lib/zabbix/ssl/certs
The volume position as a client authenticated SSL client certificate file. It is SSLCertLocation parameters zabbix_server.conf.
/var/lib/zabbix/ssl/keys
The location of the SSL private key file volumes as client authentication. It is SSLKeyLocation parameters zabbix_server.conf.
/var/lib/zabbix/ssl/ssl_ca
The volume serves as SSL certificate validation server certificate authority position (CA) file. It is SSLCALocation parameters zabbix_server.conf.
/var/lib/zabbix/snmptraps
The volume used as the position snmptraps.log file. It can be shared by zabbix-snmptraps container and volumes_from use Docker options are inherited when creating a new instance Zabbix server.
You can use shared volumes and the exchange ZBX_ENABLE_SNMP_TRAPS environment variables to enable SNMP trap processing function true.
/var/lib/zabbix/mibs
This volume allows you to add new MIB file. It does not support subdirectories, you must place all the MIB / var / lib / zabbix / mibs
Note: usually used to store path is the path to the script and configuration files
3) Start the web interface zabbix distal example, a web interface in the previous examples mysql database service instance
1 docker run --rm --name zabbix-web-nginx-mysql -t \ 2 -e DB_SERVER_HOST="mysql-server" \ 3 -e MYSQL_DATABASE="zabbix" \ 4 -e MYSQL_USER="zabbix" \ 5 -e MYSQL_PASSWORD="zabbix" \ 6 -e MYSQL_ROOT_PASSWORD="zabbix" \ 7 -e PHP_TZ="Asia/Shanghai" \ 8 --link mysql-server:mysql \ 9 --link zabbix-server-mysql:zabbix-server \ 10 -p 8080:80 \ 11 -d zabbix/zabbix-web-nginx-mysql:latest
--link mysql-server: mysql connect to the database instance, mysql-server must be fully consistent with the first step of --name mysql-server
--link zabbix-server-mysql: zabbix-server connection server zabbix instance, zabbix-server-mysql must exactly match the second step --name zabbix-server-mysql
DB_SERVER_HOST variable to specify the value of the second step -e DB_SERVER_HOST = "mysql-server" consistent
4) Check whether the three containers are mounted properly start
The state is more than three vessels all normal start
# If there is no start can be used to view a list of all containers
[root@localhost ~]# docker ps -a
ID # locate the container that fails to start, and then view the log
[
5) on the host, using the normal installation zabbix-agent is not used containers
1 #rpm -ivh https://repo.zabbix.com/zabbix/4.2/rhel/7/x86_64/zabbix-agent-4.2.5-1.el7.x86_64.rpm 2 #yum install zabbix-agent 3 #vim /etc/zabbix/zabbix_agentd.conf #修改配置文件 4 Server=172.17.0.3 5 ServerActive=172.17.0.3:10050 6 Hostname=Zabbix server 7 #systemctl restart zabbix-agent 8 #systemctl enable zabbix-agent
Note: If you want to host monitor, edit the host zabbix_agentd.conf
, will Server
address the default 127.0.0.1
, modify the docker-server
vessel address, or unreasonable; if it is to monitor other hosts IP docker-zabbix-server host is using
6) Verify landed host port 8080 to see if normal landing
Use installation zabbix server host ip add port 8080 login account Admin, password zabbix, default is English, white background, language and background colors can be adjusted in the user button option in the upper right corner
2, the use of docker-compose, install
1) mounted docker-compose
1 # curl -L https://github.com/docker/compose/releases/download/1.23.2/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose 2 # chmod +x /usr/local/bin/docker-compose 3 # docker-compose --version 4 docker-compose version 1.23.1, build b02f1306
2) write yml layout file
Create a folder
1 # mkdir /docker-compose 2 # cd /docker-compose/ 3 # vim docker-compose.yml
Write docker-compose
1 version: '3' 2 mysql: 3 image: mariadb:latest 4 ports: 5 - "3306:3306" 6 volumes: 7 - ./home/zabbix/data:/var/lib/mysql 8 - ./home/zabbix/data:/etc/mysql 9 - ./home/zabbix/data:/var/log/mysql 10 environment: 11 - MYSQL_USER=zabbix 12 - MYSQL_DATABASE=zabbix 13 - MYSQL_PASSWORD=zabbix 14 - MYSQL_ROOT_PASSWORD=123321 15 - LANG=en_US.utf8 16 - TZ=Asia/Shanghai 17 restart: always 18 services: 19 zabbix-server: 20 container_name: zabbix-server 21 image: zabbix/zabbix-server-mysql:centos-latest 22 restart: always 23 network_mode: host 24 # ports: 25 # - "10051:10051" 26 environment: 27 - DB_SERVER_HOST=192.168.73.133 28 - MYSQL_USER=zabbix 29 - MYSQL_DATABASE=zabbix 30 - MYSQL_PASSWORD=zabbix 31 - DB_SERVER_ROOT_USER=root 32 - DB_SERVER_ROOT_PASS=123321 33 - TZ='Asia/Shanghai' 34 volumes: 35 - /home/zabbix/zabbixconfig:/etc/zabbix 36 - /home/zabbix/alertscripts:/usr/lib/zabbix/alertscripts 37 - /home/zabbix/externalscripts:/usr/lib/zabbix/externalscripts 38 - /home/zabbix/modules:/var/lib/zabbix/modules 39 - /home/zabbix/enc:/var/lib/zabbix/enc 40 - /home/zabbix/ssh_keys:/var/lib/zabbix/ssh_keys 41 - /home/zabbix/ssl/certs:/var/lib/zabbix/ssl/certs 42 - /home/zabbix/ssl/keys:/var/lib/zabbix/ssl/keys 43 - /home/zabbix/ssl/ssl_ca:/var/lib/zabbix/ssl/ssl_ca 44 - /home/zabbix/snmptraps:/var/lib/zabbix/snmptraps 45 - /home/zabbix/mibs:/var/lib/zabbix/mibs 46 zabbix-web-nginx: 47 image: zabbix/zabbix-web-nginx-mysql:latest 48 restart: always 49 network_mode: bridge 50 ports: 51 - "8080:80" 52 environment: 53 - DB_SERVER_HOST=192.168.73.133 54 - MYSQL_DATABASE=zabbix 55 - MYSQL_USER=zabbix 56 - MYSQL_PASSWORD=zabbix 57 - MYSQL_ROOT_PASSWORD=123321 58 - ZBX_SERVER_HOST=192.168.73.133 59 - PHP_TZ="Asia/Shanghai" 60 - TZ='Asia/Shanghai' 61 zabbix-agent: 62 image: zabbix/zabbix-agent:latest 63 environment: 64 - ZBX_HOSTNAME=Zabbix server 65 - ZBX_SERVER_HOST=127.0.0.1 66 - ZBX_SERVER_PORT=10051 67 - TZ='Asia/Shanghai' 68 network_mode: host 69 # ports: 70 # - "10050:10050" 71 restart: always 72 privileged: true 73 # links: 74 # - zabbix-server:zabbixhost
3) be modified according to your own ip address of the host, mainly modify the layout file docker-compose.yml
Line 53 - DB_SERVER_HOST = Current IP host
105 OK - DB_SERVER_HOST = Current IP host
115 OK - ZBX_SERVER_HOST = current host IP
4) Load yml layout file (need to wait for some time because of the need to download image)
docker-compose -f docker-compose.yml up -d
5) After loading the finished viewing the container group is running
[root@localhost cmp_zabbix_server]# docker-compose ps Name Command State Ports -------------------------------------------------------------------------------------------------------------------------- cmp_zabbix_server_zabbix-agent_1_95447af24cfd /sbin/tini -- /usr/bin/doc ... Up cmp_zabbix_server_zabbix-web-nginx_1_aeec36553371 docker-entrypoint.sh Up 443/tcp, 0.0.0.0:8080->80/tcp zabbix-server
zabbix agent terminal operation
1 If the host can be installed docker, and they can use docker-compose, arrange yml write files to install, modify according to line 8 ip host ip address
1 # mkdir /docker-compose 2 # cd /docker-compose/ 3 # vim docerk-compose.yml 4 5 version: '3' 6 version: '3' 7 services: 8 zabbix-agent: 9 image: zabbix/zabbix-agent:latest 10 container_name: zabbix-agent 11 environment: 12 - ZBX_HOSTNAME=192.168.73.136 13 - ZBX_SERVER_HOST=192.168.73.133 14 - ZBX_SERVER_PORT=10051 15 - TZ='Asia/Shanghai' 16 network_mode: bridge 17 ports: 18 - "10050:10050" 19 restart: always 20 privileged: true
Loading layout files
docker-compose -f docker-compose.yml up -d --build
Check whether the container starts successfully
docker-compose ps
If the host is not installed docker, the package can be installed using rpm, mounted See agent step zabbix-server host
Operation end web
Authentication log-host port 8080 to see if normal landing, using the installation zabbix server host ip port 8080 plus login, account admin, password zabbix, default is English, white background, you can adjust the language and context of the user button option in the upper right corner colors, add just installed in the host agent configuration options
No. I can focus on the public, and if the problem wrong place, welcome that and exchanges
Reference documents:
https://www.cnblogs.com/yaun1498078591/p/10181106.html
https://www.cnblogs.com/shuaiyin/p/11070056.html
https://blog.csdn.net/firehadoop/article/details/84642907