1. 程式人生 > >安裝oralce過程中使用者、群組及相關oracle inventory的詳解

安裝oralce過程中使用者、群組及相關oracle inventory的詳解

1、單例項使用者
我們在建立單例項的時候,一般用的使用者是 oracle  使用者,oinstall ,dba ,oper組
oinstall:oinstall 組是oracle 推薦作業系統的使用者組,該使用者組應該具有oracle 軟體目錄$ORACLE_BAES,$ORACLE_HOME,和 oracle Inventory資訊目錄倉庫,oracle Inventory資訊目錄記錄了系統上安裝過的oracle產品的記錄。
       如果系統中已經安裝有oracle產品軟體,則現有的oracle Inventory目錄的所有組必須是今後用來安裝新oracle軟體產品的使用者的主組(primary group)。
       現有的oracle Inventory擁有者組可以通過/etc/oraInst.loc位置檔案瞭解:
              inventory_loc=/u01/app/oracle/oraInventory
                 inst_group=oinstall
  若/etc/oraInst.loc(少數平臺不在該位置)位置檔案不存在,那麼建議建立oinstall使用者組,注意:如果是在RAC環境中要保持各節點上使用者組的gid一致:
groupadd -g 6000 oinstall


dba:OSDBA是我們必須要建立的一種系統DBA使用者組(dba),若沒有該使用者組我們將無法安裝資料庫軟體及執行管理資料庫的任務。
oper:oper我們可以選擇要不要建立該使用者組,建立該使用者組可以滿足讓os使用者行使某些資料庫管理許可權(包括SYSOPER角色許可權)的目的。注意SYSOPER的許可權包括startup和shutdown,所以要小心為該使用者組新增成員。
 
      說到這我們可能對sysoper和sysdba的的許可權比較模糊,這兩個有什麼區別呢????
            SYSDBA:一種系統許可權,當我們以SYSDBA這個身份去登陸資料庫,我們當前的default schema是SYS,有下面許可權
 ■STARTUP and SHUTDOWN operations
■ALTER DATABASE: open, mount, back up, or change character set
■CREATE DATABASE
■DROP DATABASE
■CREATE SPFILE
■ALTER DATABASE ARCHIVELOG
■ALTER DATABASE RECOVER
■Includes the RESTRICTED SESSION privilege


              SYSOPER:一種系統許可權,當我們以SYSOPER這個身份去登陸資料庫,我們當前的default schema是PUBLIC,有下面許可權   
■ Perform STARTUP and SHUTDOWN operations
■ CREATE SPFILE
■ ALTER DATABASE OPEN/MOUNT/BACKUP
■ ALTER DATABASE ARCHIVELOG
■ ALTER DATABASE RECOVER (Complete recovery only. Any form of incomplete recovery, such as UNTILTIME|CHANGE|CANCEL|CONTROLFILE requires connecting as SYSDBA.)
■ Includes the RESTRICTED SESSION privilege
                   SYSDBA和SYSOPER系統許可權允許我們在資料庫開啟之前以這兩種身份去訪問例項。

綜上所述在單機環境(single-instance)中oracle軟體擁有者使用者(常見的oracle或者orauser),因該同時是oinstall、dba、oper使用者組的成員。同時該使用者的主使用者組必須是oinstall。

*************************************************************************************************************

很多朋友對Oracle的inventory資訊不太瞭解以至遇到相關的問題不知道如何處理,這篇文章我們將詳細講解Oracle的Central Inventory (oraInventory)和Local Inventory (Oracle Home inventory) 

首先我們通過檢視$ opatch lsinventory的輸出來丟擲幾個問題:
[[email protected]
OPatch]$ ./opatch lsinventory
Invoking OPatch 11.2.0.1.7 
Oracle Interim Patch Installer version 11.2.0.1.7
Copyright (c) 2011, Oracle Corporation.  All rights reserved.
Oracle Home       : /u01/app/oracle/product/11.2.0/db_1
Central Inventory : /u01/app/oraInventory  <<<<<=====什麼是Central Inventory?
   from           : /etc/oraInst.loc<<<<<=====oraInst.loc是什麼檔案,它有什麼作用?如果它被刪除掉了會怎麼樣?
