go-zero modd开发配置

go-zero modd开发配置

modd配置

modd.conf

#usercenter
app/usercenter/cmd/rpc/**/*.go {
    prep: go build -o data/server/usercenter-rpc  -v app/usercenter/cmd/rpc/usercenter.go
    daemon +sigkill: ./data/server/usercenter-rpc -f app/usercenter/cmd/rpc/etc/usercenter.yaml
}
app/usercenter/cmd/api/**/*.go {
    prep: go build -o data/server/usercenter-api  -v app/usercenter/cmd/api/usercenter.go
    daemon +sigkill: ./data/server/usercenter-api -f app/usercenter/cmd/api/etc/usercenter.yaml
}

#notice
#app/notice/cmd/api/**/*.go {
#   prep: go build -o data/server/notice-api  -v app/notice/cmd/api/notice.go
#   daemon +sigkill: ./data/server/notice-api -f app/notice/cmd/api/etc/notice.yaml
#}

#upload
app/upload/cmd/rpc/**/*.go {
   prep: go build -o data/server/upload-rpc  -v app/upload/cmd/rpc/upload.go
   daemon +sigkill: ./data/server/upload-rpc -f app/upload/cmd/rpc/etc/upload.yaml
}
app/upload/cmd/api/**/*.go {
   prep: go build -o data/server/upload-api  -v app/upload/cmd/api/upload.go
   daemon +sigkill: ./data/server/upload-api -f app/upload/cmd/api/etc/upload.yaml
}

#travel
app/travel/cmd/rpc/**/*.go {
    prep: go build -o data/server/travel-rpc  -v app/travel/cmd/rpc/travel.go
    daemon +sigkill: ./data/server/travel-rpc -f app/travel/cmd/rpc/etc/travel.yaml
}
app/travel/cmd/api/**/*.go {
    prep: go build -o data/server/travel-api  -v app/travel/cmd/api/travel.go
    daemon +sigkill: ./data/server/travel-api -f app/travel/cmd/api/etc/travel.yaml
}

##payment
#app/payment/cmd/rpc/**/*.go {
#    prep: go build -o data/server/payment-rpc  -v app/payment/cmd/rpc/payment.go
#    daemon +sigkill: ./data/server/payment-rpc -f app/payment/cmd/rpc/etc/payment.yaml
#}
#app/payment/cmd/api/**/*.go {
#    prep: go build -o data/server/payment-api  -v app/payment/cmd/api/payment.go
#    daemon +sigkill: ./data/server/payment-api -f app/payment/cmd/api/etc/payment.yaml
#}
##order
#app/order/cmd/rpc/**/*.go {
#    prep: go build -o data/server/order-rpc  -v app/order/cmd/rpc/order.go
#    daemon +sigkill: ./data/server/order-rpc -f app/order/cmd/rpc/etc/order.yaml
#}
#app/order/cmd/api/**/*.go {
#    prep: go build -o data/server/order-api  -v app/order/cmd/api/order.go
#    daemon +sigkill: ./data/server/order-api -f app/order/cmd/api/etc/order.yaml
#}
#app/order/cmd/mq/**/*.go {
#    prep: go build -o data/server/order-mq  -v app/order/cmd/mq/order.go
#    daemon +sigkill: ./data/server/order-mq -f app/order/cmd/mq/etc/order.yaml
#}
##mqueue
#app/mqueue/cmd/scheduler/**/*.go {
#    prep: go build -o data/server/mqueue-scheduler  -v app/mqueue/cmd/scheduler/mqueue.go
#    daemon +sigkill: ./data/server/mqueue-scheduler -f app/mqueue/cmd/scheduler/etc/mqueue.yaml
#}
#app/mqueue/cmd/job/**/*.go {
#    prep: go build -o data/server/mqueue-job  -v app/mqueue/cmd/job/mqueue.go
#    daemon +sigkill: ./data/server/mqueue-job -f app/mqueue/cmd/job/etc/mqueue.yaml
#}

项目打包编排文件

docker-compose.yml

version: '3'

######## app下api+rpc ,  Before starting this project, start the environment that the project depends on docker-compose-env.yml #######

