Closed xif10416s closed 10 years ago
使用cobar driver 需要cobar server配置cluster,配置了吗?
server配置cluster
在自己本地电脑上发布的cobar server ,本地localhost可以通过cobar driver 连接 发布在实际linux 服务器上 ,在本地通过cobar driver 访问服务器的8066就报错 怀疑是不是: socket.connect(new InetSocketAddress(host, port), timeout); 没权限连接到linux服务器上
你使用的ip地址对吗?
String url = "jdbc:mysql:serverIp" 没问题 String url = "jdbc:cobar:serverIp" 就不行
贴一下你的cluster配置和driver连接配置,cobar driver 连接用的127.0.0.1?
cluster配置 cluster node name="cobar1" property name="host" XX.XX.XX.82 property //内网ip property name="weight" 1 /property node node name="cobar2" property name="host" XX.XX.XX.67 property //内网ip property name="weight" 1 property node
String url = "jdbc:cobar://xxx.xx.xx.82:8066/hsp_clog"; //外网ip <==error String url = "jdbc:mysql://xxx.xx.xx..82:8066/hsp_clog"; //外网ip <== ok
82和67两台都配置了cluster吗?还有看一下cobar server上的log,有没有关于心跳检测的异常
82和67两台都配置了cluster,都是同一套配置内容,心跳检测也是正常的
在阿里云上的测试环境也没问题,应该是我们实际服务器设置端口权限什么的问题
这个问题解决了么?
source
try { Class.forName("com.alibaba.cobar.jdbc.Driver"); } catch (ClassNotFoundException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } String url = "jdbc:cobar://127.0.0.1:8066/test"; Properties info = new Properties(); info.setProperty("user", "test"); info.setProperty("password", "test"); Connection con = null; try { con = DriverManager.getConnection(url, info);
Statement stmt = con.createStatement();
error:
java.sql.SQLException: java.net.SocketException: Connection reset at com.alibaba.cobar.jdbc.UrlProvider.getUrl(UrlProvider.java:47) at com.alibaba.cobar.jdbc.Driver.connect(Driver.java:65) at java.sql.DriverManager.getConnection(DriverManager.java:582) at java.sql.DriverManager.getConnection(DriverManager.java:154) at com.fxi.test.main.MainTest.testDriver(MainTest.java:52) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20) at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184) at org.junit.runners.ParentRunner.run(ParentRunner.java:236) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197) Caused by: java.net.SocketException: Connection reset at java.net.SocketInputStream.read(SocketInputStream.java:168) at java.io.BufferedInputStream.fill(BufferedInputStream.java:218) at java.io.BufferedInputStream.read1(BufferedInputStream.java:258) at java.io.BufferedInputStream.read(BufferedInputStream.java:317) at com.alibaba.cobar.jdbc.util.StreamUtil.read(StreamUtil.java:33) at com.alibaba.cobar.jdbc.util.StreamUtil.readUB3(StreamUtil.java:60) at com.alibaba.cobar.jdbc.packet.BinaryPacket.read(BinaryPacket.java:39) at com.alibaba.cobar.jdbc.UrlConnection.connect(UrlConnection.java:97) at com.alibaba.cobar.jdbc.UrlProvider.getUrl(UrlProvider.java:44) ... 27 more