微服务配置中心
https://github.com/apolloconfig/apollo-build-scripts
下载
执行sql创建两个数据库
4.运行
使用bash打开(安装git后会带)
1 |
./demo.sh start |
访问 http://localhost:8070/
登录
输入用户名apollo,密码admin
创建应用
新增配置
提交后
点击发布
1.添加引用
1 2 |
Microsoft.Extensions.Configuration Com.Ctrip.Framework.Apollo.Configuration |
2.创建webapi接口
Program.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Hosting; using Com.Ctrip.Framework.Apollo; using Microsoft.AspNetCore; namespace WebApi_Apollo { public class Program { public static void Main(string[] args) { CreateWebHostBuilder(args).Build().Run(); } public static IWebHostBuilder CreateWebHostBuilder(string[] args) => WebHost.CreateDefaultBuilder(args) .ConfigureAppConfiguration((hostingContext, builder) => { //默认的application Namespace builder.AddApollo(builder.Build().GetSection("apollo")).AddDefault(); }) .UseStartup<Startup>(); } } |
Controller.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
[ApiController] [Route("[controller]")] public class ValuesController:ControllerBase { IConfiguration _configuration; public ValuesController(IConfiguration configuration) { _configuration = configuration; } [HttpGet] public string test() { var v = _configuration.GetValue<string>("time"); return v; } } |
appsettings.json
多添加一项
1 2 3 4 |
"apollo": { "AppId": "MES1", //这是我们上面添加的Apollo里面的Appid "MetaServer": "http://127.0.0.1:8080" //Apollo配置服务器地址,注意这里是8080,不是admin的8070 } |
https://github.com/apolloconfig/apollo/releases
需要创建两个数据库 ApolloPortalDB
和ApolloConfigDB
https://github.com/apolloconfig/apollo/tree/master/scripts/sql
ApolloPortalDB只需要在生产环境部署一个即可,而ApolloConfigDB需要在每个环境部署一套(如:生产一套,测试一套)
ApolloPortalDB
ApolloConfigDB
apollo-configservice和apollo-adminservice
1 2 3 |
spring.datasource.url = jdbc:mysql://localhost:3306/ApolloConfigDB?useSSL=false&characterEncoding=utf8 spring.datasource.username = someuser spring.datasource.password = somepwd |
apollo-portal
1 2 3 |
spring.datasource.url = jdbc:mysql://localhost:3306/ApolloPortalDB?useSSL=false&characterEncoding=utf8 spring.datasource.username = someuser spring.datasource.password = somepwd |
4.安装git才能在windows上运行 .sh脚本
1 2 3 |
spring.datasource.url = jdbc:mysql://localhost:3306/ApolloPortalDB?useSSL=false&characterEncoding=utf8 spring.datasource.username = someuser spring.datasource.password = somepwd |
5
1 2 3 |
set global time_zone = '+8:00'; ##修改mysql全局时区为北京时间,即我们所在的东8区 set time_zone = '+8:00'; ##修改当前会话时区 flush privileges; #立即生效 |
启动apollo-configservice-1.9.2-github
1 |
java -Xms256m -Xmx256m -Dspring.datasource.url=jdbc:mysql://l92.xxx.xxx.xxx:3306/ApolloConfigDB?characterEncoding=utf8 -Dspring.datasource.username=xxx -Dspring.datasource.password=xxx -Dsever.port=8080 -jar apollo-configservice-1.9.2.jar |
启动apollo-adminservice-1.9.2-github
1 |
java -Xms256m -Xmx256m -Dspring.datasource.url=jdbc:mysql://192.xxx:3306/ApolloConfigDB?characterEncoding=utf8 -Dspring.datasource.username=xxx -Dspring.datasource.password=xxx -Dsever.port=8090 -jar apollo-adminservice-1.9.2.jar |
启动apollo-portal-1.9.2-github
1 |
java -Xms256m -Xmx256m -Dspring.datasource.url=jdbc:mysql://192.xxx:3306/ApolloPortalDB?characterEncoding=utf8 -Dspring.datasource.username=xxx -Dspring.datasource.password=xxx -Dsever.port=8070 -jar apollo-portal-1.9.2.jar |
访问
http://127.0.0.1:8070/
from:https://www.cnblogs.com/buchizaodian/p/15474559.html