spring cloud 阿波羅 apollo 本地開(kāi)發(fā)環(huán)境搭建過(guò)程
開(kāi)源配置中心 - Apollo
Apollo(阿波羅)是攜程框架部門研發(fā)的配置管理平臺(tái),能夠集中化管理應(yīng)用不同環(huán)境、不同集群的配置,配置修改后能夠?qū)崟r(shí)推送到應(yīng)用端,并且具備規(guī)范的權(quán)限、流程治理等特性。服務(wù)端基于Spring Boot和Spring Cloud開(kāi)發(fā),打包后可以直接運(yùn)行,不需要額外安裝Tomcat等應(yīng)用容器。
檢出代碼
可以fork下然后本地使用idea打開(kāi)
數(shù)據(jù)庫(kù)腳本
執(zhí)行以下腳本創(chuàng)建ApolloConifgDB、ApolloPortalDB
- apollo.scripts.sql.apolloconfigdb.sql
- apollo.scripts.sql.apolloportaldb.sql
啟動(dòng)configservice adminservice
Main class配置
com.ctrip.framework.apollo.assembly.ApolloApplication
VM opions
-Dapollo_profile=github -Dspring.datasource.url=jdbc:mysql://localhost:3306/ApolloConfigDB?characterEncoding=utf8 -Dspring.datasource.username=root -Dspring.datasource.password= Program arguments --configservice --adminservice
啟動(dòng)完后,打開(kāi) http://localhost:8080可以看到apollo-configservice和apollo-adminservice都已經(jīng)啟動(dòng)完成并注冊(cè)到Eureka
啟動(dòng)Apollo-Portal
Main class配置
com.ctrip.framework.apollo.portal.PortalApplication -Dapollo_profile=github,auth -Ddev_meta=http://localhost:8080/ -Dserver.port=8070 -Dspring.datasource.url=jdbc:mysql://localhost:3306/ApolloPortalDB?characterEncoding=utf8 -Dspring.datasource.username=root -Dspring.datasource.password=
如果啟用了auth profile的話,默認(rèn)的用戶名是apollo,密碼是admin
應(yīng)用在SIT、UAT、生產(chǎn)環(huán)境機(jī)器上
1.新增目錄/opt/data/目錄,且有可讀寫權(quán)限;
2.新增文件:/opt/settings/server.properties 且加入配置:
env=DEV sit: env=FAT uat: env=UAT 生產(chǎn):env=PRO
客戶端例子
@Component 設(shè)置組件名稱 @RefreshScope 指定配置改變可以刷新 @ConfigurationProperties(prefix = "redis.cache") @Component("sampleRedisConfig") @RefreshScope public class SampleRedisConfig { private static final Logger logger = LoggerFactory.getLogger(SampleRedisConfig.class); private int expireSeconds; private String clusterNodes; private int commandTimeout; private Map<String, String> someMap = Maps.newLinkedHashMap(); private List<String> someList = Lists.newLinkedList(); @PostConstruct private void initialize() { logger.info( "SampleRedisConfig initialized - expireSeconds: {}, clusterNodes: {}, commandTimeout: {}, someMap: {}, someList: {}", expireSeconds, clusterNodes, commandTimeout, someMap, someList); } public void setExpireSeconds(int expireSeconds) { this.expireSeconds = expireSeconds; } public void setClusterNodes(String clusterNodes) { this.clusterNodes = clusterNodes; } public void setCommandTimeout(int commandTimeout) { this.commandTimeout = commandTimeout; } public Map<String, String> getSomeMap() { return someMap; } public List<String> getSomeList() { return someList; } @Override public String toString() { return String.format( "[SampleRedisConfig] expireSeconds: %d, clusterNodes: %s, commandTimeout: %d, someMap: %s, someList: %s", expireSeconds, clusterNodes, commandTimeout, someMap, someList); } }
設(shè)置監(jiān)聽(tīng)
@Component public class SpringBootApolloRefreshConfig { private static final Logger logger = LoggerFactory.getLogger(SpringBootApolloRefreshConfig.class); @Autowired private ApolloRefreshConfig apolloRefreshConfig; @Autowired private SampleRedisConfig sampleRedisConfig; @Autowired private RefreshScope refreshScope; @ApolloConfigChangeListener public void onChange(ConfigChangeEvent changeEvent) { logger.info("before refresh {}", sampleRedisConfig.toString()); refreshScope.refresh("sampleRedisConfig"); logger.info("after refresh {}", sampleRedisConfig.toString()); } }
總結(jié)
以上所述是小編給大家介紹的spring cloud 阿波羅 apollo 本地開(kāi)發(fā)環(huán)境搭建過(guò)程,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
相關(guān)文章
Gradle修改本地倉(cāng)庫(kù)的位置方法實(shí)現(xiàn)
這篇文章主要介紹了Gradle修改本地倉(cāng)庫(kù)的位置方法實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-07-07利用ssh實(shí)現(xiàn)服務(wù)器文件上傳下載
這篇文章主要為大家詳細(xì)介紹了如何利用ssh實(shí)現(xiàn)服務(wù)器文件上傳下載,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-09-09java接收文件流+response.body()調(diào)用兩次問(wèn)題(分別接收文件和對(duì)象)
這篇文章主要介紹了java接收文件流+response.body()調(diào)用兩次問(wèn)題(分別接收文件和對(duì)象),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-06-06Linux下啟動(dòng)jar包的幾種常見(jiàn)方式
最近在linux上發(fā)布了一個(gè)SpringBoot項(xiàng)目,研究了一下jar包在Linux上的集中啟動(dòng)方式,這篇文章主要給大家介紹了Linux下啟動(dòng)jar包的幾種常見(jiàn)方式,需要的朋友可以參考下2023-07-07Java編寫實(shí)現(xiàn)坦克大戰(zhàn)小游戲
這篇文章主要為大家詳細(xì)介紹了Java編寫實(shí)現(xiàn)坦克大戰(zhàn)小游戲,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-01-01java實(shí)現(xiàn)客戶信息管理系統(tǒng)
這篇文章主要為大家詳細(xì)介紹了java實(shí)現(xiàn)客戶信息管理系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-02-02