提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档目录
文章目录
前言
一、docker是什么?
二、安装docker
1.yum安装
2.安装docker
3 docker的基本命令、
三? zabbix是什么
四? 安装zabbix
总结
前言
使用docer部署zabblix环境:联网+centos7.5+docker
提示:以下是本篇文章正文内容,下面案例可供参考
一、docker是什么?
?Docker是一个开源的容器引擎,它有助于更快地交付应用。Docker可将应用程序和基础设施层隔离,并且能将基础设施当作程序一样进行管理。
使用Docker可更快地打包、测试以及部署应用程序,并可以缩短从编写到部署运行代码的周期。
参考链接https://www.cnblogs.com/stormlong/p/10863061.html
二、安装docker
1.yum安装
代码如下(示例):
1、Docker要求 CentOS 系统的内核版本高于3.10
# uname -r
查看操作系统版本
# cat /etc/redhat-release
2、卸载旧版本(如果安装过旧版本的话)
# yum remove docker ?docker-common docker-selinux docker-engine
3、查看 yum 源地址
# yum repolist
4、设置yum源,并更新 yum 的包索引
# yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
# yum makecache fast
5、可以查看所有仓库中所有docker版本,并选择特定版本安装
# yum list docker-ce --showduplicates | sort -r
2.安装docker
1、安装docker
# yum install docker-ce ?#由于repo中默认只开启stable仓库,故这里安装的是稳定版18.03.1
# yum install <FQPN> ?# 例如:
# yum -y install docker-ce-18.03.1.ce
2、启动并加入开机启动
# systemctl start docker?
# systemctl enable docker
3、验证安装是否成功(有client和service两部分表示docker安装启动都成功了)
# docker version
4、卸载docker
# yum -y remove docker-engine
3 docker的基本命令、
3.1查看运行进程
[root@ansible ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
576a07b39f81 zabbix-web-nginx-mysql:v1 "docker-entrypoint.sh" 19 minutes ago Up 19 minutes 8443/tcp, 0.0.0.0:8888->8080/tcp zabbix-web-nginx-mysql
be12ba2787c5 zabbix-server-mysql-centos:v1 "/sbin/tini -- /usr/…" 19 minutes ago Up 19 minutes 0.0.0.0:10051->10051/tcp zabbix-server-mysql
a0f0b92f453d zabbix-java-gateway:v1 "docker-entrypoint.s…" 19 minutes ago Up 19 minutes 10052/tcp zabbix-java-gateway
ac5e2efe817a zabbix-mysql57:v1 "docker-entrypoint.s…" 19 minutes ago Up 19 minutes 33060/tcp, 0.0.0.0:3307->3306/tcp zabbix-mysql
3.2?停止运行中的进程
[root@ansible ~]# docker stop 576a07b39f81
3.3??删除 承载改进程的容器了
[root@ansible ~]# docker rmi mysql:8.0.24
3.4 查看日志
[root@ansible ~]# docker logs --since 30m zabbix-mysql
2021-08-08T13:16:16.449714Z 0 [Note] InnoDB: page_cleaner: 1000ms intended loop took 14642ms. The settings might not be optimal. (flushed=0 and evicted=0, during the time.)
2021-08-08T13:17:11.206146Z 0 [Note] InnoDB: page_cleaner: 1000ms intended loop took 35741ms. The settings might not be optimal. (flushed=0 and evicted=0, during the time.)
2021-08-08T13:17:51.103945Z 0 [Note] InnoDB: page_cleaner: 1000ms intended loop took 27887ms. The settings might not be optimal. (flushed=0 and evicted=0, during the time.)
3.5 清理默认情况下,docker image prune 命令只会清理 虚无镜像(没被标记且没被其它任何镜像引用的镜像) 后面慎用!!!清理一切不别用的卷和镜像
root@instance-o70no2nw:~# docker images -a
REPOSITORY TAG IMAGE ID CREATED SIZE
<none> <none> 867c2dc0031b 12 hours ago 465MB
mytomcat 8.5.0 34c8c864d046 12 hours ago 465MB
ubuntu 16.04 a3551444fc85 2 days ago 119MB
mysql 8.0.16 d72169616e20 4 days ago 443MB
mysql latest d72169616e20 4 days ago 443MB
tomcat latest 5a069ba3df4d 2 weeks ago 465MB
root@instance-o70no2nw:~# docker image prune
WARNING! This will remove all dangling images.
Are you sure you want to continue? [y/N] y
Total reclaimed space: 0B
$ docker system prune --volumes
WARNING! This will remove:
- all stopped containers
- all networks not used by at least one container
- all volumes not used by at least one container
- all dangling images
- all build cache
Are you sure you want to continue? [y/N] y
三? zabbix是什么
zabbix是开源的监控系统,多的不说,学习大哥的docker脚本部署
四? 安装zabbix
1? 永久关闭SELiunx和防火墙
[root@localhost ~]# sed -i '7c \SELINUX=disabled' /etc/selinux/config
[root@localhost ~]# setenforce 0
[root@localhost ~]# getenforce
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# systemctl status firewalld
[root@localhost ~]# systemctl disable firewalld
2??vim docker_pull_image.sh
#!/bin/bash
# 删除旧的zabbix容器和镜像
docker stop $(docker ps -a)
sleep 3
docker rm -f $(docker ps -a)
docker rmi -f $(docker images | grep "zabbix")
# 拉取zabbix所需镜像
docker pull mysql:5.7 && docker pull zabbix/zabbix-server-mysql:centos-latest && docker pull zabbix/zabbix-web-nginx-mysql:latest && docker pull zabbix/zabbix-java-gateway:latest
docker pull mysql:8.0.24
# 重命名
docker tag mysql:8.0.24 zabbix-mysq8024:v1
docker tag mysql:5.7 zabbix-mysql57:v1
docker tag zabbix/zabbix-server-mysql:centos-latest zabbix-server-mysql-centos:v1
docker tag zabbix/zabbix-web-nginx-mysql:latest zabbix-web-nginx-mysql:v1
docker tag zabbix/zabbix-java-gateway:latest zabbix-java-gateway:v1
# 删除原有镜像
docker rmi mysql:8.0.24
docker rmi -f mysql:5.7
docker rmi -f zabbix/zabbix-server-mysql:centos-latest
docker rmi -f zabbix/zabbix-web-nginx-mysql:latest
docker rmi -f zabbix/zabbix-java-gateway:latest
# 删除原有数据卷挂载
rm -rf /usr/lib/zabbix/alertscripts
#删除无用的的
docker system prune
docker volume prune
3?vim install_zabbix_server.sh
#!/bin/bash
# 创建docker双向通信共享网络
docker network create -d bridge zabbix-net
# 创建数据卷
docker volume create zabbix-mysql-data
docker volume create zabbix-server-vol
docker run -it -p 3307:3306 \
--name zabbix-mysql \
--network zabbix-net \
--mount source=zabbix-mysql-data,target=/var/lib/mysql \
--restart=always \
-v /etc/localtime:/etc/localtime \
-e MYSQL_DATABASE="zabbix" \
-e MYSQL_USER="zabbix" \
-e MYSQL_PASSWORD="zabbix123" \
-e MYSQL_ROOT_PASSWORD="root123" \
-d zabbix-mysql57:v1
docker run -it -v /etc/localtime:/etc/localtime \
--restart=always \
--name=zabbix-java-gateway \
--network zabbix-net \
-d zabbix-java-gateway:v1
docker run -it -p 10051:10051 \
--mount source=zabbix-server-vol,target=/etc/zabbix \
-v /etc/localtime:/etc/localtime \
-v /usr/lib/zabbix/alertscripts:/usr/lib/zabbix/alertscripts \
--name=zabbix-server-mysql \
--restart=always \
--network zabbix-net \
-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" \
-d zabbix-server-mysql-centos:v1
docker run -it -p 8888:8080 \
-v /etc/localtime:/etc/localtime \
--name zabbix-web-nginx-mysql \
--restart=always \
--network zabbix-net \
-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_SERVER_HOST="zabbix-server-mysql" \
-d zabbix-web-nginx-mysql:v1
4、执行脚本
./docker_pull_image.sh ./install_zabbix_server.sh 等docker_pull_image.sh脚本执行成功后再执行
5、查看镜像和容器
[root@ansible ~]# docker images | grep zabbix
zabbix-web-nginx-mysql v1 59c46117948b 2 days ago 166MB
zabbix-java-gateway v1 2f5a909494f0 2 days ago 84.4MB
zabbix-mysql57 v1 8cf625070931 2 weeks ago 448MB
zabbix-server-mysql-centos v1 20d866692cd9 2 months ago 356MB
zabbix-mysq8024 v1 0627ec6901db 3 months ago 556MB
[root@ansible ~]# docker ps | grep zabbix
576a07b39f81 zabbix-web-nginx-mysql:v1 "docker-entrypoint.sh" About an hour ago Up About an hour 8443/tcp, 0.0.0.0:8888->8080/tcp zabbix-web-nginx-mysql
be12ba2787c5 zabbix-server-mysql-centos:v1 "/sbin/tini -- /usr/…" About an hour ago Up About an hour 0.0.0.0:10051->10051/tcp zabbix-server-mysql
a0f0b92f453d zabbix-java-gateway:v1 "docker-entrypoint.s…" About an hour ago Up About an hour 10052/tcp zabbix-java-gateway
ac5e2efe817a zabbix-mysql57:v1 "docker-entrypoint.s…" About an hour ago Up About an hour 33060/tcp, 0.0.0.0:3307->3306/tcp zabbix-mysql
6、浏览器访问:
http://本机ip:8888
默认账号:Admin
默认密码:zabbix
总结
?参考链接:https://blog.csdn.net/qq_43205778/article/details/117039160
?参考链接:https://www.cnblogs.com/stormlong/p/10863061.html
|