服务架构图
准备
下载发行版本
- 找到github官网
- 下载adminserver、configserver、portal的zip包
- 将3个压缩包中的jar包上传到Linux服务器上,服务器目录结构
SQL数据库创建
ApolloPortalDB需要一个库,ApolloConfigDB为DEV环境,ApolloConfigDB_PROD为PRO环境
SQL脚本可从github上下载:
https://github.com/apolloconfig/apollo/tree/master/scripts/sql
配置Eureka的地址
配置ServerConfig
表中的Eureka地址
ApolloConfigDB配置Eureka的地址
ApolloConfigDB_PROD配置Eureka的地址
ApolloPortalDB配置pro环境
在ApolloPrortalDB的ServerConfig表中的apollo.portal.envs增加 pro环境以英文 “,” 分割两个环境的配置
Portal环境配置
docker-compose.yaml配置
这个配置是用docker-compose运行jar包的方式启动的服务,jar包启动时配置链接的数据库
version: "3.2" #版本号
services:
ap_portal:
image: java:8
ports:
- "8070:8070"
restart: "always"
container_name: ap_portal #容器名称
environment:
- TZ=Asia/Shanghai #时区设置
- JAVA_OPTS=-Xmx256m -Xms256m
- server.port=8070
- spring.datasource.url=jdbc:mysql://192.168.0.132:3306/ApolloPortalDB?characterEncoding=utf8
- spring.datasource.username=root
- spring.datasource.password=admin
- dev_meta=http://192.168.0.132:8080/
- pro_meta=http://192.168.0.132:8081/
volumes:
- /usr/local/docker/apollo/service/apollo-portal.jar:/apollo-portal.jar
entrypoint: java -jar apollo-portal.jar
links:
- ap_config_dev
- ap_admin_dev
- ap_config_prod
- ap_admin_prod
ap_config_dev:
image: java:8
ports:
- "8080:8080"
restart: "always"
container_name: ap_config_dev #容器名称
environment:
- TZ=Asia/Shanghai #时区设置
- JAVA_OPTS=-Xmx256m -Xms256m
- server.port=8080
- spring.datasource.url=jdbc:mysql://192.168.0.132:3306/ApolloConfigDB?characterEncoding=utf8
- spring.datasource.username=root
- spring.datasource.password=admin
- eureka.instance.ip-address=192.168.0.132
volumes:
- /usr/local/docker/apollo/service/apollo-configservice.jar:/apollo-configservice.jar
entrypoint: java -jar apollo-configservice.jar
ap_admin_dev:
image: java:8
ports:
- "8090:8090"
restart: "always"
container_name: ap_admin_dev #容器名称
environment:
- TZ=Asia/Shanghai #时区设置
- JAVA_OPTS=-Xmx256m -Xms256m
- server.port=8090
- spring.datasource.url=jdbc:mysql://192.168.0.132:3306/ApolloConfigDB?characterEncoding=utf8
- spring.datasource.username=root
- spring.datasource.password=admin
- eureka.instance.ip-address=192.168.0.132
volumes:
- /usr/local/docker/apollo/service/apollo-adminservice.jar:/apollo-adminservice.jar
entrypoint: java -jar apollo-adminservice.jar
ap_config_prod:
image: java:8
ports:
- "8081:8081"
restart: "always"
container_name: ap_config_prod #容器名称
environment:
- TZ=Asia/Shanghai #时区设置
- JAVA_OPTS=-Xmx256m -Xms256m
- server.port=8081
- spring.datasource.url=jdbc:mysql://192.168.0.132:3306/ApolloConfigDB_PROD?characterEncoding=utf8
- spring.datasource.username=root
- spring.datasource.password=admin
- eureka.instance.ip-address=192.168.0.132
volumes:
- /usr/local/docker/apollo/service/apollo-configservice.jar:/apollo-configservice.jar
entrypoint: java -jar apollo-configservice.jar
ap_admin_prod:
image: java:8
ports:
- "8091:8091"
restart: "always"
container_name: ap_admin_prod #容器名称
environment:
- TZ=Asia/Shanghai #时区设置
- JAVA_OPTS=-Xmx256m -Xms256m
- server.port=8091
- spring.datasource.url=jdbc:mysql://192.168.0.132:3306/ApolloConfigDB_PROD?characterEncoding=utf8
- spring.datasource.username=root
- spring.datasource.password=admin
- eureka.instance.ip-address=192.168.0.132
volumes:
- /usr/local/docker/apollo/config_service_prod/apollo-adminservice.jar:/apollo-adminservice.jar
entrypoint: java -jar apollo-adminservice.jar
注意
- 通过 --eureka.instance.ip-address=192.168.0.132 指定宿主机的ip,否则注入到Eureka中的是容器的内网ip,
内网ip是不能通过ip访问到的,这个地方需要特别注意。
- 通过–eureka.instance.instance-id=192.168.0.132:8080 --eureka.instance.hostname=192.168.0.132 --eureka.instance.ip-address=192.168.0.132,配置instance-id、hostname会在eureka中显示ip+端口号的服务
启动时间较长,需要耐心等待
docker-compose up -d 启动服务
服务测试
服务器地址的8070端口访问服务
登陆的默认账号: apollo
密码: admin
点击应用进去就可以看到多了一个PRO环境的配置
创作不易欢迎点赞打赏