chore: fix docker start error

This commit is contained in:
qloog
2021-10-30 09:43:58 +08:00
parent f0b56322d4
commit f7f228eacb
5 changed files with 187 additions and 105 deletions

View File

@@ -13,12 +13,12 @@ app:
Http:
Addr: :8080
ReadTimeout: 5
WriteTimeout: 5
ReadTimeout: 3s
WriteTimeout: 3s
Grpc:
Addr: :9090
ReadTimeout: 5
WriteTimeout: 5
ReadTimeout: 3s
WriteTimeout: 3s
logger:
Development: true
@@ -36,7 +36,7 @@ logger:
LogRotateSize: 1
LogBackupCount: 7
mysql:
orm:
Name: eagle # 数据库名称
Addr: db:3306 # 如果是 docker,可以替换为 对应的服务名称eg: db:3306
UserName: root
@@ -46,6 +46,22 @@ mysql:
MaxOpenConn: 60 # 最大打开的连接数, 需要小于数据库配置中的max_connections数
ConnMaxLifeTime: 60m # 单个连接最大存活时间,建议设置比数据库超时时长(wait_timeout)稍小一些
mysql:
Dsn: "root:123456@tcp(localhost:3306)/eagle?timeout=2s&readTimeout=5s&writeTimeout=5s&parseTime=true&loc=Local&charset=utf8,utf8mb4"
ShowLog: true # 是否打印SQL日志
MaxIdleConn: 10 # 最大闲置的连接数0意味着使用默认的大小2 小于0表示不使用连接池
MaxOpenConn: 60 # 最大打开的连接数, 需要小于数据库配置中的max_connections数
ConnMaxLifeTime: 4000 # 单个连接最大存活时间,建议设置比数据库超时时长(wait_timeout)稍小一些
QueryTimeout: 200
ExecTimeout: 200
TranTimeout: 200
Braker: # 熔断器配置
window: 3s
sleep: 100ms
bucket: 100
ratio: 0.5
request: 100
redis:
Addr: redis:6379
Password: ""

View File

@@ -1,6 +1,11 @@
use mysql;
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'root';
GRANT ALL ON *.* to root@'%' IDENTIFIED BY 'root';
# create test_user
CREATE USER 'test_user'@'%' IDENTIFIED BY '123456';
GRANT ALL ON *.* to test_user@'%' IDENTIFIED BY '123456';
FLUSH PRIVILEGES;
-- 创建数据库

View File

