Commit 2964317a749299aca662ef4156aedf4c68d99083
1 parent
2ea16684
feat: docker安装部署
Showing
10 changed files
with
223 additions
and
5 deletions
 
Show diff stats
.gitignore
Makefile
| ... | ... | @@ -52,5 +52,23 @@ gen:proto excel | 
| 52 | 52 | pull: | 
| 53 | 53 | git submodule update --remote | 
| 54 | 54 | |
| 55 | +docker-build: | |
| 56 | + # docker build -t my-tab -f /abc/defg/my-dockerfile /context-dir | |
| 57 | + docker build -t pro2d -f docker/Dockerfile ./ --force-rm | |
| 58 | + | |
| 59 | +docker-http: | |
| 60 | + docker rm -f http-pro2d | |
| 61 | + docker run --restart=always -d -p 8080:8080 --name http-pro2d pro2d ./http | |
| 62 | + | |
| 63 | +docker-game: | |
| 64 | + docker rm -f game-pro2d | |
| 65 | + docker run --restart=always -d -p 8850:8850 --name game-pro2d pro2d ./game | |
| 66 | + | |
| 67 | +save: docker-build | |
| 68 | + docker save pro2d > docker/pro2d.tar | |
| 69 | + scp docker/* zhaolu@192.168.0.100:/Users/zhaolu/Documents/pro2d #passwd: zhaolu | |
| 70 | + | |
| 71 | + rm -f docker/pro2d.tar | |
| 72 | + ssh zhaolu@192.168.0.100 "/Users/zhaolu/Documents/pro2d/restart.sh" | |
| 55 | 73 | |
| 56 | 74 | .PHONY: all build protos test cert plugin doc proto pull | 
| 57 | 75 | \ No newline at end of file | ... | ... | 
common/conf.go
| ... | ... | @@ -117,7 +117,7 @@ func init() { | 
| 117 | 117 | return | 
| 118 | 118 | } | 
| 119 | 119 | //初始化日志 | 
| 120 | - err = logger.SetLogger(string(c), strings.ToLower(GlobalConf.GameConf.Name)) | |
| 120 | + err = logger.SetLogger(string(c), fmt.Sprintf("logs/%s", strings.ToLower(GlobalConf.GameConf.Name))) | |
| 121 | 121 | if err != nil { | 
| 122 | 122 | fmt.Errorf("log conf %v", err) | 
| 123 | 123 | return | ... | ... | 
conf/conf.yaml
| ... | ... | @@ -0,0 +1,33 @@ | 
| 1 | +FROM golang:1.17 as Go117Build | |
| 2 | +WORKDIR /usr/src/app | |
| 3 | +#COPY go.mod go.sum ./ | |
| 4 | +#RUN go mod download && go mod verify | |
| 5 | + | |
| 6 | +COPY . . | |
| 7 | +RUN go build -tags netgo -o /usr/local/bin/http cmd/httpserver/main.go && go build -tags netgo -o /usr/local/bin/game cmd/gameserver/*.go | |
| 8 | + | |
| 9 | +FROM alpine:3.7 as pro2d | |
| 10 | +# 配置国内源 | |
| 11 | +RUN echo "http://mirrors.aliyun.com/alpine/v3.7/main/" > /etc/apk/repositories && \ | |
| 12 | + echo "hosts: files dns" > /etc/nsswitch.conf #dns | |
| 13 | +RUN apk update && \ | |
| 14 | + apk add ca-certificates && \ | |
| 15 | + apk add libc6-compat | |
| 16 | + | |
| 17 | +WORKDIR /data | |
| 18 | + | |
| 19 | +COPY --from=0 /usr/local/bin/http . | |
| 20 | +COPY --from=0 /usr/local/bin/game . | |
| 21 | +COPY csvdata/data ./csvdata/data | |
| 22 | +COPY ./docker/conf.yaml ./conf/ | |
| 23 | + | |
| 24 | + | |
| 25 | +RUN mkdir -p /data/logs && \ | |
| 26 | + echo 'export PATH=$PATH:/data' >> /etc/profile && \ | |
| 27 | + source /etc/profile | |
| 28 | +#RUN apt-get update && \ | |
| 29 | +# apt-get install -y net-tools iputils-ping iproute2 | |
| 30 | +EXPOSE 8080 | |
| 31 | +EXPOSE 8849 | |
| 32 | + | |
| 33 | +CMD ["http"] | |
| 0 | 34 | \ No newline at end of file | ... | ... | 
| ... | ... | @@ -0,0 +1,93 @@ | 
| 1 | +develop: true | |
| 2 | +name: "Pro2DServer" | |
| 3 | +workerid: 1 | |
| 4 | +datacenterid: 1 | |
| 5 | + | |
| 6 | +mongo: &default-mongo | |
| 7 | + host: "host.docker.internal" | |
| 8 | + port: 27017 | |
| 9 | + user: "root" | |
| 10 | + password: "root" | |
| 11 | + timeout: 2 | |
| 12 | + maxnum: 50 | |
| 13 | + | |
| 14 | +redis: &default-redis | |
| 15 | + address: "host.docker.internal:6100" | |
| 16 | + auth: "" | |
| 17 | + | |
| 18 | +etcd: | |
| 19 | + dialtimeout: 5 | |
| 20 | + endpoints: | |
| 21 | + - "host.docker.internal:2379" | |
| 22 | + | |
| 23 | +server_account: | |
| 24 | + id: 1 | |
| 25 | + name: "account" | |
| 26 | + ip: "192.168.0.206" | |
| 27 | + port: 8080 | |
| 28 | + pool_size: 1 | |
| 29 | + debugport: 6062 | |
| 30 | + mongo: | |
| 31 | + <<: *default-mongo | |
| 32 | + dbname: "account" | |
| 33 | + redis: | |
| 34 | + <<: *default-redis | |
| 35 | + db: 0 | |
| 36 | + | |
| 37 | +server_game: | |
| 38 | + id: 1 | |
| 39 | + name: "game" | |
| 40 | + ip: "192.168.0.206" | |
| 41 | + encipher: false | |
| 42 | + port: 8849 | |
| 43 | + debugport: 6060 | |
| 44 | + gm: 8880 | |
| 45 | + pool_size: 1 | |
| 46 | + plugin_path: "./bin/plugin.so" | |
| 47 | + mongo: | |
| 48 | + <<: *default-mongo | |
| 49 | + dbname: "game" | |
| 50 | + redis: | |
| 51 | + <<: *default-redis | |
| 52 | + db: 0 | |
| 53 | + | |
| 54 | +server_game1: | |
| 55 | + id: 2 | |
| 56 | + name: "game" | |
| 57 | + ip: "192.168.0.206" | |
| 58 | + encipher: false | |
| 59 | + port: 8850 | |
| 60 | + debugport: 6061 | |
| 61 | + gm: 8881 | |
| 62 | + pool_size: 1 | |
| 63 | + plugin_path: "./bin/plugin.so" | |
| 64 | + mongo: | |
| 65 | + <<: *default-mongo | |
| 66 | + dbname: "game" | |
| 67 | + redis: | |
| 68 | + <<: *default-redis | |
| 69 | + db: 0 | |
| 70 | +test_client: | |
| 71 | + ip: "127.0.0.1" | |
| 72 | + port: 8849 | |
| 73 | + count: 1 | |
| 74 | + | |
| 75 | +logconf: | |
| 76 | + TimeFormat: "2006-01-02 15:04:05" | |
| 77 | + Console: | |
| 78 | + level: "TRAC" | |
| 79 | + color: true | |
| 80 | + File: | |
| 81 | + level: "TRAC" | |
| 82 | + daily: true | |
| 83 | + maxlines: 1000000 | |
| 84 | + maxsize: 1 | |
| 85 | + maxdays: -1 | |
| 86 | + append: true | |
| 87 | + permit: "0660" | |
| 88 | +# Conn: | |
| 89 | +# net: "tcp" | |
| 90 | +# addr: "127.0.0.1" | |
| 91 | +# level: "TRAC" | |
| 92 | +# reconnect: false | |
| 93 | +# reconnectOnMsg: false | |
| 0 | 94 | \ No newline at end of file | ... | ... | 
| ... | ... | @@ -0,0 +1,51 @@ | 
| 1 | +version: '3.3' | |
| 2 | +services: | |
| 3 | + db: | |
| 4 | + image: mongo | |
| 5 | + container_name: mongodb-pro2d | |
| 6 | + ports: | |
| 7 | + - '27017:27017' | |
| 8 | + restart: always | |
| 9 | + environment: | |
| 10 | + MONGO_INITDB_ROOT_USERNAME: root #mongo默认的账号 | |
| 11 | + MONGO_INITDB_ROOT_PASSWORD: root #mongo默认的密码 | |
| 12 | + volumes: | |
| 13 | + - ./.docker/mongo_data:/data/db | |
| 14 | + - ./.docker/mongo.conf:/data/mongo.conf | |
| 15 | +# command: --config /data/mongo.conf # 配置文件 | |
| 16 | + command: [--auth] # 配置文件 | |
| 17 | + etcd: | |
| 18 | + image: xieyanze/etcd3 | |
| 19 | + container_name: etcd3-pro2d | |
| 20 | + restart: always | |
| 21 | + ports: | |
| 22 | + - '2379:2379' | |
| 23 | + redis: | |
| 24 | + image: redis:latest | |
| 25 | + container_name: redis-pro2d | |
| 26 | + restart: always | |
| 27 | + ports: | |
| 28 | + - '6100:6379' | |
| 29 | + volumes: | |
| 30 | + - ./.docker/redis_data:/data/db | |
| 31 | + | |
| 32 | + account: | |
| 33 | + image: pro2d | |
| 34 | + container_name: account-pro2d | |
| 35 | + restart: always | |
| 36 | + ports: | |
| 37 | + - '8080:8080' | |
| 38 | + volumes: | |
| 39 | + - ./.docker/account_logs:/data/logs | |
| 40 | + working_dir: /data | |
| 41 | + command: [./http] | |
| 42 | + game: | |
| 43 | + image: pro2d | |
| 44 | + container_name: game-pro2d | |
| 45 | + restart: always | |
| 46 | + ports: | |
| 47 | + - '8849:8849' | |
| 48 | + volumes: | |
| 49 | + - ./.docker/game_logs:/data/logs | |
| 50 | + working_dir: /data | |
| 51 | + command: [./game] | ... | ... | 
| ... | ... | @@ -0,0 +1,7 @@ | 
| 1 | +#!/bin/bash | |
| 2 | + | |
| 3 | +host='-H 192.168.0.100:2375' | |
| 4 | +docker-compose -f /Users/zhaolu/Documents/pro2d/docker-compose.yml down | |
| 5 | +docker load < /Users/zhaolu/Documents/pro2d/pro2d.tar | |
| 6 | +docker-compose -f /Users/zhaolu/Documents/pro2d/docker-compose.yml up -d | |
| 7 | +docker ps -a | |
| 0 | 8 | \ No newline at end of file | ... | ... |