Skip to content

Commit

Permalink
refactor docker-compose.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
xmcy0011 committed Jun 22, 2022
1 parent 87dbb1d commit c6ebaf1
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 55 deletions.
19 changes: 15 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,20 +121,30 @@ See More [architecture](https://github.com/xmcy0011/CoffeeChat/blob/master/docs/
> PS:请切换到**master**分支,编译和运行!
1. 启动Server(要求安装docker desktop >= 4.0.1):

```bash
$ git clone https://github.com/xmcy0011/CoffeeChat.git
$ cd CoffeeChat/server
# 从代码编译docker镜像,安装mysql,redis等依赖,并自动初始化mysql数据
$ docker-compose.yml up -d
$ docker-compose up -d
```
2. 编译客户端。推荐iOS客户端(模拟器选择iphone 11),请移步:[client](https://github.com/xmcy0011/CoffeeChat/blob/master/client/cc_flutter_app/README.md)
3. iOS模拟器和app启动后,点击“注册”,更改服务器IP地址为本机IP(不需要输入端口),注册成功后,登录即可。
4. 内置了2个机器人(思知和微信)和3个好友,可以测试聊天功能。

1. 编译客户端。推荐iOS客户端(模拟器选择iphone 11),请移步:[client](https://github.com/xmcy0011/CoffeeChat/blob/master/client/cc_flutter_app/README.md)
1. iOS模拟器和app启动后,点击“注册”,更改服务器IP地址为本机IP(不需要输入端口),注册成功后,登录即可。
1. 内置了2个机器人(思知和微信)和3个好友,可以测试聊天功能。

更多细节,请移步:

- [client](https://github.com/xmcy0011/CoffeeChat/blob/master/client/cc_flutter_app/README.md)
- [server](https://github.com/xmcy0011/CoffeeChat/blob/master/server/src/README.md)

停止:

```bash
$ cd CoffeeChat/server
$ docker-compose down -v
```

### Document

1. [产品介绍](https://github.com/xmcy0011/CoffeeChat/blob/master/docs/01-%E4%BA%A7%E5%93%81%E4%BB%8B%E7%BB%8D.md)
Expand All @@ -145,6 +155,7 @@ $ docker-compose.yml up -d
6. [MQ在IM中的实践和选型](https://github.com/xmcy0011/CoffeeChat/blob/master/docs/06_MQ%e5%9c%a8IM%e4%b8%ad%e7%9a%84%e5%ae%9e%e8%b7%b5.md)

更多文章请移步:

- [CoffeeChat-GitBook](https://xmcy0011.github.io/CoffeeChat-GitBook/)

### Thinks
Expand Down
2 changes: 1 addition & 1 deletion server/app/im_gate/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# This dockerfile uses go build, then use the ubuntu run
# Version: 0.1
# Author: [email protected]
# Desc: 注意,编译镜像的上下文必须在src下(../../),否则会失败
# Desc: 注意,编译镜像的上下文必须在server下(../../),否则会失败
# example: docker build -t im_gate -f . ../../

##
Expand Down
4 changes: 2 additions & 2 deletions server/app/im_gate/gate-docker.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ WeChatRobotEncodingAESKey="vpIfV7aof4QP40EreXNAVygwy4Bx534JldY1inOETBY" # 替换
# 第二个节点:处理消息收发业务
[[Logic]]
#Ip="172.16.0.1"
Ip="im_logic"
Ip="cim_logic"
Port=10600
MaxConnCnt=4 # 2的整数倍

[[Logic]]
#Ip="172.16.0.1"
Ip="im_logic"
Ip="cim_logic"
Port=10600
MaxConnCnt=4 # 2的整数倍
2 changes: 1 addition & 1 deletion server/app/im_http/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# This dockerfile uses go build, then use the ubuntu run
# Version: 0.1
# Author: [email protected]
# Desc: 注意,编译镜像的上下文必须在src下(../../),否则会失败
# Desc: 注意,编译镜像的上下文必须在server下(../../),否则会失败
# example: docker build -t im_gate -f . ../../

##
Expand Down
4 changes: 2 additions & 2 deletions server/app/im_http/http-docker.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ ListenPort=18080

# 双机冗余,也可部署一个节点,随机数均衡法
[[Logic]]
Ip="im_logic"
Ip="cim_logic"
#Ip="127.0.0.1"
Port=10600

[[Logic]]
Ip="im_logic"
Ip="cim_logic"
#Ip="127.0.0.1"
Port=10600
2 changes: 1 addition & 1 deletion server/app/im_logic/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# This dockerfile uses go build, then use the ubuntu run
# Version: 0.1
# Author: [email protected]
# Desc: 注意,编译镜像的上下文必须在src下(../../),否则会失败
# Desc: 注意,编译镜像的上下文必须在server下(../../),否则会失败
# example: docker build -t im_gate -f . ../../

##
Expand Down
10 changes: 5 additions & 5 deletions server/app/im_logic/logic-docker.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@ ListenPort=10600
# 主库,读写,优先写
[[Db]]
ServerName="Master"
Host="mysql"
Host="cim_mysql"
Port=3306
DbName="coffeechat"
UserName="cim"
Password="ldMe$q2Xl9GKyUxj"
Password="coffeechat2022"
MaxConnCnt=16

# 从库,只读
# 可以和主库保持一致,这样则意味着不使用主从模式,此时,建议把maxconncnt调小一倍
[[Db]]
ServerName="Slave"
Host="mysql"
Host="cim_mysql"
Port=3306
DbName="coffeechat"
UserName="cim"
Password="ldMe$q2Xl9GKyUxj"
Password="coffeechat2022"
MaxConnCnt=16

#[Kafka]
Expand All @@ -29,7 +29,7 @@ MaxConnCnt=16

[Redis]
Name="cim"
Ip="redis"
Ip="cim_redis"
Port=6379
KeyPrefix="cim|" # redis中key的统一前缀
Password="coffeechat" # redis的密码,不允许为空
Expand Down
4 changes: 2 additions & 2 deletions server/app/im_logic/logic-example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Host="127.0.0.1"
Port=3306
DbName="coffeechat"
UserName="cim"
Password="ldMe$q2Xl9GKyUxj"
Password="coffeechat2022"
MaxConnCnt=16

# 从库,只读
Expand All @@ -21,7 +21,7 @@ Host="127.0.0.1"
Port=3306
DbName="coffeechat"
UserName="cim"
Password="ldMe$q2Xl9GKyUxj"
Password="coffeechat2022"
MaxConnCnt=16

#[Kafka]
Expand Down
79 changes: 43 additions & 36 deletions server/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,13 @@ services:
restart: always
ports:
- '27017:27017'
networks:
- CoffeeChat
environment:
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: mongopass
# mongo-express:
# image: mongo-express
# container_name: cim_mongo-express
# restart: always
# ports:
# - '27018:27018'
# environment:
# ME_CONFIG_MONGODB_ADMINUSERNAME: root
# ME_CONFIG_MONGODB_ADMINPASSWORD: mongopass
# ME_CONFIG_MONGODB_URL: mongodb://root:mongopass@mongo:27017/
mysql:
#image: 'arm64v8/mysql:8.0.28-oracle' # mac m1
# image: 'arm64v8/mysql:8.0.28-oracle' # mac m1
image: 'mysql:5.7'
restart: always
container_name: cim_mysql
Expand All @@ -34,70 +26,83 @@ services:
MYSQL_ROOT_PASSWORD: 123456
MYSQL_DATABASE: coffeechat
MYSQL_USER: cim
MYSQL_PASSWORD: ldMe$q2Xl9GKyUxj
MYSQL_PASSWORD: coffeechat2022
volumes:
- cim_mysql_data:/var/lib/mysql
# docker-entrypoint-initdb.d:这个目录下的脚本,只在容器第一次运行时被执行。
- ./setup/mysql/init/:/docker-entrypoint-initdb.d/
networks:
- local
- CoffeeChat
ports:
- "3306:3306"
command: [ '--default-authentication-plugin=mysql_native_password', '--character-set-server=utf8mb4',
'--collation-server=utf8mb4_unicode_ci' ]
redis:
build: ./setup/redis
build: setup/redis
container_name: cim_redis
volumes:
- cim_redis:/data # 持久化数据,其他如密码等,在redis.conf里已配置
networks:
- local
- CoffeeChat
ports:
- "6379:6379" # 端口改掉,预防攻击
consul:
image: bitnami/consul:latest
container_name: cim_consul
volumes:
- cim_consul:/bitnami
networks:
- local
- CoffeeChat
ports:
- '8300:8300'
- '8301:8301'
- '8301:8301/udp'
- '8500:8500'
- '8600:8600'
- '8600:8600/udp'
im_http: # http 服务
container_name: im_http
cim_http: # http 服务
container_name: cim_http
build: # 指定从dockerfile编译
context: .
dockerfile: app/im_http/Dockerfile
dockerfile: ./app/im_http/Dockerfile
volumes: # 数据卷绑定
- ./log/http:/log
deploy:
restart_policy:
condition: on-failure
delay: 5s
max_attempts: 3
window: 120s
networks:
- local
- CoffeeChat
ports:
- "18080:18080"
depends_on:
- im_logic
im_gate: # 网关服务
container_name: im_gate
- cim_logic
cim_gate: # 网关服务
container_name: cim_gate
build:
context: .
dockerfile: app/im_gate/Dockerfile
dockerfile: ./app/im_gate/Dockerfile
volumes:
- ./log/gate:/log
deploy:
restart_policy:
condition: on-failure
delay: 5s
max_attempts: 3
window: 120s
networks:
- local
- CoffeeChat
ports:
- "8000:8000"
depends_on:
- im_logic
im_logic: # 逻辑服务
container_name: im_logic
- cim_logic
cim_logic: # 逻辑服务
container_name: cim_logic
build:
context: .
dockerfile: app/im_logic/Dockerfile
dockerfile: ./app/im_logic/Dockerfile
volumes:
- ./log/logic:/log
deploy:
Expand All @@ -107,9 +112,7 @@ services:
max_attempts: 3
window: 120s
networks:
- local
# local:
# - ipv4_address: 172.16.0.100
- CoffeeChat
depends_on:
- mysql
- redis
Expand All @@ -121,8 +124,12 @@ volumes: # 声明使用的数据卷,不使用宿主机目录,可以自行更
cim_consul:
driver: local
# 为了简单,使用默认侨接网络 + DNS连接内部服务器方式
# # 根据https://docs.docker.com/compose/networking/,docker compose默认创建了网络,但是创建自己的侨接网络更安全
# #,另外一个Host主机网络只支持Linux,虽然性能更高
# 根据https://docs.docker.com/compose/networking/,docker compose默认创建了网络,但是创建自己的侨接网络更安全
# 另外一个Host主机网络只支持Linux,虽然性能更高
networks:
local:
driver: bridge # 侨接网络
CoffeeChat:
driver: bridge # 侨接网络,此时需要使用host访问(service下面的服务名)
ipam: # see: https://docs.docker.com/compose/compose-file/compose-file-v3/#network
config:
- subnet: 172.16.0.0/24
gateway: 172.16.0.1
2 changes: 1 addition & 1 deletion server/setup/mysql/init/init.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
-- CREATE USER 'luna'@'%' IDENTIFIED BY 'pwdluna';
GRANT All privileges ON coffeechat.* TO 'cim'@'%' identified by 'ldMe$q2Xl9GKyUxj';
GRANT All privileges ON coffeechat.* TO 'cim'@'%' identified by 'coffeechat2022';
flush privileges;

0 comments on commit c6ebaf1

Please sign in to comment.