我希望使用 LDAP 连接到 Oracle 数据库以进行连接字符串查找。LDAP/OID 已设置,并且手动使用从 LDAP 检索的连接字符串有效。但是,Oracle 客户端 ( sqlplus
) 的连接字符串的自动 LDAP 查找无效!根据 Google 的说法,需要设置文件sqlnet.ora
和ldap.ora
以通知 Oracle 客户端我们希望使用 LDAP 查找。据我所知,这已完成,值是正确的:
export ORACLE_HOME=/etc/oracle
$ORACLE_HOME/网络/管理员/sqlnet.ora
NAMES.DIRECTORY_PATH = (LDAP)
$ORACLE_HOME/ldap/admin/ldap.ora
DIRECTORY_SERVERS = (<host>:<port>)
DEFAULT_ADMIN_CONTEXT = "cn=OracleContext,dc=example,dc=com"
DIRECTORY_SERVER_TYPE = OID
然而,当我尝试连接时,我仍然遇到
$ sqlplus64 'user/password@identifier'
ERROR
ORA-12154: TNS:could not resolve the connect identifier specified
进一步,通过strace
运行 sqlplus 客户端,可以看到两个文件(sqlnet.ora
、ldap.ora
)至少都被打开了:
open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
open("/usr/lib/oracle/12.1/client64/lib/libsqlplus.so", O_RDONLY|O_CLOEXEC) = 3
open("/usr/lib/oracle/12.1/client64/lib/libclntsh.so.12.1", O_RDONLY|O_CLOEXEC) = 3
open("/usr/lib/oracle/12.1/client64/lib/libclntshcore.so.12.1", O_RDONLY|O_CLOEXEC) = 3
open("/usr/lib/oracle/12.1/client64/lib/libnnz12.so", O_RDONLY|O_CLOEXEC) = 3
open("/lib/x86_64-linux-gnu/libdl.so.2", O_RDONLY|O_CLOEXEC) = 3
open("/lib/x86_64-linux-gnu/libm.so.6", O_RDONLY|O_CLOEXEC) = 3
open("/lib/x86_64-linux-gnu/libpthread.so.0", O_RDONLY|O_CLOEXEC) = 3
open("/lib/x86_64-linux-gnu/libnsl.so.1", O_RDONLY|O_CLOEXEC) = 3
open("/lib/x86_64-linux-gnu/librt.so.1", O_RDONLY|O_CLOEXEC) = 3
open("/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
open("/usr/lib/oracle/12.1/client64/lib/libons.so", O_RDONLY|O_CLOEXEC) = 3
open("/lib/x86_64-linux-gnu/libaio.so.1", O_RDONLY|O_CLOEXEC) = 3
open("/usr/lib/oracle/12.1/client64/lib/libsqlplusic.so", O_RDONLY|O_CLOEXEC) = 3
open("/usr/lib/oracle/12.1/client64/lib/libociei.so", O_RDONLY|O_CLOEXEC) = 3
open("/etc/oracle/network/admin/oraaccess.xml", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/etc/oracle/network/admin/oraaccess.xml", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/etc/oracle/network/admin/sqlnet.ora", O_RDONLY) = 3
open("/etc/orabasetab", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/etc/oracle/install/orabasetab", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/etc/nsswitch.conf", O_RDONLY|O_CLOEXEC) = 3
open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
open("/lib/x86_64-linux-gnu/libnss_compat.so.2", O_RDONLY|O_CLOEXEC) = 3
open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
open("/lib/x86_64-linux-gnu/libnss_nis.so.2", O_RDONLY|O_CLOEXEC) = 3
open("/lib/x86_64-linux-gnu/libnss_files.so.2", O_RDONLY|O_CLOEXEC) = 3
open("/etc/passwd", O_RDONLY|O_CLOEXEC) = 3
open("/proc/self/fd/", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = 3
open("/etc/passwd", O_RDONLY|O_CLOEXEC) = 4
open("/etc/oracle/network/admin/sqlnet.ora", O_RDONLY) = 4
open("/usr/lib64/libnuma.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/usr/lib64/libnuma.so.1", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/proc/sys/kernel/shmmax", O_RDONLY) = 4
open("/proc/meminfo", O_RDONLY) = 4
open("/proc/sys/kernel/shmmax", O_RDONLY) = 4
open("/usr/lib64/libnuma.so", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/usr/lib64/libnuma.so.1", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/etc/localtime", O_RDONLY|O_CLOEXEC) = 4
open("/etc/hostid", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/etc/resolv.conf", O_RDONLY|O_CLOEXEC) = 4
open("/etc/host.conf", O_RDONLY|O_CLOEXEC) = 4
open("/etc/hosts", O_RDONLY|O_CLOEXEC) = 4
open("/etc/passwd", O_RDONLY|O_CLOEXEC) = 4
open("/etc/oracle/ldap/admin/fips.ora", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/dev/urandom", O_RDONLY) = 4
open("/dev/urandom", O_RDONLY) = 5
open("entropy", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/etc/oracle/ldap/admin/ldap.ora", O_RDONLY) = 6
open("/etc/oracle/ldap/admin/ldap.ora", O_RDONLY) = 6
open("/etc/resolv.conf", O_RDONLY|O_CLOEXEC) = 6
open("/etc/hosts", O_RDONLY|O_CLOEXEC) = 6
open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 6
open("/lib/x86_64-linux-gnu/libnss_mdns4_minimal.so.2", O_RDONLY|O_CLOEXEC) = 6
open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 6
open("/lib/x86_64-linux-gnu/libnss_dns.so.2", O_RDONLY|O_CLOEXEC) = 6
open("/lib/x86_64-linux-gnu/libresolv.so.2", O_RDONLY|O_CLOEXEC) = 6
open("/etc/hosts", O_RDONLY|O_CLOEXEC) = 6
open("/etc/hosts", O_RDONLY|O_CLOEXEC) = 6
open("/etc/hosts", O_RDONLY|O_CLOEXEC) = 6
open("/etc/hosts", O_RDONLY|O_CLOEXEC) = 6
strace: Process 30041 detached
请告诉我我遗漏了什么?我是 Oracle 新手,所以新手建议可能会有帮助!
客户端是安装了oracle instant client的ubuntu 16.04服务器:
oracle-instantclient12.1-devel: 12.1.0.1.0-2
oracle-instantclient12.1-basic: 12.1.0.1.0-2
oracle-instantclient12.1-sqlplus: 12.1.0.1.0-2
oracle-instantclient12.1-odbc: 12.1.0.1.0-2
答案1
您还需要设置TNS_管理员变量指向文件所在的文件夹。
例子 :
export TNS_ADMIN=$ORACLE_HOME/ldap/admin
(它可能默认指向其他地方,或者取决于您的环境变量,也许是指向一个有空文件的地方)。另外,检查您的文件权限,您的客户端需要能够读取这些文件(644)。
你还需要确保你为数据库使用了正确的 SID。你有NAMES.DEFAULT_DOMAIN变量设置sqlnet.ora文件?尝试在命令中将 .world 附加到 SID,例如:
sqlplus login/[email protected]
和/或在您的sqlnet.ora也 :
NAMES.DEFAULT_DOMAIN = WORLD
另外,你还需要检查其他几件事,你的数据库是否在 OID 中正确“注册”?(通常是用数据库管理工具)
另一件事:当您浏览 OID 时,您在“cn=OracleContext,dc=example,dc=com”下看到了什么?您应该有一个包含数据库 sid 的条目(cn=DB_SID,cn=OracleContext,dc=示例,dc=com在此条目中(如果存在),您应该有一个“orclnetdescstring”,其中包含您的数据库信息(主机、端口和 SID,实际上是真正的 tns),此信息正确吗?你的问题可能来自于那里(您尝试联系的数据库条目中的描述字符串错误,或者数据库未在 OID 中正确注册)..
你还需要做许多其他检查,如果上述方法解决了你的问题,请告诉我,谢谢