如何在Debian 9上安装WildFly(JBoss)
WildFly(以前称为JBoss)是用Java编写的跨平台开源应用程序运行时,可帮助您构建出色的应用程序。 WildFly灵活,轻便,它基于可插入子系统,可以根据需要添加或删除该子系统。
在本教程中,我们将引导您完成在Debian 9上安装WildFly应用程序服务器所需的步骤。
先决条件
您登录后的用户必须具有sudo特权才能安装软件包。
安装Java OpenJDK#
WildFly需要安装Java。 我们将安装OpenJDK,这是Debian 9中的默认Java开发和运行时:
sudo apt update
sudo apt install default-jdk
创建用户编号
创建一个新的系统用户和组,名为 wildfly
带有主目录 /opt/wildfly
它将运行WildFly服务:
sudo groupadd -r wildfly
sudo useradd -r -g wildfly -d /opt/wildfly -s /sbin/nologin wildfly
安装WildFly#
在撰写本文时,WildFly的最新版本是 16.0.0
。 在继续下一步之前,您应该检查下载页面以获取新版本。 如果有新版本,请更换 WILDFLY_VERSION
以下命令中的变量。
在以下位置下载WildFly归档文件: /tmp
使用以下目录 wget
命令:
WILDFLY_VERSION=16.0.0.Final
wget https://download.jboss.org/wildfly/$WILDFLY_VERSION/wildfly-$WILDFLY_VERSION.tar.gz -P /tmp
下载完成后,解压缩tar.gz文件并将其移至 /opt
目录:
sudo tar xf /tmp/wildfly-$WILDFLY_VERSION.tar.gz -C /opt/
创建一个符号链接 wildfly
它将指向WildFly安装目录:
sudo ln -s /opt/wildfly-$WILDFLY_VERSION /opt/wildfly
WildFly作为 wildfly
需要访问WildFly安装目录的用户。 将目录所有权更改为用户和组 wildfly
:
sudo chown -RH wildfly: /opt/wildfly
配置系统编号
WildFly软件包包括将WildFly作为服务运行所需的文件。
首先创建一个目录,其中将包含WildFly配置文件:
sudo mkdir -p /etc/wildfly
将配置文件复制到 /etc/wildfly
目录:
sudo cp /opt/wildfly/docs/contrib/scripts/systemd/wildfly.conf /etc/wildfly/
该文件允许您指定WildFly模式和绑定地址。 默认情况下,WildFly将以独立模式运行,并将在所有接口上侦听。 根据需要编辑文件。
/etc/wildfly/wildfly.conf
# The configuration you want to run
WILDFLY_CONFIG=standalone.xml
# The mode you want to run
WILDFLY_MODE=standalone
# The address to bind to
WILDFLY_BIND=0.0.0.0
接下来,复制WildFly launch.sh
脚本 /opt/wildfly/bin/
目录:
sudo cp /opt/wildfly/docs/contrib/scripts/systemd/launch.sh /opt/wildfly/bin/
里面的脚本 bin
目录需要具有可执行标志:
sudo sh -c 'chmod +x /opt/wildfly/bin/*.sh'
最后一步是将名为systemd的单位文件复制到 /etc/systemd/system/
目录:
sudo cp /opt/wildfly/docs/contrib/scripts/systemd/wildfly.service /etc/systemd/system/
重新加载systemd Manager配置:
sudo systemctl daemon-reload
启动并启用WildFly服务以在启动时自动启动:
sudo systemctl start wildfly
sudo systemctl enable wildfly
使用以下命令检查服务状态:
sudo systemctl status wildfly
* wildfly.service - The WildFly Application Server
Loaded: loaded (/etc/systemd/system/wildfly.service; disabled; vendor preset: enabled)
Active: active (running) since Sun 2019-02-17 04:59:39 PST; 2s ago
Main PID: 10005 (launch.sh)
Tasks: 62 (limit: 2319)
CGroup: /system.slice/wildfly.service
调整防火墙#
如果您的服务器受防火墙保护,并且您想从本地网络外部访问WildFly接口,则需要打开端口 8080
。
允许端口上的流量 8080
键入以下命令:
sudo ufw allow 8080/tcp
在生产环境中运行WildFly应用程序时,很可能您将拥有负载平衡器或反向代理,并且最佳做法是将对端口8080的访问限制为仅对内部网络的访问。
配置WildFly身份验证#
现在已安装并运行WildFly,下一步是创建一个用户,该用户将能够使用管理控制台或使用CLI进行远程连接。
要添加新用户,请使用 add-user.sh
位于WildFly的bin目录中的脚本:
sudo /opt/wildfly/bin/add-user.sh
系统将询问您要添加哪种类型的用户:
What type of user do you wish to add?
a) Management User (mgmt-users.properties)
b) Application User (application-users.properties)
(a):
选择 a
并击中 Enter
:
接下来,脚本将提示您输入新用户的详细信息:
Enter the details of the new user to add.
Using realm 'ManagementRealm' as discovered from the existing property files.
Username : linuxize
Password recommendations are listed below. To modify these restrictions edit the add-user.properties configuration file.
- The password should be different from the username
- The password should not be one of the following restricted values {root, admin, administrator}
- The password should contain at least 8 characters, 1 alphabetic character(s), 1 digit(s), 1 non-alphanumeric symbol(s)
Password :
Re-enter Password :
What groups do you want this user to belong to? (Please enter a comma separated list, or leave blank for none)[ ]:
About to add user 'linuxize' for realm 'ManagementRealm'
Is this correct yes/no? yes
Added user 'linuxize' to file '/opt/wildfly-16.0.0.Final/standalone/configuration/mgmt-users.properties'
Added user 'linuxize' to file '/opt/wildfly-16.0.0.Final/domain/configuration/mgmt-users.properties'
Added user 'linuxize' with groups to file '/opt/wildfly-16.0.0.Final/standalone/configuration/mgmt-groups.properties'
Added user 'linuxize' with groups to file '/opt/wildfly-16.0.0.Final/domain/configuration/mgmt-groups.properties'
Is this new user going to be used for one AS process to connect to another AS process?
e.g. for a slave host controller connecting to the master or for a Remoting connection for server to server EJB calls.
yes/no? yes
To represent the user add the following to the server-identities definition <secret value="UGFuMjNkZWo3NyNA" />
新用户将被添加到用于身份验证的属性文件中。
测试WildFly安装#
要访问默认的WildFly页面,请打开浏览器并输入: http://<your_domain_or_IP_address>:8080
假设安装成功,将出现类似以下的屏幕:
访问WildFly管理控制台#
命令行界面
要从命令行访问WildFly管理控制台,您可以使用 jboss-cli.sh
脚本。
导航到WildFly的bin目录,然后使用 --connect
选项:
cd /opt/wildfly/bin/
./jboss-cli.sh --connect
系统将要求您输入您的管理用户名和密码(在步骤6中创建):
Authenticating against security realm: ManagementRealm
Username: linuxize
Password:
登录后,控制台提示将变为 [[email protected]:9990 /]
。 类型 help
获取命令和命令语法的列表。
从这里,您可以部署和取消部署应用程序,管理用户和组以及配置和监视WildFly服务器。
Web界面编号
如果您希望通过GUI管理服务器,WildFly还提供了一个基于Web的控制台。
默认情况下,WildFly管理控制台仅可从localhost访问: http://localhost:9990/console
。 使用您在步骤6中创建的用户登录。
如果您想从远程位置访问控制台,则需要对 wildfly.service
, wildfly.conf
和 launch.sh
文件。
打开 wildfly.conf
并追加 WILDFLY_CONSOLE_BIND=0.0.0.0
在文件末尾。
/etc/wildfly/wildfly.conf
# The configuration you want to run
WILDFLY_CONFIG=standalone.xml
# The mode you want to run
WILDFLY_MODE=standalone
# The address to bind to
WILDFLY_BIND=0.0.0.0
# The address console to bind to
WILDFLY_CONSOLE_BIND=0.0.0.0
打开 launch.sh
并编辑突出显示的行:
/opt/wildfly/bin/launch.sh
#!/bin/bash
if [ "x$WILDFLY_HOME" = "x" ]; then
WILDFLY_HOME="/opt/wildfly"
fi
if [[ "$1" == "domain" ]]; then
$WILDFLY_HOME/bin/domain.sh -c $2 -b $3 -bmanagement $4
else
$WILDFLY_HOME/bin/standalone.sh -c $2 -b $3 -bmanagement $4
fi
重新启动服务以使更改生效:
sudo systemctl restart wildfly
打开 wildfly.service
并编辑突出显示的行:
/etc/systemd/system/wildfly.service
[Unit]
Description=The WildFly Application Server
After=syslog.target network.target
Before=httpd.service
[Service]
Environment=LAUNCH_JBOSS_IN_BACKGROUND=1
EnvironmentFile=-/etc/wildfly/wildfly.conf
User=wildfly
LimitNOFILE=102642
PIDFile=/var/run/wildfly/wildfly.pid
ExecStart=/opt/wildfly/bin/launch.sh $WILDFLY_MODE $WILDFLY_CONFIG $WILDFLY_BIND $WILDFLY_CONSOLE_BIND
StandardOutput=null
[Install]
WantedBy=multi-user.target
创建 /var/run/wildfly
目录并设置正确的权限:
sudo mkdir /var/run/wildfly/
sudo chown wildfly: /var/run/wildfly/
重新加载systemd Manager配置:
sudo systemctl daemon-reload
通过运行以下命令重新启动WildFly服务:
sudo systemctl restart wildfly
假设您的防火墙没有阻塞端口 9990
,您应该可以在以下位置访问WildFly管理控制台 http://<your_domain_or_IP_address>:9990/console
。
结论#
您已经在Debian 9服务器上成功安装了WildFly。 您应该访问WildFly官方文档并了解有关WildFly功能的更多信息。
如果您遇到问题或有反馈,请在下面发表评论。
Java Wildfly Debian