Apollo - environment building

abstract

This paper is based on the Apollo source code construction, to build the Apollo operating environment. Apollo's official documents are very detailed. Here is just a record and a note.

Resources

Apollo

Apollo's architecture

In a nutshell, you can think of Apollo as three parts:

  1. Apollo portal is a web application. It has its own database, Apollo portal dB. Here it mainly records data related to page operations, such as operation records, permissions, roles and so on.
  2. Admin service provides http interface for Apollo portal to operate the real configuration library, Apollo configdb.
  3. Config service provides http interface for client application to read configuration in Apollo configdb.

Here, the portal can only have one copy, and operate the Apollo configdb of each environment at the same time. However, the Apollo configdb of each environment has a set of corresponding admin service and config service. Now that you know the relationship, deploy the application.

Deployment steps

Database installation

The database script is as follows: apolloconfigdb.sql, apolloportaldb.sql script

Note here that Mysql version needs 5.6.5 +, otherwise there will be problems with timestamp type fields( Apollo distributed deployment Guide ) If the Mysql version is lower than 5.6.5 +, remove the default declaration in the timestamp field in the script.

Configure config service

Configure application.yml

spring:
  application:
    name: apollo-configservice
  profiles:
    active: ${apollo_profile}
  datasource:
    url: jdbc:mysql://ip:3306/ApolloConfigDB?useUnicode=true&characterEncoding=utf8&autoReconnect=true&allowMultiQueries=true&serverTimezone=Asia/Shanghai&zeroDateTimeBehavior=convertToNull
    username: root
    password: ***
  jpa:
     database-platform: org.hibernate.dialect.MySQLDialect

ctrip:
  appid: 100003171

server:
  port: 8080

logging:
  file: /opt/logs/100003171/apollo-configservice.log

Startup application

Execute main method

com.ctrip.framework.apollo.configservice.ConfigServiceApplication.main(String[])

The startup is normal. The default port is 8080

Configure admin service

Configure application.yml

spring:
  application:
    name: apollo-adminservice
  profiles:
    active: ${apollo_profile}
  datasource:
    url: jdbc:mysql://IP:3306/ApolloConfigDB?useUnicode=true&characterEncoding=utf8&autoReconnect=true&allowMultiQueries=true&serverTimezone=Asia/Shanghai&zeroDateTimeBehavior=convertToNull
    username: root
    password: ***
  jpa:
     database-platform: org.hibernate.dialect.MySQLDialect

ctrip:
  appid: 100003172
  
server:
  port: 8090
  
logging:
  file: /opt/logs/100003172/apollo-adminservice.log

Enable application

Execute main method

com.ctrip.framework.apollo.adminservice.AdminServiceApplication.main(String[])

The default boot is port 8090, which can be configured.

Configure Apollo portal

Configure application.yml

spring:
  application:
    name: apollo-portal
  profiles:
    active: ${apollo_profile}
  jpa:
    properties:
      hibernate:
        query:
          plan_cache_max_size: 192 # limit query plan cache max size
  datasource:
    url: jdbc:mysql://IP:3306/ApolloPortalDB?useUnicode=true&characterEncoding=utf8&autoReconnect=true&allowMultiQueries=true&serverTimezone=Asia/Shanghai&zeroDateTimeBehavior=convertToNull
    username: root
    password: ***

server:
  port: 8070
  compression:
    enabled: true
  tomcat:
    use-relative-redirects: true

logging:
  file: /opt/logs/100003173/apollo-portal.log

management:
  health:
    status:
      order: DOWN, OUT_OF_SERVICE, UNKNOWN, UP

The port configured here is 8070, which will be the port for page access.

Configure apollo-env.properties

local.meta=http://localhost:8080
dev.meta=http://localhost:8080
fat.meta=${fat_meta}
uat.meta=${uat_meta}
lpt.meta=${lpt_meta}
pro.meta=${pro_meta}

Startup application

Execute main method

com.ctrip.framework.apollo.portal.PortalApplication.main(String[])

The login account password is apollo

http://localhost:8070/

The client uses apollo

Apollo new app

It's like this after it's built

Create a new demo.properties file, click "add Namespace" - > "create Namespace" (default is "associate public Namespace"), enter "demo", and click "submit".

Client application access

Introducing apollo client

<!-- apollo -->
		<dependency>
			<groupId>com.ctrip.framework.apollo</groupId>
			<artifactId>apollo-client</artifactId>
			<version>1.6.0-SNAPSHOT</version>
		</dependency>

Configure apollo parameters

# apollo application id can have the same name as sentinel's project name.
app.id=sentinel-demo-client
# metaServer address (in fact, it is also the address of config service, which is in the same application as config service)
apollo.meta=http://localhost:8080
# Enable apollo configuration
apollo.bootstrap.enabled = true
# Configuration requires downloading those files from apollo and injecting them into spring properties. The. Properties file requires only one filename.
apollo.bootstrap.namespaces = application,demo
# Temporary storage path of downloaded files
apollo.cacheDir=/Users/michaelfeng/apollo

After automation, the apollo client will pull the application.properties and demo.properties files from the apollo platform.

Refer to official documents for more use.

Tags: Database MySQL Spring JDBC

Posted on Wed, 25 Mar 2020 13:38:51 -0400 by bltesar