当前位置:网站首页>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 .
边栏推荐
- ROW_ NUMBER()、RANK()、DENSE_ Rank difference
- What is Amazon keyword index? The consequences of not indexing are serious
- SQL solves the problem of continuous login deformation holiday filtering
- Various entanglements between qvariant and Jason -- QT
- End time processing method of wechat v3native payment settings
- 图书管理系统(山东农业大学课程设计)
- Practice of constructing ten billion relationship knowledge map based on Nebula graph
- PyC file decompile
- Add user-defined formula (time sharing t+0) to mobile app access as an example
- Set the background picture in the idea (ultra detailed)
猜你喜欢

历史上的今天:支付宝推出条码支付;分时系统之父诞生;世界上第一支电视广告...

Some problems about MySQL installation

理想之光不灭

Huawei ECS installs mysqlb for mysqld service failed because the control process exited with error code. See “sys
![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

Classifier visual interpretation stylex: Google, MIT, etc. have found the key attributes that affect image classification

原神2.6服务端下载以及搭建安装教程

数学分析_笔记_第6章:一元函数的Riemann积分

Practice of traffic recording and playback in vivo

电脑设备打印机驱动安装失败如何解决
随机推荐
Trigger: MySQL implements adding or deleting a piece of data in one table and adding another table at the same time
Yyds dry inventory executor package (parameter processing function)
mysql数据库mysqldump为啥没有创建数据库的语句
OSPF - route aggregation [(summary) including configuration commands] | address summary calculation method - detailed explanation
day4
MySQL min() finds the minimum value under certain conditions, and there are multiple results
[5g NR] RRC connection release
Conditions and solutions of deadlock
Practice of traffic recording and playback in vivo
原神2.6服务端下载以及搭建安装教程
自注意力机制和全连接的图卷积网络(GCN)有什么区别联系?
手机app通达信添加自定义公式(分时T+0)为例子讲解
Yyds dry inventory company stipulates that all interfaces use post requests. Why?
SQLServer查询哪些索引利用率低
What is Amazon keyword index? The consequences of not indexing are serious
Sim2real environment configuration tutorial
End time processing method of wechat v3native payment settings
云原生的 CICD 框架:Tekton
Recommended practice sharing of Zhilian recruitment based on Nebula graph
July 1st gift: Yi Jingjie's "hundred day battle" ended perfectly, and the database of Guiyang bank was sealed in advance