Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[doc] modify the document that uses PostgreSQL to store metadata #2322

Merged
merged 3 commits into from
Jul 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions home/docs/start/postgresql-change.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,30 @@ PostgreSQL is a RDBMS emphasizing extensibility and SQL compliance. In addition
1. Download and install the Docker environment
Docker tools download refer to [Docker official document](https://docs.docker.com/get-docker/)。
After the installation you can check if the Docker version normally output at the terminal.
```
```shell
$ docker -v
Docker version 20.10.12, build e91ed57
```
2. Install PostgreSQL with Docker
```
```shell
$ docker run -d --name postgresql -p 5432:5432 -e POSTGRES_USER=root -e POSTGRES_PASSWORD=123456 -e TZ=Asia/Shanghai postgresql:15
```
use```$ docker ps```to check if the database started successfully
3. Create database in container manually or with [script](https://github.com/apache/hertzbeat/tree/master/script/docker-compose/hertzbeat-postgresql-iotdb/conf/sql/schema.sql).

### Database creation
1. Enter postgreSQL or use the client to connect postgreSQL service
```
```shell
su - postgres
psql
```
2. Create database named hertzbeat
`CREATE DATABASE hertzbeat;`
```sql
CREATE DATABASE hertzbeat;
```
3. Check if hertzbeat database has been successfully created
`\l`
```sql
SELECT * FROM pg_database where datname='hertzbeat';
```

### Modify hertzbeat's configuration file application.yml and switch data source

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,52 +3,51 @@ id: postgresql-change
title: 关系型数据库使用 PostgreSQL 替换依赖的 H2 存储系统元数据(推荐)
sidebar_label: 元数据存储PostgreSQL(推荐)
---
PostgreSQL是一个功能强大,开源的关系型数据库管理系统(RDBMS)。Apache HertzBeat (incubating) 除了支持使用默认内置的H2数据库外,还可以切换为使用PostgreSQL存储监控信息,告警信息,配置信息等结构化关系数据。
PostgreSQL 是一个功能强大,开源的关系型数据库管理系统(RDBMS)。Apache HertzBeat (incubating) 除了支持使用默认内置的 H2 数据库外,还可以切换为使用 PostgreSQL 存储监控信息,告警信息,配置信息等结构化关系数据。

注意⚠️ 使用外置PostgreSQL数据库替换内置H2数据库为可选项,但建议生产环境配置,以提供更好的性能
注意⚠️ 使用外置 PostgreSQL 数据库替换内置 H2 数据库为可选项,但建议生产环境配置,以提供更好的性能

> 如果您已有PostgreSQL环境,可直接跳到数据库创建那一步。
> 如果您已有 PostgreSQL 环境,可直接跳到数据库创建那一步。


### 通过Docker方式安装PostgreSQL
### 通过 Docker 方式安装 PostgreSQL

1. Download and install the Docker environment
Docker tools download refer to [Docker official document](https://docs.docker.com/get-docker/)。
After the installation you can check if the Docker version normally output at the terminal.
```
1. 下载安装 Docker 环境
Docker 的安装请参考 [Docker官网文档](https://docs.docker.com/get-docker/)。安装完毕后请于终端检查 Docker 版本输出是否正常。
```shell
$ docker -v
Docker version 20.10.12, build e91ed57
```

2. Docker安装 PostgreSQL
```
2. Docker 安装 PostgreSQL
```shell
$ docker run -d --name postgresql -p 5432:5432 -e POSTGRES_USER=root -e POSTGRES_PASSWORD=123456 -e TZ=Asia/Shanghai postgresql:15
```
使用```$ docker ps```查看数据库是否启动成功

3. Create database in container manually or with [script](https://github.com/apache/hertzbeat/tree/master/script/docker-compose/hertzbeat-postgresql-iotdb/conf/sql/schema.sql).
使用 ```$ docker ps``` 查看数据库是否启动成功

### 数据库创建

1. 进入 PostgreSQL 或使用客户端连接 PostgreSQL 服务
```
```shell
su - postgres
psql
```

2. 创建名称为hertzbeat的数据库
`CREATE DATABASE hertzbeat;`

3. 查看hertzbeat数据库是否创建成功
`\l`

### 修改hertzbeat的配置文件application.yml切换数据源
2. 创建名称为 hertzbeat 的数据库
```sql
CREATE DATABASE hertzbeat;
```
3. 查看 hertzbeat 数据库是否创建成功
```sql
SELECT * FROM pg_database where datname='hertzbeat';
```
### 修改 hertzbeat 的配置文件 application.yml 切换数据源

1. 配置HertzBeat的配置文件
1. 配置 HertzBeat 的配置文件
修改位于 `hertzbeat/config/application.yml` 的配置文件
注意⚠️docker容器方式需要将application.yml文件挂载到主机本地,安装包方式解压修改位于 `hertzbeat/config/application.yml` 即可
替换里面的`spring.database`数据源参数,IP端口账户密码驱动
⚠️注意`application.yml`文件内容需完整,除下方修改内容外其他参数需保留,完整内容见[/script/application.yml](https://github.com/hertzbeat/hertzbeat/raw/master/script/application.yml)
注意⚠️ docker 容器方式需要将 application.yml 文件挂载到主机本地,安装包方式解压修改位于 `hertzbeat/config/application.yml` 即可
替换里面的 `spring.database` 数据源参数,IP 端口账户密码驱动
⚠️注意 `application.yml` 文件内容需完整,除下方修改内容外其他参数需保留,完整内容见[/script/application.yml](https://github.com/hertzbeat/hertzbeat/raw/master/script/application.yml)

```yaml
spring:
Expand All @@ -69,7 +68,7 @@ spring:
logging:
level: SEVERE
```
具体替换参数如下,需根据 PostgreSQL 环境配置账户密码IP:
具体替换参数如下,需根据 PostgreSQL 环境配置账户密码 IP:
```yaml
spring:
datasource:
Expand Down
Loading