
一、文章大纲
二、安装MySQL5.7
三、创建apollo-config
四、创建apollo-admin
五、创建apollo-portal
六、查看apollo各个组件服务状态
七、访问apollo
八、nginx代理配置转发#注意
一定要先启动apollo-config,再启动apollo-admin,最后启动apollo-portal
二、安装MySQL5.7
1、安装过程参考:离线安装mysql5.7_韩帅平的博客-CSDN博客
2、sql文件下载
apolloportaldb.sql下载地址:https://github.com/nobodyiam/apollo-build-scripts/blob/master/sql/apolloportaldb.sql
apolloconfigdb.sql下载地址:https://github.com/nobodyiam/apollo-build-scripts/blob/master/sql/apolloconfigdb.sql
#修改apolloconfigdb.sql文件
VALUES('eureka.service.url', 'default', 'http://10.96.69.115:32109/eureka/', 'Eureka服务Url,多个service以英文逗号分隔'), #修改localhost:8080为apollo-config的Service Ip+NodePort端口,可在apollo-config服务创建好之后再修改导入库表('namespace.lock.switch', 'default', 'false', '一次发布只能有一个人修改开关'),('item.key.length.limit', 'default', '128', 'item key 最大长度限制'),('item.value.length.limit', 'default', '20000', 'item value最大长度限制'),('config-service.cache.enabled', 'default', 'false', 'ConfigService是否开启缓存,开启后能提高性能,但是会增大内存消耗!');
3、数据库内导入config、admin数据库表
mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \\g.
Your MySQL connection id is 5048
Server version: 5.7.20 MySQL Community Server (GPL)Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.Type 'help;' or '\\h' for help. Type '\\c' to clear the current input statement.mysql> source /usr/local/apolloconfigdb.sql;
mysql> source /usr/local/apolloportaldb.sql;
三、创建apollo-config(以下是我在环境中已生成的服务yaml文件,可按需修改)
1、apollo-config-deployment.yaml文件
apiVersion: apps/v1
kind: Deployment
metadata:annotations:deployment.kubernetes.io/revision: "2"creationTimestamp: "2023-04-19T08:38:44Z"generation: 2labels:appName: apolloname: apollo-confignamespace: apollo
spec:progressDeadlineSeconds: 600replicas: 1revisionHistoryLimit: 10selector:matchLabels:name: apollo-configstrategy:rollingUpdate:maxSurge: 25%maxUnavailable: 25%type: RollingUpdatetemplate:metadata:creationTimestamp: nulllabels:app: apolloccse_app_name: apolloname: apollo-configsource: CCSEspec:containers:- env:- name: SPRING_DATASOURCE_URLvalue: jdbc:mysql://IP:3306/ApolloConfigDB?characterEncoding=utf8 #IP为已创建好的数据库IP- name: SPRING_DATASOURCE_USERNAMEvalue: root- name: SPRING_DATASOURCE_PASSWORDvalue: #数据库密码image: apolloconfig/apollo-configservice:latestimagePullPolicy: Alwaysname: apollo-configresources:limits:cpu: "4"memory: 4Girequests:cpu: 100mmemory: 128MiterminationMessagePath: /dev/termination-logterminationMessagePolicy: FilevolumeMounts:- mountPath: /etc/localtimename: localtimereadOnly: truednsPolicy: ClusterFirstimagePullSecrets:- name: apollonodeSelector:apollo: "151"restartPolicy: AlwaysschedulerName: default-schedulersecurityContext: {}terminationGracePeriodSeconds: 30volumes:- hostPath:path: /etc/localtimetype: ""name: localtime
2、apollo-config-service.yaml文件
apiVersion: v1
kind: Service
metadata:creationTimestamp: "2023-04-19T08:41:39Z"labels:appName: apolloworkloadKind: DeploymentworkloadName: apollo-configname: apollo-confignamespace: apollo
spec:clusterIP: 10.96.69.115externalTrafficPolicy: Clusterports:- name: "8080"nodePort: 32109port: 32109protocol: TCPtargetPort: 8080selector:name: apollo-configsessionAffinity: Nonetype: NodePort
四、创建apollo-admin
1、apollo-admin-deployment.yaml文件
apiVersion: apps/v1
kind: Deployment
metadata:annotations:deployment.kubernetes.io/revision: "1"creationTimestamp: "2023-04-19T08:53:03Z"generation: 1labels:appName: apolloname: apollo-adminnamespace: apollo
spec:progressDeadlineSeconds: 600replicas: 1revisionHistoryLimit: 10selector:matchLabels:name: apollo-adminstrategy:rollingUpdate:maxSurge: 25%maxUnavailable: 25%type: RollingUpdatetemplate:metadata:creationTimestamp: nulllabels:app: apolloccse_app_name: apolloname: apollo-adminsource: CCSEspec:containers:- env:- name: SPRING_DATASOURCE_URLvalue: jdbc:mysql://IP:3306/ApolloConfigDB?characterEncoding=utf8 #修改数据库地址- name: SPRING_DATASOURCE_USERNAMEvalue: root- name: SPRING_DATASOURCE_PASSWORDvalue: #数据库密码image: apolloconfig/apollo-adminservice:latestimagePullPolicy: Alwaysname: apollo-adminresources:limits:cpu: "4"memory: 4Girequests:cpu: 100mmemory: 128MiterminationMessagePath: /dev/termination-logterminationMessagePolicy: FilevolumeMounts:- mountPath: /etc/localtimename: localtimereadOnly: truednsPolicy: ClusterFirstimagePullSecrets:- name: apollonodeSelector:apollo: "151"restartPolicy: AlwaysschedulerName: default-schedulersecurityContext: {}terminationGracePeriodSeconds: 30volumes:- hostPath:path: /etc/localtimetype: ""name: localtime
2、apollo-admin-service.yaml文件
apiVersion: v1
kind: Service
metadata:creationTimestamp: "2023-04-19T08:56:52Z"labels:appName: apolloworkloadKind: DeploymentworkloadName: apollo-adminname: apollo-adminnamespace: apollo
spec:clusterIP: 10.96.178.0externalTrafficPolicy: Clusterports:- name: "8090"nodePort: 32108port: 32108protocol: TCPtargetPort: 8090selector:name: apollo-adminsessionAffinity: Nonetype: NodePort
五、创建apollo-portal
1、apollo-portal-deployment.yaml文件
apiVersion: apps/v1
kind: Deployment
metadata:annotations:deployment.kubernetes.io/revision: "1"creationTimestamp: "2023-04-19T08:43:15Z"generation: 1labels:appName: apolloname: apollo-portalnamespace: apollo
spec:progressDeadlineSeconds: 600replicas: 1revisionHistoryLimit: 10selector:matchLabels:name: apollo-portalstrategy:rollingUpdate:maxSurge: 25%maxUnavailable: 25%type: RollingUpdatetemplate:metadata:creationTimestamp: nulllabels:app: apolloccse_app_name: apolloname: apollo-portalsource: CCSEspec:containers:- env:- name: SPRING_DATASOURCE_URLvalue: jdbc:mysql://IP:3306/ApolloPortalDB?characterEncoding=utf8 #数据库地址- name: SPRING_DATASOURCE_USERNAMEvalue: root- name: SPRING_DATASOURCE_PASSWORDvalue: #数据库密码- name: APOLLO_PORTAL_ENVSvalue: dev- name: DEV_METAvalue: http://10.96.69.115:32109 #apollo-config的Service Ip+NodePort端口image: apolloconfig/apollo-portal:latestimagePullPolicy: Alwaysname: apollo-portalresources:limits:cpu: "4"memory: 4Girequests:cpu: 100mmemory: 128MiterminationMessagePath: /dev/termination-logterminationMessagePolicy: FilevolumeMounts:- mountPath: /etc/localtimename: localtimereadOnly: truednsPolicy: ClusterFirstimagePullSecrets:- name: apollonodeSelector:apollo: "151"restartPolicy: AlwaysschedulerName: default-schedulersecurityContext: {}terminationGracePeriodSeconds: 30volumes:- hostPath:path: /etc/localtimetype: ""name: localtime
2、apollo-portal-service.yaml文件
apiVersion: v1
kind: Service
metadata:creationTimestamp: "2023-04-19T08:55:49Z"labels:appName: apolloworkloadKind: DeploymentworkloadName: apollo-portalname: apollo-portalnamespace: apollo
spec:clusterIP: 10.96.210.42externalTrafficPolicy: Clusterports:- name: "8070"nodePort: 32110port: 32115protocol: TCPtargetPort: 8070selector:name: apollo-portalsessionAffinity: Nonetype: NodePort
六、查看Apollo各个服务组件状态
kubectl get pods,svc,deployment -n apollo -o wide | grep apollopod/apollo-admin-946b849fc-t77jj 1/1 Running 0 21h 172.26.20.166 IP <none> <none>
pod/apollo-config-547c79c5d6-nrdns 1/1 Running 0 21h 172.26.20.190 IP <none> <none>
pod/apollo-portal-9694d748c-4mzpq 1/1 Running 0 21h 172.26.20.182 IP <none> <none>
service/apollo-admin NodePort 10.96.178.0 <none> 32108:32108/TCP 22h name=apollo-admin
service/apollo-config NodePort 10.96.69.115 <none> 32109:32109/TCP 22h name=apollo-config
service/apollo-portal NodePort 10.96.210.42 <none> 32115:32110/TCP 22h name=apollo-portal
deployment.apps/apollo-admin 1/1 1 1 22h apollo-admin apolloconfig/apollo-adminservice:latest name=apollo-admin
deployment.apps/apollo-config 1/1 1 1 22h apollo-config apolloconfig/apollo-configservice:latest name=apollo-config
deployment.apps/apollo-portal 1/1 1 1 22h apollo-portal apolloconfig/apollo-portal:latest name=apollo-portal
七、访问apollo,网址:http://IP:32110/
1、apollo前端页面,默认账号密码:apollo/admin

八、nginx代理配置转发
1、内网可通过nginx代理暴露服务,conf文件配置如下:
upstream nodes2.apollo-portal {server IP:32110;server IP:32110;server IP:32110;server IP:32110;server IP:32110;server IP:32110;server IP:32110;server IP:32110;server IP:32110;server IP:32110;
} location / {proxy_pass http://nodes2.apollo-portal/;proxy_http_version 1.1;proxy_redirect off;proxy_set_header Host $http_host;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $remote_addr;proxy_set_header X-Forwarded-Port 80;proxy_set_header Upgrade $http_upgrade;proxy_set_header Connection "upgrade";limit_conn one 10000;limit_rate 40960k;}