@@ -34,8 +34,8 @@ services:
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: eagle
MYSQL_USER: root
MYSQL_PASSWORD: root
MYSQL_USER: test_user
MYSQL_PASSWORD: 123456
TZ: Asia/Shanghai
# 解决外部无法访问 for mysql8
command: [
@@ -61,16 +61,6 @@ services:
networks:
- eagle
# web 数据库管理工具tips: host使用 db:3306
adminer:
container_name: adminer_container
image: adminer
restart: always
depends_on:
- db
ports:
- 8036:8036
redis:
container_name: redis_container
image: redis:6.0.9-alpine
@@ -81,84 +71,6 @@ services:
volumes:
- redis_data:/var/lib/redis
nginx:
container_name: nginx_container
image: nginx:1.17.10-alpine
ports:
- 80:80
depends_on:
- app
volumes:
- ./config/nginx_api.conf:/etc/nginx/conf.d/eagle.conf
command: nginx -g 'daemon off';
prometheus:
container_name: prometheus_container
image: prom/prometheus
restart: always
volumes:
- ./deploy/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml:Z
command:
- '--config.file=/etc/prometheus/prometheus.yml'
- '--storage.tsdb.path=/prometheus'
- '--storage.tsdb.retention=20d'
- '--web.console.libraries=/usr/share/prometheus/console_libraries'
- '--web.console.templates=/usr/share/prometheus/consoles'
ports:
- '9090:9090'
networks:
- eagle
node_exporter:
container_name: node_exporter_container
restart: always
image: prom/node-exporter
ports:
- '9101:9100'
networks:
- eagle
grafana:
container_name: grafana_container
restart: always
image: grafana/grafana
ports:
- '3000:3000'
networks:
- eagle
jaeger:
container_name: jaeger_container
image: jaegertracing/all-in-one:1.21
environment:
- COLLECTOR_ZIPKIN_HTTP_PORT=9411
ports:
- 5775:5775/udp
- 6831:6831/udp
- 6832:6832/udp
- 5778:5778
- 16686:16686
- 14268:14268
- 14250:14250
- 9411:9411
networks:
- eagle
mongodb:
image: mongo:latest
container_name: mongodb_container
restart: always
environment:
MONGO_INITDB_ROOT_USERNAME: admin
MONGO_INITDB_ROOT_PASSWORD: admin
MONGODB_DATABASE: eagle
ports:
- 27017:27017
volumes:
- mongodb_data:/data/db
networks:
- eagle
networks:
eagle:
driver: "bridge"

View File

@@ -29,7 +29,7 @@ type Dao struct {
func New(cfg *conf.Config, db *gorm.DB) *Dao {
return &Dao{
orm: db,
db: sql.NewMySQL(cfg.MySQL),
//db: sql.NewMySQL(cfg.MySQL),
tracer: otel.Tracer("dao"),
userCache: cache.NewUserCache(),
}

View File

@@ -1,24 +1,173 @@
# yaml 配置
# 官方文档https://docs.docker.com/compose/compose-file/
version: "3.7"
services:
db:
image: mysql:5.6
app:
container_name: app_container
build: .
restart: on-failure
depends_on:
- db
- redis
links:
- db
- redis
ports:
- 3306:3306
- "8080:8080"
networks:
- eagle
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8080/health"] # 用于健康检查的指令
interval: 1m30s # 间隔时间
timeout: 10s # 超时时间
retries: 3 # 重试次数
start_period: 40s # 启动多久后开始检查
db:
container_name: mysql_container
image: mysql:5.7.33
ports:
- "3306:3306"
expose:
- "3306"
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: eagle
MYSQL_USER: root
MYSQL_PASSWORD: root
TZ: Asia/Shanghai
volumes:
- .:/docker-entrypoint-initdb.d
# 解决外部无法访问 for mysql8
command: [
'--character-set-server=utf8',
'--collation-server=utf8_unicode_ci'
'--collation-server=utf8_unicode_ci',
'--default-authentication-plugin=mysql_native_password'
]
healthcheck:
test: [ "CMD", "mysqladmin", "ping", "-h", "localhost" ] # 用于健康检查的指令
timeout: 20s # 超时时间
retries: 10 # 重试次数
start_period: 40s # 启动多久后开始检查
stdin_open: true
tty: true
# 修复问题 mbind: Operation not permitted
security_opt:
- seccomp:unconfined
volumes:
- mysql_data:/var/lib/mysql
- ./deploy/docker/mysql/my.cnf:/etc/mysql/my.cnf
- ./deploy/docker/mysql/my.cnf:/etc/mysql/mysql.conf.d/mysqld.cnf
- ./deploy/docker/mysql/:/docker-entrypoint-initdb.d/
networks:
- eagle
# web 数据库管理工具tips: host使用 db:3306
adminer:
container_name: adminer_container
image: adminer
restart: always
depends_on:
- db
ports:
- 8036:8036
networks:
- eagle
redis:
image: redis
container_name: redis_container
image: redis:6.0.9-alpine
ports:
- 6379:6379
- "6379:6379"
networks:
- eagle
volumes:
- redis_data:/var/lib/redis
nginx:
container_name: nginx_container
image: nginx:1.17.10-alpine
ports:
- 80:80
depends_on:
- app
volumes:
- ./config/nginx_api.conf:/etc/nginx/conf.d/eagle.conf
command: nginx -g 'daemon off';
networks:
- eagle
prometheus:
container_name: prometheus_container
image: prom/prometheus
restart: always
volumes:
- ./deploy/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml:Z
command:
- '--config.file=/etc/prometheus/prometheus.yml'
- '--storage.tsdb.path=/prometheus'
- '--storage.tsdb.retention=20d'
- '--web.console.libraries=/usr/share/prometheus/console_libraries'
- '--web.console.templates=/usr/share/prometheus/consoles'
ports:
- '9090:9090'
networks:
- eagle
node_exporter:
container_name: node_exporter_container
restart: always
image: prom/node-exporter
ports:
- '9101:9100'
networks:
- eagle
grafana:
container_name: grafana_container
restart: always
image: grafana/grafana
ports:
- '3000:3000'
networks:
- eagle
jaeger:
container_name: jaeger_container
image: jaegertracing/all-in-one:1.21
environment:
- COLLECTOR_ZIPKIN_HTTP_PORT=9411
ports:
- 5775:5775/udp
- 6831:6831/udp
- 6832:6832/udp
- 5778:5778
- 16686:16686
- 14268:14268
- 14250:14250
- 9411:9411
networks:
- eagle
mongodb:
image: mongo:latest
container_name: mongodb_container
restart: always
environment:
MONGO_INITDB_ROOT_USERNAME: admin
MONGO_INITDB_ROOT_PASSWORD: admin
MONGODB_DATABASE: eagle
ports:
- 27017:27017
volumes:
- mongodb_data:/data/db
networks:
- eagle
networks:
eagle:
driver: "bridge"
volumes:
mysql_data:
redis_data:
mongodb_data: