第 2 章 启动和停止 Apache Karaf

摘要

Apache Karaf 提供简单的命令行工具,用于启动和停止服务器。

2.1. 启动 Apache Karaf

部署 Apache Karaf 运行时的默认方法是将它部署为具有活跃控制台的单机服务器。您还可以在不控制台的情况下将运行时部署为后台进程。

2.1.1. 设置您的环境

您可以直接从安装的 bin 子目录中启动 Karaf 运行时,而无需修改您的环境。但是,如果您要在不同的文件夹中启动它,则需要将 glibc 安装的 bin 目录添加到 PATH 环境变量中,如下所示:

Windows

set PATH=%PATH%;InstallDir\bin

Linux/UNIX

export PATH=$PATH,InstallDir/bin`

2.1.2. 以控制台模式启动运行时

如果您要从安装目录中启动 Quarkus 运行时,请使用以下命令:

Windows

bin\fuse.bat

Linux/UNIX

./bin/fuse

如果 Karaf 启动正确,您应该在控制台中看到以下内容:

Red Hat Fuse starting up. Press Enter to open the shell now...
100% [========================================================================]

Karaf started in 8s. Bundle stats: 220 active, 220 total

 ____          _   _   _       _     _____
|  _ \ ___  __| | | | | | __ _| |_  |  ___|   _ ___  ___
| |_) / _ \/ _` | | |_| |/ _` | __| | |_ | | | / __|/ _ \
|  _ <  __/ (_| | |  _  | (_| | |_  |  _|| |_| \__ \  __/
|_| \_\___|\__,_| |_| |_|\__,_|\__| |_|   \__,_|___/___|

  Fuse (7.x.x.fuse-xxxxxx-redhat-xxxxx)
  http://www.redhat.com/products/jbossenterprisemiddleware/fuse/

Hit '<tab>' for a list of available commands
and '[cmd] --help' for help on a specific command.

Open a browser to http://localhost:8181/hawtio to access the management console

Hit '<ctrl-d>' or 'shutdown' to shutdown Red Hat Fuse.

karaf@root()>
注意

自 Fuse 6.2.1 起,启动控制台模式会创建两个进程:父进程 ./bin/karaf,即执行 Karaf 控制台;以及子进程,它在 java JVM 中执行 Karaf 服务器。但是,关闭的行为与以前相同。也就是说,您可以使用 Ctrl-D 或 osgi:shutdown 从控制台关闭服务器,从而终止这两个进程。

2.1.3. 以服务器模式启动运行时

在服务器模式中启动,可在后台运行 Apache Karaf,无需本地控制台。然后,您要使用远程控制台连接到正在运行的实例。详情请查看 第 17.2 节 “在远程连接和断开连接”

要在服务器模式中启动 Karaf,请运行以下命令

Windows

bin\start.bat

Linux/UNIX

./bin/start

2.1.4. 以客户端模式启动运行时

在生产环境中,您可能希望仅使用本地控制台访问运行时实例。换句话说,您无法通过 SSH 控制台端口远程连接到运行时。您可以使用以下命令在客户端模式中启动运行时:

Windows

bin\fuse.bat client

Linux/UNIX

./bin/fuse client
注意

在客户端模式中启动仅阻止 SSH 控制台端口(通常是端口 8101)。其他 Karaf 服务器端口(例如,JMX 管理 RMI 端口)正常打开。

2.1.5. 在 debug 模式下运行 Fuse

在调试模式下运行 Fuse 有助于更有效地识别和解决错误。默认禁用这个选项。启用之后,Fuse 在端口 5005 上启动 JDWP 套接字。

您可以通过三种方法 在调试模式下运行 Fuse。

2.1.5.1. 使用 Karaf 环境变量

这个方法启用 KARAF_DEBUG 环境变量(=1),然后启动容器。

$ export KARAF_DEBUG=1
$ bin/start

2.1.5.2. 运行 Fuse debug

此方法运行 debug,其中 suspend 选项设置为 n (无)。

$ bin/fuse debug

2.1.5.3. 运行 Fuse debugs

此方法运行 debug,其中 suspend 选项设置为 y (是)。

注意

suspend 设为 yes 会导致 JVM 仅在运行 main() 之前暂停,然后它会恢复执行。

$ bin/fuse debugs