OPatch version    : 11.2.0.1.7<<<<<=====這是OPatch版本?
OUI version       : 11.2.0.3.0<<<<<=====OUI version 這裡OUI 版本是指的什麼?  
Log file location : /u01/app/oracle/product/11.2.0/db_1/cfgtoollogs/opatch/opatch2014-03-23_21-03-24PM.log
Lsinventory Output file location : /u01/app/oracle/product/11.2.0/db_1/cfgtoollogs/opatch/lsinv/lsinventory2014-03-23_21-03-24PM.txt
--------------------------------------------------------------------------------
Installed Top-level Products (1): 
Oracle Database 11g                                                  11.2.0.3.0
There are 1 products installed in this Oracle Home. 
There are no Interim patches installed in this Oracle Home.
--------------------------------------------------------------------------------
OPatch succeeded.
這裡OPatch version 就是Opatch的版本,它是不同於資料庫版本的。
如果OPatch 版本過低那打patch時就會報錯,不過這個問題很快可以通過檢視patch的readme通過其指定的Note 下載最新的Opatch 來解決。
OUI version 就是安裝的ORACLE_HOME的版本
言歸正傳,什麼是Central Inventory (oraInventory)呢 ?
每一個安裝了Oracle產品的作業系統上都至少有一個Central Inventory (oraInventory),他通過一個叫做inventory.xml的檔案記錄了在此作業系統上安裝過的Oracle Homes等資訊。
實際上Oracle就是通過Central Inventory (oraInventory) 來確定Oracle Home的位置,名稱,是否是CRS_HOME及其他節點等資訊的。
我們可以具體看一下inventory.xml的內容:
inventory.xml位置就在< Central Inventory >/ContentsXML/inventory.xml
例如:
[
[email protected]
OPatch]$ cd /u01/app/oraInventory/ContentsXML/
[[email protected] ContentsXML]$ ls
comps.xml  inventory.xml  libs.xml
[[email protected] ContentsXML]$ cat inventory.xml 
<?xml version="1.0" standalone="yes" ?>
<!-- Copyright (c) 1999, 2011, Oracle. All rights reserved. -->
<!-- Do not modify the contents of this file by hand. -->
<INVENTORY>
<VERSION_INFO>
   <SAVED_WITH>11.2.0.3.0</SAVED_WITH>
   <MINIMUM_VER>2.1.0.6.0</MINIMUM_VER>
</VERSION_INFO>
<HOME_LIST>
<HOME NAME="OraDb11g_home1" LOC="/u01/app/oracle/product/11.2.0/db_1" TYPE="O" IDX="1"/>
</HOME_LIST>
<COMPOSITEHOME_LIST>
</COMPOSITEHOME_LIST>
</INVENTORY>
[[email protected] ContentsXML]$ pwd
/u01/app/oraInventory/ContentsXML
這裡我們只安裝了一個ORACLE_HOME它的名字叫OraDb11g_home1,路徑在/u01/app/oracle/product/11.2.0/db_1。
請注意這裡TYPE="O" IDX="1"
TYPE="O"意思是這是一個ORACLE資料庫的HOME,如果它後面還有CRS="true"這樣的標記就表明這是一個CRS_HOME。
IDX="1" 意思就是該HOME是第一個安裝的產品。
我們再看一個安裝了CRS的inventory.xml輸出來對比一下
[[email protected] ContentsXML]$ cat inventory.xml 
<?xml version="1.0" standalone="yes" ?>
<!-- Copyright (c) 1999, 2011, Oracle. All rights reserved. -->
<!-- Do not modify the contents of this file by hand. -->
<INVENTORY>
<VERSION_INFO>
   <SAVED_WITH>11.2.0.3.0</SAVED_WITH>
   <MINIMUM_VER>2.1.0.6.0</MINIMUM_VER>
