1.配置中心部署
1.1运行数据库创建脚本创建数据库
1.2.修改配置脚本script/build.bat,修改内容主要是配置数据库连接,运行脚本,无报错后查看target目录下配置文件数据库连接是否修改成功
注意:避免手工修改每个项目配置文件,防止出错
@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="666666"
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="666666"
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"
1.3.ConfigServiceApplication确认下是否配置为@EnableEurekaClient
1.4.启动顺序
一定要先启动 configserver, 然后是 adminserver, 然后是 portal
打开注册中心,检查服务有没有注册成功
http://localhost:8080/
1.5.启动apollo
localhost:8070
登录验证
apollo默认登录账号密码:
apollo/admin
2.apollo客户端整合
2.配置客户端
app:
id: springboot-apollo
apollo:
bootstrap:
enabled: true
eagerLoad:
enabled: true
# will inject 'application' and 'TEST1.apollo' namespaces in bootstrap phase
namespaces: application
meta: http://127.0.0.1:8080
logging:
level:
com:
gf:
controller: debug
timeout: 200
batch: 100
@RestController
public class DemoController {
@Value("${timeout}")
private String timeout;
@GetMapping("/test")
public String test(){
return "111"+timeout;
}
}
官方链接:
https://github.com/ctripcorp/apollo