在Web应用程序开发领域,利用强大而高效的服务器至关重要。GlassFish是一个模范的Java EE应用程序服务器,在部署和管理Java应用程序方面赢得了中坚力量的声誉。
在 Fedora 38 上安装 GlassFish
第 1 步。在 Fedora 38 上安装 GlassFish 之前,重要的是要确保我们的系统是最新的软件包。这将确保我们可以访问最新功能和错误修复,并且我们可以毫无问题地安装 GlassFish:
<span class="pln">sudo dnf update sudo dnf install dnf</span><span class="pun">-</span><span class="pln">plugins</span><span class="pun">-</span><span class="pln">core</span>
第 2 步。安装 Java 开发工具包 (JDK)
GlassFish在Java上蓬勃发展,因此安装Java开发工具包(JDK)是不可协商的。为此,请拥抱终端的强大功能:
<span class="pln">sudo dnf install java</span><span class="pun">-</span><span class="lit">11</span><span class="pun">-</span><span class="pln">openjdk</span><span class="pun">-</span><span class="pln">devel</span>
安装 Java 后,可以使用以下命令验证 Java 版本:
<span class="pln">java </span><span class="pun">-</span><span class="pln">version</span>
第 3 步。在 Fedora 38 上安装 GlassFish。
首先,创建一个专门的用户来运行 GlassFish:
<span class="pln">useradd </span><span class="pun">-</span><span class="pln">m </span><span class="pun">-</span><span class="pln">d </span><span class="pun">/</span><span class="pln">opt</span><span class="pun">/</span><span class="pln">glassfish6 </span><span class="pun">-</span><span class="pln">U </span><span class="pun">-</span><span class="pln">s </span><span class="pun">/</span><span class="pln">bin</span><span class="pun">/</span><span class="kwd">false</span><span class="pln"> glassfish</span>
导航到 GlassFish 官方网站以查找最新版本的 GlassFish。用于下载软件包:wget
<span class="pln">wget https</span><span class="pun">:</span><span class="com">//www.eclipse.org/downloads/download.php?file=/ee4j/glassfish/glassfish-7.0.7.zip</span>
解压缩下载的软件包并将其移动到所需的安装位置:
<span class="pln">unzip glassfish</span><span class="pun">-</span><span class="lit">7.0</span><span class="pun">.</span><span class="lit">7.zip</span><span class="pln"> sudo mv glassfish7 </span><span class="pun">/</span><span class="pln">opt</span><span class="pun">/</span><span class="pln">glassfish</span>
更改 Glassfish 目录的所有权:
<span class="pln">chown </span><span class="pun">-</span><span class="pln">R glassfish</span><span class="pun">:</span><span class="pln">glassfish </span><span class="pun">/</span><span class="pln">opt</span><span class="pun">/</span><span class="pln">glassfish</span>
第 4 步。创建系统服务文件。
现在创建一个服务文件,通过命令管理 GlassFish 服务:systemd
systemctl
<span class="pln">nano </span><span class="pun">/</span><span class="pln">lib</span><span class="pun">/</span><span class="pln">systemd</span><span class="pun">/</span><span class="pln">system</span><span class="pun">/</span><span class="pln">glassfish</span><span class="pun">.</span><span class="pln">service</span>
添加以下文件:
<span class="pun">[</span><span class="typ">Unit</span><span class="pun">]</span> <span class="typ">Description</span> <span class="pun">=</span> <span class="typ">GlassFish</span> <span class="typ">Server</span><span class="pln"> v7 </span><span class="typ">After</span> <span class="pun">=</span><span class="pln"> syslog</span><span class="pun">.</span><span class="pln">target network</span><span class="pun">.</span><span class="pln">target </span><span class="pun">[</span><span class="typ">Service</span><span class="pun">]</span> <span class="typ">User</span><span class="pun">=</span><span class="pln">glassfish </span><span class="typ">ExecStart</span><span class="pun">=</span><span class="str">/opt/</span><span class="pln">glassfish</span><span class="pun">/</span><span class="pln">bin</span><span class="pun">/</span><span class="pln">asadmin start</span><span class="pun">-</span><span class="pln">domain </span><span class="typ">ExecReload</span><span class="pun">=</span><span class="str">/opt/</span><span class="pln">glassfish</span><span class="pun">/</span><span class="pln">bin</span><span class="pun">/</span><span class="pln">asadmin restart</span><span class="pun">-</span><span class="pln">domain </span><span class="typ">ExecStop</span><span class="pun">=</span><span class="str">/opt/</span><span class="pln">glassfish</span><span class="pun">/</span><span class="pln">bin</span><span class="pun">/</span><span class="pln">asadmin stop</span><span class="pun">-</span><span class="pln">domain </span><span class="typ">Type</span> <span class="pun">=</span><span class="pln"> forking </span><span class="pun">[</span><span class="typ">Install</span><span class="pun">]</span> <span class="typ">WantedBy</span> <span class="pun">=</span><span class="pln"> multi</span><span class="pun">-</span><span class="pln">user</span><span class="pun">.</span><span class="pln">target</span>
保存并关闭文件,然后重新加载守护程序以应用更改:systemd
<span class="pln">sudo systemctl daemon</span><span class="pun">-</span><span class="pln">reload sudo systemctl start glassfish sudo systemctl enable glassfish</span>
第5步。设置玻璃鱼管理员密码。
默认情况下,未设置 GlassFish 默认管理员密码,因此您需要在通过网络浏览器登录 GlassFish 之前设置它。您可以使用以下命令设置管理员密码:
<span class="pln">sudo </span><span class="pun">-</span><span class="pln">u glassfish </span><span class="pun">/</span><span class="pln">opt</span><span class="pun">/</span><span class="pln">glassfish</span><span class="pun">/</span><span class="pln">bin</span><span class="pun">/</span><span class="pln">asadmin </span><span class="pun">--</span><span class="pln">port </span><span class="lit">4848</span><span class="pln"> change</span><span class="pun">-</span><span class="pln">admin</span><span class="pun">-</span><span class="pln">password</span>
默认情况下,GlassFish 基于 Web 的登录处于禁用状态,因此您还需要通过命令行启用它:
<span class="pln">sudo </span><span class="pun">-</span><span class="pln">u glassfish </span><span class="pun">/</span><span class="pln">opt</span><span class="pun">/</span><span class="pln">glassfish</span><span class="pun">/</span><span class="pln">bin</span><span class="pun">/</span><span class="pln">asadmin </span><span class="pun">--</span><span class="pln">port </span><span class="lit">4848</span><span class="pln"> enable</span><span class="pun">-</span><span class="pln">secure</span><span class="pun">-</span><span class="pln">admin</span>
最后,重新启动 GlassFish 服务以应用更改:
<span class="pln">sudo systemctl restart glassfish</span>
第 6 步。访问 GlassFish Web 界面。
打开您的网络浏览器并使用 URL 访问 GlassFish 管理控制台:。如果控制台成功加载,则您的安装可正常运行。http://localhost:4848
步骤 7.排查常见问题。
- 端口冲突:如果端口 4848 已在使用中,您可以通过修改 GlassFish 域的配置来更改端口。
- 权限:确保 GlassFish 目录和域文件的适当权限。
- Java 版本:确保您使用的是兼容的 Java 版本(在本例中为 OpenJDK 11)。
感谢您使用本教程在您的 Fedora 38 系统上安装 GlassFish。如需其他帮助或有用信息,我们建议您查看 GlassFish 官方网站。