在CentOS7上安装Eclipse GlassFish 5.1.0的步骤
以下是介绍在CentOS7上安装Eclipse GlassFish 5.1.0的步骤。
环境
CentOS Linux release 7.7.1908
root@CENTOS7 ~]# cat /etc/redhat-release
CentOS Linux release 7.7.1908 (Core)
[root@CENTOS7 ~]#
jdk-8u241(jdk-8u241-linux-x64.rpm)(jdk14では動作しませんでした。)
[root@CENTOS7 ~]# rpm -ivh jdk-8u241-linux-x64.rpm
警告: jdk-8u241-linux-x64.rpm: ヘッダー V3 RSA/SHA256 Signature、鍵 ID ec551f03: NOKEY
準備しています... ################################# [100%]
更新中 / インストール中...
1:jdk1.8-2000:1.8.0_241-fcs ################################# [100%]
Unpacking JAR files...
tools.jar...
plugin.jar...
javaws.jar...
deploy.jar...
rt.jar...
jsse.jar...
charsets.jar...
localedata.jar...
[root@CENTOS7 ~]#
2. 下载Eclipse GlassFish 5.1.0。
root@CENTOS7 ~]# cat /etc/redhat-release
CentOS Linux release 7.7.1908 (Core)
[root@CENTOS7 ~]#
[root@CENTOS7 ~]# rpm -ivh jdk-8u241-linux-x64.rpm
警告: jdk-8u241-linux-x64.rpm: ヘッダー V3 RSA/SHA256 Signature、鍵 ID ec551f03: NOKEY
準備しています... ################################# [100%]
更新中 / インストール中...
1:jdk1.8-2000:1.8.0_241-fcs ################################# [100%]
Unpacking JAR files...
tools.jar...
plugin.jar...
javaws.jar...
deploy.jar...
rt.jar...
jsse.jar...
charsets.jar...
localedata.jar...
[root@CENTOS7 ~]#
使用以下命令从下载站点下载glassfish-5.1.0.zip文件。
使用curl -OL http://mirror.kakao.com/eclipse/glassfish/glassfish-5.1.0.zip命令下载文件。
[root@CENTOS7 ~]# curl -OL http://mirror.kakao.com/eclipse/glassfish/glassfish-5.1.0.zip
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 111M 100 111M 0 0 292k 0 0:06:31 0:06:31 --:--:-- 302k
[root@CENTOS7 ~]#
用以下的命令验证下载的文件的哈希值与下载网站上的值相同。
sha512sum glassfish-5.1.0.zip 的结果
[root@CENTOS7 ~]# sha512sum glassfish-5.1.0.zip
10d99061319178d65e8f8604f41caaca2ea561cbdc426d0fdf6163ead549e9c63c154c6ff648133a5b37bec14940a48b7c893544fa19f900a8c62273e445ed14 glassfish-5.1.0.zip
[root@CENTOS7 ~]#


