环境1:

  • 系统:Linux Centos 7.4 x64
  • 内核:Linux docker 3.10.0-693.2.2.el7.x86_64
  • Docker 版本:18.09.1
  • redis 版本:nginx-1.15.7
  • 主机数量:1台
  • 主机地址:192.168.1.81

环境2:

  • 已搭建 Docker Swarm 管理
  • 已搭建 Docker 私有仓库
  • 已搭建 NFS 存储

目录结构

├── nginx
│   ├── dist.zip # 自定义项目
│   ├── Dockerfile
│   ├── nginx-1.15.7.tar.gz
│   ├── nginx.conf
│   ├── openssl-1.1.1a.tar.gz
│   ├── pcre-8.42.tar.gz
│   ├── vhosts.conf
│   └── zlib-1.2.11.tar.gz

└── service_nginx.yml


下载

  • nginx压缩包
  • 下载地址:https://pan.baidu.com/s/1yb783fGyn62kWi8j3hvtmQ
  • 密码:h41v

  • openssl压缩包
  • 下载地址:https://pan.baidu.com/s/1l5oiq0-ZzRP00oTfEd6aqA
  • 密码:8uk3

  • pcre压缩包
  • 下载地址:https://pan.baidu.com/s/1sXDtYsRlye1ANwCz3bS8BA
  • 密码:mrmd

  • zlib压缩包
  • 下载地址:https://pan.baidu.com/s/1AWsZ00uhn32KCg9eGSF1SA
  • 密码:6mwr

1、创建dockerfile

FROM centos:6
MAINTAINER xiangsikai
ENV LANG en_US.UTF-8
ENV TZ=Asia/Shanghai
RUN yum install sudo unzip -y
RUN sudo yum update -y && \
sudo yum groupinstall -y 'Development Tools' && \
sudo yum install -y epel-release && \
sudo yum install -y perl perl-devel perl-ExtUtils-Embed libxslt libxslt-devel libxml2 libxml2-devel gd gd-devel GeoIP GeoIP-devel
ADD nginx-1.15.7.tar.gz /home/root/
ADD pcre-8.42.tar.gz /home/root/
ADD zlib-1.2.11.tar.gz /home/root/
ADD openssl-1.1.1a.tar.gz /home/root/
RUN cd /home/root/nginx-1.15.7/ && ./configure --prefix=/usr/local/nginx \
--sbin-path=/usr/sbin/nginx \
--conf-path=/etc/nginx/nginx.conf \
--user=nginx \
--group=nginx \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/run/nginx.lock \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--with-select_module \
--with-poll_module \
--with-threads \
--with-file-aio \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_xslt_module=dynamic \
--with-http_image_filter_module=dynamic \
--with-http_geoip_module=dynamic \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_auth_request_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_degradation_module \
--with-http_slice_module \
--with-http_stub_status_module \
--with-mail=dynamic \
--with-mail_ssl_module \
--with-stream=dynamic \
--with-stream_ssl_module \
--with-stream_realip_module \
--with-stream_geoip_module=dynamic \
--with-stream_ssl_preread_module \
--with-compat \
--with-pcre=../pcre-8.42 \
--with-pcre-jit \
--with-zlib=../zlib-1.2.11 \
--with-openssl=../openssl-1.1.1a \
--with-openssl-opt=no-nextprotoneg \
--with-debug && \
make && make install
RUN sudo useradd nginx && sudo mkdir /etc/nginx/conf.d
COPY nginx.conf /etc/nginx/nginx.conf
COPY vhosts.conf /etc/nginx/conf.d/
ADD dist.zip /usr/local/nginx/html/
RUN unzip /usr/local/nginx/html/dist.zip -d /usr/local/nginx/html/
CMD ["nginx","-g","daemon off;"]
EXPOSE 80
# 指定系统镜像版本
FROM centos:6
# 指定管理员名称
MAINTAINER xiangsikai
# 添加变量,指定中文编码
ENV LANG en_US.UTF-8
# 添加变量,同步系统时间
ENV TZ=Asia/Shanghai
# 添加命令
RUN yum install sudo unzip -y
# 添加命令
RUN sudo yum update -y && \
sudo yum groupinstall -y 'Development Tools' && \
sudo yum install -y epel-release && \
sudo yum install -y perl perl-devel perl-ExtUtils-Embed libxslt libxslt-devel libxml2 libxml2-devel gd gd-devel GeoIP GeoIP-devel
# 添加文件
ADD nginx-1.15.7.tar.gz /home/root/
# 添加文件
ADD pcre-8.42.tar.gz /home/root/
# 添加文件
ADD zlib-1.2.11.tar.gz /home/root/
# 添加文件
ADD openssl-1.1.1a.tar.gz /home/root/
# 添加命令
RUN cd /home/root/nginx-1.15.7/ && ./configure --prefix=/usr/local/nginx \
--sbin-path=/usr/sbin/nginx \
--conf-path=/etc/nginx/nginx.conf \
--user=nginx \
--group=nginx \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/run/nginx.lock \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--with-select_module \
--with-poll_module \
--with-threads \
--with-file-aio \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_xslt_module=dynamic \
--with-http_image_filter_module=dynamic \
--with-http_geoip_module=dynamic \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_auth_request_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_degradation_module \
--with-http_slice_module \
--with-http_stub_status_module \
--with-mail=dynamic \
--with-mail_ssl_module \
--with-stream=dynamic \
--with-stream_ssl_module \
--with-stream_realip_module \
--with-stream_geoip_module=dynamic \
--with-stream_ssl_preread_module \
--with-compat \
--with-pcre=../pcre-8.42 \
--with-pcre-jit \
--with-zlib=../zlib-1.2.11 \
--with-openssl=../openssl-1.1.1a \
--with-openssl-opt=no-nextprotoneg \
--with-debug && \
make && make install
# 添加命令
RUN sudo useradd nginx && sudo mkdir /etc/nginx/conf.d
# 添加文件
COPY nginx.conf /etc/nginx/nginx.conf
# 添加文件
COPY vhosts.conf /etc/nginx/conf.d/
# 添加文件
ADD dist.zip /usr/local/nginx/html/
# 添加命令
RUN unzip /usr/local/nginx/html/dist.zip -d /usr/local/nginx/html/
# 启动命令
CMD ["nginx","-g","daemon off;"]
# 开放端口
EXPOSE 80

