在CentOS 8/CentOS 7上安装WildFly(JBoss)服务器

时间:2020-02-23 14:30:56  来源:igfitidea点击:

在这篇文章中,我们将讨论在CentOS 8/CentOS 7上安装WildFly(JBoss)服务器的步骤。WildFly以前称为JBoss,是用Java编写并由Red Hat开发的应用程序服务器。它是Java Enterprise Edition 8 Platform规范的异常快速,轻巧和强大的实现。CentOS/RHEL 8或者CentOS/RHEL 7服务器Java运行时环境具有sudo或者root访问权限的用户服务器上的Internet连接

设置准备工作

运行WildFly Application Server的服务器上需要Java。使用下面的指南在CentOS/RHEL 7&8上安装Java。

安装Java

如何在RHEL/CentOS 8上安装Java 11(OpenJDK 11)

如何在CentOS 7上安装Java 11

如果要使用Java 8,只需运行以下命令进行安装。

我们可以使用以下方法检查计算机中的默认Java版本:

sudo yum install java-1.8.0-openjdk-devel

下载文件之前,请先检查WiWildFlyDownloads页面以获取最新版本。其中我们将下载WildFly18.0.1.Final

$java --version
openjdk version "11-ea" 2016-09-25
OpenJDK Runtime Environment (build 11-ea+28)
OpenJDK 64-Bit Server VM (build 11-ea+28, mixed mode, sharing)

下载WildFly

下载文件后,将其解压缩。

sudo yum -y install wget
export WILDFLY_RELEASE="18.0.1"
wget https://download.jboss.org/wildfly/$WILDFLY_RELEASE.Final/wildfly-$WILDFLY_RELEASE.Final.tar.gz

将生成的文件夹移至"/opt/wildfly"。

tar xvf wildfly-$WILDFLY_RELEASE.Final.tar.gz

现在让我们创建一个将运行WildFly服务的系统用户和组。

sudo mv wildfly-$WILDFLY_RELEASE.Final//opt/wildfly

为WildFly配置Systemd

创建WildFly配置目录。

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

从/opt/wildfly/docs/contrib/scripts/systemd /目录中复制WildFly systemd服务,配置文件和启动脚本模板。

sudo mkdir /etc/wildfly

设置"/opt/wildfly"权限。

sudo cp /opt/wildfly/docs/contrib/scripts/systemd/wildfly.conf /etc/wildfly/
sudo cp /opt/wildfly/docs/contrib/scripts/systemd/wildfly.service /etc/systemd/system/
sudo cp /opt/wildfly/docs/contrib/scripts/systemd/launch.sh /opt/wildfly/bin/
sudo chmod +x /opt/wildfly/bin/launch.sh

重新加载系统服务。

sudo chown -R wildfly:wildfly /opt/wildfly

配置SELinux:

sudo systemctl daemon-reload

启动并启用WildFly服务:

sudo semanage fcontext  -a -t bin_t  "/opt/wildfly/bin(/.*)?"
sudo restorecon -Rv /opt/wildfly/bin/

确认WildFly Application Server状态。

sudo systemctl start wildfly
sudo systemctl enable wildfly

服务应绑定到端口8080。

$systemctl status wildfly
 ● wildfly.service - The WildFly Application Server
    Loaded: loaded (/etc/systemd/system/wildfly.service; enabled; vendor preset: disabled)
    Active: active (running) since Wed 2019-04-03 16:22:58 EAT; 6s ago
  Main PID: 31303 (launch.sh)
     Tasks: 119 (limit: 11510)
    Memory: 330.8M
    CGroup: /system.slice/wildfly.service
            ├─31303 /bin/bash /opt/wildfly/bin/launch.sh standalone standalone.xml 0.0.0.0
            ├─31304 /bin/sh /opt/wildfly/bin/standalone.sh -c standalone.xml -b 0.0.0.0
            └─31396 java -D[Standalone] -server -Xms64m -Xmx512m -XX:MetaspaceSize=96M -XX:MaxMetaspaceSize=256m -Djava.net.preferIPv4Stack=true -Djbos>
 Apr 03 16:22:58 rhel8.local systemd[1]: Started The WildFly Application Server.