services:

  #前端网关nginx-gateay (只代理looklook,admin-api不在这里做代理)
  # Front-end gateway nginx-gateway (Only agent looklook,admin-api Do not be an agent here)
  nginx-gateway:
    image: nginx:1.21.5
    container_name: nginx-gateway
    restart: always
    privileged: true
    environment:
      - TZ=Asia/Shanghai
    ports:
      - 8888:8081
    volumes:
      - ./deploy/nginx/conf.d:/etc/nginx/conf.d
      - ./data/nginx/log:/var/log/nginx
    networks:
      - looklook_net
    depends_on:
      - looklook

  #前端api + 业务rpc - Front-end API + business RPC
  looklook:
    # docker-hub : https://hub.docker.com/r/lyumikael/gomodd
    # dockerfile: https://github.com/Mikaelemmmm/gomodd , If you are macOs m1\m2 use dockerfile yourself to build the image
    image: lyumikael/gomodd:v1.20.3
    container_name: looklook
    environment:
      # 时区上海 - Timezone Shanghai
      TZ: Asia/Shanghai
      GOPROXY: https://goproxy.cn,direct
    working_dir: /go/looklook
    volumes:
      - .:/go/looklook
    privileged: true
    restart: always
    networks:
      - looklook_net

networks:
  looklook_net:
    driver: bridge
    external: true #着重看这里
    ipam:
      config:
        - subnet: 172.20.0.0/16


nginx配置文件

deploy/nginx/conf.d/looklook-gateway.conf

server{
      listen 8081;
      access_log /var/log/nginx/looklook.com_access.log;
      error_log /var/log/nginx/looklook.com_error.log;


      location ~ /order/ {
           proxy_set_header Host $http_host;
           proxy_set_header X-Real-IP $remote_addr;
           proxy_set_header REMOTE-HOST $remote_addr;
           proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
           proxy_pass http://looklook:1001;
      }
      location ~ /payment/ {
          proxy_set_header Host $http_host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header REMOTE-HOST $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_pass http://looklook:1002;
      }
      location ~ /travel/ {
         proxy_set_header Host $http_host;
         proxy_set_header X-Real-IP $remote_addr;
         proxy_set_header REMOTE-HOST $remote_addr;
         proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
         proxy_pass http://looklook:1003;
      }
      location ~ /usercenter/ {
         proxy_set_header Host $http_host;
         proxy_set_header X-Real-IP $remote_addr;
         proxy_set_header REMOTE-HOST $remote_addr;
         proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
         proxy_pass http://looklook:1004;
      }
      location ~ /lottery/ {
         proxy_set_header Host $http_host;
         proxy_set_header X-Real-IP $remote_addr;
         proxy_set_header REMOTE-HOST $remote_addr;
         proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
         proxy_pass http://looklook:1005;
      }
      location ~ /notice/ {
         proxy_set_header Host $http_host;
         proxy_set_header X-Real-IP $remote_addr;
         proxy_set_header REMOTE-HOST $remote_addr;
         proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
         proxy_pass http://looklook:1006;
      }
      location ~ /upload/ {
         proxy_set_header Host $http_host;
         proxy_set_header X-Real-IP $remote_addr;
         proxy_set_header REMOTE-HOST $remote_addr;
         proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
         proxy_pass http://looklook:1008;
      }
}

deploy/prometheus/server/prometheus.yml

global:
  scrape_interval:
  external_labels:
    monitor: 'codelab-monitor'

scrape_configs:
  - job_name: 'prometheus'
    scrape_interval: 5s  #global catch time
    static_configs:
      - targets: ['127.0.0.1:9090']

  - job_name: 'order-api'
    static_configs:
      - targets: [ 'looklook:4001' ]
        labels:
          job: order-api
          app: order-api
          env: dev
  - job_name: 'order-rpc'
    static_configs:
      - targets: [ 'looklook:4002' ]
        labels:
          job: order-rpc
          app: order-rpc
          env: dev
  - job_name: 'order-mq'
    static_configs:
      - targets: [ 'looklook:4003' ]
        labels:
          job: order-mq
          app: order-mq
          env: dev
  - job_name: 'payment-api'
    static_configs:
      - targets: [ 'looklook:4004' ]
        labels:
          job: payment-api
          app: payment-api
          env: dev
  - job_name: 'payment-rpc'
    static_configs:
      - targets: [ 'looklook:4005' ]
        labels:
          job: payment-rpc
          app: payment-rpc
          env: dev
  - job_name: 'travel-api'
    static_configs:
      - targets: [ 'looklook:4006' ]
        labels:
          job: travel-api
          app: travel-api
          env: dev
  - job_name: 'travel-rpc'
    static_configs:
      - targets: [ 'looklook:4007' ]
        labels:
          job: travel-rpc
          app: travel-rpc
          env: dev
  - job_name: 'usercenter-api'
    static_configs:
      - targets: ['looklook:4008']
        labels:
          job: usercenter-api
          app: usercenter-api
          env: dev
  - job_name: 'usercenter-rpc'
    static_configs:
      - targets: ['looklook:4009']
        labels:
          job: usercenter-rpc
          app: usercenter-rpc
          env: dev
  - job_name: 'mqueue-job'
    static_configs:
      - targets: [ 'looklook:4010' ]
        labels:
          job: mqueue-job
          app: mqueue-job
          env: dev
  - job_name: 'mqueue-scheduler'
    static_configs:
      - targets: [ 'looklook:4011' ]
        labels:
          job: mqueue-scheduler
          app: mqueue-scheduler
          env: dev
  - job_name: 'upload-api'
    static_configs:
      - targets: ['looklook:4012']
        labels:
          job: upload-api
          app: upload-api
          env: dev
  - job_name: 'upload-rpc'
    static_configs:
      - targets: ['looklook:4013']
        labels:
          job: upload-rpc
          app: upload-rpc
          env: dev

