Docker Desktop搭建
安装完成之后使用docker下载镜像,报以下错误:
解决办法:
Docker Engine配置能访问的镜像地址:
{"builder": {"gc": {"defaultKeepStorage": "20GB","enabled": true}},"experimental": false,"registry-mirrors": ["https://docker.1panel.live","https://cr.console.aliyun.com","https://hub-mirror.c.163.com","https://docker.mirrors.ustc.edu.cn","https://mirror.ccs.tencentyun.com"]
}
Mysql部署
拉取镜像:
docker pull mysql:8.4
启动并运行:
docker run --name mysql-8.4 -p 3306:3306 -v D:/data/dockerData/mysql8/data:/var/lib/mysql -v D:/data/dockerData/mysql8/logs:/var/log/mysql -v D:/data/dockerData/mysql8/conf:/etc/mysql/conf.d -e MYSQL_ROOT_PASSWORD=123456 --restart=always -d mysql:8.4
中间件Apollo部署
拉取并运行镜像:
docker pull apolloconfig/apollo-configservice:latestdocker pull apolloconfig/apollo-adminservice:latestdocker pull apolloconfig/apollo-portal:latest
其中:
- apollo-adminservice:Admin Service提供配置的修改、发布等功能,服务对象是Apollo Portal(管理界面)
- apollo-configservice:Config Service提供配置的读取、推送等功能,服务对象是Apollo客户端
- apollo-portal:Portal通过域名访问Meta Server获取Admin Service服务列表(IP+Port),而后直接通过IP+Port访问服务,同时在Portal侧会做load balance、错误重试
docker run -p 8082:8080 -e SPRING_DATASOURCE_URL="jdbc:mysql://172.17.0.2:3306/Apolloconfigdb?characterEncoding=utf8" -e SPRING_DATASOURCE_USERNAME=root -e SPRING_DATASOURCE_PASSWORD=123456 -d -v D:/data/apollo/logs:/opt/logs --name apollo-configservice apolloconfig/apollo-configservicedocker run -p 8091:8090 -e SPRING_DATASOURCE_URL="jdbc:mysql://172.17.0.2:3306/Apolloconfigdb?characterEncoding=utf8" -e SPRING_DATASOURCE_USERNAME=root -e SPRING_DATASOURCE_PASSWORD=123456 -d -v D:/data/apollo/logs:/opt/logs --name apollo-adminservice apolloconfig/apollo-adminservicedocker run -p 8071:8070 -e SPRING_DATASOURCE_URL="jdbc:mysql://172.17.0.2:3306/Apolloportaldb?characterEncoding=utf8" -e SPRING_DATASOURCE_USERNAME=root -e SPRING_DATASOURCE_PASSWORD=123456 -e APOLLO_PORTAL_ENVS=pro -e PRO_META=http://172.17.0.1:8082 -d -v D:/data/apollo/logs:/opt/logs --name apollo-portal apolloconfig/apollo-portal
其中:
- 172.17.0.2:3306 为mysql容器IP和端口,如下图所示:
- 172.17.0.1:8082 为configservice容器IP地址和端口号,如下图所示:
导入Apollo SQL脚本
创建ApolloPortalDB 并导入如下sql:
https://github.com/ctripcorp/apollo/blob/master/scripts/db/migration/portaldb/V1.0.0__initialization.sql
创建ApolloConfigDBDev 并导入如下sql:
https://github.com/ctripcorp/apollo/blob/master/scripts/db/migration/configdb/V1.0.0__initialization.sql
需要我们改一下数据库的Eureka服务连接地址Url,需要连接上configservice的配置中心,不然启动会报错。在ApolloConfigDB数据库ServerConfig表的eureka.service.url的value的值进行修改:
配置Meta Servers地址,也就是configservice的连接地址,在ApolloPortalDB数据库的ServerConfig表的apollo.portal.meta.servers的value中进行配置。和上面的DEV_META一致:
使用Spring boot连接配置中心
1. 引入依赖:
<!--携程开源框架 配置中心--><dependency><groupId>com.ctrip.framework.apollo</groupId><artifactId>apollo-client</artifactId><version>2.2.0</version></dependency>
2. 配置文件 application.yml修改配置:
apollo:meta: http://127.0.0.1:8082 #configService地址bootstrap:enabled: true #springboot在启动阶段就会加载namespaces: applicationeagerLoad:enabled: true #将Apollo配置加载提到初始化日志系统之前
3. 在启动的时候,启动类需要加上@EnableApolloConfig注解开启配置中心
4. IDEA配置环境(指定config service地址):否则会报配置中心连接超时错误
WARN 12344 --- [ngPollService-1] c.c.f.a.i.RemoteConfigLongPollService : Long polling failed, will retry in 1 seconds. appId: spring-cloud-config-dev, cluster: default, namespaces: spring-cloud-management,
long polling url: http://172.17.0.3:8080/notifications/v2?cluster=default&appId=spring-cloud-config-dev&ip=192.168.1.108¬ifications=%5B%7B%22namespaceName%22%3A%22spring-cloud-management%22%2C%22notificationId%22%3A-1%7D%5D,
reason: Could not complete get operation [Cause: connect timed out]