3. 解压glassfish-5.1.0.zip文件。
使用以下命令将glassfish-5.1.0.zip解压到/opt目录下。
de -5.1.0.zip解压到/opt
使用 unzip 命令,将 glassfish-5.1.0.zip 解压到 /opt 目录中。
[root@CENTOS7 ~]# unzip -d /opt glassfish-5.1.0.zip
Archive: glassfish-5.1.0.zip
creating: /opt/glassfish5/
creating: /opt/glassfish5/glassfish/
creating: /opt/glassfish5/glassfish/domains/
creating: /opt/glassfish5/glassfish/domains/domain1/
creating: /opt/glassfish5/glassfish/domains/domain1/config/
inflating: /opt/glassfish5/glassfish/domains/domain1/config/admin-keyfile
~~~ 省略 ~~~
inflating: /opt/glassfish5/mq/lib/props/broker/default.properties
inflating: /opt/glassfish5/mq/lib/props/broker/install.properties
inflating: /opt/glassfish5/mq/lib/tyrus-standalone-client.jar
[root@CENTOS7 ~]# cd /opt
[root@CENTOS7 opt]# ls -l
合計 0
drwxr-xr-x. 7 root root 92 1月 28 2019 glassfish5
[root@CENTOS7 opt]#
4. 创建glassfish用户
用以下的命令创建一个名为“glassfish”的用户。(密码也是“glassfish”)
新增用户并设置密码为加密后的”glassfish”,加密方式为”$6$salt03″。用户名为glassfish。
[root@CENTOS7 opt]# useradd -p $(perl -e 'print crypt("glassfish", "\$6\$salt03")') glassfish
[root@CENTOS7 opt]#
5. 更改glassfish5目录的所有者和组
使用以下命令将glassfish5目录的所有者和组更改为glassfish。
将整个glassfish5文件夹的所有权和组改为glassfish:glassfish
[root@CENTOS7 opt]# chown -R glassfish:glassfish glassfish5
[root@CENTOS7 opt]# ls -l
合計 0
drwxr-xr-x. 7 glassfish glassfish 92 1月 28 2019 glassfish5
[root@CENTOS7 opt]#
6. 修改 asenv.conf
在/opt/glassfish5/glassfish/config/asenv.conf文件的最后一行追加以下内容:
AS_JAVA=”/usr/java/jdk1.8.0_241-amd64″
#
# Copyright (c) 2004, 2018 Oracle and/or its affiliates. All rights reserved.
#
# This program and the accompanying materials are made available under the
# terms of the Eclipse Public License v. 2.0, which is available at
# http://www.eclipse.org/legal/epl-2.0.
#
# This Source Code may also be made available under the following Secondary
# Licenses when the conditions for such availability set forth in the
# Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
# version 2 with the GNU Classpath Exception, which is available at
# https://www.gnu.org/software/classpath/license.html.
#
# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
#
#
# * * * N O T E * * *
#
# Although the lines in this file are formatted as environment
# variable assignments, this file is NOT typically invoked as a script
# from another script to define these variables. Rather, this file is read
# and processed by a server as it starts up. That scanning code resolves
# the relative paths against the GlassFish installation directory.
#
# Yet, this file is also where users of earlier versions have sometimes added
# a definition of AS_JAVA to control which version of Java GlassFish
# should use. As a result, in order to run a user-specified version of Java,
# the asadmin and appclient scripts do indeed invoke this file as a
# script - but ONLY to define AS_JAVA. Any calling script should not
# rely on the other settings because the relative paths will be resolved
# against the current directory when the calling script is run, not the
# installation directory of GlassFish, and such resolution will not work
# correctly unless the script happens to be run from the GlassFish installation
# directory.
#
AS_IMQ_LIB="../../mq/lib"
AS_IMQ_BIN="../../mq/bin"
AS_CONFIG="../config"
AS_INSTALL=".."
AS_DEF_DOMAINS_PATH="../domains"
AS_DEF_NODES_PATH="../nodes"
AS_DERBY_INSTALL="../../javadb"
AS_JAVA="/usr/java/jdk1.8.0_241-amd64"
7. 防火墙的设置
我在/usr/lib/firewalld/services目录下创建以下glassfish.xml文件。
<?xml version="1.0" encoding="utf-8"?>
<service>
<short>glassfish</short>
<description>GlassFish Server</description>
<port protocol="tcp" port="4848"/>
<port protocol="tcp" port="8080"/>
<port protocol="tcp" port="8181"/>
</service>
使用以下命令通过glassfish.xml配置中的端口设置防火墙。
防火墙命令(firewall-cmd)——永久添加服务(–permanent –add-service)为glassfish。
[root@CENTOS7 services]# firewall-cmd --permanent --add-service=glassfish
success
[root@CENTOS7 services]#
使用下面的命令重新启动firewalld。
重启防火墙服务:systemctl restart firewalld.service。
[root@CENTOS7 services]# systemctl restart firewalld.service
[root@CENTOS7 services]#
使用以下命令确认服务中是否已添加了Glassfish。
firewall-cmd –list-all 可以进行原生的中文翻译,只需提供一个选项:
[root@CENTOS7 services]# firewall-cmd --list-all
public (active)
target: default
icmp-block-inversion: no
interfaces: enp0s3
sources:
services: dhcpv6-client glassfish http ssh
ports: 8888/tcp
protocols:
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
[root@CENTOS7 services]#
8. 启动GlassFish
使用以下命令切换到glassfish用户。
su – 玻璃鱼
[root@CENTOS7 services]# su - glassfish
最終ログイン: 2020/03/19 (木) 23:39:44 JST日時 pts/0
[glassfish@CENTOS7 ~]$
以下为启动、停止和重新启动Glassfish的命令:
启动:/opt/glassfish5/glassfish/bin/asadmin启动域
停止:/opt/glassfish5/glassfish/bin/asadmin停止域
重新启动:/opt/glassfish5/glassfish/bin/asadmin重新启动域
启动GlassFish。
[glassfish@CENTOS7 ~]$ /opt/glassfish5/glassfish/bin/asadmin start-domain
Waiting for domain1 to start .......
Successfully started the domain : domain1
domain Location: /opt/glassfish5/glassfish/domains/domain1
Log File: /opt/glassfish5/glassfish/domains/domain1/logs/server.log
Admin Port: 4848
Command start-domain executed successfully.
[glassfish@CENTOS7 ~]$
9. 网络连接确认
请使用浏览器从以下网址进行连接。
http://<服务器IP地址>:8080/
当你看到以下的画面打开并成功连接时,表示连接是正常的。

