[ 登录注册 ]

HTML5

JBOSS AS7 数据源配置一条龙+jersey 发布应用关键点

2016-08-17 14:05:48 admin 返回上一页

MySQL 部分:


1、下载MySQL 5.5.x 或更高版本


    下载 mysql-5.5.x-linux2.6-x86_64.tar.tar.gz 到 /opt目录下


2、解压及配置(其中 x 为实际版本)
[html]
1)、tar zxvf mysql-5.5.x-linux2.6-x86_64.tar.tar.gz 
2)、cd /opt 
3)、mv mysql-5.5.x-linux2.6-x86_64 mysql 
4)、cd /opt/mysql 
5)、创建系统MySQL用户和组 
    a、groupadd mysql 
    b、useradd -r -g mysql mysql 

    1)、tar zxvf mysql-5.5.x-linux2.6-x86_64.tar.tar.gz
    2)、cd /opt
    3)、mv mysql-5.5.x-linux2.6-x86_64 mysql
    4)、cd /opt/mysql
    5)、创建系统MySQL用户和组
        a、groupadd mysql
        b、useradd -r -g mysql mysql

    6)、配置mysql
[html]
a、chown -R mysql . 
b、chgrp -R mysql . 
c、./scripts/mysql_install_db --user=mysql 
d、cd support-files/ 
e、cp my-medium.cnf my.cnf 
f、cp my.cnf /etc/ 
g、cp mysql.server mysqld 
h、修改 mysqld 配置,将该文件中的basedir和datadir配置对应的文件路径。 
    命令 vim mysqld 
    示例: 
        basedir=/opt/mysql 
        datadir=/opt/mysql/data 
i、复制mysqld到系统默认的启动目录/etc/init.d;cp mysqld /etc/init.d/ 
j、cd /etc/init.d 
k、chkconfig mysqld on 
l、cd /opt/mysql 
m、chown -R root . 
n、chown -R mysql data 

        a、chown -R mysql .
        b、chgrp -R mysql .
        c、./scripts/mysql_install_db --user=mysql
        d、cd support-files/
        e、cp my-medium.cnf my.cnf
        f、cp my.cnf /etc/
        g、cp mysql.server mysqld
        h、修改 mysqld 配置,将该文件中的basedir和datadir配置对应的文件路径。
            命令 vim mysqld
            示例:
                basedir=/opt/mysql
                datadir=/opt/mysql/data
        i、复制mysqld到系统默认的启动目录/etc/init.d;cp mysqld /etc/init.d/
        j、cd /etc/init.d
        k、chkconfig mysqld on
        l、cd /opt/mysql
        m、chown -R root .
        n、chown -R mysql data

       

3、启动 MySQL 。 


[html]
service mysqld start 

service mysqld start


4、配置MySQL
    1)、修改密码
[html]
a、cd /opt/mysql/bin 
b、./mysqladmin -u root -p password 新密码 

        a、cd /opt/mysql/bin
        b、./mysqladmin -u root -p password 新密码

    2)、配置访问权限
[html]
a、cd /opt/mysql/bin 
b、./mysql -u root -p 
c、GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY ‘密码’ WITH GRANT OPTION; 
d、重启MySQL。 service mysqld restart 

        a、cd /opt/mysql/bin
        b、./mysql -u root -p
        c、GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY ‘密码’ WITH GRANT OPTION;
        d、重启MySQL。 service mysqld restart

 

5、使用远程客户端增加全局数据库。  库名:uec_cloud   编码:utf-8(utf-8-bin)


JBOSS(standalone 模式) 部分:


一、 创建驱动程序Module
   
    目标:mysql驱动程序模块 com.mysql
    1. 建立模块目录结构
        在$JBOSS_HOME/modules目录下依次新建文件夹,最终形成如下目录结构$JBOSS_HOME/modules/com/mysql/main
[html]
1)、cd $JBOSS_HOME/modules/com 
2)、mkdir -p mysql/main 

            1)、cd $JBOSS_HOME/modules/com
            2)、mkdir -p mysql/main

    2. 复制jar文件至模块目录

        复制mysql-connector-java-5.1.21-bin.jar至$JBOSS_HOME/modules/com/mysql/main

 


  [html]
scp mysql-connector-java-5.1.21-bin.jar root@ip:/opt/jboss-as-7.1.1.Final/modules/com/mysql/main

      scp mysql-connector-java-5.1.21-bin.jar root@ip:/opt/jboss-as-7.1.1.Final/modules/com/mysql/main

 

    3. 配置module.xml
    在$JBOSS_HOME/modules/com/mysql/main目录新建module.xml文件,内容如下:


[html]
vim module.xml 

        vim module.xml

