Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
134 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
--- | ||
layout: post | ||
title: "Docker Swarm部署服务" | ||
date: 2021-08-24 11:31:46 | ||
categories: [docker,swarm] | ||
excerpt_separator: <!--more--> | ||
--- | ||
Docker Swarm部署服务 | ||
<!--more--> | ||
|
||
## 1. 概述 | ||
Docker Swarm使用docker stack部署服务, 配置文件使用的是docker compose的配置文件,但是又不能完全使用compose文件。 | ||
|
||
## 2. 配置文件修改 | ||
|
||
* 环境变量的处理 | ||
因为docker stack不支持环境变量文件`.env`,所以需要先将compose.yml转换为完全体文件 | ||
```bash | ||
docker-compose -f docker-compose.yml -p test config | ||
``` | ||
复制输出内容到新的文件中。 | ||
|
||
|
||
* 修改网络类型 | ||
```yml | ||
networks: | ||
iotx-network: | ||
driver: overlay # 网络类型需要是overlay | ||
``` | ||
|
||
* 服务间依赖的处理 | ||
去掉所有的`depends_on` | ||
|
||
* 本地挂在的处理 | ||
由于docker swarm是分布式集群,所以不能进行本地数据挂载。 | ||
当使用docker volume时,docker stack能正常运行,但是服务数据只会存储在指定的node上,当服务迁移,数据会变为其他node上的数据。 | ||
简而言之,node间数据是不共享的。 | ||
|
||
使用NFS进行数据共享 | ||
```yml | ||
volumes: | ||
redis-data: | ||
driver: local | ||
driver_opts: | ||
type: nfs | ||
o: nfsvers=4,addr=192.168.1.118,rw | ||
device: ":/home/storage/redis-data" | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
--- | ||
layout: post | ||
title: "traefik代理基本配置" | ||
date: 2021-08-24 10:46:23 | ||
categories: [nginx] | ||
excerpt_separator: <!--more--> | ||
--- | ||
|
||
traefik代理基本配置 | ||
<!--more--> | ||
|
||
## 1. 概述 | ||
traefik是类似nginx的代理服务,与nginx不同,它是用go编写,主要面向分布式集群进行负载均衡。 | ||
traefik详细配置参照观望(https://doc.traefik.io/traefik/) | ||
这里只说明traefik的基本入门,以及可能遇到的坑。 | ||
|
||
## 2. 配置 | ||
|
||
### 2.1 默认路径 | ||
|
||
traefik主配置默认路径`/etc/traefik/traefik.yml`,支持文件类型`yml`、`yaml`、`toml`。放到其他位置不识别。可以在启动是添加参数修改默认路径。 | ||
|
||
### 2.2 动态配置 | ||
|
||
traefik的配置分为静态配置和动态配置。有些字段划分不是很明确,需要参照官网说明定义字段。 | ||
动态配置文件不要放到根目录下,某些情况会报错。 | ||
|
||
静态文件`/etc/traefik/traefik.yml`中配置动态文件路径 | ||
```yml | ||
providers: | ||
file: | ||
directory: /etc/traefik/ | ||
watch: true | ||
filename: dynamic.yml | ||
debugLogGeneratedTemplate: true | ||
``` | ||
|
||
### 2.3 UI | ||
|
||
静态文件`/etc/traefik/traefik.yml`中打开UI | ||
```yml | ||
api: | ||
insecure: true | ||
dashboard: true | ||
debug: true | ||
``` | ||
|
||
### 2.4 TLS证书 | ||
|
||
证书文件需要定义到动态文件中 | ||
|
||
动态文件`/etc/traefik/dynamic.yml` | ||
```yml | ||
tls: | ||
certificates: | ||
- certFile: /certs/certFile.pem | ||
keyFile: /certs/keyFile.key | ||
stores: | ||
default: | ||
defaultCertificate: | ||
certFile: /certs/certFile.pem | ||
keyFile: /certs/keyFile.key | ||
``` | ||
|
||
需要在路由中启用TLS | ||
```yml | ||
http: | ||
routers: | ||
ui: | ||
entryPoints: | ||
- "websecure" | ||
- "web" | ||
rule: PathPrefix(`/`) | ||
service: ui | ||
tls: {} | ||
``` |