安卓系统

如何在Ubuntu 18.04上安装Wildfly(jboss)

Wildfly installation in Amazon EC2 instance

Wildfly installation in Amazon EC2 instance

目录:

Anonim

WildFly(以前称为JBoss)是用Java编写的跨平台开源应用程序运行时,可帮助您构建出色的应用程序。 WildFly灵活,轻便,并且基于可根据需要添加或删除的可插拔子系统。

本教程将向您展示如何在Ubuntu 18.04上安装WildFly应用程序服务器。 相同的说明适用于Ubuntu 16.04和任何基于Ubuntu的发行版,包括Kubuntu,Linux Mint和Elementary OS。

先决条件

为了能够在Ubuntu系统上安装软件包,您必须以具有sudo特权的用户身份登录。

步骤1:安装Java OpenJDK

WildFly需要安装Java。 我们将安装OpenJDK,这是Ubuntu 18.04中的默认Java开发和运行时。

Java的安装非常简单。 首先更新包索引:

sudo apt update

通过运行以下命令安装OpenJDK软件包:

sudo apt install default-jdk

步骤2:建立使用者

我们将使用主目录 /opt/wildfly 创建一个名为 wildfly 的新系统用户和组,该用户和组将运行WildFly服务:

sudo groupadd -r wildfly sudo useradd -r -g wildfly -d /opt/wildfly -s /sbin/nologin wildfly

步骤3:安装WildFly

在撰写本文时,WildFly的最新版本是 16.0.0 。 在继续下一步之前,您应该检查下载页面是否有新版本。 如果有新版本, WILDFLY_VERSION 在下面的命令中替换 WILDFLY_VERSION 变量。

使用以下 wget 命令在 /tmp 目录中下载WildFly存档:

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 用户下运行。

以下命令会将目录所有权更改为user和group wildfly

sudo chown -RH wildfly: /opt/wildfly

步骤4:配置Systemd

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我们创建了一个新的单位文件:

sudo systemctl daemon-reload

通过执行以下命令来启动WildFly服务:

sudo systemctl start 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

使服务在引导时自动启动:

sudo systemctl enable wildfly

步骤5:调整防火墙

如果服务器受防火墙保护,并且您想从本地网络外部访问WildFly接口,则需要打开端口 8080

要允许端口 8080 上的流量输入以下命令:

sudo ufw allow 8080/tcp 在生产环境中运行WildFly应用程序时,很可能您将具有负载平衡器或反向代理,并且最佳做法是将对端口8080的访问限制为仅对内部网络的访问。

步骤6:配置WildFly身份验证

现在已安装并运行WildFly,下一步是创建一个用户,该用户将能够使用管理控制台或使用CLI进行远程连接。

要添加新用户,请使用位于WildFly的bin目录中的 add-user.sh 脚本:

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? eg 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

新用户将被添加到用于身份验证的属性文件中。

步骤6:测试WildFly安装

要访问默认的WildFly页面,请打开浏览器并输入: http://:8080 http://:8080

假设安装成功,将出现类似以下的屏幕:

打开 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; then WILDFLY_HOME="/opt/wildfly" fi if]; 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

Description=The WildFly Application Server After=syslog.target network.target Before=httpd.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 WantedBy=multi-user.target

创建 /var/run/wildfly 目录并设置正确的权限:

sudo mkdir /var/run/wildfly/ sudo chown wildfly: /var/run/wildfly/

通知systemd单元文件已更改:

sudo systemctl daemon-reload

通过执行以下命令重新启动WildFly服务:

sudo systemctl restart wildfly

假设您的防火墙没有阻止端口 9990 ,您应该能够通过以下网址访问WildFly管理控制台 http://:9990/console http://:9990/console

结论

您已在Ubuntu 18.04系统上成功安装WildFly。 现在,您可以访问WildFly官方文档并了解有关WildFly功能的更多信息。

java Wildfly Ubuntu