[html]
<?xml version="1.0" encoding="UTF-8"?> 
<module xmlns="urn:jboss:module:1.0" name="com.mysql"> 
    <resources> 
        <resource-root path="mysql-connector-java-5.1.21-bin.jar"/> 
    </resources> 
    <dependencies> 
        <module name="javax.api"/> 
    </dependencies> 
</module> 

        <?xml version="1.0" encoding="UTF-8"?>
        <module xmlns="urn:jboss:module:1.0" name="com.mysql">
            <resources>
                <resource-root path="mysql-connector-java-5.1.21-bin.jar"/>
            </resources>
            <dependencies>
                <module name="javax.api"/>
            </dependencies>
        </module>

二、 注册数据源驱动程序
    修改$JBOSS_HOME/standalone/configuration/standalone.xml文件,查找datasources节点下drivers节点,在drivers节点下添加:


[html]
<driver name="mysql" module="com.mysql"> 
    <driver-class>com.mysql.jdbc.Driver</driver-class> 
</driver> 

        <driver name="mysql" module="com.mysql">
            <driver-class>com.mysql.jdbc.Driver</driver-class>
        </driver>

三、 注册数据源
    修改$JBOSS_HOME/standalone/configuration/standalone.xml文件,查找datasources节点,并添加datasource节点:

[html]
<datasource jta="false" jndi-name="java:jboss/datasources/UEC_DataSourceDS" pool-name="UEC_DataSourceDS" enabled="true" use-ccm="false"> 
    <connection-url>jdbc:mysql://localhost:3306/uec_cloud?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull</connection-url> 
    <driver-class>com.mysql.jdbc.Driver</driver-class> 
    <driver>mysql</driver> 
    <transaction-isolation>TRANSACTION_READ_COMMITTED</transaction-isolation> 
    <pool> 
        <min-pool-size>10</min-pool-size> 
        <max-pool-size>100</max-pool-size> 
        <prefill>true</prefill> 
        <use-strict-min>false</use-strict-min> 
    </pool> 
    <security> 
        <user-name>root</user-name> 
        <password>eric</password> 
    </security> 
    <validation> 
        <validate-on-match>false</validate-on-match> 
        <background-validation>false</background-validation> 
    </validation> 
    <statement> 
        <share-prepared-statements>false</share-prepared-statements> 
    </statement> 
</datasource> 

        <datasource jta="false" jndi-name="java:jboss/datasources/UEC_DataSourceDS" pool-name="UEC_DataSourceDS" enabled="true" use-ccm="false">
            <connection-url>jdbc:mysql://localhost:3306/uec_cloud?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull</connection-url>
            <driver-class>com.mysql.jdbc.Driver</driver-class>
            <driver>mysql</driver>
            <transaction-isolation>TRANSACTION_READ_COMMITTED</transaction-isolation>
            <pool>
                <min-pool-size>10</min-pool-size>
                <max-pool-size>100</max-pool-size>
                <prefill>true</prefill>
                <use-strict-min>false</use-strict-min>
            </pool>
            <security>
                <user-name>root</user-name>
                <password>eric</password>
            </security>
            <validation>
                <validate-on-match>false</validate-on-match>
                <background-validation>false</background-validation>
            </validation>
            <statement>
                <share-prepared-statements>false</share-prepared-statements>
            </statement>
        </datasource>

程序发布核心参数变更:


1、JBOSS 数据源配置:
    修改 applicationContext-common.xml 配置文件,将原始dataSource屏蔽并启用JNDI数据源。

        示例:

 


[html]
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean" p:jndiName="java:jboss/datasources/UEC_DataSourceDS" /> 

        <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean" p:jndiName="java:jboss/datasources/UEC_DataSourceDS" />

2、web.xml配置:


    增加如下参数:
[html]
<!-- JBOSS AS7 Rest Config --> 
<context-param> 
    <param-name>resteasy.scan</param-name> 
    <param-value>false</param-value> 
</context-param> 
<context-param> 
    <param-name>resteasy.scan.resources</param-name> 
    <param-value>false</param-value> 
</context-param> 
<context-param> 
    <param-name>resteasy.scan.providers</param-name> 
    <param-value>false</param-value> 
</context-param> 

        <!-- JBOSS AS7 Rest Config -->
        <context-param>
            <param-name>resteasy.scan</param-name>
            <param-value>false</param-value>
        </context-param>
        <context-param>
            <param-name>resteasy.scan.resources</param-name>
            <param-value>false</param-value>
        </context-param>
        <context-param>
            <param-name>resteasy.scan.providers</param-name>
            <param-value>false</param-value>
        </context-param>

点击复制链接 与好友分享!回本站首页

文章来源:http://www.bozhiyue.com/html5/2016/0817/377534.html
返回上一页    返回分类 上一篇:   下一篇:
相关