Skip to content

Commit

Permalink
postgre-support
Browse files Browse the repository at this point in the history
  • Loading branch information
hezhangjian committed Mar 9, 2023
1 parent d1fb1ed commit 5c65e49
Show file tree
Hide file tree
Showing 6 changed files with 991 additions and 4 deletions.
115 changes: 115 additions & 0 deletions docs/zh/deployment/quick-start.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,3 +248,118 @@ Apollo Config Demo. Please input key to get the value. Input quit to exit.
app.id=你的appId
```
运行`./demo.sh client`启动Demo客户端即可。

# 五、其他数据库配置

## 5.1 初始化pg数据库

### 5.1.1 初始化ApolloPortalDB和ApolloConfigDB数据库。

方式一: 通过各种pg客户端导入sql/postgre/apollo_init_user.sql即可。

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

```\i /your_local_path/sql/postgre/apollo_init_user.sql```

### 5.1.2 初始化ApolloPortalDB数据库表

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

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

```\i /your_local_path/sql/postgre/apolloportaldb.sql```

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

```\c ApolloPortalDB```

```select "Id", "AppId", "Name" from apolloportal."App";```


| Id | AppId | Name |
|----|-----------|------------|

### 5.1.3 初始化ApolloConfigDB数据库表

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

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

```\i /your_local_path/sql/postgre/apolloconfigdb.sql```

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

```\c ApolloConfigDB```

```select "Id", "Key", "Cluster" from apolloconfig."ServerConfig";```


| Id | Key | Cluster |
|----|-----------|------------|

## 5.2 初始化Mysql数据库

### 5.2.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.2.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.3 配置其他数据库连接信息

```
# apollo portal db info
apollo_portal_db_url="jdbc:postgresql://localhost:5432/ApolloPortalDB?currentSchema=apolloconfig&characterEncoding=utf8"
apollo_portal_db_username=用户名
apollo_portal_db_password=密码(如果没有密码,留空即可)
spring_profiles_group_github=postgre
#apollo config db info
apollo_config_db_url="jdbc:postgresql://localhost:5432/ApolloConfigDB?currentSchema=apolloconfig&characterEncoding=utf8"
apollo_config_db_username=用户名
apollo_config_db_password=密码(如果没有密码,留空即可)
spring_profiles_group_github=postgre
```

## 5.4 配置mysql数据库连接信息

```
#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=密码(如果没有密码,留空即可)
# 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=密码(如果没有密码,留空即可)
```
4 changes: 2 additions & 2 deletions scripts/build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ cd ..
rem package config-service and admin-service
echo "==== starting to build config-service and admin-service ===="

call mvn clean package -DskipTests -pl apollo-configservice,apollo-adminservice -am -Dapollo_profile=github -Dspring_datasource_url=%apollo_config_db_url% -Dspring_datasource_username=%apollo_config_db_username% -Dspring_datasource_password=%apollo_config_db_password%
call mvn clean package -DskipTests -pl apollo-configservice,apollo-adminservice -am -Dapollo_profile=github -Dspring_datasource_url=%apollo_config_db_url% -Dspring_datasource_username=%apollo_config_db_username% -Dspring_datasource_password=%apollo_config_db_password% -Dspring.profiles.group.github=%spring_profiles_group_github%

echo "==== building config-service and admin-service finished ===="

echo "==== starting to build portal ===="

call mvn clean package -DskipTests -pl apollo-portal -am -Dapollo_profile=github,auth -Dspring_datasource_url=%apollo_portal_db_url% -Dspring_datasource_username=%apollo_portal_db_username% -Dspring_datasource_password=%apollo_portal_db_password% %META_SERVERS_OPTS%
call mvn clean package -DskipTests -pl apollo-portal -am -Dapollo_profile=github,auth -Dspring_datasource_url=%apollo_portal_db_url% -Dspring_datasource_username=%apollo_portal_db_username% -Dspring_datasource_password=%apollo_portal_db_password% -Dspring.profiles.group.github=%spring_profiles_group_github% %META_SERVERS_OPTS%

echo "==== building portal finished ===="

Expand Down
4 changes: 2 additions & 2 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ cd ..
# package config-service and admin-service
echo "==== starting to build config-service and admin-service ===="

mvn clean package -DskipTests -pl apollo-configservice,apollo-adminservice -am -Dapollo_profile=github -Dspring_datasource_url=$apollo_config_db_url -Dspring_datasource_username=$apollo_config_db_username -Dspring_datasource_password=$apollo_config_db_password
mvn clean package -DskipTests -pl apollo-configservice,apollo-adminservice -am -Dapollo_profile=github -Dspring_datasource_url=$apollo_config_db_url -Dspring_datasource_username=$apollo_config_db_username -Dspring_datasource_password=$apollo_config_db_password -Dspring.profiles.group.github=$spring_profiles_group_github

echo "==== building config-service and admin-service finished ===="

echo "==== starting to build portal ===="

mvn clean package -DskipTests -pl apollo-portal -am -Dapollo_profile=github,auth -Dspring_datasource_url=$apollo_portal_db_url -Dspring_datasource_username=$apollo_portal_db_username -Dspring_datasource_password=$apollo_portal_db_password $META_SERVERS_OPTS
mvn clean package -DskipTests -pl apollo-portal -am -Dapollo_profile=github,auth -Dspring_datasource_url=$apollo_portal_db_url -Dspring_datasource_username=$apollo_portal_db_username -Dspring_datasource_password=$apollo_portal_db_password -Dspring.profiles.group.github=$spring_profiles_group_github $META_SERVERS_OPTS

echo "==== building portal finished ===="
49 changes: 49 additions & 0 deletions scripts/sql/postgre/apollo_init_user.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
--
-- Copyright 2023 Apollo Authors
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
--
/* # CREATE apolloconfigdb; */
/* # ------------------------------------------------------------ */

CREATE DATABASE "ApolloConfigDB";

\c "ApolloConfigDB"

CREATE SCHEMA apolloconfig;

GRANT ALL PRIVILEGES ON DATABASE "ApolloConfigDB" to postgres;

GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA apolloconfig to postgres;

GRANT ALL PRIVILEGES ON ALL FUNCTIONS IN SCHEMA apolloconfig to postgres;

GRANT ALL PRIVILEGES ON SCHEMA apolloconfig TO postgres;


/* # CREATE apolloconfigdb; */
/* # ------------------------------------------------------------ */

CREATE DATABASE "ApolloPortalDB";

\c "ApolloPortalDB"

CREATE SCHEMA apolloportal;

GRANT ALL PRIVILEGES ON DATABASE "ApolloPortalDB" to postgres;

GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA apolloportal to postgres;

GRANT ALL PRIVILEGES ON ALL FUNCTIONS IN SCHEMA apolloportal to postgres;

GRANT ALL PRIVILEGES ON SCHEMA apolloportal TO postgres;
Loading

0 comments on commit 5c65e49

Please sign in to comment.