安裝筆記:在CentOS上安裝Apollo(配置中心)


========安裝服務端
https://github.com/ctripcorp/apollo/wiki/%E5%88%86%E5%B8%83%E5%BC%8F%E9%83%A8%E7%BD%B2%E6%8C%87%E5%8D%97

從 https://github.com/ctripcorp/apollo/releases 下載最新的Source code(zip)、apollo-adminservice-x.x.x-github.zip、apollo-configservice-x.x.x-github.zip、apollo-portal-x.x.x-github.zip

====創建ApolloPortalDB
將源碼壓縮包中的 scripts/db/migration/portaldb/V1.0.0__initialization.sql 上傳到服務器
mysql -u root -p
source V1.0.0__initialization.sql
驗證: select `Id`, `Key`, `Value`, `Comment` from `ApolloPortalDB`.`ServerConfig` limit 1;

配置項統一存儲在ApolloPortalDB.ServerConfig表中
apollo.portal.envs - 可支持的環境列表,默認值是dev,生產環境改為pro

====創建ApolloConfigDB
將源碼壓縮包中的 scripts/db/migration/configdb/V1.0.0__initialization.sql 上傳到服務器
mysql -u root -p
source V1.0.0__initialization.sql
驗證: select `Id`, `Key`, `Value`, `Comment` from `ApolloConfigDB`.`ServerConfig` limit 1;

配置項統一存儲在ApolloConfigDB.ServerConfig表中
eureka.service.url - Eureka服務Url,改為IP地址

====安裝
將apollo-adminservice-x.x.x-github.zip、apollo-configservice-x.x.x-github.zip、apollo-portal-x.x.x-github.zip解壓縮(按目錄組織好:apollo/adminservice、apollo/configservice、apollo/portal)
配置數據庫連接信息: config/application-github.properties 注意數據庫名要改為小寫
上傳到服務器

====部署apollo-configservice
/sbin/iptables -I INPUT -p tcp --dport 10000 -j ACCEPT
service iptables save

vi apollo/configservice/scripts/startup.sh
SERVER_PORT=${SERVER_PORT:=10000}

vi apollo/portal/config/apollo-env.properties
local.meta=http://IP地址:10000
對應環境.meta=http://IP地址:10000

ApolloConfigDB.ServerConfig 表中的 eureka.service.url 中的端口改為 10000

運行 apollo/configservice/scripts 下的 startup.sh 啟動服務,shutdown.sh 停止服務
chmod oug+x apollo/configservice/scripts/startup.sh
chmod oug+x apollo/configservice/scripts/shutdown.sh
./apollo/configservice/scripts/startup.sh

====部署apollo-adminservice
/sbin/iptables -I INPUT -p tcp --dport 10001 -j ACCEPT
service iptables save

vi apollo/adminservice/scripts/startup.sh
SERVER_PORT=${SERVER_PORT:=10001}

chmod oug+x apollo/adminservice/scripts/startup.sh
chmod oug+x apollo/adminservice/scripts/shutdown.sh
./apollo/adminservice/scripts/startup.sh

====部署apollo-portal
/sbin/iptables -I INPUT -p tcp --dport 10002 -j ACCEPT
service iptables save

vi apollo/portal/scripts/startup.sh
SERVER_PORT=${SERVER_PORT:=10002}

chmod oug+x apollo/portal/scripts/startup.sh
chmod oug+x apollo/portal/scripts/shutdown.sh
./apollo/portal/scripts/startup.sh

訪問 http://IP地址:10002/,初始用戶名是 apollo,密碼是 admin,通過 管理員工具->用戶管理 修改密碼

========Java客戶端使用指南
https://github.com/ctripcorp/apollo/wiki/Java%E5%AE%A2%E6%88%B7%E7%AB%AF%E4%BD%BF%E7%94%A8%E6%8C%87%E5%8D%97

Apollo Meta Server: 通過server.properties配置文件
可以在server.properties配置文件中指定apollo.meta=http://config-service-url
對於Mac/Linux,文件位置為/opt/settings/server.properties
對於Windows,文件位置為C:\opt\settings\server.properties

Environment: 通過server.properties配置文件
對於Mac/Linux,文件位置為/opt/settings/server.properties
對於Windows,文件位置為C:\opt\settings\server.properties
文件內容形如:
env=dev
env=pro

本地緩存路徑: 本地緩存路徑默認位於以下路徑,所以請確保/opt/data或C:\opt\data\目錄存在,且應用有讀寫權限
cd /opt
mkdir data
chmod oug+rw data

AppId: 確保resources/META-INF/app.properties文件存在,並且其中內容形如:app.id=YOUR-APP-ID

Maven Dependency:
<dependency>
<groupId>com.ctrip.framework.apollo</groupId>
<artifactId>apollo-client</artifactId>
<version>1.5.1</version>
</dependency>

基於XML的配置: 需要把apollo相關的xml namespace加到配置文件頭上,不然會報xml語法錯誤
<?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">
<apollo:config namespaces="application,dev.common"/>
<bean class="com.ctrip.framework.apollo.spring.TestXmlBean">
<property name="timeout" value="${timeout:100}"/>
<property name="batch" value="${batch:200}"/>
</bean>
</beans>

Spring Boot集成方式(推薦): 使用方式很簡單,只需要在application.properties/bootstrap.properties中按照如下樣例配置即可
apollo.bootstrap.enabled = true
apollo.bootstrap.namespaces = application,dev.common

已有配置遷移: https://github.com/ctripcorp/apollo/wiki/Java%E5%AE%A2%E6%88%B7%E7%AB%AF%E4%BD%BF%E7%94%A8%E6%8C%87%E5%8D%97#324-%E5%B7%B2%E6%9C%89%E9%85%8D%E7%BD%AE%E8%BF%81%E7%A7%BB

Apollo核心概念之“Namespace”: https://github.com/ctripcorp/apollo/wiki/Apollo%E6%A0%B8%E5%BF%83%E6%A6%82%E5%BF%B5%E4%B9%8B%E2%80%9CNamespace%E2%80%9D
公共組件接入指南: https://github.com/ctripcorp/apollo/wiki/Apollo%E4%BD%BF%E7%94%A8%E6%8C%87%E5%8D%97#%E4%BA%8C%E5%85%AC%E5%85%B1%E7%BB%84%E4%BB%B6%E6%8E%A5%E5%85%A5%E6%8C%87%E5%8D%97


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM