forked from apache/dubbo-website
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
88 changed files
with
1,238 additions
and
2,277 deletions.
There are no files selected for viewing
138 changes: 138 additions & 0 deletions
138
content/zh-cn/overview/mannual/java-sdk/quick-start/deploy.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
--- | ||
description: 快速部署Dubbo应用 | ||
linkTitle: 快速部署Dubbo应用 | ||
title: 快速部署Dubbo应用 | ||
type: docs | ||
weight: 3 | ||
--- | ||
|
||
在上一篇文章中,我们从头创建了一个 Dubbo 应用并详细介绍了它的代码结构,接下来,我们将学习部署这个 Dubbo 应用。 | ||
|
||
本文将以 Kubernetes 集群作为基础环境来讲解 Dubbo 应用的部署,部署架构如下图所示。 | ||
![Dubbo+Kubernetes+Nacos 部署架构图]() | ||
|
||
{{% alert title="注意" color="info" %}} | ||
在实际使用中,部署环境可能变化多样,包括 Kubernetes Service、服务网格(Service Mesh)、虚拟机等多种部署模式,请参考 [部署文档]() 了解更多详细内容。 | ||
{{% /alert %}} | ||
|
||
## 前置条件 | ||
Dubbo 社区提供了工具和解决方案来简化整个 Kubernetes 环境的打包与部署过程,所以开始前我们需要先安装相关工具。 | ||
|
||
1. 安装 dubboctl(如尚未安装) | ||
```sh | ||
curl -L https://dubbo.apache.org/downloadDubbo.sh | sh - | ||
|
||
cd dubbo-$version | ||
export PATH=$PWD/bin:$PATH | ||
``` | ||
|
||
|
||
|
||
## 部署应用 | ||
|
||
### 初始化微服务集群 | ||
|
||
1. dubboctl 安装完成之后,接下来通过以下命令初始化微服务部署环境 | ||
|
||
```sh | ||
dubboctl manifest install --profile=demo | ||
``` | ||
|
||
作为示例用途,以上命令会一键安装 Zookeeper、Dubbo Control Plane、Prometheus、Grafana、Zipkin、Ingress 等组件,关于 `--profile=demo` 更多解释及可选值请参见文档说明。 | ||
|
||
2. 检查环境准备就绪 | ||
|
||
```sh | ||
kubectl get services -n dubbo-system | ||
``` | ||
|
||
3. 最后,为目标 kubernetes namespace 开启自动注入模式,以便应用部署后能够自动连接到刚刚安装的 Zookeeper 注册中心等组件。 | ||
|
||
```shell | ||
kubectl label namespace dubbo-demo dubbo-injection=enabled --overwrite | ||
``` | ||
|
||
### 部署 Dubbo 应用 | ||
|
||
接下来我们为之前创建的应用打包镜像(请确保本地安装有 Docker 环境并且已经启动 Docker 进程),在应用根目录分别运行以下命令: | ||
|
||
```shell | ||
dubboctl build --dockerfile=./Dockerfile | ||
``` | ||
|
||
`build` 命令会将源码打包为镜像,并推送到远端仓库,取决于网络情况,可能需要一定时间等待命令执行完成。 | ||
|
||
接下来,我们需要生成部署应用的 Kubernetes 资源文件,运行以下命令: | ||
```shell | ||
dubboctl deploy | ||
``` | ||
|
||
`deploy` 命令会使用刚刚 `build` 打包的镜像生成 Kubernetes 资源清单。命令执行成功后,在当前目录看到生成的 `kube.yaml` 文件,其中包括 deployment、service 等 kubernetes 资源定义。 | ||
|
||
|
||
{{% alert title="注意" color="warning" %}} | ||
本地构建可能会花费比较长时间,如您本地构建遇到问题,也可以使用以下命令跳过 `build` 过程。 | ||
|
||
```sh | ||
dubboctl deploy --image=apache/dubbo-demo:quickstart_0.1 | ||
# `--image` 指定使用官方预先准备好的示例镜像 | ||
``` | ||
{{% /alert %}} | ||
|
||
接下来,将应用部署到 Kubernetes 环境。 | ||
|
||
```shell | ||
kubectl apply -f ./kube.yaml | ||
``` | ||
|
||
检查部署状态 | ||
```shell | ||
kubectl get services -n dubbo-demo | ||
``` | ||
|
||
## 访问应用 | ||
部署成功后,可以通过以下方式检查应用状态。 | ||
|
||
{{< tabpane text=true >}} | ||
{{< tab header="请根据情况选择:" disabled=true />}} | ||
{{% tab header="本地 Kubernetes 集群" lang="en" %}} | ||
<br/> | ||
|
||
1. 如果使用的本地 Kubernetes 集群,请使用以下方式访问应用验证部署状态: | ||
|
||
```shell | ||
dubboctl dashboard admin | ||
``` | ||
|
||
2. 以上命令会自动打开 admin 控制台,如果在您的环境下没有打开,请使用浏览器访问以下地址: | ||
|
||
http://localhost:38080/admin | ||
|
||
3. 通过 triple 协议,可以继续测试 Dubbo 服务,执行以下命令进行端口映射: | ||
|
||
```shell | ||
kubectl port-forward <pod-name> 50051:50051 | ||
``` | ||
|
||
4. 通过 curl 访问服务: | ||
|
||
```shell | ||
curl \ | ||
--header "Content-Type: application/json" \ | ||
--data '["Dubbo"]' \ | ||
http://localhost:50051/com.example.demo.dubbo.api.DemoService/sayHello/ | ||
``` | ||
|
||
{{% /tab %}} | ||
|
||
{{% tab header="阿里云ACK" lang="zh-cn" %}} | ||
<br/> | ||
|
||
对于云上托管的哦 Kubernetes 集群,可以使用以下方式验证,这里以阿里云 ACK 集群为例: | ||
|
||
ACK ingerss-controller 的访问方式...... | ||
|
||
{{% /tab %}} | ||
{{< /tabpane >}} | ||
|
||
|
7 changes: 0 additions & 7 deletions
7
content/zh-cn/overview/mannual/java-sdk/quick-start/microservice/_index.md
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
224 changes: 224 additions & 0 deletions
224
content/zh-cn/overview/mannual/java-sdk/tasks/graalvm/_index.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,224 @@ | ||
--- | ||
aliases: | ||
- /zh/docs3-v2/java-sdk/reference-manual/graalvm/ | ||
- /zh-cn/docs3-v2/java-sdk/reference-manual/graalvm/ | ||
description: "" | ||
hide_summary: true | ||
linkTitle: Dubbo 集成 Graalvm参考手册 | ||
title: Dubbo 集成 Graalvm参考手册 | ||
toc_hide: true | ||
type: docs | ||
weight: 9 | ||
--- | ||
|
||
|
||
|
||
|
||
|
||
|
||
dubbo3.0支持native-image文档 | ||
|
||
## 概述 | ||
|
||
本文档将介绍将dubbo3.0项目接入GraalVM,进行native-image编译为二进制的流程。 | ||
|
||
关于GraalVm的更多信息可以阅读 https://www.graalvm.org/docs/getting-started/container-images/ 此文档。 | ||
|
||
## 使用样例 | ||
|
||
在编译我们的dubbo项目之前,需要确保我们正基于graalVm的环境。 | ||
|
||
1. 安装GraalVM | ||
|
||
进入https://www.graalvm.org/ 官网根据自己的系统选取最新版本安装: | ||
|
||
![img](/imgs/blog/dubbo3.0-graalvm-support/graalvmgw.jpg) | ||
|
||
安装完成后,修改配置JAVA_HOME的路径,生效后查看本地jdk可以看到如下: | ||
|
||
![img](/imgs/blog/dubbo3.0-graalvm-support/graalvm_env.jpg) | ||
这里我们使用的基于jdk1.8版本的GraalVM。 | ||
|
||
- 安装native-image,只需执行gu install native-image即可。 | ||
|
||
1. 拉取dubbo代码,切换到[apache:3.0](https://github.com/apache/dubbo)分支。 | ||
2. 手动执行生成SPI代码。 | ||
|
||
由于目前编译native-image不支持代码动态生成编译,所以有关代码动态生成的部分需要我们手动先生成,这里提供了工具函数: | ||
|
||
![img](/imgs/blog/dubbo3.0-graalvm-support/code_generator.jpg) | ||
执行CodeGenerator即可在dubbo-native模块下生成SPI代码。 | ||
|
||
1. 在根目录下执行install | ||
|
||
``` | ||
MacdeMacBook-pro-3:incubator-dubbo mac$ pwd | ||
/Users/mac/Documents/Mi/project/incubator-dubbo | ||
MacdeMacBook-pro-3:incubator-dubbo mac$ mvn clean package install -Dmaven.test.skip=true | ||
``` | ||
|
||
1. 编译demo项目 | ||
|
||
这里我们提供了可直接进行编译的示例项目,dubbo-demo/dubbo-demo-native。上面步骤install完成后,先到dubbo-demo-native的provider下,执行native-image编译: | ||
|
||
``` | ||
mvn clean package -P native -Dmaven.test.skip=true | ||
``` | ||
|
||
这里由于我们在maven中引入了native-image插件,所以直接-P native即可执行该插件。 | ||
|
||
![img](/imgs/blog/dubbo3.0-graalvm-support/native_image_build.jpg) | ||
编译成功后可以在target下看到已经生成的二进制文件,本地启动一个zookeeper,直接执行该二进制,可见启动成功如下: | ||
|
||
![img](/imgs/blog/dubbo3.0-graalvm-support/run_provider.jpg) | ||
consumer端同样执行编译,在consumer的target下也会生成二进制文件:demo-native-consumer,执行该二进制可以看到调用结果如下: | ||
|
||
![img](/imgs/blog/dubbo3.0-graalvm-support/run_consumer.jpg) | ||
### 具体步骤 | ||
|
||
实际上在这个demo下我们做了一些工作来确保项目可以编译执行,主要有以下几个步骤 | ||
|
||
- 引入dubbo-native依赖 | ||
|
||
``` | ||
<dependency> | ||
<groupId>org.apache.dubbo</groupId> | ||
<artifactId>dubbo-native</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
``` | ||
|
||
该模块下有我们生成的SPI代码。 | ||
|
||
- 引入native-image插件 | ||
|
||
``` | ||
<plugin> | ||
<groupId>org.graalvm.nativeimage</groupId> | ||
<artifactId>native-image-maven-plugin</artifactId> | ||
<version>21.0.0.2</version> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>native-image</goal> | ||
</goals> | ||
<phase>package</phase> | ||
</execution> | ||
</executions> | ||
<configuration> | ||
<skip>false</skip> | ||
<imageName>demo-native-provider</imageName> | ||
<mainClass>org.apache.dubbo.demo.graalvm.provider.Application</mainClass> | ||
<buildArgs> | ||
--no-fallback | ||
--initialize-at-build-time=org.slf4j.MDC | ||
--initialize-at-build-time=org.slf4j.LoggerFactory | ||
--initialize-at-build-time=org.slf4j.impl.StaticLoggerBinder | ||
--initialize-at-build-time=org.apache.log4j.helpers.Loader | ||
--initialize-at-build-time=org.apache.log4j.Logger | ||
--initialize-at-build-time=org.apache.log4j.helpers.LogLog | ||
--initialize-at-build-time=org.apache.log4j.LogManager | ||
--initialize-at-build-time=org.apache.log4j.spi.LoggingEvent | ||
--initialize-at-build-time=org.slf4j.impl.Log4jLoggerFactory | ||
--initialize-at-build-time=org.slf4j.impl.Log4jLoggerAdapter | ||
--initialize-at-build-time=org.eclipse.collections.api.factory.Sets | ||
--initialize-at-run-time=io.netty.channel.epoll.Epoll | ||
--initialize-at-run-time=io.netty.channel.epoll.Native | ||
--initialize-at-run-time=io.netty.channel.epoll.EpollEventLoop | ||
--initialize-at-run-time=io.netty.channel.epoll.EpollEventArray | ||
--initialize-at-run-time=io.netty.channel.DefaultFileRegion | ||
--initialize-at-run-time=io.netty.channel.kqueue.KQueueEventArray | ||
--initialize-at-run-time=io.netty.channel.kqueue.KQueueEventLoop | ||
--initialize-at-run-time=io.netty.channel.kqueue.Native | ||
--initialize-at-run-time=io.netty.channel.unix.Errors | ||
--initialize-at-run-time=io.netty.channel.unix.IovArray | ||
--initialize-at-run-time=io.netty.channel.unix.Limits | ||
--initialize-at-run-time=io.netty.util.internal.logging.Log4JLogger | ||
--initialize-at-run-time=io.netty.channel.unix.Socket | ||
--initialize-at-run-time=io.netty.channel.ChannelHandlerMask | ||
--report-unsupported-elements-at-runtime | ||
--allow-incomplete-classpath | ||
--enable-url-protocols=http | ||
-H:+ReportExceptionStackTraces | ||
</buildArgs> | ||
</configuration> | ||
</plugin> | ||
``` | ||
|
||
其中定义了生成的镜像名以及一些构建镜像的参数。 | ||
|
||
- 挂载native-image-agent | ||
|
||
由于我们需要将一些反射、JNI等类先指定出来,我们需要先使用该agent以正常方式运行一遍生成这些类的json形式的信息。 | ||
|
||
在启动参数中添加: | ||
|
||
``` | ||
-agentlib:native-image-agent=config-output-dir=/tmp/config/,config-write-period-secs=300,config-write-initial-delay-secs=5 | ||
``` | ||
|
||
以正常方式启动,在项目的resources下建立文件夹META-INF.native-image,把在本地目录中生成的文件粘进去: | ||
|
||
![img](/imgs/blog/dubbo3.0-graalvm-support/resources.jpg) | ||
(可能会有缺漏没有生成的类信息,需要根据编译或运行时的报错信息手动添加。) | ||
|
||
|
||
|
||
**完成以上几步后就可以进行项目的编译了。** |
Oops, something went wrong.