安装笔记:在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

posted @ 2020-03-14 08:42  荣神益人  阅读(846)  评论(0编辑  收藏  举报