【记录】springcloud配置中心之apollo使用

一 介绍

阿波罗是首位登录月球的人类(还是飞船来着),迈出了人类的一小步,个人的一大步。这与软件没什么关系。

springboot可使用application.properties或yml进行自定义配置。在springcloud中,若干微服务各自都要写配置显得冗余,因此使用配置中心统一管理,各个微服务拉取配置使用。

springcloud核心组件中提供的是configservice,之后再看,这次先看携程开fa的开源配置中心阿波罗。

apollo号称各方面都强于configservice,你说是啥就是啥吧

二 架构

阿波罗主要有4个角色,控制台portal,管理服务admin,配置服务(内置了元数据服务即eureka)config,客户端client。控制台只需启动一个;管理、配置在每个环境(每个集群的每个环境)都要启动一组;客户端即需要拉取配置的微服务。

控制台默认使用8070端口(与分布式事务lcn的默认监听端口冲突,为什么你们都喜欢用8080附件的端口?),管理默认使用8090端口,配置(和内置注册中心)默认使用8080端口。

三 搭建(这里使用自行编译方式)

1 从git下载项目

apollo git 下载地址

2 初始化数据库,执行/scripts/docker-quick-start/sql下的apolloconfigdb.sql和apolloportaldb.sql

其中portal只需要一个,config需要在部署的各个环境都配一个,并在下一步修改serviceconfig表的eureka地址为挂靠的config地址

3 若在windows系统编译,修改运行/scripts/build.bat       若在linux编译,修改运行/scripts/build.sh

修改内容:

@echo off

rem apollo config db info
set apollo_config_db_url="jdbc:mysql://localhost:3306/ApolloConfigDB?characterEncoding=utf8"
set apollo_config_db_username="root"
set apollo_config_db_password="123456"

rem apollo portal db info
set apollo_portal_db_url="jdbc:mysql://localhost:3306/ApolloPortalDB?characterEncoding=utf8"
set apollo_portal_db_username="root"
set apollo_portal_db_password="123456"

rem meta server url, different environments should have different meta server addresses
set dev_meta="http://localhost:8080"
set fat_meta="http://localhost:8080"
set uat_meta="http://localhost:8080"
set pro_meta="http://localhost:8080"

set META_SERVERS_OPTS=-Ddev_meta=%dev_meta% -Dfat_meta=%fat_meta% -Duat_meta=%uat_meta% -Dpro_meta=%pro_meta%

rem =============== Please do not modify the following content =============== 
rem go to script directory
cd "%~dp0"

cd ..

rem package config-service and admin-service
echo "==== starting to build config-service and admin-service ===="

call mvn clean package -DskipTests -pl apollo-configservice,apollo-adminservice -am -Dapollo_profile=github -Dspring_datasource_url=%apollo_config_db_url% -Dspring_datasource_username=%apollo_config_db_username% -Dspring_datasource_password=%apollo_config_db_password%

echo "==== building config-service and admin-service finished ===="

echo "==== starting to build portal ===="

call mvn clean package -DskipTests -pl apollo-portal -am -Dapollo_profile=github,auth -Dspring_datasource_url=%apollo_portal_db_url% -Dspring_datasource_username=%apollo_portal_db_username% -Dspring_datasource_password=%apollo_portal_db_password% %META_SERVERS_OPTS%

echo "==== building portal finished ===="

pause

调整其中的数据库连接、调整各个环境的meta地址,即原数据服务地址,即config服务地址

修改各个环境apolloconfigdb库serviceconfig表的eureka地址为挂靠的config服务地址

其他不用动,若执行时编译错误检查是不是误删了什么,包括git项目最外层的文件。

4 编译完成后在admin、config、portal下的target找到jar包(或在pom中配置war生成war包),java -jar 名字 即可启动。

四 界面

1 默认账户为 apollo/admin

2 首页的项目指整个项目,项目下包含集群、命名空间。项目的appid将用于微服务查找的条件。

3 每个命名空间就是一套配置,微服务根据命名空间确定配置组,可逗号分隔关联多个命名空间。

4 命名空间的公有私有是指只能用于这个项目还是其它项目也可见,公有的命名空间可在其他项目中创建关联命名空间来使用。

5 微服务的配置:

#项目appid
app.id=TEST
#config及元数据服务地址
apollo.meta=http://localhost:8080
#集群
apollo.cluster=default
#也使用默认实例
apollo.bootstrap.enabled=true
#指定要使用的命名空间,可用逗号分隔使用多个
apollo.bootstrap.namespaces=cust

微服务入口增加注解 @EnableApolloConfig

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值