在 CentOS 7 上安装 WildFly/JBoss AS
创建一个用户来拥有 WildFly 软件。
[root@wildfly-01 ~]# useradd -r -d /opt/wildfly -s /sbin/nologin wildfly
我们创建了一个没有登录权限和自定义主目录的系统用户 wildfly。
最新或者以前版本的 WildFly 可在其网站上找到。
我们正在下载 TGZ 格式的 Java EE Full & Web Distribution (16.0.0.Final)。
[root@wildfly-01 ~]# cd /tmp [root@wildfly-01 tmp]# curl -O https://download.jboss.org/wildfly/16.0.0.Final/wildfly-16.0.0.Final.tar.gz % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 172M 100 172M 0 0 568k 0 0:05:10 0:05:10 --:--:-- 595k
在 /opt 目录中提取 TGZ 文件。
[root@wildfly-01 tmp]# tar xf wildfly-16.0.0.Final.tar.gz -C /opt/
为 WildFly 安装目录创建符号链接 /opt/wildfly。
如果我们想将 WildFly 升级/降级到不同的版本,我们会发现这个符号链接非常有用。
[root@wildfly-01 tmp]# ln -s /opt/wildfly-16.0.0.Final/ /opt/wildfly
将 /opt/wildfly 目录的所有者更改为 wildfly 用户。
[root@wildfly-01 tmp]# chown -RH wildfly:wildfly /opt/wildfly
在 WildFly Server 中部署 Java 应用程序
从 GitHub 下载 Helloworld Java 应用程序。
[root@wildfly-01 ~]# cd /opt/wildfly/standalone/deployments/ [root@wildfly-01 deployments]# curl -O https://raw.githubusercontent.com/aeimer/java-example-helloworld-war/master/dist/helloworld.war % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 74333 100 74333 0 0 20801 0 0:00:03 0:00:03 --:--:-- 20798
检查部署目录中的文件..
[root@wildfly-01 deployments]# ls helloworld.war helloworld.war.deployed README.txt
如果有文件名 *.deployed ,则表示 Java 应用已经部署成功。
否则你可能会在这里找到 *.failed 文件。
有关更多详细信息,我们可以查看 WildFly 服务器日志。
[root@wildfly-01 deployments]# tail /opt/wildfly/standalone/log/server.log | grep helloworld 2019-05-18 14:49:35,438 INFO [org.jboss.as.server.deployment] (MSC service thread 1-1) WFLYSRV0027: Starting deployment of "helloworld.war" (runtime-name: "helloworld.war") 2019-05-18 14:49:38,831 INFO [org.wildfly.extension.undertow] (ServerService Thread Pool -- 77) WFLYUT0021: Registered web context: '/helloworld' for server 'default-server' 2019-05-18 14:49:39,016 INFO [org.jboss.as.server] (DeploymentScanner-threads - 2) WFLYSRV0010: Deployed "helloworld.war" (runtime-name : "helloworld.war")
从客户端的浏览器浏览 URL http://wildfly-01.onitroad.com:8080/helloworld/。
我们的 HelloWorld Java 应用程序已经部署在 WildFly 服务器上。
在本文中,我们在 CentOS 7 上成功安装了 WildFly/JBoss 应用服务器,配置了管理控制台并在 WildFly 服务器上部署了一个 Java 应用程序。
为远程访问配置 WildFly 管理控制台
默认情况下,WildFly 管理控制台在 localhost 上运行。
如果我们想通过网络访问它,那么我们必须相应地配置它。
要登录 WildFly 管理控制台,我们需要一个 Admin 用户。
因此,使用以下脚本创建一个管理员用户。
[root@wildfly-01 tmp]# /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 the details of the new user to add. Using realm 'ManagementRealm' as discovered from the existing property files. Username : jackli 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 doirt(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 'jackli' for realm 'ManagementRealm' Is this correct yes/no? yes Added user 'jackli' to file '/opt/wildfly-16.0.0.Final/standalone/configuration/mgmt-users.properties' Added user 'jackli' to file '/opt/wildfly-16.0.0.Final/domain/configuration/mgmt-users.properties' Added user 'jackli' with groups to file '/opt/wildfly-16.0.0.Final/standalone/configuration/mgmt-groups.properties' Added user 'jackli' 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="QWhtZXJAMTIzNA==" />
在 /etc/wildfly/wildfly.conf 中创建一个环境变量。
[root@wildfly-01 tmp]# cat >> /etc/wildfly/wildfly.conf << EOF > # the address to bind console to > WILDFLY_CONSOLE_BIND=0.0.0.0 > EOF
编辑 /opt/wildfly/bin/launch.sh 脚本。
[root@wildfly-01 tmp]# vi /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
保存并退出。
最后编辑 WildFly 服务。
[root@wildfly-01 tmp]# vi /usr/lib/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
重启 WildFly 服务。
[root@wildfly-01 tmp]# systemctl daemon-reload [root@wildfly-01 tmp]# systemctl restart wildfly.service
在 Linux 防火墙中允许 WildFly 管理控制台的服务端口。
[root@wildfly-01 tmp]# firewall-cmd --permanent --add-port=9990/tcp success [root@wildfly-01 tmp]# firewall-cmd --reload success
从客户端浏览器浏览 URL http://wildfly-01.onitroad.com:9990/console,以访问 WildFly 管理控制台。
使用我们在上面创建的 admin 用户登录。
我们现在可以访问 WildFly 管理控制台的仪表板。
为 WildFly 创建一个 Systemd 服务
在 /etc 目录中创建 WildFly 配置。
[root@wildfly-01 tmp]# mkdir /etc/wildfly [root@wildfly-01 tmp]# cp /opt/wildfly/docs/contrib/scripts/systemd/wildfly.conf /etc/wildfly/
检查 WildFly 配置。
[root@wildfly-01 tmp]# cat /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 以独立模式运行,仅使用必需的技术。
我们可以根据自己的要求自定义配置。
有关更多信息,请参阅 WildFly 16 文档。
将 launch.sh 脚本复制到 /opt/wildfly/bin 目录中。
该文件是作为服务启动 WildFly 所必需的。
[root@wildfly-01 tmp]# cp /opt/wildfly/docs/contrib/scripts/systemd/launch.sh /opt/wildfly/bin/
在 Systemd 配置目录中复制 WildFly 服务单元。
[root@wildfly-01 tmp]# cp /opt/wildfly/docs/contrib/scripts/systemd/wildfly.service /usr/lib/systemd/system/
创建目录以保存 WildFly 服务的 PIDfile。
[root@wildfly-01 tmp]# mkdir /var/run/wildfly/ [root@wildfly-01 tmp]# chown -R wildfly:wildfly /var/run/wildfly/
启用并启动 WildFly 服务。
[root@wildfly-01 tmp]# systemctl enable wildfly.service Created symlink from /etc/systemd/system/multi-user.target.wants/wildfly.service to /usr/lib/systemd/system/wildfly.service. [root@wildfly-01 tmp]# systemctl start wildfly.service
在 CentOS 7 上安装 OpenJDK 8
WildFly 是一个基于 Java 的应用平台,因此它需要在服务器上安装 JDK(Java 开发工具包)。
WildFly 16 需要 Java EE 8 或者更高版本,因此,我们使用 yum 命令安装 OpenJDK 8.
[root@wildfly-01 ~]# yum install -y java-1.8.0-openjdk
设置 Java 相关环境变量。
[root@wildfly-01 ~]# echo "export JAVA_HOME=/usr/lib/jvm/jre-1.8.0-openjdk-1.8.0.212.b04-0.el7_6.x86_64" >> /etc/profile [root@wildfly-01 ~]# . /etc/profile [root@wildfly-01 ~]# env | grep JAVA_HOME JAVA_HOME=/usr/lib/jvm/jre-1.8.0-openjdk-1.8.0.212.b04-0.el7_6.x86_64
通过检查版本确保 Java 安装。
[root@wildfly-01 ~]# java -version openjdk version "1.8.0_212" OpenJDK Runtime Environment (build 1.8.0_212-b04) OpenJDK 64-Bit Server VM (build 25.212-b04, mixed mode)
CentOS 7 服务器上已安装 OpenJDK 8.
WildFly,以前称为 JBoss AS(应用服务器),是 JBoss 社区支持的免费开源 Java EE 应用服务器。
Red Hat 还开发了 WildFly 的商业版本,命名为 JBoss EAP(企业应用平台)。
在本文中,我们将在 CentOS 7 上安装 WildFly/JBoss 应用服务器 16,配置用于远程访问的 WildFly 管理控制台,最后在 WildFly 服务器上部署 Java 应用程序。
为 WildFly 配置 Linux 防火墙
在 Linux 防火墙中允许 WildFly 服务端口。
[root@wildfly-01 tmp]# firewall-cmd --permanent --add-port=8080/tcp success [root@wildfly-01 tmp]# firewall-cmd --reload success
在客户端浏览器中浏览 URL http://wildfly-01.onitroad.com:8080/。
显示 WildFly 已成功安装在我们的 CentOS 7 服务器上,并且其服务正在指定端口上运行。