当前位置:网站首页>Take you ten days to easily complete the go micro service series (I)
Take you ten days to easily complete the go micro service series (I)
2022-07-02 16:32:00 【Wan Junfeng, Kevin】
This article begins , We will publish a series of articles to show you one in detail go-zero Microservice example , The whole series is divided into ten articles , The directory structure is as follows :
- Environment building ( this paper )
- Service split
- Customer service
- Product service
- Order service
- Payment services
- RPC service Auth verification
- Service monitoring
- Link tracking
- Distributed transactions
I hope this series will take you to use it locally Docker Environmental utilization go-zero Quickly develop a mall system , Let you get started with micro services quickly .
Complete sample code : https://github.com/nivin-studio/go-zero-mall
1 Environmental requirements
Golang1.15+EtcdRedisMysqlPrometheusGrafanaJaegerDTM
2 Docker Local development environment construction
For the convenience of development and debugging , We use Docker Building a local development environment .Windows and macOS The system can be downloaded Docker Desktop Install and use , For specific download and installation methods, you can search relevant tutorials by yourself .
Here we use Docker Compose To orchestrate and manage our containers , Create the following directory :
2.1 To write Dockerfile
stay go-zero In the microservices of grpc Communication between services , and grpc You need to use protoc And translate into go Language rpc stub Code plug-ins protoc-gen-go.
To improve development efficiency , Reduce the error rate of code , Reduce the workload of business development ,go-zero It also provides goctl Code generation tool .
therefore , We need to protoc, protoc-gen-go, goctl, Install in advance to golang In the container , For later use .
therefore golang Container of Dockerfile The code is as follows :
Other service containers Dockerfile No special treatment required , Just based on the existing image .
| service | Based on the image |
|---|---|
| DTM | yedf/dtm |
| Etcd | bitnami/etcd |
| Mysql | mysql:5.7 |
| Redis | redis:5.0 |
| Mysql Manage | phpmyadmin/phpmyadmin |
| Redis Manage | erikdubbelboer/phpredisadmin |
| Prometheus | bitnami/prometheus |
| Grafana | grafana/grafana |
| Jaeger | jaegertracing/all-in-one:1.28 |
2.2 To write .env The configuration file
2.3 To write docker-compose.yml The configuration file
2.4 Build and run
- Use
docker-composeCommand to build and start our service container , Execute the following command in the root directory :
Container building

stay
WindowsThe system container construction appears as shown in the following figure , Please selectShare itThis will allowWindowsMount the file directory of to the container directory .
The container has started running


2.5 Container description
| Container name | Exposed port | host Address | explain |
|---|---|---|---|
| golang | 8000:8000<br>8001:8001<br>8002:8002<br>8003:8003<br>9000:9000<br>9001:9001<br>9002:9002<br>9003:9003 | golang | In the production environment, microservices are generally deployed in clusters , Maybe one microservice and one server , It may also be a microservice and a container . For the convenience of development and debugging , We will be in golang Start all microservices in the container , And assign them different port numbers for listening to distinguish .<br>80: The port number at the beginning will be used for api service <br>90: The port number at the beginning will be used for rpc service |
| dtm | 36789:36789<br>36790:36790 | dtm | dtm Of http The protocol and grpc Protocol service port number , For client interaction .<br> In this project, we only Docker Access between internal containers , Therefore, the port number can not be exposed to the host |
| etcd | 2379:2379 | etcd | Etcdhttp api Service port number , For client interaction .<br> In this project, we only Docker Access between internal containers , Therefore, the port number can not be exposed to the host |
| mysql | 3306:3306 | mysql | Mysql Service default port number , The host computer can pass through 127.0.0.1:3306 Connect to the database |
| redis | 6379:6379 | redis | Redis Service default port number , The host computer can pass through 127.0.0.1:6379 Connect to the database |
| mysql-manage | 1000:80 | mysql-manage | phpMyAdminweb Service port number , It can be on the host 127.0.0.1:1000 visit |
| redis-manage | 2000:80 | redis-manage | phpRedisAdminweb Service port number , It can be on the host 127.0.0.1:2000 visit |
| prometheus | 3000:9090 | prometheus | Prometheusweb Service port number , It can be on the host 127.0.0.1:3000 visit |
| grafana | 4000:3000 | grafana | Grafanaweb Service port number , It can be on the host 127.0.0.1:4000 visit |
| jaeger | 5000:16686 | jaeger | Jaegerweb Service port number , It can be on the host 127.0.0.1:5000 visit |
2.6 Access validation
MysqlAccess validation
RedisAccess validation
PrometheusAccess validation
GrafanaAccess validation
JaegerAccess validation
Project address
https://github.com/zeromicro/go-zero
Welcome to use go-zero and star Support us !
WeChat ac group
Focus on 『 Microservice practice 』 Official account and click Communication group Get community group QR code .
边栏推荐
- Does bone conduction earphone have external sound? Advantages of bone conduction earphones
- 云原生的 CICD 框架:Tekton
- 去除router-link中的下划线
- 路由模式:hash和history模式
- Remove the underline in router link
- How to use stustr function in Oracle view
- Figure database | Nepal graph v3.1.0 performance report
- 结构体的内存对齐
- 潘多拉 IOT 开发板学习(RT-Thread)—— 实验2 RGB LED 实验(学习笔记)
- HMS core machine learning service helps zaful users to shop conveniently
猜你喜欢
![OSPF - route aggregation [(summary) including configuration commands] | address summary calculation method - detailed explanation](/img/8b/36be3191a7d71f4a8c8181eaed8417.jpg)
OSPF - route aggregation [(summary) including configuration commands] | address summary calculation method - detailed explanation

TypeScript数组乱序输出

Add user-defined formula (time sharing t+0) to mobile app access as an example

结构体的内存对齐

Mathematical analysis_ Notes_ Chapter 5: univariate differential calculus
![[Yu Yue education] reference materials of sensing and intelligent control technology of Nanjing University of Technology](/img/5c/5f835c286548907f3f09ecb66b2068.jpg)
[Yu Yue education] reference materials of sensing and intelligent control technology of Nanjing University of Technology

2022 the latest and most detailed will successfully set the background image in vscade and solve unsupported problems at the same time

Practice of constructing ten billion relationship knowledge map based on Nebula graph

忆当年高考|成为程序员的你,后悔了吗?

MySQL calculates the data within the longitude and latitude range
随机推荐
Everyone Xinfu builds: a one-stop intelligent business credit service platform
微信v3native支付设置的结束时间处理办法
Sqlserver queries which indexes are underutilized
[5g NR] RRC connection release
Construction and business practice of Zhongke brain knowledge map platform
Maui学习之路(三)--Winui3深入探讨
Win11应用商店无法加载页面怎么办?Win11商店无法加载页面
Multi data source configuration code
HMS core machine learning service helps zaful users to shop conveniently
手机app通达信添加自定义公式(分时T+0)为例子讲解
IDEA中设置背景图片(超详细)
2022 the latest and most detailed will successfully set the background image in vscade and solve unsupported problems at the same time
Seal Library - installation and introduction
Memory alignment of structure
Today in history: Alipay launched barcode payment; The father of time-sharing system was born; The first TV advertisement in the world
Practice of traffic recording and playback in vivo
Introduction to database system Chapter 1 short answer questions - how was the final exam?
Song of cactus - throwing stones to ask the way (3)
电脑管理员权限在哪里可以打开
SQL solves the problem of continuous login deformation holiday filtering