文件注释

2、创建镜像(nginx目录下)

docker build -t 192.168.1.81:5000/nginx:v1 .

3、上传镜像

docker push 192.168.1.81:5000/nginx:v1

4、创建 service_nginx.yml

version: '3.7'
services: nginx:
image: 192.168.1.81:5000/nginx:v1
ports:
- 2008:80
networks:
- networkce
deploy:
mode: replicated
replicas: 2
update_config:
parallelism: 1
delay: 10s
failure_action: rollback
order: start-first
rollback_config:
parallelism: 1
delay: 10s
failure_action: rollback
order: start-first
volumes:
- type: volume
source: nfs-nginx_log
target: /var/log/nginx
volume:
nocopy: true
configs:
- source: nginx_config
target: /etc/nginx/nginx.conf
- source: nginx_vhosts
target: /etc/nginx/conf.d/vhosts.conf networks:
networkce:
driver: overlay volumes:
nfs-nginx_log:
driver: local
driver_opts:
type: "nfs"
o: "addr=192.168.1.81,vers=4,soft,timeo=180,bg,tcp,rw"
device: "192.168.1.81:/docker/service/zs/nginx/log" configs:
nginx_config:
file: /docker/service/zs/nginx/config/nginx.conf
nginx_vhosts:
file: /docker/service/zs/nginx/config/vhosts.conf
# 指定版本
version: '3.7'
# 服务
services: # 指定服务名
nginx:
# 指定使用镜像
image: 192.168.1.81:5000/nginx:v1
# 指定开放端口
ports:
- 2008:80
# 指定网络
networks:
- networkce
# 管理容器
deploy:
# 设置副本模式
mode: replicated
# 副本数
replicas: 2
# 更新配置
update_config:
# 每次更新数量
parallelism: 1
# 每次更新时间
delay: 10s
# 更新失败设置,rollback回滚
failure_action: rollback
# 更新状态,start-firest 更新同时叠加旧版本,之后删除
order: start-first
# 回滚配置
rollback_config:
# 每次回滚数量
parallelism: 1
# 每次回滚时间
delay: 10s
# 回滚失败设置,rollback回滚
failure_action: rollback
# 回滚状态,start-firest 回滚同时叠加旧版本,之后删除
order: start-first
# 配置持久化数据
volumes:
# 数据类型
- type: volume
# 设置名称
source: nfs-nginx_log
# 挂载容器路径
target: /var/log/nginx
# 默认
volume:
nocopy: true
# 配置文件配置
configs:
# 配置文件名称
- source: nginx_config
# 上传容器文件路径
target: /etc/nginx/nginx.conf
# 配置文件名称
- source: nginx_vhosts
# 上传容器文件路径
target: /etc/nginx/conf.d/vhosts.conf # 网络
networks:
# 添加网络名称
networkce:
driver: overlay # 数据持久化
volumes:
# 数据名称
nfs-nginx_log:
driver: local
driver_opts:
# 类型
type: "nfs"
# 官方默认配置
o: "addr=192.168.1.81,vers=4,soft,timeo=180,bg,tcp,rw"
device: "192.168.1.81:/docker/service/zs/nginx/log" # 本地配置文件配置
configs:
# 配置文件名称
nginx_config:
# 本地配置文件路径
file: /docker/service/zs/nginx/config/nginx.conf
# 配置文件名称
nginx_vhosts:
# 本地配置文件路径
file: /docker/service/zs/nginx/config/vhosts.conf

文件注释

5、创建服务

docker stack deploy -c service_nginx.yml nginx

