CentOS安装GlassFish4.0 配置JDBC连接MySQL

转自:http://linux.it.net.cn/CentOS/course/2014/0724/3319.html

版本glassfish-4.0.zip

1、解压,拷贝到指定安装路径

 
unzip glassfish-4.0.zip 
cp cp glassfish4 /usr/local/ -rf

2、设置glassfish环境变量 Linux学习,http:// linux.it.net.cn

 
vim  /etc/profile
export GLASSFISH_HOME=/usr/local/glassfish4
export PATH=.:$PATH:$JAVAHOME/bin:$MYSQLHOME/bin:$GLASSFISH_HOME/bin
 
source /etc/profle

进入/usr/local/glassfish4/glassfish/config,编辑该目录下的asevn.conf文件,在文件末尾加入AS_JAVA="/usr/local/jdk"(值为本机jdk安装路径) Linux学习,http:// linux.it.net.cn

 
AS_JAVA="/usr/jdk1.7.0_60"

IT网,http://www.it.net.cn

3、如果不想使用默认domain可在此步骤创建自己的domain,并指定domaindir和admin port

执行如下命令,创建端口为4848,名称为虹盘的domain

 
asadmin create-domain --adminport 4848 hongpan

Enter admin user name [Enter to accept default "admin" / no password]>

Bad Network Configuration.  DNS can not resolve the hostname:  IT网,http://www.it.net.cn

java.net.UnknownHostException: dev: dev: Name or service not known

Using port 4848 for Admin. Linux学习,http:// linux.it.net.cn

Using default port 8080 for HTTP Instance.

Using default port 7676 for JMS.

Using default port 3700 for IIOP. IT网,http://www.it.net.cn

Using default port 8181 for HTTP_SSL. Linux学习,http:// linux.it.net.cn

Using default port 3820 for IIOP_SSL.

Using default port 3920 for IIOP_MUTUALAUTH. IT网,http://www.it.net.cn

Using default port 8686 for JMX_ADMIN. IT网,http://www.it.net.cn

Using default port 6666 for OSGI_SHELL.

Using default port 9009 for JAVA_DEBUGGER.

Distinguished Name of the self-signed X.509 Server Certificate is:

[CN=localhost,OU=GlassFish,O=Oracle Corporation,L=Santa Clara,ST=California,C=US] IT网,http://www.it.net.cn

Distinguished Name of the self-signed X.509 Server Certificate is:

[CN=localhost-instance,OU=GlassFish,O=Oracle Corporation,L=Santa Clara,ST=California,C=US]

Domain hongpan created. Linux学习,http:// linux.it.net.cn

Domain hongpan admin port is 4848.

Domain hongpan allows admin login as user "admin" with no password.

Command create-domain executed successfully.

4、启动刚才建立的domain虹盘

 
asadmin start-domain hongpan

Waiting for hongpan to start .........................

Successfully started the domain : hongpan

domain  Location: /usr/local/glassfish4/glassfish/domains/hongpan

Log File: /usr/local/glassfish4/glassfish/domains/hongpan/logs/server.log IT网,http://www.it.net.cn

Admin Port: 4848

Command start-domain executed successfully.

5、修改刚刚创建的domain的admin密码,并使之能够通过web登录到控制台

 
asadmin change-admin-password

Linux学习,http:// linux.it.net.cn

Enter admin user name [default: admin]>

Enter the admin password>

Enter the new admin password>

Enter the new admin password again>

Command change-admin-password executed successfully.

Linux学习,http:// linux.it.net.cn

每次操作的时候控制台都提示输入用户名密码,比较麻烦

可以建立密码配置文件

AS_ADMIN_PASSWORD=xxxx

6、开启远程登录权限

 
asadmin enable-secure-admin

Enter admin user name>

Enter admin password>

You must restart all running servers for the change in secure admin to take effect.

Command enable-secure-admin executed successfully.

7、重启domain Linux学习,http:// linux.it.net.cn

 
asadmin restart-domain hongpan

现在就可通过控制台进行管理了

CentOS安装GlassFish4.0 配置JDBC连接MySQL

IT网,http://www.it.net.cn

下面开始配置jdbc连接mysql

1、拷贝连接mysql的jar包到glassfish库目录里

1
cp mysql-connector-java-5.1.16-bin.jar /usr/local/glassfish4/glassfish/lib/

2、重启domain

3、登陆mysql控制台,到JDBC连接池界面

CentOS安装GlassFish4.0 配置JDBC连接MySQL点击new新建JDBC连接池

Linux学习,http:// linux.it.net.cn

CentOS安装GlassFish4.0 配置JDBC连接MySQL配置连接属性

CentOS安装GlassFish4.0 配置JDBC连接MySQL测试连通性

Succeeded IT网,http://www.it.net.cn

4、创建JDBC资源,程序到时候只需要连接JNDI名称即可 IT网,http://www.it.net.cn

CentOS安装GlassFish4.0 配置JDBC连接MySQL
下图JNDI Name填写名称,Pools Name选择刚才创建的JDBC连接池。

CentOS安装GlassFish4.0 配置JDBC连接MySQL
配置完成,大功告成!

上一篇:JavaScript是如何工作: 深入探索WebSocket和HTTP/2与SSE + 如何选择正确的路径!


下一篇:MySQL学习(一)——Java连接MySql数据库