-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
binghe001
committed
Aug 6, 2024
1 parent
b7981a3
commit ae1c483
Showing
6 changed files
with
230 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,219 @@ | ||
--- | ||
title: 第01节:高性能Polaris网关研发环境搭建 | ||
pay: https://articles.zsxq.com/id_jkro4eac7ix3.html | ||
--- | ||
|
||
# 《高性能Polaris网关》环境搭建-第01节:高性能Polaris网关研发环境搭建 | ||
|
||
作者:冰河 | ||
<br/>星球:[http://m6z.cn/6aeFbs](http://m6z.cn/6aeFbs) | ||
<br/>博客:[https://binghe.gitcode.host](https://binghe.gitcode.host) | ||
<br/>文章汇总:[https://binghe.gitcode.host/md/all/all.html](https://binghe.gitcode.host/md/all/all.html) | ||
<br/>源码获取地址:[https://t.zsxq.com/0dhvFs5oR](https://t.zsxq.com/0dhvFs5oR) | ||
|
||
> 沉淀,成长,突破,帮助他人,成就自我。 | ||
* 本章难度:★★☆☆☆ | ||
* 本节重点:统一安装运行高性能Polaris网关所需要的研发依赖环境,重点涉及到Docker环境、docker-compose环境,以及基于docker-compose一键安装高性能Polaris网关所依赖的基础服务和其他中间件,包括:MySQL、Redis、ElasticSearch、Logstash、Kibana、Nacos、Sentinel等。另外,项目源码中会提供基于docker-compose的开箱即用的yml脚本文件。 | ||
|
||
**大家好,我是冰河~~** | ||
|
||
在充分了解了高性能Polaris网关的需求、业务流程、技术流程和架构设计之后,在正式开始研发高性能Polaris网关之前,还需要搭建高性能Polaris网关的研发环境。 | ||
|
||
**注意:本节源码的README.md文件中,已经给出了安装docker和docker-compose的命令,大家打开源码的README.md文件查看即可。** | ||
|
||
## 一、前言 | ||
|
||
在架构和设计高性能Polaris网关时,我们不止是希望网关能够在服务器本身上运行,也希望网关能够运行在K8S集群上。这样我们自己手写的高性能Polaris网关才能具备更好的可用性和可伸缩性。所以,在正式设计和研发Polaris网关之前,我们需要对一些基础的研发环境进行安装和测试。 | ||
|
||
## 二、本节诉求 | ||
|
||
还是那句话:磨刀不无砍柴功。在动手写代码之前,将所有要准备的工作完成,这样写起代码来才会更加顺畅。本节,会在CentOS7操作系统之上搭建Docker环境、docker-compose环境,基于docker-compose环境一键安装高性能Polaris网关所依赖的基础软件和中间件环境,随后会对搭建的环境进行测试。 | ||
|
||
**注意:如何安装VMWare以及安装CentOS7操作系统,小伙伴们可以参见Seckill秒杀系统的《 [第7章:秒杀系统基础环境搭建](https://articles.zsxq.com/id_k0a488ltsvsc.html) 》,并且本节所有环境和软件的安装,都需要CentOS7能够正常联网才行,如果小伙伴们的虚拟机不能正常联网,可以参见Seckill秒杀系统的《 [第7章:秒杀系统基础环境搭建](https://articles.zsxq.com/id_k0a488ltsvsc.html) 》一章的内容解决。** | ||
|
||
## 三、安装Docker环境 | ||
|
||
之前安装的操作系统为CentOS7版本,所以,这里以CentOS7为例安装Docker环境,具体安装步骤如下所示。 | ||
|
||
### 3.1 查看操作系统内核版本 | ||
|
||
由于Docker CE 支持 64 位版本 CentOS 7,并且要求内核版本不低于 3.10,所以这里先查看下安装的CentOS7操作系统的内核版本。在,命令行输入如下命令。 | ||
|
||
```bash | ||
uname -srm | ||
``` | ||
|
||
输出的结果信息如下所示。 | ||
|
||
```bash | ||
Linux 3.10.0-1160.el7.x86_64 x86_64 | ||
``` | ||
|
||
可以看到,内核版本是3.10,符合要求。 | ||
|
||
### 3.2 卸载旧版本Docker | ||
|
||
如果之前安装过旧版本的Docker,则可以执行如下命令卸载。 | ||
|
||
```bash | ||
yum remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-selinux docker-engine-selinux docker-engine docker-ce | ||
``` | ||
|
||
### 3.3 安装gcc环境 | ||
|
||
安装gcc环境主要是为了更加顺利的安装Docker环境,在命令行分别执行如下两条命令来安装gcc环境。 | ||
|
||
```bash | ||
yum -y install gcc | ||
yum -y install gcc-c++ | ||
``` | ||
|
||
### 3.4 安装yum工具 | ||
|
||
在命令行执行如下命令安装yum工具。 | ||
|
||
```bash | ||
yum install -y yum-utils device-mapper-persistent-data lvm2 --skip-broken | ||
``` | ||
|
||
### 3.5 设置Docker镜像仓库 | ||
|
||
这里,我将Docker的镜像仓库设置为阿里镜像源,执行如下命令即可。 | ||
|
||
```bash | ||
yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo | ||
``` | ||
|
||
执行如下命令将docker-ce.repo镜像仓库配置文件中的镜像源修改成阿里镜像源。 | ||
|
||
```bash | ||
sed -i 's/download.docker.com/mirrors.aliyun.com\/docker-ce/g' /etc/yum.repos.d/docker-ce.repo | ||
``` | ||
|
||
### 3.6 更新yum包软件索引 | ||
|
||
更新yum包软件索引后,执行yum命令安装软件会快一些,在命令行执行如下命令更新yum包软件索引。 | ||
|
||
```bash | ||
yum makecache fast | ||
``` | ||
|
||
### 3.7 安装Docker | ||
|
||
在命令行执行如下命令安装Docker。 | ||
|
||
```bash | ||
yum -y install docker-ce docker-ce-cli containerd.io | ||
``` | ||
|
||
### 3.8 启动Docker | ||
|
||
在命令行执行如下命令启动Docker。 | ||
|
||
```bash | ||
systemctl start docker | ||
``` | ||
|
||
### 3.9 设置Docker开机自启动 | ||
|
||
在命令行执行如下命令设置Docker开机自启动。 | ||
|
||
```bash | ||
systemctl enable docker | ||
``` | ||
|
||
### 3.10 查看Docker版本 | ||
|
||
在命令行输入如下命令查看Docker版本。 | ||
|
||
```bash | ||
docker version | ||
``` | ||
|
||
输出的结果信息如下所示。 | ||
|
||
```bash | ||
Client: Docker Engine - Community | ||
Version: 23.0.6 | ||
API version: 1.42 | ||
Go version: go1.19.9 | ||
Git commit: ef23cbc | ||
Built: Fri May 5 21:21:29 2023 | ||
OS/Arch: linux/amd64 | ||
Context: default | ||
|
||
Server: Docker Engine - Community | ||
Engine: | ||
Version: 23.0.6 | ||
API version: 1.42 (minimum version 1.12) | ||
Go version: go1.19.9 | ||
Git commit: 9dbdbd4 | ||
Built: Fri May 5 21:20:38 2023 | ||
OS/Arch: linux/amd64 | ||
Experimental: false | ||
containerd: | ||
Version: 1.6.21 | ||
GitCommit: 3dce8eb055cbb6872793272b4f20ed16117344f8 | ||
runc: | ||
Version: 1.1.7 | ||
GitCommit: v1.1.7-0-g860f061 | ||
docker-init: | ||
Version: 0.19.0 | ||
GitCommit: de40ad0 | ||
``` | ||
|
||
### 3.11 Docker常用命令 | ||
|
||
这里,给大家列举一些常用的Docker命令,如下所示。 | ||
|
||
```bash | ||
systemctl daemon-reload //重载系统服务 | ||
systemctl list-unit-files --type service //查看全部服务命令 | ||
systemctl status docker // 查看docker服务状态 | ||
systemctl enable docker //设置docker开机自启动 | ||
systemctl disable docker // 关闭docker开机启动 | ||
systemctl start docker // 启动docker服务 | ||
systemctl stop docker // 停止docker服务 | ||
systemctl restart docker // 重启docker服务 | ||
``` | ||
|
||
## 四、安装docker-compose环境 | ||
|
||
安装docker-compose环境相对就比较简单了,在命令行执行如下命令下载并安装docker-compose。 | ||
|
||
```bash | ||
curl -SL https://github.com/docker/compose/releases/download/v2.17.3/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose | ||
``` | ||
|
||
下载并安装成功后,使用如下命令创建docker-compose软链接。 | ||
|
||
```bash | ||
ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose | ||
``` | ||
|
||
随后查看docker-compose版本,如下所示。 | ||
|
||
```bash | ||
[root@binghe]# docker-compose version | ||
Docker Compose version v2.17.3 | ||
``` | ||
|
||
可以看到,安装的docker-compose版本为2.17.3,说明docker-compose安装成功。 | ||
|
||
有些小伙伴由于网络问题,可能下载docker-compose会失败,这里冰河将其放到了专栏对应的源码工程的`environment/docker-compose`目录下,如图1-1。 | ||
|
||
<div align="center"> | ||
<img src="https://binghe.gitcode.host/images/project/gateway/2024-08-06-001.png?raw=true" width="50%"> | ||
<br/> | ||
</div> | ||
|
||
## 五、一键安装依赖环境 | ||
|
||
高性能Polaris网关在设计上,不仅会运行在服务器本身上,还会运行在K8S集群上。所以,我们在Docker环境中安装一些基础软件和中间件,比如MySQL、Redis、Sentinel、Nacos、prometheus、grafana、ElasticSearch、Logstash、Kinaba等等,如果这些环境都需要大家一个个手动安装的话,既费时又费力,安装过程中可能还会出现各种各样的错误。所以,这里,冰河基于docker-compose提供开箱即用的一件部署配置,安装好docker-compose后,只需要运行一个命令就可以一键安装所需要的各种基础服务和中间件。 | ||
|
||
这些基于docker-compose安装基础服务和中间件的配置文件位于项目的`/environment`目录下,具体说明如图1-2所示。 | ||
|
||
## 查看完整文章 | ||
|
||
加入[冰河技术](https://public.zsxq.com/groups/48848484411888.html)知识星球,解锁完整技术文章、小册、视频与完整代码 |