如何在CentOS 7上安装WildFly(JBoss)
WildFly(以前称为JBoss)是用Java编写的跨平台开源应用程序运行时,可构建出色的应用程序。
WildFly是灵活,轻便的,并且基于可根据需要添加或者删除的可插拔子系统。
本教程说明了如何在CentOS 7上安装WildFly应用程序服务器。
准备工作
我们需要以具有sudo访问权限的用户身份登录才能在CentOS系统上安装软件包。
步骤1:安装Java OpenJDK
WildFly 9需要Java SE 8或者更高版本。
在本教程中,我们将安装OpenJDK,这是Java平台的开源实现,它是CentOS 7中的默认Java开发和运行时。
通过运行以下命令安装OpenJDK软件包:
sudo yum install java-1.8.0-openjdk-devel
步骤2:建立使用者
以root用户身份运行WildFly具有安全风险,因此不被视为最佳实践。
要使用主目录“/opt/wildfly”创建一个名为“ wildfly”的新系统用户和组,请运行:
sudo groupadd -r wildflysudo useradd -r -g wildfly -d /opt/wildfly -s /sbin/nologin wildfly
步骤3:安装WildFly
在撰写本文时,WildFly的最新版本为'16 .0.0'。
在继续下一步之前,我们应该检查下载页面以获取新版本。
如果有新版本,请在下面的命令中替换“ WILDFLY_VERSION”变量。
使用以下“ wget”命令将WildFly归档文件下载到“/tmp”目录中:
WILDFLY_VERSION=16.0.0.Finalwget 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”用户下运行。
使用以下chown命令将目录所有权更改为用户和组“ 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 wildflysudo systemctl enable wildfly
验证服务正在运行:
sudo systemctl status wildfly
● wildfly.service - The WildFly Application Server Loaded: loaded (/etc/systemd/system/wildfly.service; disabled; vendor preset: disabled) Active: active (running) since Fri 2019-03-01 20:13:39 UTC; 3s ago Main PID: 3680 (launch.sh) CGroup: /system.slice/wildfly.service
步骤5:调整防火墙
如果服务器受防火墙保护,并且我们想从本地网络的外部访问WildFly实例,则还需要打开端口8080。
使用以下命令打开必要的端口:
sudo firewall-cmd --zone=public --permanent --add-port=8080/tcpsudo firewall-cmd --reload
在生产环境中运行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 : theitroad 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 'theitroad' for realm 'ManagementRealm' Is this correct yes/no? yes Added user 'theitroad' to file '/opt/wildfly-16.0.0.Final/standalone/configuration/mgmt-users.properties' Added user 'theitroad' to file '/opt/wildfly-16.0.0.Final/domain/configuration/mgmt-users.properties' Added user 'theitroad' with groups to file '/opt/wildfly-16.0.0.Final/standalone/configuration/mgmt-groups.properties' Added user 'theitroad' 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"
新用户将被添加到用于身份验证的属性文件中。
步骤6:测试WildFly安装
要访问默认的WildFly页面,请打开浏览器并输入:'http://<域或者IP地址>:8080'
假设安装成功,将显示类似于以下内容的屏幕:
步骤7:访问WildFly管理控制台
命令行界面
要从命令行访问WildFly管理控制台,可以使用'jboss-cli.sh'脚本。
导航到WildFly的bin目录,然后使用“ --connect”选项运行脚本:
cd /opt/wildfly/bin/./jboss-cli.sh --connect
系统将要求我们输入管理用户名和密码(在步骤6中创建):
Authenticating against security realm: ManagementRealm Username: theitroad Password:
登录后,控制台提示符将更改为'[standalone @ localhost:9990 /]'。
键入“ help”以获取命令和命令语法的列表。
从其中我们可以部署和取消部署应用程序,管理用户和组以及配置和监视WildFly服务器。
网页界面
如果我们希望通过GUI管理服务器,WildFly还提供了一个基于Web的控制台。
默认情况下,WildFly管理控制台仅可从本地主机(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 [[ "" == "domain" ]]; then $WILDFLY_HOME/bin/domain.sh -c -b -bmanagement else $WILDFLY_HOME/bin/standalone.sh -c -b -bmanagement 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单元文件已更改:
sudo systemctl daemon-reload
通过执行以下命令重新启动WildFly服务:
sudo systemctl restart wildfly
假设防火墙中未阻止端口“ 9990”,则我们应该能够通过“ http://<域或者IP地址>:9990/console”访问WildFly管理控制台。