Preparation
Local runtime environment
- JDK : 1.8+
- MySQL : 5.6.5+
- Maven : 3.6.1
- IDE : IntelliJ IDEA
Apollo's table structure uses multiple default declarations for timestamp, so it requires more than 5.6.5 versions.
From the official warehouse https://github.com/ctripcorp/apollo Fork comes out of its own warehouse https://github.com/wupeixuan/apollo.
Use IntelliJ IDEA to pull the replacement code from Fork's warehouse. When the pull is complete, Maven downloads the required dependency packages.
Create a database
The Apollo server has two databases:
- ApolloPortalDB
- ApolloConfigDB
Apollo PortalDB only needs to deploy one in the production environment, while Apollo ConfigDB needs to deploy one in each environment, such as fat, uat and pro, which deploy three sets of Apollo ConfigDB respectively.
According to the actual situation, you can choose to import SQL manually or automatically through Flyway to create SQL.
The scripts directory under the Apollo project provides the corresponding initialization scripts:
Create Apollo PortalDB
Modify the configuration of flyway.user, flyway.password and flyway.url in flyway-portaldb.properties according to the actual situation.
Execute mvn-N-Pportaldb flyway: migrate under the apollo project root directory
After successful import, the table structure is as follows:
Create Apollo ConfigDB
Modify the configuration of flyway.user, flyway.password and flyway.url in flyway-configdb.properties according to the actual situation.
Execute mvn-N-Pconfigdb flyway: migrate under the apollo project root directory
After successful import, the table structure is as follows:
Local boot
Start Apollo Config Service and Apollo Admin Service
At the same time, start the apollo-adminservice and apollo-configservice projects, based on the apollo-assembly project to start.
- Configure IDEA Application
Main class:com.ctrip.framework.apollo.assembly.ApolloApplication VM options: -Dapollo_profile=github -Dspring.datasource.url=jdbc:mysql://localhost:3306/ApolloConfigDB?characterEncoding=utf8 -Dspring.datasource.username=root -Dspring.datasource.password=123456 -Dlogging.file=D:/logs/apollo-assembly.log Program arguments:--configservice --adminservice Use classpath of module:apollo-assembly
- Spring. data source configuration to connect to ApolloConfigDB database
- Log. file configuration log output file
- Start IDEA Application
When the startup is complete, it opens http://localhost:8080/ Seeing APOLLO-ADMINSERVICE and APOLLO-CONFIGSERVICE registered in Eureka represents successful start-up.
Start Apollo-Portal
- Configure IDEA Application
Main class:com.ctrip.framework.apollo.portal.PortalApplication VM options: -Dapollo_profile=github,auth -Ddev_meta=http://localhost:8080/ -Dserver.port=8070 -Dspring.datasource.url=jdbc:mysql://localhost:3306/ApolloPortalDB?characterEncoding=utf8 -Dspring.datasource.username=root -Dspring.datasource.password=123456 -Dlogging.file=D:/logsh/apollo-portal.log Use classpath of module:apollo-portal
Built-in account
- username : Apollo
- password : admin
- Start IDEA Application
When the startup is complete, it opens http://localhost:8070 When the following occurs, the startup is successful.
Demo Application Access
To test, you need to create a test application, Appid 100004458. As shown in the following figure:
- Configure IDEA Application
Main class:com.ctrip.framework.apollo.demo.api.SimpleApolloConfigDemo VM options: -Denv=dev -Ddev_meta=http://localhost:8080 Use classpath of module:apollo-demo
- Start IDEA Application
After success, the output log is as follows:
Apollo Config Demo. Please input key to get the value. Input quit to exit.
Enter timeout, return, output as follows:
timeout > [apollo-demo][main]2019-09-17 01:40:32,775 INFO [com.ctrip.framework.apollo.demo.api.SimpleApolloConfigDemo] Loading key : timeout with value: 100
The default client log level is DEBUG, which can be adjusted by modifying the level configuration in apollo-demo/src/main/resources/log4j2.xml
<logger name="com.ctrip.framework.apollo" additivity="false" level="trace"> <AppenderRef ref="Async" level="DEBUG"/> </logger>