文章目录
- 1、apollo
- 2、数据库准备
- 3、启动后会用到的几个地址
- 4、docker-compose运行 apollo
- 方式一:使用容器 hostName 作为网络媒介
- 方式二:使用端口映射+固定 ip 作为网络媒介
- 6、客户端
1、apollo
https://www.apolloconfig.com/#/zh/deployment/quick-start-docker
单机单环境
单机双环境
单机三环境
2、数据库准备
- 启动本地 mysql
- 初始化数据库
CREATE DATABASE ApolloConfigDB;
CREATE DATABASE ApolloPortalDB;
- 新增用户
userapollo/userapollo
CREATEUSER'userapollo'@'%' IDENTIFIED BY'userapollo';
GRANTALL PRIVILEGES ON ApolloConfigDB.*TO'userapollo'@'%';
GRANTALL PRIVILEGES ON ApolloPortalDB.*TO'userapollo'@'%';
FLUSH PRIVILEGES;
- 表结构&数据初始化
https://github.com/apolloconfig/apollo/tree/master/scripts/sql
3、启动后会用到的几个地址
-
http://127.0.0.1:8070/
Portal 登录地址,默认登录账户 apollo/admin -
http://127.0.0.1:8080/
Eureka 管理页面
-
http://127.0.0.1:8080/services/config
service-config 配置查询接口
未来客户端通过下面 url 获取配置信息的拉取 url,即 homepageUrl 字段
客户端访问 http://127.0.0.1:8080/services/config
[{"appName":"APOLLO-CONFIGSERVICE","instanceId":"config-service:apollo-configservice:8080","homepageUrl":"http://config-service:8080"}]
-
http://127.0.0.1:8070/system_info.html
Portal 登录页面,查看 config-service、admin-service 运行状态
-
http://127.0.0.1:8070/server_config_manage.html#/portal_db
配置 apollo.portal.meta.servers -
http://127.0.0.1:8070/server_config_manage.html#/config_db
配置 eureka.service.url
4、docker-compose运行 apollo
须知1:https://blog.csdn.net/bestcxx/article/details/140250249
须知 2: 在启动顺序上,首次启动可能会失败,原因是 admin-service 、portal 需要等待 config-service 完全启动之后才能启动,这里建议首次启动后,重启 admin-service 和 portal
docker-compose 首次启动后,可以借助 Docker Desktop 管理Docker 容器,来进行重启操作
方式一:使用容器 hostName 作为网络媒介
- 修改数据库配置
UPDATE `ApolloConfigDB`.`ServerConfig` SET `Value` = 'http://config-service:8080/eureka/' WHERE (`Id` = '1');
UPDATE `ApolloPortalDB`.`ServerConfig` SET `Value` = '{\"dev\":\"http://config-service:8081\"}' WHERE (`Id` = '8');
- 修改 宿主机 /etc/hosts 文件
127.0.0.1 config-service
- docker-compose.yml
version: '3.6'services:config-service:image: apolloconfig/apollo-configservicecontainer_name: apollo-config-servicehostname: config-serviceenvironment:- SPRING_DATASOURCE_URL=jdbc:mysql://host.docker.internal:3306/ApolloConfigDB?useSSL=false&characterEncoding=utf8- SPRING_DATASOURCE_USERNAME=userapollo- SPRING_DATASOURCE_PASSWORD=userapollo- JAVA_OPTS=-Deureka.instance.homePageUrl=http://config-service:8080ports:- 8080:8080 # 宿主机端口 : 容器端口networks:apollo-network:admin-service:image: apolloconfig/apollo-adminservicecontainer_name: apollo-admin-servicehostname: admin-serviceenvironment:- SPRING_DATASOURCE_URL=jdbc:mysql://host.docker.internal:3306/ApolloConfigDB?useSSL=false&characterEncoding=utf8- SPRING_DATASOURCE_USERNAME=userapollo- SPRING_DATASOURCE_PASSWORD=userapollo- CONFIGSERVICE_URL=http://config-service:8080- JAVA_OPTS=-Deureka.instance.homePageUrl=http://admin-service:8090ports:- 8090:8090depends_on:- config-servicenetworks:apollo-network:portal:image: apolloconfig/apollo-portalcontainer_name: apollo-portalhostname: portalenvironment:- SPRING_DATASOURCE_URL=jdbc:mysql://host.docker.internal:3306/ApolloPortalDB?useSSL=false&characterEncoding=utf8- SPRING_DATASOURCE_USERNAME=userapollo- SPRING_DATASOURCE_PASSWORD=userapollo- APOLLO_PORTAL_ENVS=dev- DEV_META=http://config-service:8080- JAVA_OPTS=-Deureka.instance.homePageUrl=http://portal:8070ports:- 8070:8070depends_on:- config-service- admin-servicenetworks:apollo-network:networks:apollo-network:#driver: bridge
方式二:使用端口映射+固定 ip 作为网络媒介
- 修改数据库配置
UPDATE `ApolloConfigDB`.`ServerConfig` SET `Value` = 'http://192.168.128.2:8080/eureka/' WHERE (`Id` = '1');
UPDATE `ApolloPortalDB`.`ServerConfig` SET `Value` = '{\"dev\":\"192.168.128.2:8080\"}' WHERE (`Id` = '8');
- docker-compose.yml
version: '3.6'services:config-service:image: apolloconfig/apollo-configservicecontainer_name: apollo-config-servicehostname: config-serviceenvironment:- SPRING_DATASOURCE_URL=jdbc:mysql://host.docker.internal:3306/ApolloConfigDB?useSSL=false&characterEncoding=utf8- SPRING_DATASOURCE_USERNAME=userapollo- SPRING_DATASOURCE_PASSWORD=userapollo- JAVA_OPTS=-Deureka.instance.homePageUrl=http://config-service:8080ports:- 8080:8080 # 宿主机端口 : 容器端口networks:apollo-network:ipv4_address: 192.168.128.2admin-service:image: apolloconfig/apollo-adminservicecontainer_name: apollo-admin-servicehostname: admin-serviceenvironment:- SPRING_DATASOURCE_URL=jdbc:mysql://host.docker.internal:3306/ApolloConfigDB?useSSL=false&characterEncoding=utf8- SPRING_DATASOURCE_USERNAME=userapollo- SPRING_DATASOURCE_PASSWORD=userapollo- CONFIGSERVICE_URL=http://192.168.128.2:8080- JAVA_OPTS=-Deureka.instance.homePageUrl=http://admin-service:8090ports:- 8090:8090depends_on:- config-servicenetworks:apollo-network:ipv4_address: 192.168.128.3portal:image: apolloconfig/apollo-portalcontainer_name: apollo-portalhostname: portalenvironment:- SPRING_DATASOURCE_URL=jdbc:mysql://host.docker.internal:3306/ApolloPortalDB?useSSL=false&characterEncoding=utf8- SPRING_DATASOURCE_USERNAME=userapollo- SPRING_DATASOURCE_PASSWORD=userapollo- APOLLO_PORTAL_ENVS=dev- DEV_META=http://192.168.128.2:8080- JAVA_OPTS=-Deureka.instance.homePageUrl=http://portal:8070ports:- 8070:8070depends_on:- config-service- admin-servicenetworks:apollo-network:ipv4_address: 192.168.128.4networks:apollo-network:driver: bridgeipam:config:- subnet: 192.168.128.0/24
6、客户端
{"apollo": {"AppId": "helloabp","Env": "dev","Cluster": "default","MetaServer": "http://localhost:8080","Namespaces": ["helloabp.web.json"]},"ClientId": "bestcxxLocal"
}