要用docker
跑zabbix-server
,須要如下幾個組件css
組件名稱 | 做用 |
---|---|
數據庫 | MySQL 或是PostgreSQL |
Zabbix Java gateway | Java管理擴展,能夠不添加 |
Zabbix server | zabbix 服務端 |
zabbix-web | 與MySQL服務器實例和Zabbix server實例關聯 |
zabbix-agent | zabbix客戶端 |
數據庫我選擇MySQL
,仍是得寫Dockerfile
,改一下時區,時間不對很麻煩,字符集也改一下吧java
# mkdir /data/docker/mysql -p /data/docker/mysql]# vim Dockerfile FROM mysql:5.7 ENV LANG en_US.utf8 RUN ln -snf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \ echo Asia/Shanghai > /etc/timezone \
#docker build -t debian-mysql5.7 . # docker images REPOSITORY TAG IMAGE ID CREATED SIZE debian-mysql5.7 latest 3d3c7dc9608c 14 seconds ago 372MB mysql 5.7 563a026a1511 3 weeks ago 372MB
# docker run --hostname mysql --name debian-mysql-5.7 -t \ -e MYSQL_USER="zabbix" \ -e MYSQL_DATABASE="zabbix" \ -e MYSQL_PASSWORD="passwd" \ -e MYSQL_ROOT_PASSWORD="passwd" \ -v /data/mysql:/var/lib/mysql:rw \ -d debian-mysql5.7 9a98a2ba0896a8a146d515764d2d8eef4bc32a9f0dbea445c360fab5668a5cfe # docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 9a98a2ba0896 debian-mysql5.7 "docker-entrypoint.s…
變量 | |
---|---|
MYSQL_USER | 啓動時要添加的用戶 |
MYSQL_DATABASE | 啓動時要建立的數據庫 |
MYSQL_PASSWORD | 指定添加用的的密碼 |
MYSQL_ROOT_PASSWORD | root用戶的密碼 |
這個看我的,若是不監控java
應用服務器能夠不安裝這個,仍是得寫Dockerfile
,改一下時區和編碼。mysql
/data/docker/java-gateway]# cat Dockerfile FROM zabbix/zabbix-java-gateway:latest ENV LANG en_US.utf8 RUN apk add -U tzdata RUN ln -snf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \ echo Asia/Shanghai > /etc/timezone \ /data/docker/java-gateway]# docker build -t zabbix-java-gateway . /data/docker/java-gateway]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE zabbix-java-gateway latest 7948dffa9af0 35 seconds ago 80.1MB
須要映射一下10052
端口nginx
# docker run --hostname zabbix-java-gateway \ -name zabbix-java-gateway -t \ -p 10052:10052 \ -d zabbix-java-gateway 5e2434e7a4c6f3f947e6408ff5a90097e802c6a36282c36ce7e4cd5819474f7a # docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 5e2434e7a4c6 zabbix-java-gateway "docker-entrypoint.sh" 9 seconds ago Up 7 seconds 0.0.0.0:10052->10052/tcp zabbix-java-gateway 9a98a2ba0896 debian-mysql5.7 "docker-entrypoint.s…" 33 minutes ago Up 33 minutes 3306/tcp, 33060/tcp debian-mysql-5.7
編寫Dockerfileweb
/data/docker/zabbix-server]# cat Dockerfile FROM zabbix/zabbix-server-mysql:latest ENV LANG en_US.utf8 RUN apk add -U tzdata RUN ln -snf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \ echo Asia/Shanghai > /etc/timezone \ /data/docker/zabbix-server]# docker build -t zabbix-server . /data/docker/zabbix-server]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE zabbix-server latest 531aa3116f61 About a minute ago 62.3MB
須要映射10051
端口,指定數據庫服務器,鏈接MySQL
和zabbix-java-gateway
容器sql
10051:10051 \
--hostname zabbix-server \
-e DB_SERVER_HOST="debian-mysql-5.7" \
-e MYSQL_DATABASE="zabbix" \
-e MYSQL_USER="zabbix" \
-e MYSQL_PASSWORD="passwd" \
-e MYSQL_ROOT_PASSWORD="passwd" \
-e ZBX_JAVAGATEWAY="zabbix-java-gateway" \
--link debian-mysql-5.7:mysql \
--link zabbix-java-gateway:zabbix-java-gateway \
-d zabbix-server
# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a45ef352cc68 zabbix-server "docker-entrypoint.sh" 9 minutes ago Up 8 minutes 0.0.0.0:10051->10051/tcp zabbix-serverdocker
編寫Dockerfile
數據庫
/data/docker/zabbix-web]# cat Dockerfile FROM zabbix/zabbix-web-nginx-mysql:latest ENV LANG en_US.utf8 RUN apk add -U tzdata RUN ln -snf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \ echo Asia/Shanghai > /etc/timezone \ /data/docker/zabbix-web]# docker build -t zabbix-web . /data/docker/zabbix-web]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE zabbix-web latest 6ff51e2f0545 About a minute ago 164MB
須要映射80端口到宿主機,鏈接數據庫,鏈接zabbix-server
容器vim
# docker run --name zabbix-web -t \ -p 80:80 \ --hostname zabbix-web \ -e PHP_TZ="Asia/Shanghai" \ -e DB_SERVER_HOST="debian-mysql-5.7" \ -e MYSQL_DATABASE="zabbix" \ -e MYSQL_USER="zabbix" \ -e MYSQL_PASSWORD="passwd" \ -e MYSQL_ROOT_PASSWORD="passwd" \ --link debian-mysql-5.7:mysql \ --link zabbix-server:zabbix-server \ -d zabbix-web f0c33f227992ce220730da9454df2f354565ed0b3d0813513a87797c2b752702 # docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES f0c33f227992 zabbix-web "docker-entrypoint.sh" 13 seconds ago Up 10 seconds 0.0.0.0:80->80/tcp, 443/tcp zabbix-web
以上方式安裝的是最新版本,由於在指定鏡像的時候沒有指定版本號,默認的就是laster
,也就是最新版本,建議zabbix-agent
版本要和服務端一致。服務器
# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES b4b2524953b4 zabbix-web "docker-entrypoint.sh" About an hour ago Up About an hour 0.0.0.0:80->80/tcp, 443/tcp zabbix-web d5a45e58b69d zabbix-server "docker-entrypoint.sh" 2 hours ago Up 2 hours 0.0.0.0:10051->10051/tcp zabbix-server cd16d62b98c4 zabbix-java-gateway "docker-entrypoint.sh" 2 hours ago Up 2 hours 0.0.0.0:10052->10052/tcp zabbix-java-gateway 6a4b9ce12398 debian-mysql5.7 "docker-entrypoint.s…" 2 hours ago Up 2 hours 3306
/tcp, 33060/tcp debian-mysql-5.
訪問:http://宿主機IP:80
#rpm -i https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm #yum -y install zabbix-agent-4.0.1
#vim /etc/zabbix/zabbix_agentd.conf Server=192.168.130.6 UnsafeUserParameters=1 Include=/etc/zabbix/zabbix_agentd.d/*.conf # systemctl start zabbix-agent
注意:若是要對宿主機進行監控,請編輯宿主機的zabbix_agentd.conf
,將Server
地址,默認127.0.0.1
,修改成docker-server
容器地址,不然不通;若是是對其餘主機的監控則使用docker-zabbix-server宿主機的IP。
# docker exec -it zabbix-server ip addr 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever 23: eth0@if24: <BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN> mtu 1500 qdisc noqueue state UP link/ether 02:42:ac:11:00:04 brd ff:ff:ff:ff:ff:ff inet 172.17.0.4/16 brd 172.17.255.255 scope global eth0 valid_lft forever preferred_lft forever
要用docker
跑zabbix-server
,須要如下幾個組件
組件名稱 | 做用 |
---|---|
數據庫 | MySQL 或是PostgreSQL |
Zabbix Java gateway | Java管理擴展,能夠不添加 |
Zabbix server | zabbix 服務端 |
zabbix-web | 與MySQL服務器實例和Zabbix server實例關聯 |
zabbix-agent | zabbix客戶端 |
數據庫我選擇MySQL
,仍是得寫Dockerfile
,改一下時區,時間不對很麻煩,字符集也改一下吧
# mkdir /data/docker/mysql -p /data/docker/mysql]# vim Dockerfile FROM mysql:5.7 ENV LANG en_US.utf8 RUN ln -snf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \ echo Asia/Shanghai > /etc/timezone \
#docker build -t debian-mysql5.7 . # docker images REPOSITORY TAG IMAGE ID CREATED SIZE debian-mysql5.7 latest 3d3c7dc9608c 14 seconds ago 372MB mysql 5.7 563a026a1511 3 weeks ago 372MB
# docker run --hostname mysql --name debian-mysql-5.7 -t \ -e MYSQL_USER="zabbix" \ -e MYSQL_DATABASE="zabbix" \ -e MYSQL_PASSWORD="passwd" \ -e MYSQL_ROOT_PASSWORD="passwd" \ -v /data/mysql:/var/lib/mysql:rw \ -d debian-mysql5.7 9a98a2ba0896a8a146d515764d2d8eef4bc32a9f0dbea445c360fab5668a5cfe # docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 9a98a2ba0896 debian-mysql5.7 "docker-entrypoint.s…
變量 | |
---|---|
MYSQL_USER | 啓動時要添加的用戶 |
MYSQL_DATABASE | 啓動時要建立的數據庫 |
MYSQL_PASSWORD | 指定添加用的的密碼 |
MYSQL_ROOT_PASSWORD | root用戶的密碼 |
這個看我的,若是不監控java
應用服務器能夠不安裝這個,仍是得寫Dockerfile
,改一下時區和編碼。
/data/docker/java-gateway]# cat Dockerfile FROM zabbix/zabbix-java-gateway:latest ENV LANG en_US.utf8 RUN apk add -U tzdata RUN ln -snf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \ echo Asia/Shanghai > /etc/timezone \ /data/docker/java-gateway]# docker build -t zabbix-java-gateway . /data/docker/java-gateway]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE zabbix-java-gateway latest 7948dffa9af0 35 seconds ago 80.1MB
須要映射一下10052
端口
# docker run --hostname zabbix-java-gateway \ -name zabbix-java-gateway -t \ -p 10052:10052 \ -d zabbix-java-gateway 5e2434e7a4c6f3f947e6408ff5a90097e802c6a36282c36ce7e4cd5819474f7a # docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 5e2434e7a4c6 zabbix-java-gateway "docker-entrypoint.sh" 9 seconds ago Up 7 seconds 0.0.0.0:10052->10052/tcp zabbix-java-gateway 9a98a2ba0896 debian-mysql5.7 "docker-entrypoint.s…" 33 minutes ago Up 33 minutes 3306/tcp, 33060/tcp debian-mysql-5.7
編寫Dockerfile
/data/docker/zabbix-server]# cat Dockerfile FROM zabbix/zabbix-server-mysql:latest ENV LANG en_US.utf8 RUN apk add -U tzdata RUN ln -snf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \ echo Asia/Shanghai > /etc/timezone \ /data/docker/zabbix-server]# docker build -t zabbix-server . /data/docker/zabbix-server]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE zabbix-server latest 531aa3116f61 About a minute ago 62.3MB
須要映射10051
端口,指定數據庫服務器,鏈接MySQL
和zabbix-java-gateway
容器
10051:10051 \
--hostname zabbix-server \
-e DB_SERVER_HOST="debian-mysql-5.7" \
-e MYSQL_DATABASE="zabbix" \
-e MYSQL_USER="zabbix" \
-e MYSQL_PASSWORD="passwd" \
-e MYSQL_ROOT_PASSWORD="passwd" \
-e ZBX_JAVAGATEWAY="zabbix-java-gateway" \
--link debian-mysql-5.7:mysql \
--link zabbix-java-gateway:zabbix-java-gateway \
-d zabbix-server
# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a45ef352cc68 zabbix-server "docker-entrypoint.sh" 9 minutes ago Up 8 minutes 0.0.0.0:10051->10051/tcp zabbix-server
編寫Dockerfile
/data/docker/zabbix-web]# cat Dockerfile FROM zabbix/zabbix-web-nginx-mysql:latest ENV LANG en_US.utf8 RUN apk add -U tzdata RUN ln -snf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \ echo Asia/Shanghai > /etc/timezone \ /data/docker/zabbix-web]# docker build -t zabbix-web . /data/docker/zabbix-web]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE zabbix-web latest 6ff51e2f0545 About a minute ago 164MB
須要映射80端口到宿主機,鏈接數據庫,鏈接zabbix-server
容器
# docker run --name zabbix-web -t \ -p 80:80 \ --hostname zabbix-web \ -e PHP_TZ="Asia/Shanghai" \ -e DB_SERVER_HOST="debian-mysql-5.7" \ -e MYSQL_DATABASE="zabbix" \ -e MYSQL_USER="zabbix" \ -e MYSQL_PASSWORD="passwd" \ -e MYSQL_ROOT_PASSWORD="passwd" \ --link debian-mysql-5.7:mysql \ --link zabbix-server:zabbix-server \ -d zabbix-web f0c33f227992ce220730da9454df2f354565ed0b3d0813513a87797c2b752702 # docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES f0c33f227992 zabbix-web "docker-entrypoint.sh" 13 seconds ago Up 10 seconds 0.0.0.0:80->80/tcp, 443/tcp zabbix-web
以上方式安裝的是最新版本,由於在指定鏡像的時候沒有指定版本號,默認的就是laster
,也就是最新版本,建議zabbix-agent
版本要和服務端一致。
# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES b4b2524953b4 zabbix-web "docker-entrypoint.sh" About an hour ago Up About an hour 0.0.0.0:80->80/tcp, 443/tcp zabbix-web d5a45e58b69d zabbix-server "docker-entrypoint.sh" 2 hours ago Up 2 hours 0.0.0.0:10051->10051/tcp zabbix-server cd16d62b98c4 zabbix-java-gateway "docker-entrypoint.sh" 2 hours ago Up 2 hours 0.0.0.0:10052->10052/tcp zabbix-java-gateway 6a4b9ce12398 debian-mysql5.7 "docker-entrypoint.s…" 2 hours ago Up 2 hours 3306
/tcp, 33060/tcp debian-mysql-5.
訪問:http://宿主機IP:80
#rpm -i https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm #yum -y install zabbix-agent-4.0.1
#vim /etc/zabbix/zabbix_agentd.conf Server=192.168.130.6 UnsafeUserParameters=1 Include=/etc/zabbix/zabbix_agentd.d/*.conf # systemctl start zabbix-agent
注意:若是要對宿主機進行監控,請編輯宿主機的zabbix_agentd.conf
,將Server
地址,默認127.0.0.1
,修改成docker-server
容器地址,不然不通;若是是對其餘主機的監控則使用docker-zabbix-server宿主機的IP。
# docker exec -it zabbix-server ip addr 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever 23: eth0@if24: <BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN> mtu 1500 qdisc noqueue state UP link/ether 02:42:ac:11:00:04 brd ff:ff:ff:ff:ff:ff inet 172.17.0.4/16 brd 172.17.255.255 scope global eth0 valid_lft forever preferred_lft forever