</VERSION_INFO>
<HOME_LIST>
<HOME NAME="Ora11g_gridinfrahome1" LOC="/u01/app/11.2.0/grid" TYPE="O" IDX="1" CRS="true">
   <NODE_LIST>
      <NODE NAME="nascds10"/>
      <NODE NAME="nascds11"/>
   </NODE_LIST>
</HOME>
<HOME NAME="OraDb11g_home1" LOC="/u01/app/oracle/product/11.2.0/db_1" TYPE="O" IDX="2">
   <NODE_LIST>
      <NODE NAME="nascds10"/>
      <NODE NAME="nascds11"/>
   </NODE_LIST>
</HOME>
</HOME_LIST>
<COMPOSITEHOME_LIST>
</COMPOSITEHOME_LIST>
</INVENTORY>
通過對比我們已經非常明顯的看到inventory.xml 裡記錄了詳細ORACLE_HOME資訊。
問題是Oracle是如何知道< Central Inventory >在哪裡的呢?
答案很多人可能已經猜到了就是opatch lsinventory裡列出來的
from           : /etc/oraInst.loc 
這個/etc/oraInst.loc是有專業名稱的,它的名字就叫Central Inventory Pointer File。
這個指向檔案在不同的作業系統上有不同的預設位置,例如:
Linux And AIX — /etc/oraInst.loc 
Other Unix Platforms — /var/opt/oracle/oraInst.loc 
Windows — The pointer is located in the registry key:
\\HKEY_LOCAL_MACHINE\\Software\Oracle\inst.loc
Opatch就是通過Central Inventory Pointer File找到< Central Inventory >的路徑,然後讀取ORACLE_HOME的詳細資訊的。
現在又有新的問題了?
1.我們是否可以刪除Central Inventory Pointer File?或者如果Central Inventory Pointer File丟失了會怎麼樣?
2. Central Inventory丟失或者損壞了會怎麼樣?
3. 我們能否手工修改Central Inventory的內容?
我先回答這幾個問題,然後通過幾個實驗來看一下具體的情況。
答案:
1.不能刪除Central Inventory Pointer File,如果Central Inventory Pointer File丟失了可以手工重建該檔案。如果Central Inventory Pointer File丟失或者損壞那麼opatch的所有命令都將失敗。
2.也不能刪除Central Inventory的檔案,如果Central Inventory的檔案是損壞的,比如內容不完整,或者內容是錯誤的,都將導致opatch失敗。Central Inventory在ORACLE_HOME完好的情況下可以通過重建的方式解決以上問題。
3.Oracle官方不support手工修改Central Inventory的內容。


請注意以下所有的實驗都不要在生產環境操作,以免導致Inventory錯誤.
實驗1: 模擬Central Inventory Pointer File丟失的場景
[[email protected]]# mv /etc/oraInst.loc /etc/oraInst.loc.bak  <<<<<<=====這裡手工mv了oraInst.loc檔案,實驗結束後需要手工再mv 回來
[[email protected]]# exit
exit
[[email protected]]$ cd /u01/app/oracle/product/11.2.0/db_1/OPatch/
[[email protected] OPatch]$ ./opatch lsinventory
Invoking OPatch 11.2.0.1.7
Oracle Interim Patch Installer version 11.2.0.1.7
Copyright (c) 2011, Oracle Corporation.  All rights reserved.
Oracle Home       : /u01/app/oracle/product/11.2.0/db_1
Central Inventory : n/a
   from           : 
