GBase 8s数据库配置使用IPv6

1, 网卡配置(CentOS 7)

修改/etc/sysconfig/network-scripts/ifcfg-ens33配置文件,按以下内容提示修改

TYPE="Ethernet"
PROXY_METHOD="none"
BROWSER_ONLY="no"
BOOTPROTO="none"
DEFROUTE="yes"
IPV4_FAILURE_FATAL="yes"
# 确认IPV6INIT的值为yes
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_FAILURE_FATAL="no"
IPV6_ADDR_GEN_MODE="stable-privacy"
# 增加IPV6ADDR和IPV6_DEFAULTGW,注意不要使用私网地址
IPV6ADDR="3ffe:ffff:ffff:ffff::12/64"
IPV6_DEFAULTGW="3ffe:ffff:ffff:ffff::1"
NAME="ens33"
UUID="caab0c05-8e0d-4526-9dcf-e966cd9eef34"
DEVICE="ens33"
ONBOOT="yes"
IPADDR="192.168.80.70"
PREFIX="24"
GATEWAY="192.168.80.2"
DNS1="192.168.80.2"
DOMAIN="192.168.80.2"
IPV6_PRIVACY="no"

重启网络

systemctl restart network

使用ip a确认IPv6地址生效
只有状态是scope global noprefixroute才是可以使用的

2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:e9:74:ef brd ff:ff:ff:ff:ff:ff
    inet 192.168.80.70/24 brd 192.168.80.255 scope global noprefixroute ens33
       valid_lft forever preferred_lft forever
    inet6 3ffe:ffff:ffff:ffff::12/64 scope global noprefixroute                         # 只有状态是scope global noprefixroute才是可以使用的
       valid_lft forever preferred_lft forever
    inet6 fe80::53f5:39c2:5f0:3bd8/64 scope link noprefixroute
       valid_lft forever preferred_lft forever

2,数据库IPv6配置

在sqlhosts配置文件中增加ipv6接口配置

gbase01     onsoctcp 192.168.80.80           9088
gbase01_ip6 onsoctcp 3ffe:ffff:ffff:ffff::12 9098

修改onconfig配置文件,在DBSERVERNAMEALIASES中增加gbase01_ip6的服务名配置

DBSERVERNAME gbase01
DBSERVERALIASES gbase01_ip6

重启数据库,通过onstat -g ntt确认网络接口生效

GBase Database Server Version 12.10.FC4G1AEE -- On-Line -- Up 00:16:33 -- 768812 Kbytes

global network information:
  #netscb connects         read        write    q-free  q-limits  q-exceed alloc/max
   6/   7        1            9            9    1/   1  240/  10    0/   0    1/   1

Individual thread network information (times):
          netscb thread name    sid     open     read    write address
        47e6eaa8 sm_discon       10 06:21:34
        47e60668 sm_listen        7 06:21:34
        49940c90 soctcplst        5 06:21:34 06:21:56          3ffe:ffff:ffff:ffff::12|9098|soctcp     # 确认存在该端口
        47e4c618 soctcplst        4 06:21:34                   192.168.80.70|9088|soctcp
        47e4c290 sm_poll          3 06:21:34
        47e42ab0 soctcppoll       2 06:21:34

3,数据库连接

1)、dbaccess 简单连接测试
使用dbaccess sysmaster@gbase01_ip6 - 进行连接, 另开一个窗口,使用netstat -an | grep 9098进行检查

tcp6       0      0 3ffe:ffff:ffff:fff:9098 :::*                    LISTEN
tcp6       0      0 3ffe:ffff:ffff:fff:9098 3ffe:ffff:ffff:ff:50336 ESTABLISHED
tcp6       0      0 3ffe:ffff:ffff:ff:50336 3ffe:ffff:ffff:fff:9098 ESTABLISHED

2)、使用JDBC连接测试
编写简单的测试TestIpv6.java,示例如下:

import java.io.IOException;
import java.sql.*;

public class TestIpv6 {

    public static void main(String[] args) throws SQLException, ClassNotFoundException, InterruptedException, IOException {
        System.out.println("测试数据库使用IPv6连接");
        String url = "jdbc:gbasedbt-sqli://3ffe:ffff:ffff:ffff::12:9098/testdb:GBASEDBTSERVER=gbase01;DB_LOCALE=zh_CN.utf8;CLIENT_LOCALE=zh_CN.utf8;IFX_LOCK_MODE_WAIT=30;";
        String user = "gbasedbt";
        String pass = "GBase123";

        Class.forName("com.gbasedbt.jdbc.Driver");
        Connection connection = DriverManager.getConnection(url, user, pass);
        Statement statement = connection.createStatement();

        ResultSet resultSet = statement.executeQuery("select DBSERVERNAME,current from dual");
        while(resultSet.next()){
            System.out.println("服务名称: " + resultSet.getObject(1));
            System.out.println("系统时间: " + resultSet.getObject(2));
        }
        resultSet.close();
        statement.close();
        connection.close();

    }
}

javac编译,执行测试(java环境需包含jdbc驱动地址)

javac TestIpv6.java
java -cp .:gbasedbtjdbc_3.3.0_3.jar TestIpv6

示例结果:

测试数据库使用IPv6连接
服务名称: gbase01
系统时间: 2023-03-07 06:52:03.0

标签: GBase, ipv6, scope global noprefixroute

添加新评论