攜程Apollo(阿波羅)安裝部署以及java整合實(shí)現(xiàn)
服務(wù)器部署
可以按照apollo wiki 進(jìn)行部署
https://github.com/ctripcorp/apollo/wiki/Quick-Start
安裝 Java 環(huán)境
java
創(chuàng)建數(shù)據(jù)庫(kù)
Apollo服務(wù)端共需要兩個(gè)數(shù)據(jù)庫(kù):ApolloPortalDB和ApolloConfigDB,我們把數(shù)據(jù)庫(kù)、表的創(chuàng)建和樣例數(shù)據(jù)都分別準(zhǔn)備了sql文件,只需要導(dǎo)入數(shù)據(jù)庫(kù)即可。
執(zhí)行兩個(gè)sql文件
sql/apolloportaldb.sql
sql/apolloconfigdb.sql
會(huì)創(chuàng)建兩個(gè)數(shù)據(jù)庫(kù)
下載安裝包
https://github.com/nobodyiam/apollo-build-scripts
服務(wù)器部署
將快速部署包apollo-quick-start放進(jìn)服務(wù)器
解壓文件
服務(wù)器配置
Apollo服務(wù)端需要知道如何連接到你前面創(chuàng)建的數(shù)據(jù)庫(kù),所以需要編輯demo.sh,修改ApolloPortalDB和ApolloConfigDB相關(guān)的數(shù)據(jù)庫(kù)連接串信息。
#apollo config db info apollo_config_db_url=jdbc:mysql://localhost:3306/ApolloConfigDB?characterEncoding=utf8 apollo_config_db_username=用戶名 apollo_config_db_password=密碼(如果沒(méi)有密碼,留空即可) # apollo portal db info apollo_portal_db_url=jdbc:mysql://localhost:3306/ApolloPortalDB?characterEncoding=utf8 apollo_portal_db_username=用戶名 apollo_portal_db_password=密碼(如果沒(méi)有密碼,留空即可)
修改服務(wù)器端口地址信息
meta server url
config_server_url=http://10.168.16.125:8080 admin_server_url=http://10.168.16.125:8090 portal_url=http://10.168.16.125:8070
如果部署在linux服務(wù)器上需要將地址改為服務(wù)器IP地址
注意:不要修改demo.sh的其它部分
確保端口未被占用
Quick Start腳本會(huì)在本地啟動(dòng)3個(gè)服務(wù),分別使用8070, 8080, 8090端口,請(qǐng)確保這3個(gè)端口當(dāng)前沒(méi)有被使用。
例如,在Linux/Mac下,可以通過(guò)如下命令檢查:
lsof -i:8080
執(zhí)行啟動(dòng)腳本
./demo.sh start
當(dāng)看到如下輸出后,就說(shuō)明啟動(dòng)成功了!
==== starting service ==== Service logging file is ./service/apollo-service.log Started [10768] Waiting for config service startup....... Config service started. You may visit http://localhost:8080 for service status now! Waiting for admin service startup.... Admin service started ==== starting portal ==== Portal logging file is ./portal/apollo-portal.log Started [10846] Waiting for portal startup...... Portal started. You can visit http://localhost:8070 now!
使用Apollo配置中心
訪問(wèn) 服務(wù)器的IP:8070 可以進(jìn)行訪問(wèn)
例如 :http://10.168.16.125:8070
默認(rèn) 用戶名密碼是 apollo admin
登陸后如下界面
可以創(chuàng)建自己的項(xiàng)目
添加namespace
namespace 相當(dāng)于配置文件名稱
在namespace中添加屬性,可以以文本形式添加
可以自己研究琢磨下
java服務(wù)整合
pom整合
官方提供的maven
<dependency> <groupId>com.ctrip.framework.apollo</groupId> <artifactId>apollo-client</artifactId> <version>0.9.1</version> </dependency>
發(fā)現(xiàn)拉不下來(lái)jar包
解決方案
下載源代碼
https://github.com/ctripcorp/apollo.git
編譯其中的 apollo-client 包并安裝到本地
引入編譯后的jar包即可
<dependency> <groupId>com.ctrip.framework.apollo</groupId> <artifactId>apollo-client</artifactId> <version>0.10.0-SNAPSHOT</version> </dependency>
現(xiàn)有應(yīng)用接入
在應(yīng)用接入Apollo之后,這些配置是可以非常方便的遷移到Apollo的,具體步驟如下:
在Apollo為應(yīng)用新建項(xiàng)目
在應(yīng)用中配置好META-INF/app.properties
把原先配置(必須是properties格式)復(fù)制一下,然后通過(guò)Apollo提供的文本編輯模式全部粘帖到應(yīng)用的application namespace,發(fā)布配置
如果原來(lái)是其它格式,如yml,請(qǐng)先轉(zhuǎn)成properties格式
把原先的配置文件如bootstrap.properties, application.properties從項(xiàng)目中刪除
app.properties 內(nèi)容是創(chuàng)建項(xiàng)目的APPID(應(yīng)用ID)如前面創(chuàng)建的12345
# test app.id=12345
并在resources 下加入apollo-env.properties 各環(huán)境的服務(wù)器地址
local.meta=http://10.168.16.125:8080 dev.meta=http://10.168.16.125:8080 fat.meta=${fat_meta} uat.meta=${uat_meta} lpt.meta=${lpt_meta} pro.meta=${pro_meta}
修改環(huán)境
修改/opt/settings/server.properties(Mac/Linux)或C:\opt\settings\server.properties(Windows)文件,設(shè)置env為DEV:
env=DEV
Spring 整合
apollo啟動(dòng)配置
<apollo:config/>
apollo加載namespace配置
<apollo:config namespaces="dubbo" order="1"/>
####官方配置如下
Apollo也支持和Spring整合(Spring 3.1.1+),只需要做一些簡(jiǎn)單的配置就可以了。
Apollo目前既支持比較傳統(tǒng)的基于XML的配置,也支持目前比較流行的基于Java(推薦)的配置。
需要注意的是,如果之前有使用org.springframework.beans.factory.config.PropertyPlaceholderConfigurer的,請(qǐng)?zhí)鎿Q成org.springframework.context.support.PropertySourcesPlaceholderConfigurer。Spring 3.1以后就不建議使用PropertyPlaceholderConfigurer了,要改用PropertySourcesPlaceholderConfigurer。
基于XML的配置
注:需要把a(bǔ)pollo相關(guān)的xml namespace加到配置文件頭上,不然會(huì)報(bào)xml語(yǔ)法錯(cuò)誤。
1.注入默認(rèn)namespace的配置到Spring中
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:apollo="http://www.ctrip.com/schema/apollo" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.ctrip.com/schema/apollo http://www.ctrip.com/schema/apollo.xsd"> <!-- 這個(gè)是最簡(jiǎn)單的配置形式,一般應(yīng)用用這種形式就可以了,用來(lái)指示Apollo注入application namespace的配置到Spring環(huán)境中 --> <apollo:config/> <bean class="com.ctrip.framework.apollo.spring.TestXmlBean"> <property name="timeout" value="${timeout:100}"/> <property name="batch" value="${batch:200}"/> </bean> </beans>
2.注入多個(gè)namespace的配置到Spring中
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:apollo="http://www.ctrip.com/schema/apollo" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.ctrip.com/schema/apollo http://www.ctrip.com/schema/apollo.xsd"> <!-- 這個(gè)是最簡(jiǎn)單的配置形式,一般應(yīng)用用這種形式就可以了,用來(lái)指示Apollo注入application namespace的配置到Spring環(huán)境中 --> <apollo:config/> <!-- 這個(gè)是稍微復(fù)雜一些的配置形式,指示Apollo注入FX.apollo和FX.soa namespace的配置到Spring環(huán)境中 --> <apollo:config namespaces="FX.apollo,FX.soa"/> <bean class="com.ctrip.framework.apollo.spring.TestXmlBean"> <property name="timeout" value="${timeout:100}"/> <property name="batch" value="${batch:200}"/> </bean> </beans>
dubbo服務(wù)整合
<apollo:config/> <apollo:config namespaces="dubbo" order="1"/> <!-- 公共信息,也可以用dubbo.properties配置 --> <dubbo:application name="${dubbo.application.name}" /> <!-- 需要強(qiáng)制指定地址,配置文件默認(rèn)可以不配置 --> <dubbo:registry address="${dubbo.registry.address}"/> <bean id="xxxService" class="com.xxx.cache.service.impl.RedisServiceImpl"/> <dubbo:service interface="com.xxx.xxx.service.RedisService" ref="redisService" version="${dubbo.version}"/>
dubbo 默認(rèn)沒(méi)有不需要配置,但使用apollo后沒(méi)有自動(dòng)注入dubbo注冊(cè)地址,需要手動(dòng)聲明,原因待定
<dubbo:registry address="${dubbo.registry.address}"/>
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
解決mybatis用Map返回的字段全變大寫的問(wèn)題
這篇文章主要介紹了解決mybatis用Map返回的字段全變大寫的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-12-12Maven Plugin的@Mojo和@Execute的具體使用
本文主要介紹了Maven Plugin的@Mojo和@Execute的具體使用,文中通過(guò)示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-09-09Java Mybatis框架Dao層的實(shí)現(xiàn)與映射文件以及核心配置文件詳解分析
MyBatis 是一款優(yōu)秀的持久層框架,它支持自定義 SQL、存儲(chǔ)過(guò)程以及高級(jí)映射。MyBatis 免除了幾乎所有的 JDBC 代碼以及設(shè)置參數(shù)和獲取結(jié)果集的工作。MyBatis 可以通過(guò)簡(jiǎn)單的 XML 或注解來(lái)配置和映射原始類型、接口和 Java POJO為數(shù)據(jù)庫(kù)中的記錄2021-10-10java 中mongodb的各種操作查詢的實(shí)例詳解
這篇文章主要介紹了java 中mongodb的各種操作查詢的實(shí)例詳解的相關(guān)資料,希望通過(guò)本文能幫助到大家,需要的朋友可以參考下2017-09-09HttpUtils 發(fā)送http請(qǐng)求工具類(實(shí)例講解)
下面小編就為大家?guī)?lái)一篇HttpUtils 發(fā)送http請(qǐng)求工具類(實(shí)例講解)。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-07-07Java整數(shù)和字符串相互轉(zhuǎn)化實(shí)例詳解
這篇文章主要介紹了Java整數(shù)和字符串相互轉(zhuǎn)化實(shí)例詳解,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-02-02