OPatch version    : 11.2.0.1.7
OUI version       : 11.2.0.3.0
Log file location : n/a<<<<<<=========
OPatch cannot find a valid oraInst.loc file to locate Central Inventory. <<<<<<=========
OPatch failed with error code 104<<<<<<=========
[[email protected] OPatch]$
通過這個實驗我們看到當Oracle不能找到一個有效的Central Inventory Pointer File時Opatch以失敗告終。
這個時候如果我們確定Central Inventory是完好無損的情況下,可以在不同平臺對應的預設路徑下手工建立或者編輯oraInst.loc 檔案
例如在linux平臺,正常的內容如下
$ cat /etc/oraInst.loc 
inventory_loc=/u01/app/oraInventory
inst_group=oinstall
實驗2: 模擬Central Inventory丟失的場景
[[email protected] app]$ mv oraInventory oraInventory.bak<<<<<<=====這裡手工刪除了oraInventory
[[email protected] app]$ ls
oracle  oraInventory.bak
[[email protected] app]$ cd /u01/app/oracle/product/11.2.0/db_1/OPatch/
[[email protected] OPatch]$ ./opatch lsinventory
Invoking OPatch 11.2.0.1.7
Oracle Interim Patch Installer version 11.2.0.1.7
Copyright (c) 2011, Oracle Corporation.  All rights reserved.
Oracle Home       : /u01/app/oracle/product/11.2.0/db_1
Central Inventory : /u01/app/oraInventory
   from           : /etc/oraInst.loc
OPatch version    : 11.2.0.1.7
OUI version       : 11.2.0.3.0
Log file location : /u01/app/oracle/product/11.2.0/db_1/cfgtoollogs/opatch/opatch2014-03-24_12-15-04PM.log
OPatch failed to locate Central Inventory.  <<<<<<=====報錯無法載入Central Inventory.
Possible causes are: 
    The Central Inventory is corrupted
    The oraInst.loc file specified is not valid.
LsInventorySession failed: OPatch failed to locate Central Inventory.
Possible causes are: 
    The Central Inventory is corrupted
    The oraInst.loc file specified is not valid.
OPatch failed with error code 73<<<<<<=====
這個實驗可以說明當Central Inventory 丟失時Opatch也是失敗的。
實驗3 模擬Central Inventory內容損壞
為實驗目的我們手工修改ORACLE_HOME LOC成/u01/app/oracle/product/11.2.0/db_100 實際上這個目錄是不存在的。但請注意手工修改inventory.xml的任何內容都是不support的。
<HOME NAME="OraDb11g_home1" LOC="/u01/app/oracle/product/11.2.0/db_100" TYPE="O" IDX="1"/>
[[email protected] OPatch]$ cd /u01/app/oraInventory/ContentsXML/
[[email protected] ContentsXML]$ cp inventory.xml inventory.xml.bak
[[email protected] ContentsXML]$ ls
comps.xml  inventory.xml  inventory.xml.bak  libs.xml
[[email protected] ContentsXML]$ vi inventory.xml
[[email protected] ContentsXML]$ cat inventory.xml
<?xml version="1.0" standalone="yes" ?>
<!-- Copyright (c) 1999, 2011, Oracle. All rights reserved. -->
<!-- Do not modify the contents of this file by hand. -->
<INVENTORY>
<VERSION_INFO>
   <SAVED_WITH>11.2.0.3.0</SAVED_WITH>
   <MINIMUM_VER>2.1.0.6.0</MINIMUM_VER>
</VERSION_INFO>
<HOME_LIST>
<HOME NAME="OraDb11g_home1" LOC="/u01/app/oracle/product/11.2.0/db_100" TYPE="O" IDX="1"/>
</HOME_LIST>
<COMPOSITEHOME_LIST>
</COMPOSITEHOME_LIST>
</INVENTORY>
[[email protected] ContentsXML]$ /u01/app/oracle/product/11.2.0/db_1/OPatch/opatch lsinventory
Invoking OPatch 11.2.0.1.7
Oracle Interim Patch Installer version 11.2.0.1.7
Copyright (c) 2011, Oracle Corporation.  All rights reserved.


Oracle Home       : /u01/app/oracle/product/11.2.0/db_1
Central Inventory : /u01/app/oraInventory
   from           : /etc/oraInst.loc
OPatch version    : 11.2.0.1.7
OUI version       : 11.2.0.3.0
Log file location : /u01/app/oracle/product/11.2.0/db_1/cfgtoollogs/opatch/opatch2014-03-24_12-25-43PM.log
List of Homes on this system:
  Home name= OraDb11g_home1, Location= "/u01/app/oracle/product/11.2.0/db_100"