各服务中的配置里要写上如下配置

用于给Prometheus提供监控服务

如:
app/upload/cmd/api/etc/upload.yaml

#监控
Prometheus:
  Host: 0.0.0.0
  Port: 4014
  Path: /metrics

环境配置
docker-compose-env.yml

version: '3'

######## 项目依赖的环境,启动项目之前要先启动此环境 #######
######## The environment that the project depends on, starting this environment before starting the project #######

services:
  #jaeger链路追踪 — Jaeger for tracing
  jaeger:
    image: jaegertracing/all-in-one:1.42.0
    container_name: jaeger
    restart: always
    ports:
      - "5775:5775/udp"
      - "6831:6831/udp"
      - "6832:6832/udp"
      - "5778:5778"
      - "16686:16686"
      - "14268:14268"
      - "9411:9411"
    environment:
      - SPAN_STORAGE_TYPE=elasticsearch
      - ES_SERVER_URLS=http://elasticsearch:9200
      - LOG_LEVEL=debug
    networks:
      - looklook_net

  #prometheus监控 — Prometheus for monitoring
  prometheus:
    image: prom/prometheus:v2.28.1
    container_name: prometheus
    environment:
      # 时区上海 - Time zone Shanghai (Change if needed)
      TZ: Asia/Shanghai
    volumes:
      - ./deploy/prometheus/server/prometheus.yml:/etc/prometheus/prometheus.yml
      - ./data/prometheus/data:/prometheus
    command:
      - '--config.file=/etc/prometheus/prometheus.yml'
      - '--storage.tsdb.path=/prometheus'
    restart: always
    user: root
    ports:
      - 9090:9090
    networks:
      - looklook_net

  #查看prometheus监控数据 - Grafana to view Prometheus monitoring data
  grafana:
    image: grafana/grafana:8.0.6
    container_name: grafana
    hostname: grafana
    user: root
    environment:
      # 时区上海 - Time zone Shanghai (Change if needed)
      TZ: Asia/Shanghai
    restart: always
    volumes:
        - ./data/grafana/data:/var/lib/grafana
    ports:
        - "3001:3000"
    networks:
        - looklook_net

  #搜集kafka业务日志、存储prometheus监控数据 - Kafka for collecting business logs and storing Prometheus monitoring data
  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.13.4
    container_name: elasticsearch
    user: root
    environment:
      - discovery.type=single-node
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
      - TZ=Asia/Shanghai
      - LANG=en_US.UTF-8
      - cluster.name="docker-cluster"
      - network.host=0.0.0.0
      # 开启es跨域
      - http.cors.enabled=true
      - http.cors.allow-origin="*"
      - http.cors.allow-headers=Authorization,Content-Type
    volumes:
      - ./data/elasticsearch/data:/usr/share/elasticsearch/data
    restart: always
    ports:
    - 9200:9200
    - 9300:9300
    networks:
      - looklook_net

  #查看elasticsearch数据 - Kibana to view Elasticsearch data
  kibana:
    image: docker.elastic.co/kibana/kibana:7.13.4
    container_name: kibana
    environment:
      - elasticsearch.hosts=http://elasticsearch:9200
      - TZ=Asia/Shanghai
      - i18n.locale=zh-CN # 中文
      - LANG=en_US.UTF-8
      - server.name=kibana
      - server.host="0.0.0.0"
    restart: always
    networks:
      - looklook_net
    ports:
      - "5601:5601"
    depends_on:
      - elasticsearch

  #消费kafka中filebeat收集的数据输出到es - The data output collected by FileBeat in Kafka is output to ES
  go-stash:
    image: kevinwan/go-stash:1.0 # if you "macOs intel" or "linux amd"
