1.server端开启TCP连接和CATALOG认证
##查看是否开启TCP连接
[db2inst1@dxyun ~]$ db2set -all
[i] DB2_SKIPINSERTED=YES
[i] DB2_USE_ALTERNATE_PAGE_CLEANING=YES
[i] DB2_EVALUNCOMMITTED=YES
[i] DB2_SKIPDELETED=YES
[i] DB2COMM=TCPIP
[i] DB2CODEPAGE=1208
[i] DB2_PARALLEL_IO=*
[i] DB2AUTOSTART=YES
[g] DB2SYSTEM=dxyun
一般DB2都会开启TCP连接,如果不是TCPIP需要:
db2set DB2COMM=TCPIP
然后重启db2实例
##查看是否开启catalog认证
$ db2 get dbm cfg |grep -i CATALOG_NOAUTH
Cataloging allowed without authority (CATALOG_NOAUTH) = NO
$ db2 update dbm cfg using CATALOG_NOAUTH yes
2.client端配置编目
##创建节点
db2 catalog tcpip node dxyun remote 28.143.132.64 server 50000 ##dxyun是节点名,50000是db2端口号
db2 uncatalog node dxyun #如果需要取消
##创建catalog db
db2 catalog db dsgdb as dsgdb at node dxyun authentication server ##dsgdb是数据库的名称,dxyun是上面创建的节点名称
db2 uncatalog database dsgdb ##如果需要取消
db2 terminate
##查看配置的编目信息
[db2inst1@db2test1 ~]$ db2 list node directory
Node Directory
Number of entries in the directory = 1
Node 1 entry:
Node name = DXYUN
Comment =
Directory entry type = LOCAL
Protocol = TCPIP
Hostname = 28.143.132.64
Service name = 50000
[db2inst1@db2test1 ~]$ db2 list db directory
System Database Directory
Number of entries in the directory = 1
Database 1 entry:
Database alias = DSGDB
Database name = DSGDB
Node name = DXYUN
Database release level = 15.00
Comment =
Directory entry type = Remote
Catalog database partition number = -1
Alternate server hostname =
Alternate server port number =
3.在client端登录
[db2inst1@db2test1 ~]$ db2 connect to DSGDB user dsg using XXXX
Database Connection Information
Database server = DB2/LINUXX8664 11.5.0.0
SQL authorization ID = DSG
Local database alias = DSGDB
4.遇到的问题
配置完成之后遇到:
[db2inst1@db2test1 ~]$ db2 connect to DSGDB user db2inst1 using db2inst1
SQL30081N A communication error has been detected. Communication protocol
being used: "TCP/IP". Communication API being used: "SOCKETS". Location
where the error was detected: "223.247.138.64". Communication function
detecting the error: "connect". Protocol specific error code(s): "111", "*",
"*". SQLSTATE=08001
可能是第一次配置错误,后面执行:
db2 terminate
恢复。
如果遇到其它错误,见下面的说明:
The specific return code listed in thiserror output is a 10061, which is the tcp/ip error ECONNREFUSED. "Theconnection has been refused. If you are trying to connect to thedatabase, check that the database manager and TCP/IP protocol support atthe server has been started successfully".Typically this particular error message occurs under one of thefollowing scenarios:1. The instance is not running. Issue a db2start to confirm that theinstance is online and try the connection again.2. The instance on the remote server has not been configured to acceptTCP/IP communication requests. On the server, please verify thefollowing:a. Issue a db2set -all and confirm that the parameter DB2COMM=TCPIP.If this is not set, issue:db2set DB2COMM=TCPIPb. Issue the command "db2 get dbm cfg | grep SVCENAME" and confirm thatthis parameter is not blank. This may either specify a service namedefined in your /etc/services file, or a port number, but this valuemust be set. If this is blank, please update the dbm cfg using:db2 update dbm cfg using SVCENAME 50000db2stopdb2startOnce the instance has been restarted, verify that the TCP/IP port islistening with the command:netstat -an | grep 50000This should return output similar to the following:tcp4 0 0 *.50000 *.*LISTENAlso note that if the SVCENAME parameter specifies a service name ratherthan a port number, this service name must be defined in /etc/services.3. The catalog on the client has specified the wrong port number. Onthe client, please issue the command "db2 list node directory" andlocate the entry for the system in question. Please verify that theport number listed here under the Service name field matches that of theport number specified in the SVCENAME parameter on the server. As onthe server, if the service name specifies a name rather than a port,this must exist by the same name (case sensitive) in the /etc/servicesfile on Unix, or in the C:\Windows\System32\drivers\etc\services file onWindows.4. The catalog on the client may have the wrong host name specified, ora correct host name that can not be identified by the network. Pleasecheck the Hostname parameter in the "db2 list node directory" from item3 above, and confirm if this target can be reached using the pingcommand:ping <hostname>If the ping is successful, your network should be configured correctlyto reach this machine. If the ping failed, please verify that the/etc/hosts file on the client (if Unix) or theC:\Windows\system32\drivers\etc\hosts file (on Windows) has an IPaddress specified for this host name. Alternately, you may catalog theconnection directly specifying the IP address.5. If the client and the server are on opposite sides of a firewall,please ensure that your firewall or router are not configured to blockcommunication on the port specified for the SVCENAME parameter on theserver.