Oracle wallet配置/管理/使用


在公司配置数据库时,向wallet中增加了一个新的数据库,现实无需输入用户名与密码来登陆数据库,增加完成后,导致整个监控系统都是报用户名与密码的错误,无法登陆来数据库。但是Oracle用户是能正常登陆数据库,不需要输入密码。其实原因很简单,因为我们的监控系统是nagios,而wallet相关的文件的默认权限是600,除ORACLE外其它的用户都是不可以读写的,正常情况下我们是改成了777的权限,让其它的用户也能使用钱包这个功能,当是我对wallet进行新增加一个数据库时,wallet会自己把cwallet.sso与ewallet.p12文件的权限自己改成600。这就导致了今天我的悲剧。

下面是wallet的配置/管理/维护/现象的模拟

1.创建wallet

  1. [oracle@test db_1]$ mkdir wallet 
  2. [oracle@test db_1]$ pwd 
  3. /u01/app/oracle/product/11.2.0/db_1 
  4. [oracle@test db_1]$ mkstore -wrl /u01/app/oracle/product/11.2.0/db_1/wallet -create 
  5. Oracle Secret Store Tool : Version 11.2.0.2.0 - Production 
  6. Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved. 
  7. #这里输入wallet的密码,对密码是有限制条件的 
  8. 1.密码长度要是8位以上。 
  9. 2.密码最大长度没有限制。 
  10. 3.密码要有字符与数据。 
  11. Enter password:              
  12.  
  13. Enter password again:              

2.配置wallet到sqlnet.ora中

  1. [oracle@test db_1]$ cat $ORACLE_HOME/network/admin/sqlnet.ora 
  2. NAMES.DIRECTORY_PATH= (TNSNAMES, EZCONNECT) 
  3. #DIRECTORY这里就是指定wallet所在的目录
  4. WALLET_LOCATION=(SOURCE=(METHOD=FILE)(METHOD_DATA=(DIRECTORY=/u01/app/oracle/product/11.2.0/db_1/wallet))) 
  5. SQLNET.WALLET_OVERRIDE=TRUE 
