Skip to content

Commit

Permalink
添加生产部署(#141
Browse files Browse the repository at this point in the history
* add production deployment

* update
  • Loading branch information
Doom9527 authored Jul 8, 2024
1 parent cc7a0b0 commit 15c1eb5
Show file tree
Hide file tree
Showing 3 changed files with 344 additions and 9 deletions.
162 changes: 162 additions & 0 deletions docs/docs/deployment.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
---
sidebar_position: 5
title: Deployment
description: Astraios deployment guide
---

[//]: # (Copyright 2024 Paion Data)

[//]: # (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.)

This section discusses deploying [Astraios] in production.

Prepare for Production Development
----------------------------------

### Installing Java (on Ubuntu)

```bash
sudo apt update
sudo apt install openjdk-17-jdk
```

At the end of the last command prompt, something like the below will show up:

```bash
The following additional packages will be installed:
...
Suggested packages:
...
The following NEW packages will be installed:
...
Need to get 170 MB of archives.
After this operation, 877 MB of additional disk space will be used.
Do you want to continue? [Y/n]
```

Enter `Y` to complete the installation.

:::

If we see something similar after typing the command with the version flag below we're good to go

```bash
$ java -version
openjdk version "17.0.11" 2024-04-16
OpenJDK Runtime Environment (build 17.0.11+9-Ubuntu-120.04.2)
OpenJDK 64-Bit Server VM (build 17.0.11+9-Ubuntu-120.04.2, mixed mode, sharing)
```

### Installing Maven

```bash
sudo apt install maven
```

At the end of the last command prompt, something like the below will show up:

```bash
The following additional packages will be installed:
...
Suggested packages:
...
The following NEW packages will be installed:
...
Need to get 9,657 kB of archives.
After this operation, 12.6 MB of additional disk space will be used.
Do you want to continue? [Y/n]
```

Enter `Y` to complete the installation.

:::

If we see something similar after typing the command with the version flag below we're good to go

```bash
$ mvn -version
Apache Maven 3.6.3
Maven home: /usr/share/maven
Java version: 17.0.11, vendor: Ubuntu, runtime: /usr/lib/jvm/java-17-openjdk-amd64
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "5.4.0-182-generic", arch: "amd64", family: "unix"
```

In the example, Maven is obviously using the correct JDK, so there is no need to set the JAVA_HOME environment variable
extra. However, if you want to explicitly set JAVA_HOME, or in some cases (for example, when there are multiple JDK
installations) make sure Maven always uses a specific JDK 17, You can add the following lines to your shell
configuration file (such as.bashrc,.zshrc, or.profile) :

```bash
export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64
```

### Loading Data Models

```bash
git clone git@github.com:paion-data/astraios-data-models-example.git
cd astraios-data-models-example
mvn clean install
```

Now that we have the model installed locally, we need to get astraios to load the model through the maven configuration
file, add the following configuration information via **~/.m2/settings.xml** ~/.m2/settings.xml:

```xml
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
http://maven.apache.org/xsd/settings-1.0.0.xsd">

<profiles>
<profile>
<id>astraios-data-models</id>
<properties>
<model.package.jar.group.id>com.paiondata</model.package.jar.group.id>
<model.package.jar.artifact.id>astraios-data-models-example</model.package.jar.artifact.id>
<model.package.jar.version>1.0.0</model.package.jar.version>
</properties>
</profile>
</profiles>

<activeProfiles>
<activeProfile>astraios-data-models</activeProfile>
</activeProfiles>
</settings>
```

### Packaging Astraios

```bash
git clone git@github.com:paion-data/astraios.git
export MODEL_PACKAGE_NAME=com.paiondata.astraios.data.models
export DB_USER=YOUR_DB_USER
export DB_PASSWORD=YOUR_DB_PASSWORD
export DB_URL=YOUR_DB_URL
export DB_DRIVER=YOUR_DB_DRIVER
export DB_DIALECT=YOUR_DB_DIALECT
mvn clean package
```

[Astraios] is built on [Springboot](https://spring.io/projects/spring-boot) and has a built-in web container, which we
used maven to package into a jar file.

### Running the JAR Package

```bash
java -jar target/astraios-1.0-SNAPSHOT.jar
```

The webservice will run on port **8080**, and you will be able to see the data you inserted.

[Astraios]: https://paion-data.github.io/astraios/
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,35 @@ title: 配置

- **MODEL_PACKAGE_NAME**: 包含了所有 Elide JPA data model 的完全限定 Java 包路径名

(Elide) JPA DataStore
(Elide) JPA数据存储
---------------------

:::note

以下配置可以放置在名为 **jpadatastore.properties** 的配置文件中
以下配置可以放置在名为**jpadatastore.properties**的属性文件中

:::

- **DB_USER**: 持久化数据库用户名(需要具有读写权限)。
- **DB_PASSWORD**: 持久化数据库用户密码。
- **DB_URL**: 持久化数据库 URL,比如 "jdbc:mysql://localhost/elide?serverTimezone=UTC"。
- **DB_DRIVER**: SQL 数据库驱动类名,例如 "com.mysql.jdbc.Driver"。
- **DB_DIALECT**: SQL 数据库语法类名,例如 "org.hibernate.dialect.MySQLDialect"。
- **DB_USER**: 持久性数据库用户名(需要有读写权限)。
- **DB_PASSWORD**: 持久性数据库用户密码。
- **DB_URL**: 持久性数据库URL,如"jdbc:mysql://localhost/elide?serverTimezone=UTC"。
- **DB_DRIVER**: SQL数据库驱动类名,如"com.mysql.jdbc.Driver"。
- **DB_DIALECT**: SQL数据库方言名称,如"org.hibernate.dialect.MySQLDialect"。
- **HIBERNATE_HBM2DDL_AUTO**: Web服务启动时对现有JPA数据库的处理方式;可以是四个值之一:

[Java 系统属性]: https://docs.oracle.com/javase/tutorial/essential/environment/sysprop.html
1. _validate_: 验证模式是否匹配,不对数据库的模式做任何更改。_这是**HIBERNATE_HBM2DDL_AUTO**的默认值_
2. _update_: 更新模式以反映要持久化的实体
3. _create_: 为您的实体创建必要的模式,销毁以前的任何数据。
4. _create-drop_: 如同在create中一样创建模式,但在会话结束时也删除模式。这非常适合开发或测试。

[操作系统的环境变量]: https://docs.oracle.com/javase/tutorial/essential/environment/env.html
:::note

此属性与[Hibernate `hibernate.hbm2ddl.auto`属性]完全相同。

:::

[Hibernate `hibernate.hbm2ddl.auto`属性]: https://stackoverflow.com/questions/18077327/hibernate-hbm2ddl-auto-possible-values-and-what-they-do

[Java系统属性]: https://docs.oracle.com/javase/tutorial/essential/environment/sysprop.html

[操作系统环境变量]: https://docs.oracle.com/javase/tutorial/essential/environment/env.html
159 changes: 159 additions & 0 deletions docs/i18n/zh-cn/docusaurus-plugin-content-docs/current/deployment.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
---
sidebar_position: 5
title: 部署
description: Astraios 部署指南
---

[//]: # (Copyright 2024 Paion Data)

[//]: # (Licensed under the Apache License, Version 2.0 &#40;the "License"&#41;;)
[//]: # (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.)

本节讨论如何在生产环境中部署[Astraios]

准备在生产环境上开发
-----------------

### 安装Java(在Ubuntu上)

```bash
sudo apt update
sudo apt install openjdk-17-jdk
```

在最后一个命令提示符的末尾,将显示如下内容:

```bash
The following additional packages will be installed:
...
Suggested packages:
...
The following NEW packages will be installed:
...
Need to get 170 MB of archives.
After this operation, 877 MB of additional disk space will be used.
Do you want to continue? [Y/n]
```

输入`Y`完成安装。

:::

如果在输入查看版本的命令后看到类似内容,则表示一切正常

```bash
$ java -version
openjdk version "17.0.11" 2024-04-16
OpenJDK Runtime Environment (build 17.0.11+9-Ubuntu-120.04.2)
OpenJDK 64-Bit Server VM (build 17.0.11+9-Ubuntu-120.04.2, mixed mode, sharing)
```

### 安装Maven

```bash
sudo apt install maven
```

在最后一个命令提示符的末尾,将显示如下内容:

```bash
The following additional packages will be installed:
...
Suggested packages:
...
The following NEW packages will be installed:
...
Need to get 9,657 kB of archives.
After this operation, 12.6 MB of additional disk space will be used.
Do you want to continue? [Y/n]
```

输入`Y`完成安装。

:::

如果在输入查看版本的命令后看到类似内容,则表示一切正常

```bash
$ mvn -version
Apache Maven 3.6.3
Maven home: /usr/share/maven
Java version: 17.0.11, vendor: Ubuntu, runtime: /usr/lib/jvm/java-17-openjdk-amd64
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "5.4.0-182-generic", arch: "amd64", family: "unix"
```

在这个的例子中,Maven 显然正在使用正确的 JDK,因此不需要额外设置 JAVA_HOME 环境变量。然而,如果你希望明确设置 JAVA_HOME,或者在某些情况下
(例如,当有多个 JDK 安装时)确保 Maven 总是使用特定的 JDK 17,你可以在你的 shell 配置文件(如 .bashrc, .zshrc 或 .profile)中添加以
下行:

```bash
export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64
```

### 加载数据模型

```bash
git clone git@github.com:paion-data/astraios-data-models-example.git
cd astraios-data-models-example
mvn clean install
```

现在我们已经将model安装到了本地,我们需要让astraios 通过maven配置文件来读取安装的model,在 **~/.m2/settings.xml** 下添加以下配置信息:

```xml
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
http://maven.apache.org/xsd/settings-1.0.0.xsd">

<profiles>
<profile>
<id>astraios-data-models</id>
<properties>
<model.package.jar.group.id>com.paiondata</model.package.jar.group.id>
<model.package.jar.artifact.id>astraios-data-models-example</model.package.jar.artifact.id>
<model.package.jar.version>1.0.0</model.package.jar.version>
</properties>
</profile>
</profiles>

<activeProfiles>
<activeProfile>astraios-data-models</activeProfile>
</activeProfiles>
</settings>
```

### 打包Astraios

```bash
git clone git@github.com:paion-data/astraios.git
export MODEL_PACKAGE_NAME=com.paiondata.astraios.data.models
export DB_USER=YOUR_DB_USER
export DB_PASSWORD=YOUR_DB_PASSWORD
export DB_URL=YOUR_DB_URL
export DB_DRIVER=YOUR_DB_DRIVER
export DB_DIALECT=YOUR_DB_DIALECT
mvn clean package
```

[Astraios][Springboot](https://spring.io/projects/spring-boot)构建,并具有内置Web容器,我们使用maven将其打包成jar文件。

### 运行JAR包

```bash
java -jar target/astraios-1.0-SNAPSHOT.jar
```

服务将在端口**8080**上运行,您将能够看到您插入的数据。

[Astraios]: https://paion-data.github.io/astraios/

0 comments on commit 15c1eb5

Please sign in to comment.