# spring-cloud-learning **Repository Path**: alexpycn/spring-cloud-learning ## Basic Information - **Project Name**: spring-cloud-learning - **Description**: No description available - **Primary Language**: Java - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2022-03-08 - **Last Updated**: 2022-08-15 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Spring Cloud Learning ### 开发环境 - Mac 12.2.x - IDEA 2021.3.x - MySQL 8.x - RabbitMQ 3.7.x - Redis 5.x - Docker 20.x - PostMan 9.x - Chrome 96.x - SpringCloud Hoxton.SR12 - SpringBoot 2.3.12.RELEASE ### 微服务组件 | Name | Version | Description | |:-----------|:--------|:-------------| | Eureka | 1.10.14 | 注册中心 | | Config | 2.2.8 | 配置中心 | | Zuul | 1.3.1 | 网关 | | Gateway | 2.2.9 | 网关 | | Ribbon | 2.3.0 | 负载均衡 | | OpenFeign | 3.8.0 | 远程调用 | | hystrix | 2.2.9 | 熔断降级 | --- ### 端口分配 ```text MySQL 3306 RabbitMQ 5672 Redis 6379 Zuul 8081 172.18.0.81 Gateway 8081 172.18.0.81 Job 8082 172.18.0.82 Eureka 8085 172.18.0.85 Config 8888 172.18.0.88 serviceA 10010 172.18.0.10 serviceB 10020 172.18.0.20 serviceC 10030 172.18.0.30 ``` --- ### 数据库初始化 ```text -- 创建数据库 CREATE DATABASE IF NOT EXISTS `cooboot` default character set utf8mb4 collate utf8mb4_unicode_ci; -- 创建用户 CREATE USER IF NOT EXISTS 'cooboot'@'%' IDENTIFIED BY '123456'; -- 授权 use mysql; GRANT ALL PRIVILEGES ON `cooboot`.* TO 'cooboot'@'%'; ``` --- ### 设置 hosts ```text vim /etc/hosts 本机IP eureka1 本机IP config1 本机IP server1 本机IP database1 本机IP redis1 本机IP rabbitmq1 本机IP job1 ``` --- ### Docker 新建自定义网络 - 支持自定义固定 IP (默认网络不支持) ```text docker network create --subnet=172.18.0.0/16 cooboot ``` - 网络列表 ```text docker network ls ``` - 删除网络 ```text docker network rm {ID} ``` --- ### 启动顺序 [Redis](run-redis.sh) [RabbitMQ](run-rabbitmq.sh) **Docker 启动除 Eureka Config 外的其他服务, 需要修改 bootstrap.yml -> sit** - 1 Eureka 注册中心 - 2 Config 配置中心 - 3 Zuul / Gateway 网关 - 4 ServiceA / ServiceB / ServiceC / ... 其他服务 ### Test ```text # 直接调用 server1:8085/hello server1:8888/hello server1:8081/hello server1:10010/hello server1:10020/hello server1:10030/hello # 网关调用 http://server1:28081/api/a/hello http://server1:28081/api/b/hello http://server1:28081/api/c/hello # 服务间调用 a -> b -> c http://server1:28081/api/a/a http://server1:28081/api/b/b http://server1:28081/api/c/c ```