#    image: kevinwan/go-stash:1.0-arm64 #  if you "macOs m1" or "linux arm"
    container_name: go-stash
    environment:
      # 时区上海 - Time zone Shanghai (Change if needed)
      TZ: Asia/Shanghai
    user: root
    restart: always
    volumes:
      - ./deploy/go-stash/etc:/app/etc
    networks:
      - looklook_net
    depends_on:
      - elasticsearch
      - kafka

  #收集业务数据 - Collect business data
  filebeat:
    image: elastic/filebeat:7.13.4
    container_name: filebeat
    environment:
      # 时区上海 - Time zone Shanghai (Change if needed)
      TZ: Asia/Shanghai
    user: root
    restart: always
    entrypoint: "filebeat -e -strict.perms=false"  #解决配置文件权限问题 - Solving the configuration file permissions
    volumes:
      - ./deploy/filebeat/conf/filebeat.yml:/usr/share/filebeat/filebeat.yml
      # 此处需指定docker的containers目录,取决于你docker的配置 - The containers directory of docker needs to be specified here, depending on your docker configuration
      # 如snap安装的docker,则为/var/snap/docker/common/var-lib-docker/containers - Example if docker is installed by Snap /var/snap/docker/common/var-lib-docker/containers
      # - /var/snap/docker/common/var-lib-docker/containers:/var/lib/docker/containers
      - /var/lib/docker/containers:/var/lib/docker/containers
    networks:
      - looklook_net
    depends_on:
      - kafka


  #zookeeper是kafka的依赖 - Zookeeper is the dependencies of Kafka
  zookeeper:
    image: wurstmeister/zookeeper
    container_name: zookeeper
    environment:
      # 时区上海 - Time zone Shanghai (Change if needed)
      TZ: Asia/Shanghai
    restart: always
    ports:
      - 2181:2181
    networks:
      - looklook_net

  #消息队列 - Message queue
  kafka:
    image: wurstmeister/kafka
    container_name: kafka
    ports:
      - 9092:9092
    environment:
      - KAFKA_ADVERTISED_HOST_NAME=kafka
      - KAFKA_ZOOKEEPER_CONNECT=zookeeper:2181
      - KAFKA_AUTO_CREATE_TOPICS_ENABLE=false
      - TZ=Asia/Shanghai
    restart: always
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    networks:
      - looklook_net
    depends_on:
      - zookeeper

  #asynqmon asynq延迟队列、定时队列的webui - Asynqmon asynq delay queue, timing queue's webUI
  asynqmon:
    image: hibiken/asynqmon:latest
    container_name: asynqmon
    ports:
      - 8980:8080
    command:
      - '--redis-addr=redis:6379'
      - '--redis-password=G62m50oigInC30sf'
    restart: always
    networks:
      - looklook_net
    depends_on:
      - redis

  mysql:
    image: mysql/mysql-server:8.0.28
    container_name: mysql
    environment:
      # 时区上海 - Time zone Shanghai (Change if needed)
      TZ: Asia/Shanghai
      # root 密码 - root password
      MYSQL_ROOT_PASSWORD: PXDN93VRKUm8TeE7
    ports:
      - 33069:3306
    volumes:
      # 数据挂载 - Data mounting
      - ./data/mysql/data:/var/lib/mysql
      # 日志
    command:
      # 将mysql8.0默认密码策略 修改为 原先 策略 (mysql8.0对其默认策略做了更改 会导致密码无法匹配) 
      # Modify the Mysql 8.0 default password strategy to the original strategy (MySQL8.0 to change its default strategy will cause the password to be unable to match)
      --default-authentication-plugin=mysql_native_password
      --character-set-server=utf8mb4
      --collation-server=utf8mb4_general_ci
      --explicit_defaults_for_timestamp=true
      --lower_case_table_names=1
    privileged: true
    restart: always
    networks:
      - looklook_net

  #redis容器 - Redis container
  redis:
    image: redis:6.2.5
    container_name: redis
    ports:
      - 36379:6379
    environment:
      # 时区上海 - Time zone Shanghai (Change if needed)
      TZ: Asia/Shanghai
    volumes:
      # 数据文件 - data files
      - ./data/redis/data:/data:rw
    command: "redis-server --requirepass G62m50oigInC30sf  --appendonly yes"
    privileged: true
    restart: always
    networks:
      - looklook_net


networks:
  looklook_net:
    driver: bridge
    external: true #着重看这里
    ipam:
      config:
        - subnet: 172.16.0.0/16

启动环境
第三方服务,数据库等

docker-compose -f docker-compose-env.yml up -d

启动modd开发服务
项目的开发环境

docker-compose -f docker-compose.ymkl up -d

查询各服务是否启动
http://192.168.160.100:9090/targets
image

posted @ 2024-01-29 18:13  HaimaBlog  阅读(132)  评论(0编辑  收藏  举报