Inventory load failed... OPatch cannot load inventory for the given Oracle Home.<<<=========
Possible causes are:
   Oracle Home dir. path does not exist in Central Inventory
   Oracle Home is a symbolic link
   Oracle Home inventory is corrupted
LsInventorySession failed: OracleHomeInventory gets null oracleHomeInfo
OPatch failed with error code 73
Central Inventory 如果損壞或者丟失是可以重建的。
重建過程非常簡單,也不需要停機。我們來看下面的實驗
實驗4 重建Central Inventory
[[email protected] ~]$ cd /u01/app
[[email protected] app]$ ls
oracle  oraInventory
[[email protected] app]$ mv oraInventory oraInventory.bak
[[email protected] app]$ opatch lsinventory
Oracle Interim Patch Installer version 11.2.0.3.6
Copyright (c) 2013, Oracle Corporation.  All rights reserved.
Oracle Home       : /u01/app/oracle/product/11.2.0/db_1
Central Inventory : /u01/app/oraInventory
   from           : /u01/app/oracle/product/11.2.0/db_1/oraInst.loc
OPatch version    : 11.2.0.3.6
OUI version       : 11.2.0.3.0
Log file location : /u01/app/oracle/product/11.2.0/db_1/cfgtoollogs/opatch/opatch2014-03-25_17-13-48PM_1.log
OPatch failed to locate Central Inventory.
Possible causes are: 
    The Central Inventory is corrupted
    The oraInst.loc file specified is not valid.
LsInventorySession failed: OPatch failed to locate Central Inventory.<<<==== Central Inventory 被刪除了,這個報錯就是期待的報錯。
Possible causes are: 
    The Central Inventory is corrupted
    The oraInst.loc file specified is not valid.
OPatch failed with error code 73<<<<<<<<<<<<<=================
[[email protected] app]$ cd $ORACLE_HOME/oui/bin
[[email protected] bin]$ pwd
/u01/app/oracle/product/11.2.0/db_1/oui/bin
[[email protected] bin]$ ./runInstaller -silent -ignoreSysPrereqs -attachHome ORACLE_HOME="/u01/app/oracle/product/11.2.0/db_1" ORACLE_HOME_NAME="OraDb11g_home1"
Starting Oracle Universal Installer...
Checking swap space: must be greater than 500 MB.   Actual 2996 MB    Passed
The inventory pointer is located at /etc/oraInst.loc
The inventory is located at /u01/app/oraInventory
'AttachHome' was successful.
[[email protected] bin]$ opatch lsinventory
Oracle Interim Patch Installer version 11.2.0.3.6
Copyright (c) 2013, Oracle Corporation.  All rights reserved.
Oracle Home       : /u01/app/oracle/product/11.2.0/db_1
Central Inventory : /u01/app/oraInventory
   from           : /u01/app/oracle/product/11.2.0/db_1/oraInst.loc
OPatch version    : 11.2.0.3.6
OUI version       : 11.2.0.3.0
Log file location : /u01/app/oracle/product/11.2.0/db_1/cfgtoollogs/opatch/opatch2014-03-25_17-16-37PM_1.log
Lsinventory Output file location : /u01/app/oracle/product/11.2.0/db_1/cfgtoollogs/opatch/lsinv/lsinventory2014-03-25_17-16-37PM.txt
--------------------------------------------------------------------------------
Installed Top-level Products (1): 
Oracle Database 11g                                                  11.2.0.3.0
There are 1 product(s) installed in this Oracle Home.
Interim patches (1) :
Patch  17540582     : applied on Mon Mar 24 17:08:31 CST 2014
Unique Patch ID:  16985511
Patch description:  "Database Patch Set Update : 11.2.0.3.9 (17540582)"
   Created on 7 Jan 2014, 03:01:22 hrs PST8PDT
