Skip to content

Commit

Permalink
add h2 quick start doc
Browse files Browse the repository at this point in the history
  • Loading branch information
hezhangjian committed Dec 4, 2023
1 parent b67db2b commit f223e5b
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 90 deletions.
99 changes: 53 additions & 46 deletions docs/en/deployment/quick-start.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,60 +66,26 @@ Quick Start is only for local testing, so generally users do not need to downloa
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.
# II. Database Initialization and Configuration

> 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.
This section uses the h2 database as an example (h2 database support started after version 2.2.0), explaining how to initialize the database and configure the database connection information. As the h2 database is an in-memory database, data initialization and access are done in memory, so there is no need for installation and import. However, as the h2 database is an in-memory database, data will be lost after restarting the machine, so it is not recommended for use in production environments. If you need to use other databases, such as MySQL, refer to [Using Other Databases](#v-using-other-databases)

### 2.1.1 Creating ApolloPortalDB
Just import [sql/apolloportaldb.sql](https://github.com/apolloconfig/apollo-quick-start/blob/master/sql/apolloportaldb.sql) through various MySQL clients.
The Apollo server needs to know how to connect to the database you created earlier, so you need to edit [demo.sh](https://github.com/apolloconfig/apollo-quick-start/blob/master/demo.sh) and modify the database connection string information related to ApolloPortalDB and ApolloConfigDB.

The following is an example of a native MySQL client.
```sql
source /your_local_path/sql/apolloportaldb.sql
```

After the successful import, you can verify it by executing the following sql statement.
```sql
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](https://github.com/apolloconfig/apollo-quick-start/blob/master/sql/apolloconfigdb.sql) through various MySQL clients.

The following is an example of a native MySQL client.
```sql
source /your_local_path/sql/apolloconfigdb.sql
```

After the successful import, you can verify it by executing the following sql statement.
```sql
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](https://github.com/apolloconfig/apollo-quick-start/blob/master/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.
> Note: The user entered must have read and write permissions for ApolloPortalDB and ApolloConfigDB.
```sh
#apollo config db info
apollo_config_db_url="jdbc:mysql://localhost:3306/ApolloConfigDB?characterEncoding=utf8&serverTimezone=Asia/Shanghai"
apollo_config_db_username=username
apollo_config_db_password=password (if you don't have a password, just leave it blank)
spring.profiles.group.github=h2
spring.datasource.url=jdbc:h2:mem:testdb;mode=mysql;DATABASE_TO_UPPER=FALSE;BUILTIN_ALIAS_OVERRIDE=TRUE;
spring.datasource.username=sa
spring.datasource.password=

# apollo portal db info
apollo_portal_db_url="jdbc:mysql://localhost:3306/ApolloPortalDB?characterEncoding=utf8&serverTimezone=Asia/Shanghai"
apollo_portal_db_username=username
apollo_portal_db_password=password (if you don't have a password, just leave it blank)
spring.profiles.group.github=h2
spring.datasource.url=jdbc:h2:mem:testdb;mode=mysql;DATABASE_TO_UPPER=FALSE;BUILTIN_ALIAS_OVERRIDE=TRUE;
spring.datasource.username=sa
spring.datasource.password=
```

> Note: Do not modify other parts of demo.sh
Expand Down Expand Up @@ -257,3 +223,44 @@ app.id=your appId
```
Run `./demo.sh client` to start the demo client.
```

# V. Using Other Databases

## 5.1 MySQL

### 5.1.1 Initializing ApolloPortalDB Database and Table Structure

Method 1: Import sql/apolloportaldb.sql using various MySQL clients.

Method 2: Using MySQL native client as an example:

```bash
source /your_local_path/sql/apolloportaldb.sql
```

After successful import, you can verify by executing the following SQL statement:

```sql
select `Id`, `AppId`, `Name` from ApolloPortalDB.App;
```

| NamespaceId | Key | Value | Comment |
|-------------|---------|-------|------------------|
| 1 | timeout | 100 | sample timeout配置 |

#### 5.1.3 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](https://github.com/apolloconfig/apollo-quick-start/blob/master/demo.sh) and modify the database connection string information related to ApolloPortalDB and ApolloConfigDB.
```
#apollo config db info
spring.profiles.group.github=mysql
apollo_config_db_url="jdbc:mysql://localhost:3306/ApolloConfigDB?characterEncoding=utf8&serverTimezone=Asia/Shanghai"
apollo_config_db_username=用户名
apollo_config_db_password=密码(如果没有密码,留空即可)
# apollo portal db info
spring.profiles.group.github=mysql
apollo_portal_db_url="jdbc:mysql://localhost:3306/ApolloPortalDB?characterEncoding=utf8&serverTimezone=Asia/Shanghai"
apollo_portal_db_username=用户名
apollo_portal_db_password=密码(如果没有密码,留空即可)
```
108 changes: 64 additions & 44 deletions docs/zh/deployment/quick-start.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,60 +66,26 @@ Quick Start只针对本地测试使用,所以一般用户不需要自己下载
2. 在根目录下执行`mvn clean package -pl apollo-assembly -am -DskipTests=true`
3. 复制apollo-assembly/target下的jar包,rename为apollo-all-in-one.jar

# 二、安装步骤
## 2.1 创建数据库
Apollo服务端共需要两个数据库:`ApolloPortalDB``ApolloConfigDB`,我们把数据库、表的创建和样例数据都分别准备了sql文件,只需要导入数据库即可。
# 二、数据库初始化及配置

> 注意:如果你本地已经创建过Apollo数据库,请注意备份数据。我们准备的sql文件会清空Apollo相关的表。
本部分以h2数据库为例(h2数据库在2.2.0版本后开始支持),介绍如何初始化数据库及配置数据库连接信息。由于h2数据库是内存数据库,数据的初始化和访问都是在内存中进行的,所以不需要安装和导入。并且,由于h2数据库是内存数据库,所以重启机器后,数据会丢失,不推荐在生产环境使用。 如果需要使用其他数据库,如MySQL,可以参考[使用其他数据库](#五使用其它数据库)

### 2.1.1 创建ApolloPortalDB
通过各种MySQL客户端导入[sql/apolloportaldb.sql](https://github.com/apolloconfig/apollo-quick-start/blob/master/sql/apolloportaldb.sql)即可。

下面以MySQL原生客户端为例:
```sql
source /your_local_path/sql/apolloportaldb.sql
```

导入成功后,可以通过执行以下sql语句来验证:
```sql
select `Id`, `AppId`, `Name` from ApolloPortalDB.App;
```

| Id | AppId | Name |
|----|-----------|------------|
| 1 | SampleApp | Sample App |

### 2.1.2 创建ApolloConfigDB
通过各种MySQL客户端导入[sql/apolloconfigdb.sql](https://github.com/apolloconfig/apollo-quick-start/blob/master/sql/apolloconfigdb.sql)即可。

下面以MySQL原生客户端为例:
```sql
source /your_local_path/sql/apolloconfigdb.sql
```

导入成功后,可以通过执行以下sql语句来验证:
```sql
select `NamespaceId`, `Key`, `Value`, `Comment` from ApolloConfigDB.Item;
```
| NamespaceId | Key | Value | Comment |
|-------------|---------|-------|--------------------|
| 1 | timeout | 100 | sample timeout配置 |

## 2.2 配置数据库连接信息
Apollo服务端需要知道如何连接到你前面创建的数据库,所以需要编辑[demo.sh](https://github.com/apolloconfig/apollo-quick-start/blob/master/demo.sh),修改ApolloPortalDB和ApolloConfigDB相关的数据库连接串信息。

> 注意:填入的用户需要具备对ApolloPortalDB和ApolloConfigDB数据的读写权限。
```sh
#apollo config db info
apollo_config_db_url="jdbc:mysql://localhost:3306/ApolloConfigDB?characterEncoding=utf8&serverTimezone=Asia/Shanghai"
apollo_config_db_username=用户名
apollo_config_db_password=密码(如果没有密码,留空即可)
spring.profiles.group.github=h2
spring.datasource.url=jdbc:h2:mem:testdb;mode=mysql;DATABASE_TO_UPPER=FALSE;BUILTIN_ALIAS_OVERRIDE=TRUE;
spring.datasource.username=sa
spring.datasource.password=

# apollo portal db info
apollo_portal_db_url="jdbc:mysql://localhost:3306/ApolloPortalDB?characterEncoding=utf8&serverTimezone=Asia/Shanghai"
apollo_portal_db_username=用户名
apollo_portal_db_password=密码(如果没有密码,留空即可)
spring.profiles.group.github=h2
spring.datasource.url=jdbc:h2:mem:testdb;mode=mysql;DATABASE_TO_UPPER=FALSE;BUILTIN_ALIAS_OVERRIDE=TRUE;
spring.datasource.username=sa
spring.datasource.password=
```

> 注意:不要修改demo.sh的其它部分
Expand Down Expand Up @@ -248,3 +214,57 @@ Apollo Config Demo. Please input key to get the value. Input quit to exit.
app.id=你的appId
```
运行`./demo.sh client`启动Demo客户端即可。

# 五、使用其它数据库

## 5.1 MySQL

### 5.1.1 初始化ApolloPortalDB数据库及表结构。

方式一: 通过各种MySQL客户端导入sql/apolloportaldb.sql即可。

方式二: 下面以MySQL原生客户端为例:

```source /your_local_path/sql/apolloportaldb.sql```

导入成功后,可以通过执行以下sql语句来验证:

```select `Id`, `AppId`, `Name` from ApolloPortalDB.App;```


| Id | AppId | Name |
|----|-----------|------------|
| 1 | SampleApp | Sample App |

#### 5.1.2 初始化ApolloConfigDB数据库及表结构

方式一: 通过各种MySQL客户端导入sql/apolloconfigdb.sql即可。

方式二: 下面以MySQL原生客户端为例:

```source /your_local_path/sql/apolloconfigdb.sql```

导入成功后,可以通过执行以下sql语句来验证:

```select `NamespaceId`, `Key`, `Value`, `Comment` from ApolloConfigDB.Item;```

| NamespaceId | Key | Value | Comment |
|-------------|---------|-------|------------------|
| 1 | timeout | 100 | sample timeout配置 |

#### 5.1.3 配置数据库连接信息

Apollo服务端需要知道如何连接到你前面创建的数据库,所以需要编辑[demo.sh](https://github.com/apolloconfig/apollo-quick-start/blob/master/demo.sh),修改ApolloPortalDB和ApolloConfigDB相关的数据库连接串信息。
```
#apollo config db info
spring.profiles.group.github=mysql
apollo_config_db_url="jdbc:mysql://localhost:3306/ApolloConfigDB?characterEncoding=utf8&serverTimezone=Asia/Shanghai"
apollo_config_db_username=用户名
apollo_config_db_password=密码(如果没有密码,留空即可)
# apollo portal db info
spring.profiles.group.github=mysql
apollo_portal_db_url="jdbc:mysql://localhost:3306/ApolloPortalDB?characterEncoding=utf8&serverTimezone=Asia/Shanghai"
apollo_portal_db_username=用户名
apollo_portal_db_password=密码(如果没有密码,留空即可)
```

0 comments on commit f223e5b

Please sign in to comment.