apollo
Apollo
目录
架构图
组件
名称 | 功能说明 | 接口服务对象 |
---|---|---|
Portal | 提供Web界面供用户管理配置 | 配置管理员 |
AdminService | 提供配置管理接口 | Portal |
ConfigService | 提供配置获取接口 | Apollo客户端程序 |
Eureka | Config Service和Admin Service会向Eureka注册服务,并保持心跳 | Config和Admin |
Meta Server | Meta Server从Eureka获取Config Service和Admin Service的服务信息 | Portal和Client |
部署环境
运行环境 | 版本 | 库 |
---|---|---|
mysql | 5.6.5+ | ApolloPortalDB ApolloConfigDB ApolloPortalDevDB ApolloConfigProDB ApolloConfigFatDB |
java 环境 | 1.8+ | |
测版本 | 1.5.1 | 1.6.1 |1.7.1 | 1.8.1 |1.9.2 | |
制作docker image
configService
version=${version:=1.5.1}
wget https://github.com/ctripcorp/apollo/releases/download/v${version}/apollo-configservice-${version}-github.zip -O /opt/apollo-configservice-${version}-github.zip
unzip apollo-configservice-${version}-github.zip -d /opt/apollo-configservice-${version}
wget -O /opt/apollo-configservice-${version}/scripts/startup.sh https://raw.githubusercontent.com/apolloconfig/apollo/1.5.1/scripts/apollo-on-kubernetes/apollo-config-server/scripts/startup-kubernetes.sh
FROM 1209233066/jre:1.8.0_281
ARG version=1.5.1
#ENV APOLLO_CONFIG_SERVICE_NAME="service-apollo-config-server.sre"
ENV SERVICE_NAME=apollo-configservice-${version}
ENV SERVER_PORT=8080
ADD . /apollo-config-server
RUN ln -sf /apollo-config-server/apollo-configservice-${version}.jar /apollo-config-server/apollo-configservice.jar
EXPOSE 8080
CMD ["/apollo-config-server/scripts/startup.sh"]
adminservice
version=${version:=1.5.1}
wget https://github.com/ctripcorp/apollo/releases/download/v${version}/apollo-adminservice-${version}-github.zip
unzip apollo-adminservice-${version}-github.zip -d /opt/apollo-adminservice-${version}
wget -O /opt/apollo-adminservice-${version}/scripts/startup.sh https://raw.githubusercontent.com/apolloconfig/apollo/1.5.1/scripts/apollo-on-kubernetes/apollo-admin-server/scripts/startup-kubernetes.sh
FROM 1209233066/jre:1.8.0_281
ARG VERSION=1.5.1
ENV SERVICE_NAME=apollo-adminservice-${VERSION}
ENV SERVER_PORT=8090
ADD . /apollo-admin-server/
RUN ln -sf /apollo-admin-server/apollo-adminservice-${VERSION}.jar /apollo-admin-server/apollo-adminservice.jar
EXPOSE 8090
CMD ["/apollo-admin-server/scripts/startup.sh"]
portal
version=${version:=1.5.1}
wget https://github.com/ctripcorp/apollo/releases/download/v${version}/apollo-portal-${version}-github.zip
unzip apollo-portal-${version}-github.zip -d /opt/apollo-portal-${version}
wget -O /opt/apollo-portal-${version}/scripts/startup.sh https://raw.githubusercontent.com/apolloconfig/apollo/1.5.1/scripts/apollo-on-kubernetes/apollo-portal-server/scripts/startup-kubernetes.sh
FROM 1209233066/jre:1.8.0_281
ARG VERSION=1.5.1
#ENV APOLLO_CONFIG_SERVICE_NAME="service-apollo-config-server.sre"
ENV SERVICE_NAME=apollo-portal-${VERSION}
ENV SERVER_PORT=8070
ADD . /apollo-portal-server/
RUN ln -sf /apollo-portal-server/apollo-portal-${VERSION}.jar /apollo-portal-server/apollo-portal.jar
EXPOSE 8070
CMD ["/apollo-portal-server/scripts/startup.sh"]
部署
mysql
apiVersion: v1
kind: Namespace
metadata:
name: apollo
---
apiVersion: v1
kind: Service
metadata:
name: mysql
namespace: apollo
spec:
ports:
- name: mysql
port: 3306
targetPort: 3306
selector:
app: mysql
clusterIP: None
type: ClusterIP
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: mysql
namespace: apollo
spec:
replicas: 1
serviceName: mysql
selector:
matchLabels:
app: mysql
template:
metadata:
labels:
app: mysql
spec:
containers:
- name: mysql
image: harbor.od.com/public/mysql:8.0.27
imagePullPolicy: Always
ports:
- name: mysql-port
containerPort: 3306
env:
- name: MYSQL_ROOT_PASSWORD
value: "123"
volumeMounts:
- name: mysqldata
mountPath: /var/lib/mysql
volumes:
- name: mysqldata
nfs:
path: /data/nfs-volume/mysql
server: 10.4.7.200
set character_set_connection=gb2312;
set character_set_database=gb2312;
set character_set_results=gb2312;
set character_set_server=gb2312;
set character_set_system=gb2312;
set collation_connection=gb2312;
set collation_database=gb2312;
set collation_server=gb2312;
部署文档
--
wget
https://raw.githubusercontent.com/ctripcorp/apollo/1.5.1/scripts/db/migration/configdb/V1.0.0__initialization.sql -O
configdb.sql
--
wget https://raw.githubusercontent.com/apolloconfig/apollo/1.5.1/scripts/db/migration/portaldb/V1.0.0__initialization.sql -O
portaldb.sql
--
source configdb.sql
source portaldb.sql
--
grant select,insert,update,delete on ApolloConfigDB.* to apolloconfig@'%' ;
grant select,insert,update,delete on ApolloPortalDB.* to apolloportal@'%' ;
--
alter user apolloconfig@'%' identified by '123456';
alter user apolloportal@'%' identified by '123456';
--
flush privileges;
修改eureka地址
update ServerConfig set value='http://config.od.com/eureka' where id =1;
select * from ServerConfig limit 1;
vi /etc/named/od.com.zone
config A 10.4.7.11
configserver
apiVersion: v1
kind: ConfigMap
metadata:
name: apollo-configservice-cm
namespace: apollo
data:
application-github.properties: |
# DataSource
spring.datasource.url = jdbc:mysql://mysql:3306/ApolloConfigDB?characterEncoding=utf8
spring.datasource.username = apolloconfig
spring.datasource.password = 123456
eureka.service.url = http://config.od.com/eureka
#apollo.eureka.server.enabled=true
app.properties: |
appId=100003171
---
kind: Deployment
apiVersion: apps/v1
metadata:
name: apollo-configservice
namespace: apollo
labels:
name: apollo-configservice
spec:
replicas: 1
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 1
maxSurge: 1
revisionHistoryLimit: 7
progressDeadlineSeconds: 600
selector:
matchLabels:
name: apollo-configservice
template:
metadata:
labels:
app: apollo-configservice
name: apollo-configservice
spec:
restartPolicy: Always
terminationGracePeriodSeconds: 30
containers:
- name: apollo-configservice
image: harbor.od.com/public/apollo-configservice:1.5.1
imagePullPolicy: IfNotPresent
ports:
- containerPort: 8080
protocol: TCP
volumeMounts:
- name: configmap-volume
mountPath: /apollo-config-server/config
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
securityContext:
runAsUser: 0
volumes:
- name: configmap-volume
configMap:
name: apollo-configservice-cm
---
apiVersion: v1
kind: Service
metadata:
name: apollo-configservice
namespace: apollo
spec:
ports:
- protocol: TCP
port: 8080
targetPort: 8080
selector:
app: apollo-configservice
---
kind: Ingress
apiVersion: extensions/v1beta1
metadata:
name: apollo-configservice
namespace: apollo
spec:
rules:
- host: config.od.com
http:
paths:
- path: /
backend:
serviceName: apollo-configservice
servicePort: 8080
adminserver
apiVersion: v1
kind: ConfigMap
metadata:
name: apollo-adminservice-cm
namespace: apollo
data:
application-github.properties: |
#DataSource
spring.datasource.url = jdbc:mysql://mysql:3306/ApolloConfigDB?characterEncoding=utf8
spring.datasource.username = apolloconfig
spring.datasource.password = 123456
eureka.service.url = http://config.od.com/eureka
app.properties: |
appId=100003172
---
kind: Deployment
apiVersion: apps/v1
metadata:
name: apollo-adminservice
namespace: apollo
labels:
name: apollo-adminservice
spec:
replicas: 1
selector:
matchLabels:
name: apollo-adminservice
template:
metadata :
labels:
app: apollo-adminservice
name: apollo-adminservice
spec:
volumes:
- name: configmap-volume
configMap:
name: apollo-adminservice-cm
containers:
- name: apollo-adminservice
image: harbor.od.com/public/apollo-adminservice:1.5.1
ports:
- containerPort: 8090
protocol: TCP
volumeMounts:
- name: configmap-volume
mountPath: /apollo-admin-server/config
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
imagePullPolicy: IfNotPresent
imagePullSecrets:
- name: harbor
restartPolicy: Always
terminationGracePeriodSeconds: 30
securityContext:
runAsUser: 0
schedulerName: default-scheduler
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 1
maxSurge: 1
revisionHistoryLimit: 7
progressDeadlineSeconds: 600
protal
apiVersion: v1
kind: ConfigMap
metadata:
name: apollo-portal-cm
namespace: apollo
data:
apollo-env.properties: |
dev.meta=http://apollo-configservice
application-github.properties: |
# DataSource
spring.datasource.url = jdbc:mysql://mysql:3306/ApolloPortalDB?characterEncoding=utf8
spring.datasource.username = protaldb
spring.datasource.password = 123456
app.properties: |
appId=100003173
apollo-env.properties: |
local.meta=http://localhost:8080
dev.meta=http://config.od.com
fat.meta=http://fill-in-fat-meta-server:8080
uat.meta=http://fill-in-uat-meta-server:8080
lpt.meta=${lpt_meta}
pro.meta=http://fill-in-pro-meta-server:8080
---
kind: Deployment
apiVersion: extensions/v1beta1
metadata:
name: apollo-portal
namespace: apollo
labels:
name: apollo-portal
spec:
replicas: 1
selector:
matchLabels:
name: apollo-portal
template:
metadata:
labels:
app: apollo-portal
name: apollo-portal
spec:
volumes:
- name: portal-volume
configMap:
name: apollo-portal-cm
containers:
- name: apollo-portal
image: harbor.od.com/public/apollo-portal:1.5.1
ports:
- containerPort: 8070
protocol: TCP
volumeMounts:
- name: portal-volume
mountPath: /apollo-portal-server/config
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
imagePullPolicy: IfNotPresent
imagePullSecrets:
- name: harbor
restartPolicy: Always
terminationGracePeriodSeconds: 30
securityContext:
runAsUser: 0
schedulerName: default-scheduler
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 1
maxSurge: 1
revisionHistoryLimit: 7
progressDeadlineSeconds: 600
---
kind: Service
apiVersion: v1
metadata:
name: apollo-portal
namespace: apollo
spec:
ports:
- protocol: TCP
port: 8070
targetPort: 8070
selector:
app: apollo-portal
---
kind: Ingress
apiVersion: extensions/v1beta1
metadata:
name: apollo-portal
namespace: apollo
spec:
rules:
- host: portal.od.com
http:
paths:
- path: /
backend:
serviceName: apollo-portal
servicePort: 8070
分环境
默认支持环境说明
名称 | 说明 |
---|---|
DEV | 开发环境 |
FAT | 测试环境,相当于alpha环境(功能测试) |
UAT | 集成环境,相当于beta环境(回归测试) |
PRO | 生产环境 |
wget https://raw.githubusercontent.com/ctripcorp/apollo/1.5.1/scripts/db/migration/configdb/V1.0.0__initialization.sql -O configdb.sql
---
sed -i s/ApolloConfigDB/ApolloConfigTestDB/g configdb.sql
---
source configdb.sql;
---
grant select,insert,update,delete on ApolloConfigTestDB.* to apolloconfig@'%' ;
--
alter user apolloconfig@'%' identified by '123456';
--
flush privileges;
update ApolloConfigTestDB.ServerConfig set value='http://config-test.od.com/eureka' where id =1;
select * from ApolloConfigTestDB.ServerConfig limit 1;
vi /etc/named/od.com.zone
config-test A 10.4.7.11
kind: ConfigMap
metadata:
name: apollo-portal-cm
namespace: infra
data:
apollo-env.properties: |
dev.meta=http://config.od.com
fat.meta=http://config-test.od.com
pro.meta=http://config-prod.od.com
application-github.properties: |
# DataSource
spring.datasource.url = jdbc:mysql://mysql.od.com:3306/ApolloPortalDB?characterEncoding=utf8
spring.datasource.username = apolloportal
spring.datasource.password = 123456
app.properties: |
appId=100003173
update ApolloPortalDB.ServerConfig set value='DEV,FAT,UAT,PRO' where ID=1;
namespace 创建一个指定名称的 namespace
clusterrole Create a ClusterRole.
clusterrolebinding 为一个指定的 ClusterRole 创建一个 ClusterRoleBinding
role Create a role with single rule.
rolebinding 为一个指定的 Role 或者 ClusterRole创建一个 RoleBinding
configmap 从本地 file, directory 或者 literal value 创建一个 configmap
secret 使用指定的 subcommand 创建一个 secret
deployment 创建一个指定名称的 deployment.
cronjob Create a cronjob with the specified name.
job Create a job with the specified name.
poddisruptionbudget 创建一个指定名称的 pod disruption budget.
priorityclass Create a priorityclass with the specified name.
quota 创建一个指定名称的 quota.
service 使用指定的 subcommand 创建一个 service.
serviceaccount
主要的表功能
表明 | Key | Value |
---|---|---|
ApolloPortalDB.ServerConfig | apollo.portal.envs | DEV,FAT,UAT,PRO |
ApolloPortalDB.ServerConfig | organizations | [{"orgId":"TEST1","orgName":"1"},{"orgId":"TEST2","orgName":"2"}] |