Sub-patch  16902043; "Database Patch Set Update : 11.2.0.3.8 (16902043)"
Sub-patch  16619892; "Database Patch Set Update : 11.2.0.3.7 (16619892)"
Sub-patch  16056266; "Database Patch Set Update : 11.2.0.3.6 (16056266)"
Sub-patch  14727310; "Database Patch Set Update : 11.2.0.3.5 (14727310)"
Sub-patch  14275605; "Database Patch Set Update : 11.2.0.3.4 (14275605)"
Sub-patch  13923374; "Database Patch Set Update : 11.2.0.3.3 (13923374)"
Sub-patch  13696216; "Database Patch Set Update : 11.2.0.3.2 (13696216)"
Sub-patch  13343438; "Database Patch Set Update : 11.2.0.3.1 (13343438)"
   Bugs fixed:
     13593999, 10350832, 14138130, 12919564, 13561951, 14198511, 13588248
     13080778, 13804294, 16710324, 12873183, 14472647, 12880299, 13369579
   ...............
     13059165, 14062797, 12959852, 12345082, 16703112, 13890080, 17333198
     16450169, 12658411, 13780035, 14062793, 13038684, 16742095, 13742464
     14052474, 13060271, 13911821, 13457582, 7509451, 13791364, 12821418
     13502183, 13705338, 16794239, 15862024, 13554409, 13645917, 13103913, 12772404
--------------------------------------------------------------------------------
OPatch succeeded.
[[email protected] bin]$ cd /u01/app
[[email protected] app]$ ls -l
total 12
drwxrwxr-x 9 oracle oinstall 4096 Nov 24 23:25 oracle
drwxrwx--- 4 oracle oinstall 4096 Mar 25 17:16 oraInventory<<<<<<<==新建立的Central Inventory
drwxrwx--- 5 oracle oinstall 4096 Mar 24 17:12 oraInventory.bak
Central Inventory裡只記錄了Oracle的HOME資訊,但是在這個HOME下打了哪些patch Oracle是怎麼知道的呢?
答案就是Local Inventory (Oracle Home inventory)。
Local Inventory (Oracle Home inventory) 存在於每一個ORACLE_HOME中,它記錄了這個HOME中的相關資訊,比如這個HOME中包含的元件,打過的補丁集(patchset 資訊),打過的小補丁和PSU等資訊。這些資訊被記錄在Local Inventory 中的comps.xml檔案。
ORACLE_HOME/inventory/ContentsXML/comps.xml
同樣Local Inventory (Oracle Home inventory)裡的任何檔案都是不允許手工修改的。
一個重要的資訊是Oracle的Local Inventory (Oracle Home inventory)如果丟失或者損壞時無法重建的,只能通過重新安裝ORACLE軟體的方式解決。
參考文章:
FAQs on Central Inventory and Oracle Home Inventory (Local Inventory) in Oracle RDBMS (Doc ID 564192.1)
Steps To Recreate Central Inventory(oraInventory) In RDBMS Homes (Doc ID 556834.1)

Steps to Recreate Central Inventory in Real Applications Clusters (Doc ID 413939.1)

2 叢集環境:
11g release2中oracle建議獨立地管理Grid Infrastructure和ASM例項,因此有必要建立更多的os使用者組以滿足不同的許可權分配
asmadmin:如果使用ASM,那麼我們必須建立osasm(asmadmin)使用者組,該OSASM使用者組的成員將被賦予SYSASM許可權,以滿足組成員管理Oracle Clusterware和Oracle ASM的許可權需求。
asmdba:OSDBA(asmdba)使用者組的成員將被賦予讀寫訪問ASM檔案的許可權。GI/CRS擁有者使用者和所有oracle資料庫軟體的擁有者必須是該組的成員。同時所有OSDBA(dba)使用者組的成員也必須是asmdba組的成員。
asmoper:asmoper和oper類似都是額外的可選擇建立的使用者組,建立該獨立的使用者組以滿足賦予使用者一套受限的ASM例項管理許可權(ASM的SYSOPER角色),該許可權包括了啟動和停止ASM例項,預設情況下OSASM(asmadmin)組成員將擁有所有SYSOPER的ASM管理許可權

叢集環境暫不做過多的解釋。