当前位置:网站首页>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
Golang
1.15+Etcd
Redis
Mysql
Prometheus
Grafana
Jaeger
DTM
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-compose
Command to build and start our service container , Execute the following command in the root directory :
Container building
stay
Windows
The system container construction appears as shown in the following figure , Please selectShare it
This will allowWindows
Mount 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 | Etcd http 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 | phpMyAdmin web Service port number , It can be on the host 127.0.0.1:1000 visit |
redis-manage | 2000:80 | redis-manage | phpRedisAdmin web Service port number , It can be on the host 127.0.0.1:2000 visit |
prometheus | 3000:9090 | prometheus | Prometheus web Service port number , It can be on the host 127.0.0.1:3000 visit |
grafana | 4000:3000 | grafana | Grafana web Service port number , It can be on the host 127.0.0.1:4000 visit |
jaeger | 5000:16686 | jaeger | Jaeger web Service port number , It can be on the host 127.0.0.1:5000 visit |
2.6 Access validation
Mysql
Access validationRedis
Access validationPrometheus
Access validationGrafana
Access validationJaeger
Access 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 .
边栏推荐
- Headline | Asian control technology products are selected in the textile and clothing industry digital transformation solution key promotion directory of Textile Federation
- Bean configuration override in boot
- In memory of becoming the first dayu200 tripartite demo contributor
- 做机器视觉哪个软件好?
- Memory alignment of structure
- Source code look me
- Library management system (Shandong Agricultural University Curriculum Design)
- SQLServer查询哪些索引利用率低
- Unity使用UGUI设置一个简单多级水平方向下拉菜单(不需要代码)
- Typescript array out of order output
猜你喜欢
Practice of constructing ten billion relationship knowledge map based on Nebula graph
Understand the key technology of AGV -- the difference between laser slam and visual slam
Dimension table and fact table in data warehouse
Add user-defined formula (time sharing t+0) to mobile app access as an example
Trigger: MySQL implements adding or deleting a piece of data in one table and adding another table at the same time
关于mysql安装的一些问题
MySQL min() finds the minimum value under certain conditions, and there are multiple results
JS learning notes - process control
2022最新最详细必成功的在Vscode中设置背景图、同时解决不受支持的问题
Pandora IOT development board learning (RT thread) - Experiment 2 RGB LED experiment (learning notes)
随机推荐
Yyds dry inventory method of deleting expired documents in batch
数学分析_笔记_第5章:一元微分学
Mathematical analysis_ Notes_ Chapter 5: univariate differential calculus
Data Lake (11): Iceberg table data organization and query
JS learning notes - variables
day4
Leetcode --- longest public prefix
Mysql database mysqldump why there is no statement to create a database
云原生的 CICD 框架:Tekton
Summary | three coordinate systems in machine vision and their relationships
PCL point cloud image transformation
sql解决连续登录问题变形-节假日过滤
Yyds dry inventory KVM new inventory to expand space for home
Classifier visual interpretation stylex: Google, MIT, etc. have found the key attributes that affect image classification
Summary of multithreading and thread synchronization knowledge
Multi data source configuration code
PCL 最小中值平方法拟合平面
虚假的暑假
请问怎么在oracle视图中使用stustr函数
JS learning notes - operators