最近看了一个问题,看问题的表现着实比较奇怪,困扰了我好一会儿。
问题的背景是帮助开发的同学解决一个数据库问题,最后问题解决之后,我想做一个操作系统级的检查,帮他们看看还有什么需要注意的地方。然后在命令行中国登陆到了这台数据库服务器,切换到Oracle用户之后,查看到数据库实例为cytj,然后准备做一番检查。
#ps -ef|grep smon
root 3657 32596 0 17:37 pts/2 00:00:00 grep smon
oracle 5433 1 0 2015 ? 00:45:46 ora_smon_cytj
但是这个时候,奇怪的问题就发生了。
#su - oracle
-bash: ulimit: open files: cannot modify limit: Operation not permitted
$sqlplus / as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Mon Mar 7 17:37:56 2016
Copyright (c) 1982, 2013, Oracle. All rights reserved.
ERROR:
ORA-01017: invalid username/password; logon denied
Enter user-name:
碰到这种问题,看起来还是哪几种常规的思路,其中之一就是看看ORACLE_HOME是否完全映射。根据smon的进程得到进程号为5433,在/proc/5433下面可以得到一个环境变量的列表。
$cat /proc/5433/environ|xargs -0 -n1 |grep ORACLE_HOME
ORACLE_HOME=/U01/app/oracle/product/11.2.0.4
解析得到ORACLE_HOME的路径
然后查看系统环境变量的值$ORACLE_HOME,发现也确实是完全映射的。
$echo $ORACLE_BASE
/U01/app/oracle
$echo $ORACLE_HOME
/U01/app/oracle/product/11.2.0.4
那么ORACLE_SID,ORACLE_HOME都没有问题,怎么就连接不到这个实例了呢?
一种分析问题的思路就是,查看网络的配置情况,是否为/etc/hosts的配置问题。然后查看数据库
$cat /etc/sysconfig/network
NETWORKING=yes
NETWORKING_IPV6=no
#GATEWAY=
HOSTNAME=BJ-BX-131-190
$cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
10.127.131.190 BJ-BX-131-190
$cat /U01/app/oracle/product/11.2.0.4/network/admin/sqlnet.ora
# sqlnet.ora Network Configuration File: D:\oracle\product\11.2.0\dbhome_1\network\admin\sqlnet.ora
# Generated by Oracle configuration tools.
# This file is actually generated by netca. But if customers choose to
# install "Software Only", this file wont exist and without the native
# authentication, they will not be able to connect to the database on NT.
SQLNET.AUTHENTICATION_SERVICES= (NTS)
NAMES.DIRECTORY_PATH= (TNSNAMES, EZCONNECT)
使用tnsping来检测tns连接串的情况,也没有发现任何问题。当然这个地方和sqlplus / as sysdba 应该没有直接关系,但是通过这个可以说明网络服务配置都是合理的。
[admin]$tnsping cytj
TNS Ping Utility for Linux: Version 11.2.0.4.0 - Production on 07-MAR-2016 18:02:35
Copyright (c) 1997, 2013, Oracle. All rights reserved.
Used parameter files:
/U01/app/oracle/product/11.2.0.4/network/admin/sqlnet.ora
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 10.127.131.190)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = cytj)))
OK (20 msec)
使用一个普通用户来本地连接测试,发现scott用户是锁定的,通过这个也能够说明连接是起了作用了。
[admin]$sqlplus scott/tiger
SQL*Plus: Release 11.2.0.4.0 Production on Mon Mar 7 18:03:40 2016
Copyright (c) 1982, 2013, Oracle. All rights reserved.
ERROR:
ORA-28000: the account is locked
然后换做tns连接的方式,发现错误也是一样,说明走网络连接的方式也起作用了。
[admin]$sqlplus scott/tiger@cytj
SQL*Plus: Release 11.2.0.4.0 Production on Mon Mar 7 18:03:40 2016
Copyright (c) 1982, 2013, Oracle. All rights reserved.
ERROR:
ORA-28000: the account is locked
然后对于这个错误,在这个系统中摸索了一番,发现这个路径着实够乱,竟然存在两个ORACLE_HOME,
当前的是:
/U01/app/oracle/product/11.2.0.4/dbs
发现的新ORACLE_HOME是
/home/U01/app/oracle/product/11.2.0.4/dbs
但是经过一番论证发现然并卵,这个路径对这个问题实际上没有造成什么影响。
因为ORACLE_HOME这些配置完全和另外一个ORACLE_HOME没有任何关联。
还有一些可能就是和密码文件有关,于是我手工修改了sys密码,再次登录。
[dbs]$sqlplus system/oracle
SQL*Plus: Release 11.2.0.4.0 Production on Mon Mar 7 22:12:11 2016
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning and Real Application Testing options
SQL> alter user sys identified by oracle;
User altered.
然后再次登录,问题依旧。
这个时候还可以进一步排除密码文件的影响,比如我指定了一个不存在的实例test,这个时候sqlplus / as sysdba应该接入一个空实例。
$export ORACLE_SID=test
$sqlplus / as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Mon Mar 7 19:28:42 2016
Copyright (c) 1982, 2013, Oracle. All rights reserved.
ERROR:
ORA-01017: invalid username/password; logon denied
然后进一步测试,发现dg broker登录也有问题。
[dbs]$dgmgrl /
DGMGRL for Linux: Version 11.2.0.4.0 - 64bit Production
Copyright (c) 2000, 2009, Oracle. All rights reserved.
Welcome to DGMGRL, type "help" for information.
ORA-01017: invalid username/password; logon denied
使用rman来登录发现也是同样的错误。
[dbs]$rman target /
Recovery Manager: Release 11.2.0.4.0 - Production on Mon Mar 7 19:29:36 2016
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-00554: initialization of internal recovery manager package failed
RMAN-04005: error from target database:
ORA-01017: invalid username/password; logon denied
好了,事已至此,可以充分肯定问题出在这个本地操作系统认证上,oracle所在的用户组都是没有问题的。
操作系统认证在$ORACLE_HOME/network/admin/sqlnet.ora也有一些关系。
我们看看这个文件是怎么配置的。
[admin]$vi sqlnet.ora
# sqlnet.ora Network Configuration File: D:\oracle\product\11.2.0\dbhome_1\network\admin\sqlnet.ora
# Generated by Oracle configuration tools.
# This file is actually generated by netca. But if customers choose to
# install "Software Only", this file wont exist and without the native
# authentication, they will not be able to connect to the database on NT.