通过mysql-proxy、haproxy和keepalived配置的负载均衡加读写分离后java客户端通过vip的4000端口无法访问数据库

只是学习学习 2017-12-11 06:36:31
最近在学习搭建mysql的负载均衡加读写分离,搭建完成后,使用navicatk可以使用vip连接服务但是如果我在Java中去连接就用不了,不知道哪位大神可以帮忙看下,以下是我的配置:
keepaplived.config
global_defs {
notificationd LVS_DEVEL
}
vrrp_script chk_haproxy {
script "/etc/keepalived/chk.sh"
interval 2
}
vrrp_instance VI_1 {
state BACKUP
nopreempt
interface eth0
virtual_router_id 11
priority 110

advert_int 1
authentication {
auth_type PASS
auth_pass asd
}
virtual_ipaddress {
192.168.1.250
}
track_script {
chk_haproxy
}

notify_backup "/etc/init.d/haproxy restart"
notify_fault "/etc/init.d/haproxy stop"
}

keepalived的chk.sh内容
#!/bin/bash
#
if [ $(ps -C haproxy --no-header | wc -l) -eq 0 ]; then
/etc/init.d/keepalived stop
fi

haproxy的配置,haproxy.cnf:
global

log 127.0.0.1 local2
chroot /var/lib/haproxy
pidfile /var/run/haproxy.pid
maxconn 4000
user haproxy
group haproxy
daemon
stats socket /var/lib/haproxy/stats

defaults
mode tcp
log global
option dontlognull
option redispatch
retries 3
timeout http-request 10s
timeout queue 1m
timeout connect 10s
timeout client 1m
timeout server 1m
timeout http-keep-alive 10s
timeout check 10s
maxconn 600

listen stats
mode http
bind :8888
stats enable
stats hide-version
stats uri /haproxyadmin?stats
stats realm Haproxy\ Statistics
stats auth admin:admin

frontend main
bind 0.0.0.0:3306
default_backend mysql

backend mysql
balance leastconn
server mysql1 192.168.1.9:3306 check port 3306 maxconn 300

mysql-proxy的配置mysql-proxy.cnf:
[mysql-proxy]
user=root
admin-username=root
admin-password=root
proxy-address=192.168.1.162:4000
proxy-read-only-backend-addresses=192.168.1.162:3306
proxy-backend-addresses=192.168.1.33:3306
proxy-lua-script=/usr/local/mysql-proxy/lua/rw-splitting.lua
admin-lua-script=/usr/local/mysql-proxy/lua/admin-sql.lua
log-file=/var/log/mysql-proxy.log
log-level=debug
daemon=true
keepalive=true

mysql-proxy启动的方式:
/usr/local/mysql-proxy/bin/mysql-proxy -P 192.168.1.250:4000 --defaults-file=/etc/mysql-proxy.cnf &

java中配置文件的连接方式
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://192.168.1.250:4000/blog?characterEncoding=utf-8
jdbc.username=root
jdbc.password=root

启动项目时报的错误:
Mon Dec 11 17:34:28 CST 2017 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.
Mon Dec 11 17:34:29 CST 2017 WARN: Invalid value 'null' for server variable named 'auto_increment_increment', falling back to sane default of '1'.
2017-12-11 17:34:29,290 [Druid-ConnectionPool-Create-781348922] [com.alibaba.druid.pool.DruidDataSource]-[ERROR] create connection error
com.mysql.jdbc.PacketTooBigException: Packet for query is too large (27 > -1). You can change this value on the server by setting the max_allowed_packet' variable.
at com.mysql.jdbc.MysqlIO.readPacket(MysqlIO.java:577)
at com.mysql.jdbc.MysqlIO.getResultSet(MysqlIO.java:417)
at com.mysql.jdbc.MysqlIO.readResultsForQueryOrUpdate(MysqlIO.java:3112)
at com.mysql.jdbc.MysqlIO.readAllResults(MysqlIO.java:2341)
Mon Dec 11 17:34:29 CST 2017 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.
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2736)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2483)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2441)
at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1381)
at com.mysql.jdbc.SQLError.convertShowWarningsToSQLWarnings(SQLError.java:704)
at com.mysql.jdbc.MysqlIO.scanForAndThrowDataTruncation(MysqlIO.java:4188)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2804)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2483)
at com.mysql.jdbc.ConnectionImpl.setupServerForTruncationChecks(ConnectionImpl.java:5150)
at com.mysql.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:3393)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2235)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2017)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:779)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)

我已经尝试过在mysql连接后加useSSL=false但是没有用依然报错
请问大神,我这里是哪个地方报错了
...全文
424 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
只是学习学习 2017-12-14
  • 打赏
  • 举报
回复
引用 1 楼 rucypli 的回复:
1 按照报错尝试在server端口执行set global max_allowed_packet=4194304 2 看下mysql-proxy的日志有无信息
我的数源信息在另一个文章中http://bbs.csdn.net/topics/392298015
只是学习学习 2017-12-14
  • 打赏
  • 举报
回复
引用 1 楼 rucypli 的回复:
1 按照报错尝试在server端口执行set global max_allowed_packet=4194304 2 看下mysql-proxy的日志有无信息
谢谢你的回答,不过现在不报错了,但启动时一直卡住,
2017-12-14 14:35:19,226 [RMI TCP Connection(3)-127.0.0.1] [org.apache.ibatis.io.ResolverUtil]-[DEBUG] Checking to see if class com.geekfaith.entity.User matches criteria [is assignable to Object]
2017-12-14 14:35:19,228 [RMI TCP Connection(3)-127.0.0.1] [org.apache.ibatis.io.ResolverUtil]-[DEBUG] Checking to see if class com.geekfaith.entity.UserOperation matches criteria [is assignable to Object]
2017-12-14 14:35:19,229 [RMI TCP Connection(3)-127.0.0.1] [org.apache.ibatis.io.ResolverUtil]-[DEBUG] Checking to see if class com.geekfaith.entity.UserOperationType matches criteria [is assignable to Object]
2017-12-14 14:35:19,231 [RMI TCP Connection(3)-127.0.0.1] [org.mybatis.spring.SqlSessionFactoryBean]-[DEBUG] Scanned package: 'com.geekfaith.entity' for aliases
2017-12-14 14:35:19,231 [RMI TCP Connection(3)-127.0.0.1] [org.mybatis.spring.SqlSessionFactoryBean]-[DEBUG] Registered plugin: 'com.baomidou.mybatisplus.plugins.CachePaginationInterceptor@6ce0a0d0'
Thu Dec 14 14:35:19 CST 2017 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.
14-Dec-2017 14:35:22.244 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory D:\Java\apache-tomcat-8.0.28\webapps\manager
14-Dec-2017 14:35:22.349 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory D:\Java\apache-tomcat-8.0.28\webapps\manager has finished in 103 ms
在网上各种找也没有找到原因,项目无法启动
rucypli 2017-12-12
  • 打赏
  • 举报
回复
1 按照报错尝试在server端口执行set global max_allowed_packet=4194304 2 看下mysql-proxy的日志有无信息

56,677

社区成员

发帖
与我相关
我的任务
社区描述
MySQL相关内容讨论专区
社区管理员
  • MySQL
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