Docker Swarm nginx 集群搭建的更多相关文章

  1. Docker Swarm redis 集群搭建

    Docker Swarm redis 集群搭建 环境1: 系统:Linux Centos 7.4 x64 内核:Linux docker 3.10.0-693.2.2.el7.x86_64 Docke ...

  2. Docker Swarm部署集群

    一.Swarm简介 Swarm是Docker的一个编排工具,参考官网:https://docs.docker.com/engine/swarm/ Swarm 模式简介 要在Swarm模式下运行dock ...

  3. Docker下ETCD集群搭建

    搭建集群之前首先准备两台安装了CentOS 7的主机,并在其上安装好Docker. Master 10.100.97.46 Node 10.100.97.64 ETCD集群搭建有三种方式,分别是Sta ...

  4. docker实验--redis集群搭建

    背景介绍: 我经常在做一些小项目的时候,采用了Redis来做缓存,但是都是基于单节点的,一旦redis挂了,整个项目就挂了.于是乎,想到了多节点集群的方式来使用,就开始折腾着怎么去搭建这个集群.在网上 ...

  5. docker redis4.0集群搭建

    一.前言 redis集群对于很多人来说非常熟悉,在前些日子,我也有一位大兄弟也发布过一篇关于在阿里云(centOS7)上搭建redis 集群的文章,虽然集群搭建的文章在网上很多,我比较喜欢这篇文章的地 ...

  6. docker Swarm mode集群

    基本概念 Swarm 是使用 SwarmKit 构建的 Docker 引擎内置(原生)的集群管理和编排工具. 使用 Swarm 集群之前需要了解以下几个概念. 节点 运行 Docker 的主机可以主动 ...

  7. quay.io/coreos/etcd 基于Docker镜像的集群搭建

    etcd是一个高可用的键值存储系统,主要用于共享配置和服务发现.etcd是由CoreOS开发并维护的,灵感来自于 ZooKeeper 和 Doozer,它使用Go语言编写,并通过Raft一致性算法处理 ...

  8. 基于Docker的redis集群搭建

    Redis集群官方介绍:http://www.redis.cn/topics/cluster-tutorial.html 基于Docker搭建Redis集群 环境:6个节点,三主三从 制作Redis镜 ...

  9. 从零开始,使用Docker Swarm部署集群教程

    本文首先从Dockerfile创建了一个简单web镜像 然后将web镜像推送到了远程仓库,以备后面集群中不同机器自动下载 之后使用docker-compose.yml配置了一个应用 而后新建了2台虚拟 ...

随机推荐

  1. java基础---->java8中的函数式接口

    这里面简单的讲一下java8中的函数式接口,Function.Consumer.Predicate和Supplier. 函数式接口例子 一.Function:接受参数,有返回参数 package co ...

  2. Qt编写自定义控件3-速度仪表盘

    前言 速度仪表盘,写作之初的本意是用来展示当前测试的网速用的,三色圆环+数码管显示当前速度,Qt自带了数码管控件QLCDNumber,直接集成即可,同时还带有动画功能,其实也可以用在汽车+工业领域等, ...

  3. [转] 又踩到了crontab的老坑,特意记录下。

    http://xiachaofeng.iteye.com/blog/1405184 今天遇见一个问题,crontab的定时任务不能自动执行,但是手动执行脚本一直能成功.查到最后,发现是脚本里用了系统的 ...

  4. 三种不同类型的ssh隧道

    何谓SSH隧道 隧道是一种把一种网络协议封装进另外一种网络协议进行传输的技术.这里我们研究ssh隧道,所以所有的网络通讯都是加密的.又被称作端口转发,因为ssh隧道通常会绑定一个本地端口,所有发向这个 ...

  5. Ubuntu下开启Mysql远程访问的方法

    首先想说,JetProfiler对分析项目中MySQL问题以及优化,是个非常好的工具.但是看网上文章,中文介绍真的不多.是因为国内现在都不用MySQL了吗? 因为公司JetProfiler是共用的,安 ...

  6. Nodejs exec和spawn的区别

    spawn child_process.spaen会返回一个带有stdout和stderr流的对象.你可以通过stdout流来读取子进程返回给Node.js的数据. stdout拥有’data’,’e ...

  7. 案例源码解读及思路:RabbitMQ在springboot中的配置

    程序员的高级之处不是什么都会,而是对自己不会的进行抽象,然后完成自己的工作.比如对于RabbitMQ,按照字面理解,就将其看成Message Queue,也就是用来容纳对象的集合.很多功能都拆分给一个 ...

  8. HTML load事件和DOMCOntentLoaded事件

    JS高程 p14 “异步脚本一定会在页面的load事件前执行,但可能会在DOMContentLoaded事件触发之前或之后执行”   普通script标签会阻塞DOM的解析 DOMcontentLoa ...

  9. common lisp的几个基本概念

    S-表达式 quote nil 与 () cons car cdr 真假 predicate 谓词与 t 与 nil null 函数 与 not 函数 if then else and 与 or de ...

  10. 【C++语法基础】实验1

    实验内容: 题目:输入 1~7 的整数,如果输入的是 1~5,则输出“workday. Let’s work hard”:如果输入的是 6~7,则输出“weekend. Let’s have a re ...