10. 设置管理页面
请使用浏览器通过以下URL连接到管理界面。
http://<服务器IP地址>:4848/

如果出现错误提示,请按照以下方式进行设置。
设置管理用户的密码。
将/opt/glassfish5/glassfish/bin/asadmin change-admin-password翻译成中文:修改管理密码
[glassfish@CENTOS7 ~]$ /opt/glassfish5/glassfish/bin/asadmin change-admin-password
Enter admin user name [default: admin]>(そのまま)
Enter the admin password>(そのまま)
Enter the new admin password>admin
Enter the new admin password again>admin
Command change-admin-password executed successfully.
[glassfish@CENTOS7 ~]$
请使用以下命令将enable-secure-admin功能启用。
/opt/glassfish5/glassfish/bin/asadmin –host 本地主机 –port 4848 启用安全管理
[glassfish@CENTOS7 ~]$ /opt/glassfish5/glassfish/bin/asadmin --host localhost --port 4848 enable-secure-admin
Enter admin user name> admin
Enter admin password for user "admin">
You must restart all running servers for the change in secure admin to take effect.
Command enable-secure-admin executed successfully.
[glassfish@CENTOS7 ~]$
重新启动GlassFish。
重启域的命令是/opt/glassfish5/glassfish/bin/asadmin restart-domain。
[glassfish@CENTOS7 ~]$ /opt/glassfish5/glassfish/bin/asadmin restart-domain
Successfully restarted the domain
Command restart-domain executed successfully.
[glassfish@CENTOS7 ~]$
请再次使用以下的URL从浏览器连接到管理界面。
http://<服务器的IP地址>:4848/

使用预设的管理用户/密码(admin/admin)登录。

我成功登录了管理界面。
11. 创建systemd的service文件
在/usr/lib/systemd/system下创建以下的glassfish.service。
[Unit]
Description=GlassFish Server v5.1
After=syslog.target network.target remote-fs.target
[Service]
Type=oneshot
RemainAfterExit=yes
PIDFile=/var/run/glassfish.pid
ExecStart=/opt/glassfish5/glassfish/bin/asadmin start-domain
ExecStop=/opt/glassfish5/glassfish/bin/asadmin stop-domain
ExecReload=/opt/glassfish5/glassfish/bin/asadmin restart-domain
TimeoutStartSec=300
TimeoutStopSec=30
User=glassfish
Group=glassfish
[Install]
WantedBy=multi-user.target
在系统管理命令行工具下,启动、停止和重新启动的命令如下。
启动:使用systemctl命令启动glassfish
停止:使用systemctl命令停止glassfish
重新启动:使用systemctl命令重新启动glassfish
请提供更多上下文信息,以便我能够更准确地为您提供翻译。
Eclipse GlassFish | 项目.eclipse.org
错误信息
Eclipse GlassFish | 项目.eclipse.org
这次我安装并运行了JDK-8u241作为Java。
然而,在jdk14中出现了以下错误,导致无法执行。
[glassfish@CENTOS7 ~]$ /opt/glassfish5/glassfish/bin/asadmin start-domain
Exception in thread "main" java.lang.NullPointerException
at com.sun.enterprise.module.common_impl.AbstractModulesRegistryImpl.initializeServiceLocator(AbstractModulesRegistryImpl.java:128)
at com.sun.enterprise.module.common_impl.AbstractModulesRegistryImpl.newServiceLocator(AbstractModulesRegistryImpl.java:120)
at com.sun.enterprise.module.common_impl.AbstractModulesRegistryImpl.createServiceLocator(AbstractModulesRegistryImpl.java:194)
at com.sun.enterprise.module.common_impl.AbstractModulesRegistryImpl.createServiceLocator(AbstractModulesRegistryImpl.java:200)
at com.sun.enterprise.module.single.StaticModulesRegistry.createServiceLocator(StaticModulesRegistry.java:64)
at com.sun.enterprise.admin.cli.CLIContainer.getServiceLocator(CLIContainer.java:193)
at com.sun.enterprise.admin.cli.CLIContainer.getLocalCommand(CLIContainer.java:231)
at com.sun.enterprise.admin.cli.CLICommand.getCommand(CLICommand.java:207)
at com.sun.enterprise.admin.cli.AdminMain.executeCommand(AdminMain.java:347)
at com.sun.enterprise.admin.cli.AdminMain.doMain(AdminMain.java:282)
at org.glassfish.admin.cli.AsadminMain.main(AsadminMain.java:33)
[glassfish@CENTOS7 ~]$
上述内容