现在发布了WildFly 16,并为管理界面启用了安全性。我们需要创建一个可以访问WildFly管理控制台或者远程使用CLI的用户。提供了用于管理用户的脚本。

# ss -tunelp | grep 8080
tcp    LISTEN   0   128    0.0.0.0:8080  0.0.0.0:*  users:(("java",pid=6854,fd=389)) uid:999 ino:30339 sk:3 <->

添加WildFly用户

通过执行以下命令运行它:

系统将要求我们选择要添加的用户类型。由于这是第一个用户,因此我们要使其成为管理员。所以选择。

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):

设置用户密码:

Enter the details of the new user to add.
Using realm 'ManagementRealm' as discovered from the existing property files.
Username : theitroad

按Enter键并同意后续提示以完成用户创建。

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 : <Enter Password>
Re-enter Password :  <Confirm Password>

注意:

What groups do you want this user to belong to? (Please enter a comma separated list, or leave blank for none)[  ]: <Enter>
 About to add user 'theitroad' for realm 'ManagementRealm'
 Is this correct yes/no? yes
 Added user 'theitroad' to file '/opt/wildfly/standalone/configuration/mgmt-users.properties'
 Added user 'theitroad' to file '/opt/wildfly/domain/configuration/mgmt-users.properties'
 Added user 'theitroad' with groups  to file '/opt/wildfly/standalone/configuration/mgmt-groups.properties'
 Added user 'theitroad' with groups  to file '/opt/wildfly/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

用户信息保存在:/opt/wildfly/domain/configuration/mgmt-users.properties
组信息保留在:/opt/wildfly/standalone/configuration/mgmt-groups.properties

为了能够从当前的shell会话中运行WildFly脚本,请将/opt/wildfly/bin /添加到$PATH中。

访问WildFly管理控制台

源bashrc文件。

cat >> ~/.bashrc <<EOF
export WildFly_BIN="/opt/wildfly/bin/"
export PATH=$PATH:$WildFly_BIN                                                                                                                    
EOF

现在通过使用jboss-cli.sh命令从CLI连接到WildFly管理控制台进行测试。

source ~/.bashrc

默认情况下,可以在端口9990的本地主机IP上访问控制台。

# jboss-cli.sh --connect
[theitroad@localhost:9990 /] version
JBoss Admin Command-line Interface
JBOSS_HOME: /opt/wildfly
Release: 8.0.0.Final
Product: WildFly Full 16.0.0.Final
JAVA_HOME: /usr/lib/jvm/java-11-openjdk-11.0.ea.28-8.el8.x86_64
java.version: 11-ea
java.vm.vendor: Oracle Corporation
java.vm.version: 11-ea+28
os.name: Linux
os.version: 4.18.0-32.el8.x86_64

从Web界面访问WildFly管理控制台

我们可以从本地服务器外部访问的其他IP地址启动它。编辑/opt/wildfly/bin/launch.sh看起来像这样:

# ss -tunelp | grep 9990
tcp    LISTEN   0    50    127.0.0.1:9990  0.0.0.0:* users:(("java",pid=6769,fd=404)) uid:999 ino:30407 sk:3 <->

我们添加了-bmanagement = 0.0.0.0以开始脚本行。这会将管理接口绑定到所有可用的IP地址。

.....
if [[ "" == "domain" ]]; then
    $WILDFLY_HOME/bin/domain.sh -c  -b 
else
    $WILDFLY_HOME/bin/standalone.sh -c  -b  -bmanagement=0.0.0.0
fi

重新启动wildfly服务

确认

sudo systemctl restart wildfly

在防火墙上打开端口

$ss -tunelp | grep 9990
tcp    LISTEN   0  50     0.0.0.0:9990  0.0.0.0:*  users:(("java",pid=9496,fd=320)) uid:999 ino:73367 sk:c <->

打开浏览器和URL" http://serverip:9990"以访问WildFly Web控制台。

sudo firewall-cmd --permanent --add-port={8080,9990}/tcp
sudo firewall-cmd --reload

使用先前创建的用户名和密码进行身份验证。 WildFly控制台将显示在下一个窗口中。

我们已经在RHEL/CentOS 8/7上成功安装了WildFly Application Server。访问WildFly文档页面以进一步阅读。