3.查看wallet的命令帮忙 wallet这个很好,因为直接用help就可以看到命令的帮忙了,不需要我们再去记复杂的参数,只用记住mkstore这个命令来管理wallet就可以了。
  1. [oracle@test db_1]$ mkstore -help 
  2. Oracle Secret Store Tool : Version 11.2.0.2.0 - Production 
  3. Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved. 
  4.  
  5. mkstore [-wrl wrl] [-create] [-createSSO] [-createLSSO] [-createALO] [-delete
  6. [-deleteSSO] [-list] [-createEntry alias secret] [-viewEntry alias] 
  7. [-modifyEntry alias secret] [-deleteEntry alias] 
  8. [-createCredential connect_string username password] [-listCredential] 
  9. [-modifyCredential connect_string username password] [-deleteCredential connect_string] [-help] [-nologo] 

4.增加数据库到wallet中去,并测试是否成功

  1. 3.1#增加net service为htz scott为用户 oracle为用户的密码。 
  2. #建议密码用''引起来,因为在生产环境中的密码基本上都是特殊字符的。 
  3. [oracle@test db_1]$ mkstore -wrl  /u01/app/oracle/product/11.2.0/db_1/wallet -createCredential htz scott 'oracle' 
  4. Oracle Secret Store Tool : Version 11.2.0.2.0 - Production 
  5. Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved. 
  6.  
  7. Enter wallet password:              
  8.  
  9. Create credential oracle.security.client.connect_string1 
  10. 3.2 #查看是否增加成功。 
  11. [oracle@test db_1]$ mkstore -wrl  /u01/app/oracle/product/11.2.0/db_1/wallet -listCredential  
  12. Oracle Secret Store Tool : Version 11.2.0.2.0 - Production 
  13. Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved. 
  14.  
  15. Enter wallet password:              
  16.  
  17. List credential (index: connect_string username) 
  18. 1: htz scott 
  19. 3.3 测试是否可以实现无需要输入用户与密码登陆 
  20. [oracle@test db_1]$ sqlplus /@htz 
  21.  
  22. SQL*Plus: Release 11.2.0.2.0 Production on Sat Sep 8 09:19:15 2012 
  23.  
  24. Copyright (c) 1982, 2010, Oracle.  All rights reserved. 
  25.  
  26.  
  27. Connected to
  28. Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production 
  29. With the Partitioning, OLAP, Data Mining and Real Application Testing options 
  30. #显示的是scott,成功了。 
  31. SQL> show user
  32. USER is "SCOTT" 
  33. SQL> exit 
  34. Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production 
  35. With the Partitioning, OLAP, Data Mining and Real Application Testing options 

5.查看entry

  1. #这里看到我们增加一个数据进来就会增加3个entries。 
  2. #分别是一个连接符,一个用户名,一个密码。 
  3. #当我们增加了很多数据库与用户进来后,数据库与用户还有密码他们是怎么关联的呢?其实他们就是通过后面的这个数字来关键的。 
  4. [oracle@test db_1]$ mkstore -wrl  /u01/app/oracle/product/11.2.0/db_1/wallet -list 
  5. Oracle Secret Store Tool : Version 11.2.0.2.0 - Production 
  6. Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved. 
  7.  
  8. Enter wallet password:              
  9.  
  10. Oracle Secret Store entries:  
  11. oracle.security.client.connect_string1 
  12. oracle.security.client.password1 
  13. oracle.security.client.username1 

6.创建默认用户与密码

这样可以实现,登陆所以的数据库都可以使用默认的用户与密码

  1. 6.1 #创建默认的用户。 
  2. [oracle@test db_1]$ mkstore -wrl  /u01/app/oracle/product/11.2.0/db_1/wallet -createEntry  oracle.security.client.default_username scott 
  3. Oracle Secret Store Tool : Version 11.2.0.2.0 - Production 
  4. Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved. 
  5.  
  6. Enter wallet password:              
  7. 6.2 #创建默认用户的密码。 
  8. [oracle@test db_1]$ mkstore -wrl  /u01/app/oracle/product/11.2.0/db_1/wallet -createEntry  oracle.security.client.default_password oracle 
  9. Oracle Secret Store Tool : Version 11.2.0.2.0 - Production 
  10. Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved. 
  11.  
  12. Enter wallet password:              
  13. 6.3 #查看是否创建成功 
  14. [oracle@test db_1]$ mkstore -wrl  /u01/app/oracle/product/11.2.0/db_1/wallet -list 
  15. Oracle Secret Store Tool : Version 11.2.0.2.0 - Production 
  16. Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved. 
  17.  
  18. Enter wallet password:              
  19.  
  20. Oracle Secret Store entries:  
  21. oracle.security.client.connect_string1 
  22. oracle.security.client.default_password 
  23. oracle.security.client.default_username 
  24. oracle.security.client.password1 
  25. oracle.security.client.username1 

7.当默认用户与手动增加的数据库信息到wallet中时,那一个生效呢?

下面我们测试一下,当wallet里面创建了默认的用户与密码时,手动再增加一个增加的信息到wallet时,到底是默认用户还是手动增加的生效呢?其实是手动增加的生效。

  1. 7.1 #由于默认用户增加的SCOTT普通用户,所以这里我们增加sys这个用户来做测试,net service名是htzb 
  2. [oracle@test db_1]$ mkstore -wrl $ORACLE_HOME/wallet -createCredential htzb sys 'oracle' 
  3. Oracle Secret Store Tool : Version 11.2.0.2.0 - Production 
  4. Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved. 
  5.  
  6. Enter wallet password:              
  7.  
  8. Create credential oracle.security.client.connect_string1 
  9. 7.2 #登陆测试。 
  10. 这里没有增加as sysdba就是为了能区别普通用户与sys用户登陆的区别。如果是sys用户生效,就会报没有增加as sysdba登陆,如果是scott这个默认用户生效,就会登陆成功。 
  11. [oracle@test db_1]$ sqlplus /@htzb 
  12.  
  13. SQL*Plus: Release 11.2.0.2.0 Production on Sat Sep 8 09:33:07 2012 
  14.  
  15. Copyright (c) 1982, 2010, Oracle.  All rights reserved. 
  16. #这里报错,说明手动增加的SYS用户的生效。默认用户没有生效 
  17. ERROR: 
  18. ORA-28009: connection as SYS should be as SYSDBA or SYSOPER 
  19.  
  20.  
  21. Enter user-name:   
  22. 7.3 #这里我们再登陆htz,登陆成功。说明我们默认用户在其它的net service是生效的。 
  23. [oracle@test db_1]$ sqlplus /@htz 
  24.  
  25. SQL*Plus: Release 11.2.0.2.0 Production on Sat Sep 8 09:33:23 2012 
  26.  
  27. Copyright (c) 1982, 2010, Oracle.  All rights reserved. 
  28.  
  29.  
  30. Connected to
  31. Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production 
  32. With the Partitioning, OLAP, Data Mining and Real Application Testing options 
  33.  
  34. SQL> exit 
  35. Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production 
  36. With the Partitioning, OLAP, Data Mining and Real Application Testing options 
  37.  
  38. 7.4 #以sys as sysdba登陆成功 
  39. [oracle@test db_1]$ sqlplus /@htzb as sysdba 
  40.  
  41. SQL*Plus: Release 11.2.0.2.0 Production on Sat Sep 8 09:33:30 2012 
  42.  
  43. Copyright (c) 1982, 2010, Oracle.  All rights reserved. 
  44.  
  45.  
  46. Connected to
  47. Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production 
  48. With the Partitioning, OLAP, Data Mining and Real Application Testing options 
  49.  
  50. SQL> show user 
  51. USER is "SYS" 

8.下面测试的是通过mkstore修改wallet中的内容后,导致wallet相关的文件,权限自动改成600.

  1. 8.1 #把wallet的文件权限改成777 
  2. [oracle@test db_1]$ chmod 777 $ORACLE_HOME/wallet/* 
  3. [oracle@test db_1]$ ls -l $ORACLE_HOME/wallet 
  4. total 16 
  5. -rwxrwxrwx 1 oracle oinstall 4565 Sep  8 09:38 cwallet.sso 
  6. -rwxrwxrwx 1 oracle oinstall 4488 Sep  8 09:38 ewallet.p12 
  7. 8.2 #手动在wallet中增加一个net service的配置信息 
  8. [oracle@test db_1]$ mkstore -wrl $ORACLE_HOME/wallet -deleteCredential htz  
  9. Oracle Secret Store Tool : Version 11.2.0.2.0 - Production 
  10. Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved. 
  11.  
  12. Enter wallet password:              
  13.  
  14. Delete credential  
  15. Delete 2 
  16. 8.3 #再次查看权限时发现权限已经自己改成了600了 
  17. [oracle@test db_1]$ ls -l $ORACLE_HOME/wallet 
  18. total 16 
  19. -rw------- 1 oracle oinstall 4205 Sep  8 09:39 cwallet.sso 
  20. -rw------- 1 oracle oinstall 4128 Sep  8 09:39 ewallet.p12 

9. 当用户的密码发生变化的时候需要修改wallet中的密码

  1. [oracle@test ~]$ mkstore -wrl $ORACLE_HOME/wallet -modifyCredential htz scott 'oracleoracle'
  2. Oracle Secret Store Tool : Version 11.2.0.2.0 - Production 
  3. Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved. 
  4.  
  5. Enter wallet password:              
  6.  
  7. Modify credential  
  8. Modify 1 

10.查看wallet中有那些认证的信息

  1. [oracle@test ~]$ mkstore -wrl $ORACLE_HOME/wallet -listCredential  
  2. Oracle Secret Store Tool : Version 11.2.0.2.0 - Production 
  3. Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved. 
  4.  
  5. Enter wallet password:              
  6.  
  7. List credential (index: connect_string username) 
  8. 1: htz scott 

11 从wallet删除一个net service的配置信息

  1. [oracle@test ~]$ mkstore -wrl $ORACLE_HOME/wallet -deleteCredential  htz 
  2. Oracle Secret Store Tool : Version 11.2.0.2.0 - Production 
  3. Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved. 
  4.  
  5. Enter wallet password:              
  6.  
  7. Delete credential  
  8. Delete 1 

12.修改默认的用户名

修改默认的用户名的密码的方法也一样。

  1. [oracle@test ~]$ mkstore -wrl $ORACLE_HOME/wallet -viewEntry oracle.security.client.default_username 
  2. Oracle Secret Store Tool : Version 11.2.0.2.0 - Production 
  3. Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved. 
  4.  
  5. Enter wallet password:              
  6.  
  7. oracle.security.client.default_username = scott 
  8. [oracle@test ~]$ mkstore -wrl $ORACLE_HOME/wallet -modifyEntry oracle.security.client.default_username 
  9. Oracle Secret Store Tool : Version 11.2.0.2.0 - Production 
  10. Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved. 
  11.  
  12. Your secret/Password is missing in the command line  
  13. Enter your secret/Password:          
  14.  
  15. Re-enter your secret/Password:          
  16.  
  17. Enter wallet password:              
  18.  
  19. [oracle@test ~]$ mkstore -wrl $ORACLE_HOME/wallet -viewEntry oracle.security.client.default_username 
  20. Oracle Secret Store Tool : Version 11.2.0.2.0 - Production 
  21. Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved. 
  22.  
  23. Enter wallet password:              
  24.  
  25. oracle.security.client.default_username = oracle 

13 删除默认的用户名

  1. [oracle@test ~]$ mkstore -wrl $ORACLE_HOME/wallet -deleteEntry oracle.security.client.default_username 
  2. Oracle Secret Store Tool : Version 11.2.0.2.0 - Production 
  3. Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved. 
  4.  
  5. Enter wallet password:   

我们一般的维护就这么多。

相关内容

    暂无相关文章