Maison > Article > base de données > Ubuntu12.04 安装 GlassFish3.1.2
由于公司产品的一致性需求,我们又从Jetty切换到GlassFish3.1.2. 这次是在Ubuntu12.04 server(64bit)上安装 GlassFish web profile. 本文内容主要来源于http://www.nabisoft.com/tutorials/glassfish/installing-glassfish-311-on-ubuntu 上文非常全面,我做
由于公司产品的一致性需求,我们又从Jetty切换到GlassFish3.1.2. 这次是在Ubuntu12.04 server(64bit)上安装 GlassFish web profile.
本文内容主要来源于http://www.nabisoft.com/tutorials/glassfish/installing-glassfish-311-on-ubuntu
上文非常全面,我做了删减,去掉了不需要的iptables一节,因为我们用nginx做转发。同时也解决了一些其他问题。
比如GlassFish3.1.2改变了安全规则。需要一些额外的步骤。
一 安装JDK,设置好环境变量。
我安装的是jdk1.6
root@ciappserver1:~# java -version java version "1.6.0_32" Java(TM) SE Runtime Environment (build 1.6.0_32-b05) Java HotSpot(TM) 64-Bit Server VM (build 20.7-b02, mixed mode)
先创建glassfish系统帐号
# adduser --home /home/glassfish --system --shell /bin/bash glassfish Adding system user `glassfish' (UID 108) ... Adding new user `glassfish' (UID 108) with group `nogroup' ... Creating home directory `/home/glassfish' ...
# groupadd glassfishadm
# usermod -a -G glassfishadm glassfish
chgrp -R glassfishadm /home/glassfish
apt-get install unzip
切换到glassfish用户,并下载和解压
su glassfish cd /home/glassfish mkdir downloads cd downloads wget http://download.java.net/glassfish/3.1.2/release/glassfish-3.1.2-web.zip unzip glassfish-3.1.2-web.zip将解压后的文件复制到/hom/glassfish目录下,然后退出该用户
mv /home/glassfish/downloads/glassfish3/* /home/glassfish/ mv /home/glassfish/downloads/glassfish3/.org.opensolaris,pkg /home/glassfish/.org.opensolaris,pkg
exit
要想在glassfish用户下可以使用java命令,添加两个软链接:
ln -s /usr/jdk1.6/bin/java /etc/alternatives/java ln -s /etc/alternatives/java /usr/bin/java
确保程序可以在glassfish用户下运行
root@ciappserver1:~# chown -R glassfish /home/glassfish root@ciappserver1:~# chmod -R ug+rwx /home/glassfish/bin/ root@ciappserver1:~# chmod -R ug+rwx /home/glassfish/glassfish/bin/ root@ciappserver1:~# chmod -R o-rwx /home/glassfish/bin/ root@ciappserver1:~# chmod -R o-rwx /home/glassfish/glassfish/bin/
修改/home/glassfish/glassfish/domains/domain1/config/domain.xml如下:
<network-listeners> <network-listener port="8081" protocol="http-listener-1" transport="tcp" name="http-listener-1" thread-pool="http-thread-pool"></network-listener> <network-listener port="8181" protocol="http-listener-2" transport="tcp" name="http-listener-2" thread-pool="http-thread-pool"></network-listener> <network-listener port="4848" protocol="admin-listener" transport="tcp" name="admin-listener" thread-pool="admin-thread-pool"></network-listener> </network-listeners>
七 启动服务
$ su glassfish $ /home/glassfish/glassfish/bin/asadmin start-domain domain1 There is a process already using the admin port 4848 -- it probably is another instance of a GlassFish server.这是个GlassFish启动常见的错误,到/etc/hosts目录下看一下
原来这里错了,hostname命令返回的是ciappserver1
127.0.1.1 UBUNTU1204TEMPLATE修改成:
127.0.0.1 ciappserver1
glassfish@ciappserver1:/root$ /home/glassfish/bin/asadmin start-domain domain1 Waiting for domain1 to start ....... Successfully started the domain : domain1 domain Location: /home/glassfish/glassfish/domains/domain1 Log File: /home/glassfish/glassfish/domains/domain1/logs/server.log Admin Port: 4848 Command start-domain executed successfully.
因为3.1.2加强了安全性。游戏规则改变了。默认admin密码也不再是adminadmin,而是空。
注意:如果是localhost可以直接进入管理员页面,无需密码。
八 启动后启用secure-admin
修改admin默认密码
./asadmin change-admin-password Enter admin user name [default: admin]> (Press enter to use the default user name) Enter admin password> (Press enter to use the default password) Enter new admin password> Enter new admin password again> Command change-admin-password executed successfully.
./asadmin --host 10.112.18.178 --port 4848 enable-secure-admin--host 指定glassfish所在IP,回答两个问题,用户名和密码,分别是admin/123456.
重新启动glassfish.
再次打开网站myserver:4848,突然进行HTTPS提示,同意后。登录,终于看到了。
九 查看glassfish的用户
下面这个命令帮助我们查看当前glassfish的用户:
./asadmin list-file-users --authrealmname admin-realm只有一个admin.
十 创建系统服务
先创建/etc/init.d/glassfish脚本
export AS_JAVA=/usr/lib/jvm/java-6-sun GLASSFISHPATH=/home/glassfish/bin case "$1" in start) echo "starting glassfish from $GLASSFISHPATH" sudo -u glassfish $GLASSFISHPATH/asadmin start-domain domain1 ;; restart) $0 stop $0 start ;; stop) echo "stopping glassfish from $GLASSFISHPATH" sudo -u glassfish $GLASSFISHPATH/asadmin stop-domain domain1 ;; *) echo $"usage: $0 {start|stop|restart}" exit 3 ;; esac :增加可执行权限:
chmod +x ./glassfish
创建自启动脚本
update-rc.d glassfish defaults
servcie glassfis (start|stop|restart) 来测试了
然后重新启动后继续看是否已经自启动。
产品环境下使用还需要修改默认的master password,可以参考前面引用文章的最后一节: