In order to let you get started with Apollo Configuration Center faster, we have prepared a Quick Start here, which can deploy and start Apollo Configuration Center in your local environment in a few minutes.

If you are familiar with Docker, you can refer to Apollo Quick Start Docker Deployment to deploy Apollo via Docker. Apollo Quick Start Docker.

However, it should be noted that Quick Start is only for local testing, if you want to deploy to production environment, please refer to distributed-deployment-guide separately.

Note: Quick Start requires a bash environment, Windows users please install Git Bash, we recommend using the latest version, older versions may encounter unknown problems. You can also start directly through the IDE environment, see Apollo Development Guide for details.

 

I. Preparation

1.1 Java

  • Apollo server: 1.8+
  • Apollo client: 1.8+
    • For running in Java 1.7 runtime environment, please use apollo client of 1.x version, such as 1.9.1

Once configured, this can be checked with the following command.

  1. java -version

Sample output.

  1. java version "1.8.0_74"
  2. Java(TM) SE Runtime Environment (build 1.8.0_74-b02)
  3. Java HotSpot(TM) 64-Bit Server VM (build 25.74-b02, mixed mode)
  4. `

Windows users please make sure that JAVA_HOME environment variable is set.

1.2 MySQL

  • Version requirement: 5.6.5+

Apollo’s table structure uses multiple default declarations for timestamp, so version 5.6.5+ is required.

After connecting to MySQL, you can check with the following command.

  1. SHOW VARIABLES WHERE Variable_name = 'version';
Variable_name Value
version 5.7.11

1.3 Downloading the Quick Start installation package

We have prepared a Quick Start installation package, you just need to download it locally and you can use it directly, eliminating the need to compile and package the process.

The installation package is 50M, if you can’t access github, you can download it from Baidu.com.

  1. Download from GitHub
  2. Download from Baidu.com
    • Downloaded via weblink, extraction code: 9wwe
    • After downloading to local, unzip apollo-quick-start.zip locally
  3. why is the installation package so large as 58M?
    • Because it is a self-starting jar package, which contains all the dependent jar packages and a built-in tomcat container

1.3.1 Manually packaged Quick Start installation package

Quick Start is only for local testing, so generally users do not need to download the source code to package it themselves, but just download the already typed package. However, there are some users who want to repackage the package after modifying the code, then you can refer to the following steps.

  1. Modify the apollo-configservice, apollo-adminservice and apollo-portal pom.xml, comment out spring-boot-maven-plugin and maven-assembly-plugin
  2. Execute mvn clean package -pl apollo-assembly -am -DskipTests=true in the root directory.
  3. Copy the jar package under apollo-assembly/target and rename it to apollo-all-in-one.jar

II. Installation steps

2.1 Create the database

Apollo server side needs a total of two databases: ApolloPortalDB and ApolloConfigDB, we have prepared the database, table creation and sample data as sql files respectively, just import the database.

Note: If you have already created Apollo database locally, please take care to backup the data. The sql file we prepared will clear the Apollo related tables.

2.1.1 Creating ApolloPortalDB

Just import sql/apolloportaldb.sql through various MySQL clients.

The following is an example of a native MySQL client.

  1. source /your_local_path/sql/apolloportaldb.sql

After the successful import, you can verify it by executing the following sql statement.

  1. select `Id`, `AppId`, `Name` from ApolloPortalDB.App;
Id AppId Name
1 SampleApp Sample App

2.1.2 Creating ApolloConfigDB

You can import sql/apolloconfigdb.sql through various MySQL clients.

The following is an example of a native MySQL client.

  1. source /your_local_path/sql/apolloconfigdb.sql

After the successful import, you can verify it by executing the following sql statement.

  1. select `NamespaceId`, `Key`, `Value`, `Comment` from ApolloConfigDB.Item;
NamespaceId Key Value Comment
1 timeout 100 sample timeout configuration

2.2 Configuring Database Connection Information

The Apollo server needs to know how to connect to the database you created earlier, so you need to edit demo.sh and modify ApolloPortalDB and ApolloConfigDB related database connection string information.

Note: The filled in user needs to have read and write access to ApolloPortalDB and ApolloConfigDB data.

  1. #apollo config db info
  2. apollo_config_db_url="jdbc:mysql://localhost:3306/ApolloConfigDB?characterEncoding=utf8&serverTimezone=Asia/Shanghai"
  3. apollo_config_db_username=username
  4. apollo_config_db_password=password (if you don't have a password, just leave it blank)
  5. # apollo portal db info
  6. apollo_portal_db_url="jdbc:mysql://localhost:3306/ApolloPortalDB?characterEncoding=utf8&serverTimezone=Asia/Shanghai"
  7. apollo_portal_db_username=username
  8. apollo_portal_db_password=password (if you don't have a password, just leave it blank)

Note: Do not modify other parts of demo.sh

III. Start Apollo Configuration Center

3.1 Make sure the port is not occupied

The Quick Start script will start 3 services locally, using ports 8070, 8080, 8090 respectively, please make sure these 3 ports are not currently used.

For example, under Linux/Mac, you can check with the following command.

  1. lsof -i:8080

3.2 Execute the startup script

  1. ./demo.sh start

When you see the following output, you’ve started successfully!

  1. ==== starting service ====
  2. Service logging file is . /service/apollo-service.log
  3. Started [10768]
  4. Waiting for config service startup .......
  5. Config service started. You may visit http://localhost:8080 for service status now!
  6. Waiting for admin service startup....
  7. Admin service started
  8. ==== starting portal ====
  9. Portal logging file is . /portal/apollo-portal.log
  10. Started [10846]
  11. Waiting for portal startup ......
  12. Portal started. You can visit http://localhost:8070 now!
  13. You can visit now!

3.3 Troubleshooting

If you encounter an exception in the startup, you can check the log files in the service and portal directories respectively to troubleshoot the problem.

Note: During start-up of apollo-configservice, eureka registration failure message will be output in the log, e.g. com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException: Connection refused. Note that this is expected because apollo-configservice needs to register the service with Meta Server (itself), but since it is not up yet during the startup process itself, this error is reported. A retry action will be performed later, so it will register properly when the service is up by itself.

3.4 Note

Quick Start is only used to help you quickly experience Apollo project, please refer to: distributed-deployment-guide for details.

It should be noted that Quick Start does not support adding environments, but only through distributed deployment, please refer to: distributed-deployment-guide

IV. Using Apollo Configuration Center

4.1 Using the sample project

4.1.1 Viewing the sample configuration

  1. Open http://localhost:8070

Quick Start integrates with Spring Security simple authentication, for more information you can refer to Portal implementing user login function

login

  1. Enter username apollo and password admin and log in

Home

  1. Click on SampleApp to enter the configuration screen, you can see that there is currently a configuration timeout=100 Configuration Console

If prompted system error, please retry or contact system owner, please retry a few seconds later, because there is a refresh delay for services registered through Eureka.

4.1.2 Running the client application

We have prepared a simple Demo client to demonstrate getting configuration from Apollo Configuration Center.

The program is simple: the user enters the name of a key, and the program outputs the value corresponding to that key.

If the key is not found, undefined is output.

Also, the client listens for configuration change events and outputs the changed configuration information once there is a change.

Run ./demo.sh client to start the demo client and ignore the previous debugging information, you can see the following prompt.

  1. Apollo Config Demo. Please input key to get the value. Input quit to exit.
  2. >

Enter timeout and you will see the following message.

  1. > timeout
  2. > [SimpleApolloConfigDemo] Loading key : timeout with value: 100

If you encounter problems running the client, you can view more detailed logging information by changing the level in client/log4j2.xml to DEBUG

  1. <logger name="com.ctrip.framework.apollo" additivity="false" level="trace">
  2. <AppenderRef ref="Async" level="DEBUG"/>
  3. </logger>

4.1.3 Modify the configuration and publish

  1. In the configuration screen, click the edit button for the timeout item Edit Configuration

  2. In the popup box, change the value to 200 and submit Update Configuration

  3. Click the Publish button and fill in the publish information Publish Configuration

Release Info

4.1.4 Client view the modified value

If the client has been running, it will listen for configuration changes after the configuration is published and output the modified configuration information as follows.

  1. [SimpleApolloConfigDemo] Changes for namespace application
  2. [SimpleApolloConfigDemo] Change - key: timeout, oldValue: 100, newValue: 200, changeType: MODIFIED

Type timeout again to see the corresponding value and you will see the following message.

  1. > timeout
  2. > [SimpleApolloConfigDemo] Loading key : timeout with value: 200

4.2 Using the new project

4.2.1 App access to Apollo

This part can be found in Java Application Access Guide

4.2.2 Run the client application

Since a new project is used, the client needs to modify the appId information.

Edit client/META-INF/app.properties and change app.id to your newly created app id.

  1. app.id=your appId
  1. Run `./demo.sh client` to start the demo client.