From be73d2810f0d477fd01d6a91996e09969b854882 Mon Sep 17 00:00:00 2001 From: llitfkitfk Date: Mon, 23 Mar 2020 00:05:53 +0800 Subject: [PATCH 1/8] add docker support --- .dockerignore | 1 + Dockerfile | 24 ++++++++++++++++++++++++ docker-compose.yml | 38 ++++++++++++++++++++++++++++++++++++++ web/.dockerignore | 1 + web/Dockerfile | 5 +++++ 5 files changed, 69 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 docker-compose.yml create mode 100644 web/.dockerignore create mode 100644 web/Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..6f3439a3 --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +web \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..bce2147c --- /dev/null +++ b/Dockerfile @@ -0,0 +1,24 @@ +FROM golang:alpine AS builder +RUN apk add --no-cache git +WORKDIR /home/app + +# comment this if using vendor +# ENV GOPROXY=https://mod.gokit.info +# COPY go.mod go.sum ./ +# RUN go mod download + +COPY . . +ENV GOPROXY=https://mod.gokit.info +RUN go build -o ./bin/monapi src/modules/monapi/monapi.go + +FROM alpine:3.10 +LABEL maintainer="llitfkitfk@gmail.com" +RUN apk add --no-cache ca-certificates + +WORKDIR /app + +COPY --from=builder /home/app/etc /app/etc +COPY --from=builder /home/app/bin /usr/local/bin + +# ENTRYPOINT [] +# CMD [] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..e2f65185 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,38 @@ +version: "3" +volumes: + mysql-data: +services: + api: + build: . + image: api + + monapi: + image: api + restart: always + command: monapi + + web: + build: + context: web + restart: always + ports: + - 8010:8010 + + redis: + image: redis + restart: always + ports: + - 6379:6379 + + mysql: + image: mysql:5.7 + restart: always + environment: + - MYSQL_ROOT_PASSWORD=1234 + ports: + - 3306:3306 + volumes: + - ./sql:/docker-entrypoint-initdb.d + - mysql-data:/var/lib/mysql + + \ No newline at end of file diff --git a/web/.dockerignore b/web/.dockerignore new file mode 100644 index 00000000..b512c09d --- /dev/null +++ b/web/.dockerignore @@ -0,0 +1 @@ +node_modules \ No newline at end of file diff --git a/web/Dockerfile b/web/Dockerfile new file mode 100644 index 00000000..cce595dc --- /dev/null +++ b/web/Dockerfile @@ -0,0 +1,5 @@ +FROM node:lts-alpine AS builder + +WORKDIR /home/app + +COPY . . \ No newline at end of file From 087333808eaf6893fa8af15fe026c804f1b9c3b4 Mon Sep 17 00:00:00 2001 From: llitfkitfk Date: Mon, 23 Mar 2020 00:42:22 +0800 Subject: [PATCH 2/8] add nginx & update monapi --- Dockerfile | 8 ++-- README.md | 7 ++++ docker-compose.yml | 27 +++++++++---- docker/etc/address.yml | 34 ++++++++++++++++ docker/etc/monapi.yml | 52 ++++++++++++++++++++++++ docker/etc/mysql.yml | 16 ++++++++ docker/nginx/nginx.conf | 89 +++++++++++++++++++++++++++++++++++++++++ web/Dockerfile | 6 ++- 8 files changed, 226 insertions(+), 13 deletions(-) create mode 100644 docker/etc/address.yml create mode 100644 docker/etc/monapi.yml create mode 100644 docker/etc/mysql.yml create mode 100644 docker/nginx/nginx.conf diff --git a/Dockerfile b/Dockerfile index bce2147c..a1038c1a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ FROM golang:alpine AS builder RUN apk add --no-cache git -WORKDIR /home/app +WORKDIR /app # comment this if using vendor # ENV GOPROXY=https://mod.gokit.info @@ -13,12 +13,12 @@ RUN go build -o ./bin/monapi src/modules/monapi/monapi.go FROM alpine:3.10 LABEL maintainer="llitfkitfk@gmail.com" -RUN apk add --no-cache ca-certificates +RUN apk add --no-cache tzdata ca-certificates WORKDIR /app -COPY --from=builder /home/app/etc /app/etc -COPY --from=builder /home/app/bin /usr/local/bin +COPY --from=builder /app/etc /app/etc +COPY --from=builder /app/bin /usr/local/bin # ENTRYPOINT [] # CMD [] \ No newline at end of file diff --git a/README.md b/README.md index 8ac237f8..7b11b6b9 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,13 @@ git clone https://github.com/didi/nightingale.git cd nightingale && ./control build ``` +## Quick Start (need install docker for [mac](https://docs.docker.com/docker-for-mac/install/)/[win](https://docs.docker.com/docker-for-windows/install/)) + +```bash +docker-compose up -d +# open http://localhost in web browser +``` + ## Team [ulricqin](https://github.com/ulricqin) [710leo](https://github.com/710leo) [jsers](https://github.com/jsers) [hujter](https://github.com/hujter) [n4mine](https://github.com/n4mine) [heli567](https://github.com/heli567) diff --git a/docker-compose.yml b/docker-compose.yml index e2f65185..7eff13f2 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,15 @@ version: "3" volumes: mysql-data: -services: +services: + nginx: + image: nginx:stable-alpine + ports: + - 80:80 + volumes: + - ./docker/nginx/nginx.conf:/etc/nginx/nginx.conf + - ./docker/nginx/conf.d:/etc/nginx/conf.d + - ./pub:/home/n9e/pub api: build: . image: api @@ -10,13 +18,18 @@ services: image: api restart: always command: monapi - - web: - build: - context: web - restart: always + volumes: + - ./docker/etc:/app/etc ports: - - 8010:8010 + - 5800:5800 + + # web: + # build: + # context: web + # restart: always + # command: npm run dev + # ports: + # - 8010:8010 redis: image: redis diff --git a/docker/etc/address.yml b/docker/etc/address.yml new file mode 100644 index 00000000..bea44bad --- /dev/null +++ b/docker/etc/address.yml @@ -0,0 +1,34 @@ +--- +monapi: + http: 0.0.0.0:5800 + addresses: + - 127.0.0.1 + +transfer: + http: 0.0.0.0:5810 + rpc: 0.0.0.0:5811 + addresses: + - 127.0.0.1 + +tsdb: + http: 0.0.0.0:5820 + rpc: 0.0.0.0:5821 + addresses: + - 127.0.0.1 + +index: + http: 0.0.0.0:5830 + rpc: 0.0.0.0:5831 + addresses: + - 127.0.0.1 + +judge: + http: 0.0.0.0:5840 + rpc: 0.0.0.0:5841 + addresses: + - 127.0.0.1 + +collector: + http: 0.0.0.0:2058 + + diff --git a/docker/etc/monapi.yml b/docker/etc/monapi.yml new file mode 100644 index 00000000..e3335a00 --- /dev/null +++ b/docker/etc/monapi.yml @@ -0,0 +1,52 @@ +--- +salt: "PLACE_SALT" + +logger: + dir: "logs/monapi" + level: "WARNING" + keepHours: 24 + +http: + secret: "PLACE_SECRET" + +# for ldap authorization +ldap: + host: "ldap.example.org" + port: 389 + baseDn: "dc=example,dc=org" + bindUser: "cn=manager,dc=example,dc=org" + bindPass: "*******" + # openldap: (&(uid=%s)) + # AD: (&(sAMAccountName=%s)) + authFilter: "(&(uid=%s))" + tls: false + startTLS: false + +# notify support: voice, sms, mail, im +# if we have all of notice channel +# notify: +# p1: ["voice", "sms", "mail", "im"] +# p2: ["sms", "mail", "im"] +# p3: ["mail", "im"] + +# if we only have mail channel +notify: + p1: ["mail"] + p2: ["mail"] + p3: ["mail"] + +# addresses accessible using browsers +link: + stra: http://n9e.example.com/#/monitor/strategy/%v + event: http://n9e.example.com/#/monitor/history/his/%v + claim: http://n9e.example.com/#/monitor/history/cur/%v + +# for alarm event and message queue +redis: + addr: "redis:6379" + pass: "" + # in ms + # timeout: + # conn: 500 + # read: 3000 + # write: 3000 diff --git a/docker/etc/mysql.yml b/docker/etc/mysql.yml new file mode 100644 index 00000000..a65d0094 --- /dev/null +++ b/docker/etc/mysql.yml @@ -0,0 +1,16 @@ +--- +uic: + addr: "root:1234@tcp(mysql:3306)/n9e_uic?charset=utf8&parseTime=True&loc=Asia%2FShanghai" + max: 16 + idle: 4 + debug: false +mon: + addr: "root:1234@tcp(mysql:3306)/n9e_mon?charset=utf8&parseTime=True&loc=Asia%2FShanghai" + max: 16 + idle: 4 + debug: false +hbs: + addr: "root:1234@tcp(mysql:3306)/n9e_hbs?charset=utf8&parseTime=True&loc=Asia%2FShanghai" + max: 16 + idle: 4 + debug: false \ No newline at end of file diff --git a/docker/nginx/nginx.conf b/docker/nginx/nginx.conf new file mode 100644 index 00000000..12cca06b --- /dev/null +++ b/docker/nginx/nginx.conf @@ -0,0 +1,89 @@ +user root; + +worker_processes auto; +worker_cpu_affinity auto; + +error_log /var/log/nginx/error.log; +pid /run/nginx.pid; + +include /usr/share/nginx/modules/*.conf; + +events { + use epoll; + worker_connections 204800; +} + +http { + log_format main '$remote_addr - $remote_user [$time_local] "$request" ' + '$status $body_bytes_sent "$http_referer" ' + '"$http_user_agent" "$http_x_forwarded_for"'; + + access_log /var/log/nginx/access.log main; + + sendfile on; + tcp_nopush on; + tcp_nodelay on; + keepalive_timeout 65; + types_hash_max_size 2048; + + include /etc/nginx/mime.types; + default_type application/octet-stream; + + include /etc/nginx/conf.d/*.conf; + + + proxy_connect_timeout 500ms; + proxy_send_timeout 1000ms; + proxy_read_timeout 3000ms; + proxy_buffers 64 8k; + proxy_busy_buffers_size 128k; + proxy_temp_file_write_size 64k; + proxy_redirect off; + proxy_next_upstream error invalid_header timeout http_502 http_504; + + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Real-Port $remote_port; + proxy_set_header Host $http_host; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + + upstream n9e.monapi { + server monapi:5800; + keepalive 10; + } + + upstream n9e.index { + server 127.0.0.1:5830; + keepalive 10; + } + + upstream n9e.transfer { + server 127.0.0.1:5810; + keepalive 10; + } + + server { + listen 80 default_server; + server_name _; + root /usr/share/nginx/html; + + # Load configuration files for the default server block. + include /etc/nginx/default.d/*.conf; + + location / { + root /home/n9e/pub; + } + + location /api/portal { + proxy_pass http://n9e.monapi; + } + + location /api/index { + proxy_pass http://n9e.index; + } + + location /api/transfer { + proxy_pass http://n9e.transfer; + } + } + +} \ No newline at end of file diff --git a/web/Dockerfile b/web/Dockerfile index cce595dc..101ad977 100644 --- a/web/Dockerfile +++ b/web/Dockerfile @@ -1,5 +1,7 @@ FROM node:lts-alpine AS builder -WORKDIR /home/app +WORKDIR /app -COPY . . \ No newline at end of file +COPY . . + +RUN npm install \ No newline at end of file From 553dcbd9fa0dd79b7750539e2757bf16d79a63a2 Mon Sep 17 00:00:00 2001 From: llitfkitfk Date: Mon, 23 Mar 2020 01:05:17 +0800 Subject: [PATCH 3/8] update: index config & transfer --- Dockerfile | 6 ++++-- docker-compose.yml | 22 +++++++++++++++++++++- docker/etc/index.yml | 7 +++++++ docker/etc/transfer.yml | 11 +++++++++++ docker/nginx/nginx.conf | 6 +++--- 5 files changed, 46 insertions(+), 6 deletions(-) create mode 100644 docker/etc/index.yml create mode 100644 docker/etc/transfer.yml diff --git a/Dockerfile b/Dockerfile index a1038c1a..d85bb470 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,11 +9,13 @@ WORKDIR /app COPY . . ENV GOPROXY=https://mod.gokit.info -RUN go build -o ./bin/monapi src/modules/monapi/monapi.go +RUN go build -mod vendor -o ./bin/monapi src/modules/monapi/monapi.go \ + && go build -mod vendor -o ./bin/index src/modules/index/index.go \ + && go build -mod vendor -o ./bin/transfer src/modules/transfer/transfer.go FROM alpine:3.10 LABEL maintainer="llitfkitfk@gmail.com" -RUN apk add --no-cache tzdata ca-certificates +RUN apk add --no-cache tzdata ca-certificates bash WORKDIR /app diff --git a/docker-compose.yml b/docker-compose.yml index 7eff13f2..2a3ba7be 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -22,7 +22,27 @@ services: - ./docker/etc:/app/etc ports: - 5800:5800 - + + index: + image: api + restart: always + command: index + volumes: + - ./docker/etc:/app/etc + ports: + - 5830:5830 + - 5831:5831 + + transfer: + image: api + restart: always + command: transfer + volumes: + - ./docker/etc:/app/etc + ports: + - 5810:5810 + - 5811:5811 + # web: # build: # context: web diff --git a/docker/etc/index.yml b/docker/etc/index.yml new file mode 100644 index 00000000..6640c261 --- /dev/null +++ b/docker/etc/index.yml @@ -0,0 +1,7 @@ +logger: + dir: logs/index + level: WARNING + keepHours: 2 +identity: + specify: "" + shell: /sbin/ifconfig `/sbin/route|grep '^default'|awk '{print $NF}'`|grep inet|awk '{print $2}'|head -n 1 diff --git a/docker/etc/transfer.yml b/docker/etc/transfer.yml new file mode 100644 index 00000000..869f8089 --- /dev/null +++ b/docker/etc/transfer.yml @@ -0,0 +1,11 @@ +backend: + # in ms + # connTimeout: 1000 + # callTimeout: 3000 + cluster: + tsdb01: 127.0.0.1:5821 + +logger: + dir: logs/transfer + level: WARNING + keepHours: 2 \ No newline at end of file diff --git a/docker/nginx/nginx.conf b/docker/nginx/nginx.conf index 12cca06b..d1864e67 100644 --- a/docker/nginx/nginx.conf +++ b/docker/nginx/nginx.conf @@ -52,12 +52,12 @@ http { } upstream n9e.index { - server 127.0.0.1:5830; + server index:5830; keepalive 10; } upstream n9e.transfer { - server 127.0.0.1:5810; + server transfer:5810; keepalive 10; } @@ -67,7 +67,7 @@ http { root /usr/share/nginx/html; # Load configuration files for the default server block. - include /etc/nginx/default.d/*.conf; + include /etc/nginx/conf.d/*.conf; location / { root /home/n9e/pub; From 5e2ff73e24519bb022f3a7374a7a41844ad30fcd Mon Sep 17 00:00:00 2001 From: llitfkitfk Date: Mon, 23 Mar 2020 13:46:52 +0800 Subject: [PATCH 4/8] add: other modules --- Dockerfile | 20 +++++++++++++++----- docker-compose.yml | 39 ++++++++++++++++++++++++++++++++++----- docker/etc/collector.yml | 30 ++++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+), 10 deletions(-) create mode 100644 docker/etc/collector.yml diff --git a/Dockerfile b/Dockerfile index d85bb470..a7924a8a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ -FROM golang:alpine AS builder -RUN apk add --no-cache git +FROM golang AS builder +# RUN apk add --no-cache git gcc WORKDIR /app # comment this if using vendor @@ -9,9 +9,18 @@ WORKDIR /app COPY . . ENV GOPROXY=https://mod.gokit.info -RUN go build -mod vendor -o ./bin/monapi src/modules/monapi/monapi.go \ - && go build -mod vendor -o ./bin/index src/modules/index/index.go \ - && go build -mod vendor -o ./bin/transfer src/modules/transfer/transfer.go +RUN echo "build monapi" \ + && go build -v -o ./bin/monapi src/modules/monapi/monapi.go \ + && echo "build transfer" \ + && go build -v -o ./bin/transfer src/modules/transfer/transfer.go \ + && echo "build tsdb" \ + && go build -v -o ./bin/tsdb src/modules/tsdb/tsdb.go \ + && echo "build index" \ + && go build -v -o ./bin/index src/modules/index/index.go \ + && echo "build judge" \ + && go build -v -o ./bin/judge src/modules/judge/judge.go \ + && echo "build collector" \ + && go build -v -o ./bin/collector src/modules/collector/collector.go FROM alpine:3.10 LABEL maintainer="llitfkitfk@gmail.com" @@ -22,5 +31,6 @@ WORKDIR /app COPY --from=builder /app/etc /app/etc COPY --from=builder /app/bin /usr/local/bin + # ENTRYPOINT [] # CMD [] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 2a3ba7be..7fde11c5 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -22,7 +22,27 @@ services: - ./docker/etc:/app/etc ports: - 5800:5800 + + transfer: + image: api + restart: always + command: transfer + volumes: + - ./docker/etc:/app/etc + ports: + - 5810:5810 + - 5811:5811 + tsdb: + image: api + restart: always + command: tsdb + volumes: + - ./docker/etc:/app/etc + ports: + - 5820:5820 + - 5821:5821 + index: image: api restart: always @@ -33,16 +53,25 @@ services: - 5830:5830 - 5831:5831 - transfer: + judge: image: api restart: always - command: transfer + command: judge volumes: - ./docker/etc:/app/etc ports: - - 5810:5810 - - 5811:5811 - + - 5840:5840 + - 5841:5841 + + collector: + image: api + restart: always + command: collector + volumes: + - ./docker/etc:/app/etc + ports: + - 2058:2058 + # web: # build: # context: web diff --git a/docker/etc/collector.yml b/docker/etc/collector.yml new file mode 100644 index 00000000..dae982f0 --- /dev/null +++ b/docker/etc/collector.yml @@ -0,0 +1,30 @@ +logger: + dir: logs/collector + level: WARNING + keepHours: 2 +identity: + specify: "" + shell: /sbin/ifconfig `/sbin/route|grep '^default'|awk '{print $NF}'`|grep inet|awk '{print $2}'|head -n 1 +sys: + # timeout in ms + # interval in second + timeout: 1000 + interval: 20 + ifacePrefix: + - eth + - em + mountPoint: [] + mountIgnorePrefix: + - /var/lib + + ignoreMetrics: + - cpu.core.idle + - cpu.core.util + - cpu.core.sys + - cpu.core.user + - cpu.core.nice + - cpu.core.guest + - cpu.core.irq + - cpu.core.softirq + - cpu.core.iowait + - cpu.core.steal From cbe0c282788b2cd4e69fe53785083d06c77bb6b0 Mon Sep 17 00:00:00 2001 From: llitfkitfk Date: Mon, 23 Mar 2020 14:21:27 +0800 Subject: [PATCH 5/8] update: docker build --- Dockerfile | 16 ++-------------- control | 4 ++-- docker-compose.yml | 12 ++++++------ 3 files changed, 10 insertions(+), 22 deletions(-) diff --git a/Dockerfile b/Dockerfile index a7924a8a..398ce1d1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,19 +8,7 @@ WORKDIR /app # RUN go mod download COPY . . -ENV GOPROXY=https://mod.gokit.info -RUN echo "build monapi" \ - && go build -v -o ./bin/monapi src/modules/monapi/monapi.go \ - && echo "build transfer" \ - && go build -v -o ./bin/transfer src/modules/transfer/transfer.go \ - && echo "build tsdb" \ - && go build -v -o ./bin/tsdb src/modules/tsdb/tsdb.go \ - && echo "build index" \ - && go build -v -o ./bin/index src/modules/index/index.go \ - && echo "build judge" \ - && go build -v -o ./bin/judge src/modules/judge/judge.go \ - && echo "build collector" \ - && go build -v -o ./bin/collector src/modules/collector/collector.go +RUN ./control build FROM alpine:3.10 LABEL maintainer="llitfkitfk@gmail.com" @@ -28,7 +16,7 @@ RUN apk add --no-cache tzdata ca-certificates bash WORKDIR /app -COPY --from=builder /app/etc /app/etc +COPY --from=builder /app/docker/etc /app/etc COPY --from=builder /app/bin /usr/local/bin diff --git a/control b/control index accb98c6..99d6f25e 100755 --- a/control +++ b/control @@ -136,13 +136,13 @@ status() build_one() { mod=$1 - go build -o n9e-${mod} --tags "md5" src/modules/${mod}/${mod}.go + go build -o bin/n9e-${mod} --tags "md5" src/modules/${mod}/${mod}.go } build() { export GO111MODULE=on - export GOPROXY=https://mirrors.aliyun.com/goproxy/ + export GOPROXY=https://mod.gokit.info mod=$1 if [ "x${mod}" = "x" ]; then diff --git a/docker-compose.yml b/docker-compose.yml index 7fde11c5..d2b5e069 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -17,7 +17,7 @@ services: monapi: image: api restart: always - command: monapi + command: n9e-monapi volumes: - ./docker/etc:/app/etc ports: @@ -26,7 +26,7 @@ services: transfer: image: api restart: always - command: transfer + command: n9e-transfer volumes: - ./docker/etc:/app/etc ports: @@ -36,7 +36,7 @@ services: tsdb: image: api restart: always - command: tsdb + command: n9e-tsdb volumes: - ./docker/etc:/app/etc ports: @@ -46,7 +46,7 @@ services: index: image: api restart: always - command: index + command: n9e-index volumes: - ./docker/etc:/app/etc ports: @@ -56,7 +56,7 @@ services: judge: image: api restart: always - command: judge + command: n9e-judge volumes: - ./docker/etc:/app/etc ports: @@ -66,7 +66,7 @@ services: collector: image: api restart: always - command: collector + command: n9e-collector volumes: - ./docker/etc:/app/etc ports: From 76b7237347ee5f7cfa060929562a86dda9a49a07 Mon Sep 17 00:00:00 2001 From: llitfkitfk Date: Mon, 23 Mar 2020 14:38:58 +0800 Subject: [PATCH 6/8] update: docker base image --- Dockerfile | 3 +-- docker/etc/collector.yml | 2 +- docker/etc/judge.yml | 22 ++++++++++++++++++++++ docker/etc/tsdb.yml | 8 ++++++++ 4 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 docker/etc/judge.yml create mode 100644 docker/etc/tsdb.yml diff --git a/Dockerfile b/Dockerfile index 398ce1d1..b9040f39 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,9 +10,8 @@ WORKDIR /app COPY . . RUN ./control build -FROM alpine:3.10 +FROM buildpack-deps:buster-curl LABEL maintainer="llitfkitfk@gmail.com" -RUN apk add --no-cache tzdata ca-certificates bash WORKDIR /app diff --git a/docker/etc/collector.yml b/docker/etc/collector.yml index dae982f0..f1218cdd 100644 --- a/docker/etc/collector.yml +++ b/docker/etc/collector.yml @@ -4,7 +4,7 @@ logger: keepHours: 2 identity: specify: "" - shell: /sbin/ifconfig `/sbin/route|grep '^default'|awk '{print $NF}'`|grep inet|awk '{print $2}'|head -n 1 + shell: /usr/sbin/ifconfig `/usr/sbin/route|grep '^default'|awk '{print $NF}'`|grep inet|awk '{print $2}'|head -n 1 sys: # timeout in ms # interval in second diff --git a/docker/etc/judge.yml b/docker/etc/judge.yml new file mode 100644 index 00000000..b5714c33 --- /dev/null +++ b/docker/etc/judge.yml @@ -0,0 +1,22 @@ +query: + connTimeout: 1000 + callTimeout: 2000 + indexCallTimeout: 2000 + +redis: + addrs: + - redis:6379 + pass: "" + # timeout: + # conn: 500 + # read: 3000 + # write: 3000 + +identity: + specify: "" + shell: /usr/sbin/ifconfig `/usr/sbin/route|grep '^default'|awk '{print $NF}'`|grep inet|awk '{print $2}'|head -n 1 + +logger: + dir: logs/judge + level: WARNING + keepHours: 2 \ No newline at end of file diff --git a/docker/etc/tsdb.yml b/docker/etc/tsdb.yml new file mode 100644 index 00000000..863a3bae --- /dev/null +++ b/docker/etc/tsdb.yml @@ -0,0 +1,8 @@ +rrd: + storage: data/5821 +cache: + keepMinutes: 120 +logger: + dir: logs/tsdb + level: WARNING + keepHours: 2 \ No newline at end of file From ec0aeecc93a4b049b82b1b067dfd1379ebbf0d15 Mon Sep 17 00:00:00 2001 From: llitfkitfk Date: Mon, 23 Mar 2020 14:41:30 +0800 Subject: [PATCH 7/8] update: golang mod proxy --- Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Dockerfile b/Dockerfile index b9040f39..eb4757ba 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,6 +8,7 @@ WORKDIR /app # RUN go mod download COPY . . +ENV GOPROXY=https://mod.gokit.info RUN ./control build FROM buildpack-deps:buster-curl From 3d13c44ae12f25c83d0f76f6882db5f393846939 Mon Sep 17 00:00:00 2001 From: llitfkitfk Date: Tue, 24 Mar 2020 22:30:37 +0800 Subject: [PATCH 8/8] remove duplicate etc config yml && add sed scripts --- Dockerfile | 8 +++++-- control | 18 +++++++++++++- docker-compose.yml | 12 ---------- docker/etc/address.yml | 34 -------------------------- docker/etc/collector.yml | 30 ----------------------- docker/etc/index.yml | 7 ------ docker/etc/judge.yml | 22 ----------------- docker/etc/monapi.yml | 52 ---------------------------------------- docker/etc/mysql.yml | 16 ------------- docker/etc/transfer.yml | 11 --------- docker/etc/tsdb.yml | 8 ------- docker/scripts/sed.sh | 8 +++++++ 12 files changed, 31 insertions(+), 195 deletions(-) delete mode 100644 docker/etc/address.yml delete mode 100644 docker/etc/collector.yml delete mode 100644 docker/etc/index.yml delete mode 100644 docker/etc/judge.yml delete mode 100644 docker/etc/monapi.yml delete mode 100644 docker/etc/mysql.yml delete mode 100644 docker/etc/transfer.yml delete mode 100644 docker/etc/tsdb.yml create mode 100755 docker/scripts/sed.sh diff --git a/Dockerfile b/Dockerfile index eb4757ba..b89cab9c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,14 +9,18 @@ WORKDIR /app COPY . . ENV GOPROXY=https://mod.gokit.info -RUN ./control build +RUN ./control build docker FROM buildpack-deps:buster-curl LABEL maintainer="llitfkitfk@gmail.com" WORKDIR /app -COPY --from=builder /app/docker/etc /app/etc +COPY --from=builder /app/docker/scripts /app/scripts +COPY --from=builder /app/etc /app/etc +# Change default address (hard code) +RUN ./scripts/sed.sh + COPY --from=builder /app/bin /usr/local/bin diff --git a/control b/control index da36d118..95c87583 100755 --- a/control +++ b/control @@ -134,6 +134,12 @@ status() } build_one() +{ + mod=$1 + go build -o n9e-${mod} --tags "md5" src/modules/${mod}/${mod}.go +} + +build_docker() { mod=$1 go build -o bin/n9e-${mod} --tags "md5" src/modules/${mod}/${mod}.go @@ -141,7 +147,7 @@ build_one() build() { - export GO111MODULE=on + export GO111MODULE=on mod=$1 if [ "x${mod}" = "x" ]; then @@ -153,6 +159,16 @@ build() build_one tsdb return fi + + if [ "x${mod}" = "xdocker" ]; then + build_docker monapi + build_docker transfer + build_docker index + build_docker judge + build_docker collector + build_docker tsdb + return + fi build_one $mod } diff --git a/docker-compose.yml b/docker-compose.yml index d2b5e069..43acc57a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -18,8 +18,6 @@ services: image: api restart: always command: n9e-monapi - volumes: - - ./docker/etc:/app/etc ports: - 5800:5800 @@ -27,8 +25,6 @@ services: image: api restart: always command: n9e-transfer - volumes: - - ./docker/etc:/app/etc ports: - 5810:5810 - 5811:5811 @@ -37,8 +33,6 @@ services: image: api restart: always command: n9e-tsdb - volumes: - - ./docker/etc:/app/etc ports: - 5820:5820 - 5821:5821 @@ -47,8 +41,6 @@ services: image: api restart: always command: n9e-index - volumes: - - ./docker/etc:/app/etc ports: - 5830:5830 - 5831:5831 @@ -57,8 +49,6 @@ services: image: api restart: always command: n9e-judge - volumes: - - ./docker/etc:/app/etc ports: - 5840:5840 - 5841:5841 @@ -67,8 +57,6 @@ services: image: api restart: always command: n9e-collector - volumes: - - ./docker/etc:/app/etc ports: - 2058:2058 diff --git a/docker/etc/address.yml b/docker/etc/address.yml deleted file mode 100644 index bea44bad..00000000 --- a/docker/etc/address.yml +++ /dev/null @@ -1,34 +0,0 @@ ---- -monapi: - http: 0.0.0.0:5800 - addresses: - - 127.0.0.1 - -transfer: - http: 0.0.0.0:5810 - rpc: 0.0.0.0:5811 - addresses: - - 127.0.0.1 - -tsdb: - http: 0.0.0.0:5820 - rpc: 0.0.0.0:5821 - addresses: - - 127.0.0.1 - -index: - http: 0.0.0.0:5830 - rpc: 0.0.0.0:5831 - addresses: - - 127.0.0.1 - -judge: - http: 0.0.0.0:5840 - rpc: 0.0.0.0:5841 - addresses: - - 127.0.0.1 - -collector: - http: 0.0.0.0:2058 - - diff --git a/docker/etc/collector.yml b/docker/etc/collector.yml deleted file mode 100644 index f1218cdd..00000000 --- a/docker/etc/collector.yml +++ /dev/null @@ -1,30 +0,0 @@ -logger: - dir: logs/collector - level: WARNING - keepHours: 2 -identity: - specify: "" - shell: /usr/sbin/ifconfig `/usr/sbin/route|grep '^default'|awk '{print $NF}'`|grep inet|awk '{print $2}'|head -n 1 -sys: - # timeout in ms - # interval in second - timeout: 1000 - interval: 20 - ifacePrefix: - - eth - - em - mountPoint: [] - mountIgnorePrefix: - - /var/lib - - ignoreMetrics: - - cpu.core.idle - - cpu.core.util - - cpu.core.sys - - cpu.core.user - - cpu.core.nice - - cpu.core.guest - - cpu.core.irq - - cpu.core.softirq - - cpu.core.iowait - - cpu.core.steal diff --git a/docker/etc/index.yml b/docker/etc/index.yml deleted file mode 100644 index 6640c261..00000000 --- a/docker/etc/index.yml +++ /dev/null @@ -1,7 +0,0 @@ -logger: - dir: logs/index - level: WARNING - keepHours: 2 -identity: - specify: "" - shell: /sbin/ifconfig `/sbin/route|grep '^default'|awk '{print $NF}'`|grep inet|awk '{print $2}'|head -n 1 diff --git a/docker/etc/judge.yml b/docker/etc/judge.yml deleted file mode 100644 index b5714c33..00000000 --- a/docker/etc/judge.yml +++ /dev/null @@ -1,22 +0,0 @@ -query: - connTimeout: 1000 - callTimeout: 2000 - indexCallTimeout: 2000 - -redis: - addrs: - - redis:6379 - pass: "" - # timeout: - # conn: 500 - # read: 3000 - # write: 3000 - -identity: - specify: "" - shell: /usr/sbin/ifconfig `/usr/sbin/route|grep '^default'|awk '{print $NF}'`|grep inet|awk '{print $2}'|head -n 1 - -logger: - dir: logs/judge - level: WARNING - keepHours: 2 \ No newline at end of file diff --git a/docker/etc/monapi.yml b/docker/etc/monapi.yml deleted file mode 100644 index e3335a00..00000000 --- a/docker/etc/monapi.yml +++ /dev/null @@ -1,52 +0,0 @@ ---- -salt: "PLACE_SALT" - -logger: - dir: "logs/monapi" - level: "WARNING" - keepHours: 24 - -http: - secret: "PLACE_SECRET" - -# for ldap authorization -ldap: - host: "ldap.example.org" - port: 389 - baseDn: "dc=example,dc=org" - bindUser: "cn=manager,dc=example,dc=org" - bindPass: "*******" - # openldap: (&(uid=%s)) - # AD: (&(sAMAccountName=%s)) - authFilter: "(&(uid=%s))" - tls: false - startTLS: false - -# notify support: voice, sms, mail, im -# if we have all of notice channel -# notify: -# p1: ["voice", "sms", "mail", "im"] -# p2: ["sms", "mail", "im"] -# p3: ["mail", "im"] - -# if we only have mail channel -notify: - p1: ["mail"] - p2: ["mail"] - p3: ["mail"] - -# addresses accessible using browsers -link: - stra: http://n9e.example.com/#/monitor/strategy/%v - event: http://n9e.example.com/#/monitor/history/his/%v - claim: http://n9e.example.com/#/monitor/history/cur/%v - -# for alarm event and message queue -redis: - addr: "redis:6379" - pass: "" - # in ms - # timeout: - # conn: 500 - # read: 3000 - # write: 3000 diff --git a/docker/etc/mysql.yml b/docker/etc/mysql.yml deleted file mode 100644 index a65d0094..00000000 --- a/docker/etc/mysql.yml +++ /dev/null @@ -1,16 +0,0 @@ ---- -uic: - addr: "root:1234@tcp(mysql:3306)/n9e_uic?charset=utf8&parseTime=True&loc=Asia%2FShanghai" - max: 16 - idle: 4 - debug: false -mon: - addr: "root:1234@tcp(mysql:3306)/n9e_mon?charset=utf8&parseTime=True&loc=Asia%2FShanghai" - max: 16 - idle: 4 - debug: false -hbs: - addr: "root:1234@tcp(mysql:3306)/n9e_hbs?charset=utf8&parseTime=True&loc=Asia%2FShanghai" - max: 16 - idle: 4 - debug: false \ No newline at end of file diff --git a/docker/etc/transfer.yml b/docker/etc/transfer.yml deleted file mode 100644 index 869f8089..00000000 --- a/docker/etc/transfer.yml +++ /dev/null @@ -1,11 +0,0 @@ -backend: - # in ms - # connTimeout: 1000 - # callTimeout: 3000 - cluster: - tsdb01: 127.0.0.1:5821 - -logger: - dir: logs/transfer - level: WARNING - keepHours: 2 \ No newline at end of file diff --git a/docker/etc/tsdb.yml b/docker/etc/tsdb.yml deleted file mode 100644 index 863a3bae..00000000 --- a/docker/etc/tsdb.yml +++ /dev/null @@ -1,8 +0,0 @@ -rrd: - storage: data/5821 -cache: - keepMinutes: 120 -logger: - dir: logs/tsdb - level: WARNING - keepHours: 2 \ No newline at end of file diff --git a/docker/scripts/sed.sh b/docker/scripts/sed.sh new file mode 100755 index 00000000..36372e97 --- /dev/null +++ b/docker/scripts/sed.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +set -xe + +sed -i 's/127.0.0.1:6379/redis:6379/g' /app/etc/judge.yml +sed -i 's/127.0.0.1:6379/redis:6379/g' /app/etc/monapi.yml +sed -i 's/127.0.0.1:3306/mysql:3306/g' /app/etc/mysql.yml +sed -i 's/127.0.0.1:5821/tsdb:5821/g' /app/etc/transfer.yml \ No newline at end of file