阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

MySQL 5.6升级为MySQL 5.7部署JBoss/WildFly应用项目

171次阅读
没有评论

共计 4650 个字符,预计需要花费 12 分钟才能阅读完成。

一、部署 MySQL5.7 二进制版

解压 tar -xvf

mv mysql-5.7  /usr/local/mysql5.7  或者其他文件夹

cd  /usr/local/mysql.57

useradd -s /sbin/nologin -M mysql

mkdir  -p /usr/local/mysql5.7/etc

启动初始化数据

bin/mysqld  –initialize  –basedir=/usr/local/mysql5.7  –datadir=/usr/local/mysql5.7/data

修改配置文件

chown –R mysql:mysql  /usr/local/mysql5.7

vim /usr/local/mysql5.7/etc/my.cnf

详见文件 my.cnf

制作 systemd 启动 MYSQL 服务

vim /lib/systemd/system/mysqld.service,详见文件

启动服务

systemctl start  mysqld

systemctl  enable  mysqld

更改环境变量

vim /etc/profile

export PATH=$PATH:/usr/local/mysql5.7/bin

source /etc/profile

进入 mysql,第一次登录 mysql, 没有 root 密码,解决方式:

在 /usr/local/mysql5.7/etc/my.cnf 中添加 skip-grant-tables 参数。此参数的作用是登录 Mysql 数据库不进行用户密码验证。

[mysqld]

skip-grant-tables

保存 my.cnf 后,重启 msyql

systemctl restart mysqld

然后登录 mysql  -uroot

执行以下语句:

update mysql.user set authentication_string=password(‘ 密码 ’) where user=’root’;

flush privileges;

exit;

systemctl restart mysqld

mysql -uroot -p

Enter password: 在这里输入刚才设置的密码, 如果不成功或者提示密码过期需要修改密码,重新登录 mysql

use mysql;

update user set password_expired=’N’ where user=’root’;

flush privileges;

重新登录,成功。

在 my.cnf 文件中的 skip-grant-tables 注释掉,systemctl restart mysqld

二、导入 mysql5.6 数据

创建授权账户 grant all on *.* to ‘***’@’%’ identified by ‘***’;

flush privileges;

create database *** default character set utf8;

在导入 sql 数据时,会出现有的函数及过程不能导入的情况,在 my.cnf 文件的 mysqld 段加入 log_bin_trust_function_creators=1, 重启 mysql 导入成功。成功后注释掉该行。

对于外键限制,先行取消限制,导入后在开启限制

set FOREIGN_KEY_CHECKS=0;

执行 sql 导入或者用 navigat 导入,成功后执行 Set FOREIGN_KEY_CHECKS=1

三、jboss/wildfly 应用项目部署

1、部署 jboss/wildfly

解压,tar xvf ;  mv  /usr/local/jboss/wildfly

设置路径 vim /etc/profile, 加 export

WILDFLY_HOME=/usr/local/wildfly;export PATH=$PATH:$WILDFLY_HOME/bin

source /etc/profile

2、更改配置

修改 /usr/local/wildfly/standalone/configuration/standalone.xml

<interface name=”management”>

  <inet-address value=”${jboss.bind.address.management:0.0.0.0}”/>

</interface>

<interface name=”public”>

  <inet-address value=”${jboss.bind.address:0.0.0.0}”/>

更改默认端口,由 8080 改为 80,也可以改为其他

<socket-binding name=”http” port=”${jboss.http.port:80}”/>

启动服务:standalone.sh,

3、配置数据源

由 console 管理 wildfly 添加数据源, 提示 add-user.sh, 添加用户 admin

登陆 本机 ip:9990

添加 driver:

step 1: 下载好 mysql-connector-Java-5.1.47.jar

step 2: 登陆 本机 ip:9990 选择 Runtime/Manage Deployments/add mysql-connector, 名称为 mysql,runname 为 mysql,然后 save, 再 enable     

step 3: 选 Configuration/Connctor/Datasources , 增加 jndi 数据源

name: ***,JNDI Name: java:jboss/datasources/***, Driver 为我们刚才导入的 jar 包的驱动:mysql_com.mysql.jdbc.Driver_5_1,connection url: jdbc:mysql://ip/ 数据库 ***, 其中的 IP 地址为部署的数据库服务器的 ip,username:***,password:***,save 之后 enable, 同时测试是否连接成功 test connection, 成功即为创建成功。

4、部署应用项目

  编辑 standalone.xml 文件,在 <subsystem xmlns=”urn:jboss:domain:deployment-scanner:2.0″> 端内增加

<deployment-scanner name=” 项目名 ” path=” 项目所在路径 ” scan-enabled=”true” scan-interval=”5000″ auto-deploy-zipped=”true” auto-deploy-exploded=”false” deployment-timeout=”60″/>

在“项目所在的路径“目录下 mkdir 项目名.war,touch 项目名.dodeploy,把项目所有文件放入项目名.war 目录下。

5. 重新启动 Jboss/wildfly

standalone.sh

四、错误及故障处理

1、ERROR [stderr] (XNIO-1 task-4) Wed Jan 09 15:19:57 CST 2019 WARN: Establishing SSL connection without server’s identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn’t set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to ‘false’. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.

排除:在 standalone.xml 文件中修改

<connection-url>jdbc:mysql://ip 地址 / 数据库名?useSSL=true</connection-url> 添加?useSSL=true

错误排除

2、启动 jboss 出现

Address “0.0.0.0” is a wildcard address, which will not match against any specific address. Do not use the ‘inet-address’ configuration elementto specify that an interface should use a wildcard address; use ‘any-address’, ‘any-ipv4-address’, or ‘any-ipv6-address’

解决:在 jboss/standalone/configuration/standlone.xml 文件中改

<interface name=”public”> 中 inet-address 为 any-ipv4-address 重启 jboss/bin/standlone.sh

3、登录应用项目,提示密码错误,无法登陆

经排查,为 mysql5.6 数据库升级为 mysql5.7 而出现的故障,需在 my.cnf 文件中加入 sql_mode=,故障消除

4、应用项目查询特别慢问题

经排查为 mysql5.6 数据库升级为 mysql5.7 而出现的故障,需要关闭 derived_merge,在 mysql 启动后执行

mysql -u*** -p***  -e  “set  GLOBAL optimizer_switch=’derived_merge=off’;”

重新进入应用项目,查询速度恢复正常。

5、配置 jboss/wildfly 数据源,因数据源超时问题的解决

Caused by: java.lang.RuntimeException: org.springframework.dao.RecoverableDataAccessException:
### Error querying database.  Cause: com.mysql.cj.jdbc.exceptions.CommunicationsException: The last packet successfully received from the server was 154,231 milliseconds ago.  The last packet sent successfully to the server was 154,231 milliseconds ago. is longer than the server configured value of ‘wait_timeout’. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property ‘autoReconnect=true’ to avoid this problem.

可以更改 my.cnf 文件中的

wait_timeout=2147483
interactive_timeout=2147483

将两个值改大,也不能改的太大。

重启 mysql 服务器,重启应用,问题解决。

正文完
星哥说事-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-22发表,共计4650字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中