# 1.1 快速开始

# 1.1.1 Go编译器安装

  1. 安装Go多版本管理器(推荐)

    • Linux/macOS下自动安装Go多版本管理器(适用于 bash、zsh)
    $ curl -sSL https://raw.githubusercontent.com/voidint/g/master/install.sh | bash
    $ cat << 'EOF' >> ~/.bashrc
    # 可选。检查g别名是否被占用
    if [[ -n $(alias g 2>/dev/null) ]]; then
        unalias g
    fi
    EOF 
    $ source "$HOME/.g/env"
    
    1
    2
    3
    4
    5
    6
    7
    8
    • Windows下自动安装Go多版本管理器(适用于 pwsh)
    $ iwr https://raw.githubusercontent.com/voidint/g/master/install.ps1 -useb | iex
    
    1
  2. 安装Go编译器

    $ g install 1.25.0
    
    1

# 1.1.2 工具链安装

  1. 安装protobuf编译器(使用场景:开发mesh微服务、使用protobuf作为与客户端通信的协议)

    • Linux, using apt or apt-get, for example:
    $ apt install -y protobuf-compiler
    $ protoc --version  # Ensure compiler version is 3+
    
    1
    2
    • MacOS, using Homebrew:
    $ brew install protobuf
    $ protoc --version  # Ensure compiler version is 3+
    
    1
    2
  2. 安装protobuf go代码生成工具(使用场景:开发mesh微服务、使用protobuf作为与客户端通信的协议)

    $ go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
    
    1
  3. 安装grpc代码生成工具(使用场景:使用GRPC (opens new window)组件开发mesh微服务)

    $ go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
    
    1
  4. 安装rpcx代码生成工具(使用场景:使用RPCX (opens new window)组件开发mesh微服务)

    $ go install github.com/rpcxio/protoc-gen-rpcx@latest
    
    1
  5. 安装gorm dao代码生成工具(使用场景:使用GORM (opens new window)作为数据库orm)

    $ go install github.com/dobyte/gorm-dao-generator@latest
    
    1
  6. 安装mongo dao代码生成工具(使用场景:使用MongoDB (opens new window)作为数据库orm)

    $ go install github.com/dobyte/mongo-dao-generator@latest
    
    1

# 1.1.3 Docker环境安装

  1. 安装docker

进入docker (opens new window)官网下载最新版docker (opens new window)安装包安装

  1. 安装docker-compose
  • Linux
$ sudo curl -L "https://github.com/docker/compose/releases/download/v2.36.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
$ sudo chmod +x /usr/local/bin/docker-compose
1
2
  1. 安装开发组件
$ cd ./docker
$ docker-compose up -d
1
2
  1. docker-compose.yaml
version: "3"

services:
  mysql:
    image: mysql:5.7
    container_name: dev-mysql
    platform: linux/x86_64
    command: --default-authentication-plugin=mysql_native_password
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: 123456
    ports:
      - '3306:3306'
    volumes:
      - ./mysql:/var/lib/mysql
    networks:
      cluster-network:
        ipv4_address: 192.168.10.2
  redis:
    image: redis:6.0
    container_name: dev-redis
    platform: linux/x86_64
    restart: always
    ports:
      - '6379:6379'
    volumes:
      - ./redis:/data
    networks:
      cluster-network:
        ipv4_address: 192.168.10.3
  etcd:
    image: bitnami/etcd:latest
    container_name: dev-etcd
    platform: linux/x86_64
    restart: always
    environment:
      - ALLOW_NONE_AUTHENTICATION=yes
      - ETCD_ADVERTISE_CLIENT_URLS=http://etcd:2379
    ports:
      - '2379:2379'
      - '2380:2380'
    networks:
      cluster-network:
        ipv4_address: 192.168.10.4
  consul:
    image: bitnami/consul:latest
    container_name: dev-consul
    platform: linux/x86_64
    restart: always
    ports:
      - '8300:8300'
      - '8301:8301'
      - '8301:8301/udp'
      - '8500:8500'
      - '8600:8600'
      - '8600:8600/udp'
    volumes:
      - ./consul:/bitnami
    networks:
      cluster-network:
        ipv4_address: 192.168.10.5
  kafka:
    image: apache/kafka:latest
    container_name: dev-kafka
    platform: linux/x86_64
    restart: always
    ports:
      - '9092:9092'
    networks:
      cluster-network:
        ipv4_address: 192.168.10.6
  nats:
    image: nats:latest
    container_name: dev-nats
    platform: linux/x86_64
    restart: always
    ports:
      - '4222:4222'
      - '6222:6222'
      - '8222:8222'
    networks:
      cluster-network:
        ipv4_address: 192.168.10.7
  nacos:
    image: nacos/nacos-server:v2.5.1
    container_name: dev-nacos
    platform: linux/x86_64
    restart: always
    environment:
      - PREFER_HOST_MODE=hostname
      - MODE=standalone
      - NACOS_AUTH_IDENTITY_KEY=serverIdentity
      - NACOS_AUTH_IDENTITY_VALUE=security
      - NACOS_AUTH_TOKEN=SecretKey012345678901234567890123456789012345678901234567890123456789
    volumes:
      - ./nacos/logs:/home/nacos/logs
      - ./nacos/conf/application.properties:/home/nacos/conf/application.properties
    ports:
      - '8848:8848'
      - '9848:9848'
    networks:
      cluster-network:
        ipv4_address: 192.168.10.8
  mongo:
    image: mongo:4.4-rc-focal
    container_name: dev-mongo
    platform: linux/x86_64
    restart: always
    environment:
      - MONGO_INITDB_ROOT_USERNAME=root
      - MONGO_INITDB_ROOT_PASSWORD=12345678
    ports:
      - '27017:27017'
    volumes:
      - ./mongo/data:/data/db
    networks:
      cluster-network:
        ipv4_address: 192.168.10.9
  memcache:
    image: devdb/memcache:latest
    container_name: dev-memcache
    platform: linux/x86_64
    restart: always
    ports:
      - '11211:11211'
    networks:
      cluster-network:
        ipv4_address: 192.168.10.10
networks:
  cluster-network:
    driver: bridge
    ipam:
      driver: default
      config:
        - subnet: 192.168.10.0/24
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135