第一章 在Centos7.1上安裝oracle11gR2-靜默安裝
# 後跟命令表示以作業系統下root使用者操作;
$ 後跟命令表示以作業系統下oracle使用者操作;
1.1 上傳軟體
假如放在/wangnc/oracle/11g/目錄下.
# mkdir -p /wangnc/oracle/11g/
# cd /wangnc/oracle/11g/
可通過SecureFX工具sftp上傳資料庫安裝檔案.
1.2 Package安裝檢查
# rpm -q \
binutils \
compat-libstdc++-33 \
elfutils-libelf \
elfutils-libelf-devel \
expat \
gcc \
gcc-c++ \
glibc \
glibc-common \
glibc-devel \
glibc-headers \
libaio \
libaio-devel \
libgcc \
libstdc++ \
libstdc++-devel \
make \
pdksh \
sysstat \
unixODBC \
unixODBC-devel | grep "not installed"
1.3 增加資料庫組和使用者
# id oracle (確認oracle使用者是否存在)
# /usr/sbin/groupadd oinstall
# /usr/sbin/groupadd dba (建立資料庫安裝組)
# /usr/sbin/groupadd asmadmin (建立ASM管理組)
# /usr/sbin/groupadd asmdba (建立Grid管理組)
# /usr/sbin/useradd -g oinstall -G dba,asmdba oracle -d /home/oracle (oinstall為主要組,確保/home/oracle原不存在)
# id oracle (記住oracle使用者的uid和gid)
uid=501(oracle) gid=501(oinstall) groups=501(oinstall),502(dba),504(asmdba)
# passwd oracle
1.4 調整OS核心引數
設定原則:
kernel.shmmax 為 4GB-1byte或一半的實體記憶體, 哪個值更低用哪個;
fs.file-max 為512 * PROCESSES.
# vi /etc/sysctl.conf (增加或修改以下引數, 參考值為最小需求, kernel.shmmax預設即可無需設定 )
#------------------------------------------
fs.aio-max-nr = 1048576
fs.file-max = 6815744
kernel.shmall = 2097152
#kernel.shmmax = 536870912
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
net.ipv4.ip_local_port_range = 9000 65500
net.core.rmem_default = 262144
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 1048586
#------------------------------------------
# /sbin/sysctl -p (設定引數立即生效)
1.5 增加shell限制
為了提升效能增加oracle使用者的shell限制.
# vi /etc/security/limits.conf (在檔案最後增加或修改以下引數)
oracle soft nproc 2047
oracle hard nproc 16384
oracle soft nofile 1024
oracle hard nofile 65536
# vi /etc/pam.d/login (在檔案最後增加或修改以下引數)
session required pam_limits.so
# vi /etc/profile (在檔案最後增加或修改以下指令碼)
if [ $USER = "oracle" ]; then
if [ $SHELL = "/bin/ksh" ]; then
ulimit -p 16384
ulimit -n 65536
else
ulimit -u 16384 -n 65536
fi
fi
1.6 建立必需目錄
# more /etc/oratab (確認原來是否存在Oracle主目錄)
# more /etc/oraInst.loc (確認原來是否存在Oracle產品清單目錄)
# mkdir -p /u01/app/oracle/ (Oracle基礎目錄, 一般為/mount_point/app/oracle_owner)
# chown -R oracle:oinstall /wangnc/oracle
chown -R oracle:oinstall /u01
chown -R oracle:oinstall /u02
chown -R oracle:oinstall /u03
chown -R oracle:oinstall /u04
# chmod -R 775 /wangnc/oracle
chmod -R 775 /u01
chmod -R 775 /u02
chmod -R 775 /u03
chmod -R 775 /u04
1.7 設定oracle使用者環境變數
如果伺服器有多網絡卡, 注意設定ORACLE_HOSTNAME為某網絡卡IP對應的主機名, 參照/etc/hosts檔案.
# su - oracle
$ vi ~/.bash_profile
umask 022
export ORACLE_HOSTNAME=rhel5
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/dbhome_1
export ORACLE_SID=ORCL
export PATH=.:$ORACLE_HOME/bin:$ORACLE_HOME/OPatch:$ORACLE_HOME/jdk/bin:$PATH
export LC_ALL="en_US"
export LANG="en_US"
export NLS_LANG="AMERICAN_AMERICA.ZHS16GBK"
export NLS_DATE_FORMAT="YYYY-MM-DD HH24:MI:SS"
$ . ~/.bash_profile
1.8 解壓Oracle安裝檔案
$ cd /wangnc/oracle/11g
$ unzip linux*_11gR2_database_1of2.zip -d /u01 (解壓到/u01目錄下,可選目錄)
$ unzip linux*_11gR2_database_2of2.zip -d /u01
$ cd /u01/database
$ export DISTRIB=`pwd`
在解壓後oracle軟體的response目錄裡有各種響應檔案的模版.
1.9 生成響應檔案模板
1) 方法一(推薦)
$ vi $DISTRIB/db_swonly.rsp
#--------------------------------------------------------------------
#以下引數不要更改
oracle.install.responseFileVersion=/oracle/install/rspfmt_dbinstall_response_schema_v11_2_0
oracle.install.option=INSTALL_DB_SWONLY
DECLINE_SECURITY_UPDATES=true
#以下引數根據實際情況更改,一般也無需更改
UNIX_GROUP_NAME=oinstall
INVENTORY_LOCATION=/u01/app/oracle/oraInventory
SELECTED_LANGUAGES=en,zh_CN,zh_TW
ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1
ORACLE_BASE=/u01/app/oracle
oracle.install.db.InstallEdition=EE
oracle.install.db.isCustomInstall=true
oracle.install.db.customComponents=oracle.rdbms.partitioning:11.2.0.1.0,oracle.oraolap:11.2.0.1.0,oracle.rdbms.lbac:11.2.0.1.0,oracle.rdbms.dm:11.2.0.1.0,oracle.rdbms.dv:11.2.0.1.0,oracle.rdbms.rat:11.2.0.1.0
oracle.install.db.DBA_GROUP=dba
oracle.install.db.OPER_GROUP=oinstall
#--------------------------------------------------------------------
各引數含義如下:
-silent 表示以靜默方式安裝,不會有任何提示
-force 允許安裝到一個非空目錄
-noconfig 表示不執行配置助手netca
-responseFile 表示使用哪個響應檔案,必需使用絕對路徑
oracle.install.responseFileVersion 響應檔案模板的版本,該引數不要更改
oracle.install.option 安裝選項,本例只安裝oracle軟體,該引數不要更改
DECLINE_SECURITY_UPDATES 是否需要線上安全更新,設定為false,該引數不要更改
ORACLE_HOSTNAME 安裝主機名
UNIX_GROUP_NAME oracle使用者用於安裝軟體的組名
INVENTORY_LOCATION oracle產品清單目錄
SELECTED_LANGUAGES oracle執行語言環境,一般包括引文和簡繁體中文
ORACLE_HOME Oracle安裝目錄
ORACLE_BASE oracle基礎目錄
oracle.install.db.InstallEdition 安裝版本型別,一般是企業版
oracle.install.db.isCustomInstall 是否定製安裝,預設Partitioning,OLAP,RAT都選上了
oracle.install.db.customComponents 定製安裝元件列表:除了以上預設的,可加上Label Security和Database Vault
oracle.install.db.DBA_GROUP oracle使用者用於授予OSDBA許可權的組名
oracle.install.db.OPER_GROUP oracle使用者用於授予OSOPER許可權的組名
2) 方法二(圖形介面)
$ ./runInstaller &
一步步設定到Summary頁, 然後點選Save Response File按鈕, 選擇合適的存放路徑並Finish後, 回到Summary頁, 點選Cancel退出OUI.
1.10 開始安裝oracle軟體
1) 通過response檔案靜默安裝, 大概2-3分鐘:
$ ./runInstaller -silent -force -noconfig -responseFile $DISTRIB/db_swonly.rsp
控制檯直到出現以下提示則表示安裝完成:
#-------------------------------------------------------------------
...
/u01/app/oracle/oraInventory/orainstRoot.sh
/u01/app/oracle/product/11.2.0/dbhome_1/root.sh
To execute the configuration scripts:
1. Open a terminal window
2. Log in as "root"
3. Run the scripts
4. Return to this window and hit "Enter" key to continue
Successfully Setup Software.
#-------------------------------------------------------------------
2) 安裝期間檢視安裝日誌資訊瞭解安裝進度:
$ cd $ORACLE_BASE/oraInventory/logs
$ tail -100f installActions*.log
3) 安裝的軟體資訊會寫入inventory.xml檔案, 如果需重執行則把該檔案的對應安裝條目資訊刪除即可:
$ vi $ORACLE_BASE/oraInventory/ContentsXML/inventory.xml
1.11 執行orainstRoot.sh和root.sh
若本機第一次安裝oracle軟體, 則執行orainstRoot.sh來建立oraInst.loc檔案和修改許可權:
$ su -
# /u01/app/oracle/oraInventory/orainstRoot.sh
# more /etc/oraInst.loc
執行$ORACLE_HOME下的root.sh來建立oratab,dbhome,oraenv,coraenv檔案, 如果提示則一直回車:
# /u01/app/oracle/product/11.2.0/dbhome_1/root.sh
# more /etc/oratab
1.1 靜默配置監聽
通過response檔案執行netca, 生成sqlnet.ora和listener.ora檔案, 位於$ORACLE_HOME/network/admin目錄下:
# su - oracle
$ $ORACLE_HOME/bin/netca /silent /responsefile $DISTRIB/response/netca.rsp
$ ll $ORACLE_HOME/network/admin/*.ora
$ lsnrctl status
執行完後, 監聽就已經啟動了, 預設埠是1521, 預設是動態監聽, 只要例項啟動了就會監聽到.
1.2 靜默建庫
1) 生成響應檔案模板:
$ vi $DISTRIB/db_create.rsp
#--------------------------------------------------------------------
#以下引數不要更改
[GENERAL]
RESPONSEFILE_VERSION = "11.2.0"
OPERATION_TYPE = "createDatabase"
#以下引數必須設定
[CREATEDATABASE]
GDBNAME = "ORCL.LK"
TEMPLATENAME = "General_Purpose.dbc"
#以下引數不設定則使用預設值,建議設定
CHARACTERSET = "ZHS16GBK"
TOTALMEMORY = "1024"
#--------------------------------------------------------------------
2) dbca靜默建庫, 大概3-4分鐘:
種子資料庫和控制檔案位於$ORACLE_HOME/assistants/dbca/templates/下, 即Seed_Database.dfb和Seed_Database.ctl檔案, 實際上建庫就是基於通過rman恢復種子資料庫和控制檔案來實現的.
$ $ORACLE_HOME/bin/dbca -silent -responseFile $DISTRIB/db_create.rsp
Enter SYS user password:
<輸入sys使用者密碼>
Enter SYSTEM user password:
<輸入system使用者密碼>
Copying database files
...
37% complete
Creating and starting Oracle instance
...
62% complete
Completing Database Creation
...
100% complete
Look at the log file "/u01/app/oracle/cfgtoollogs/dbca/ORCL/ORCL.log" for further details.
各引數含義如下:
-silent 表示以靜默方式安裝
-responseFile 表示使用哪個響應檔案,必需使用絕對路徑
RESPONSEFILE_VERSION 響應檔案模板的版本,該引數不要更改
OPERATION_TYPE 安裝型別,該引數不要更改
GDBNAME 全域性資料庫名,點號前面預設是db_name,點號後面預設就是db_domain
TEMPLATENAME 建庫模板名,參考各模板定義:$ORACLE_HOME/assistants/dbca/templates/*.dbc
CHARACTERSET 字符集,預設是WE8MSWIN1252
TOTALMEMORY 例項記憶體,預設是伺服器實體記憶體的40%
3) 安裝期間檢視日誌資訊瞭解進度:
$ tail -100f $ORACLE_BASE/cfgtoollogs/dbca/$ORACLE_SID/$ORACLE_SID.log
4) 建庫後例項檢查
$ ps -ef | grep ora_ | grep -v grep | wc -l
21
$ ps -ef | grep ora_ | grep -v grep
oracle 1855 1 0 10:07 ? 00:00:00 ora_pmon_ORCL
oracle 1857 1 0 10:07 ? 00:00:00 ora_vktm_ORCL
oracle 1861 1 0 10:07 ? 00:00:00 ora_gen0_ORCL
oracle 1863 1 0 10:07 ? 00:00:00 ora_diag_ORCL
oracle 1865 1 0 10:07 ? 00:00:00 ora_dbrm_ORCL
oracle 1867 1 0 10:07 ? 00:00:00 ora_psp0_ORCL
oracle 1869 1 0 10:07 ? 00:00:00 ora_dia0_ORCL
oracle 1871 1 0 10:07 ? 00:00:00 ora_mman_ORCL
oracle 1873 1 0 10:07 ? 00:00:00 ora_dbw0_ORCL
oracle 1875 1 0 10:07 ? 00:00:00 ora_lgwr_ORCL
oracle 1877 1 0 10:07 ? 00:00:00 ora_ckpt_ORCL
oracle 1879 1 0 10:07 ? 00:00:00 ora_smon_ORCL
oracle 1881 1 0 10:07 ? 00:00:00 ora_reco_ORCL
oracle 1883 1 0 10:07 ? 00:00:00 ora_mmon_ORCL
oracle 1885 1 0 10:07 ? 00:00:00 ora_mmnl_ORCL
oracle 1887 1 0 10:07 ? 00:00:00 ora_d000_ORCL
oracle 1889 1 0 10:07 ? 00:00:00 ora_s000_ORCL
oracle 1969 1 0 10:07 ? 00:00:00 ora_qmnc_ORCL
oracle 1985 1 0 10:07 ? 00:00:00 ora_cjq0_ORCL
oracle 2003 1 0 10:08 ? 00:00:00 ora_q000_ORCL
oracle 2005 1 0 10:08 ? 00:00:00 ora_q001_ORCL
5) 建庫後監聽檢查
$ lsnrctl status
...
Services Summary...
Service "ORCL.LK" has 1 instance(s).
Instance "ORCL", status READY, has 1 handler(s) for this service...
Service "ORCLXDB.LK" has 1 instance(s).
Instance "ORCL", status READY, has 1 handler(s) for this service...
The command completed successfully
例項應該被動態註冊到監聽程式了. 如果未被動態註冊到監聽程式, 則可以手工註冊:
$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.1.0 Production on Wed Sep 16 11:11:46 2009
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining,
Oracle Database Vault and Real Application Testing options
SQL> alter system register;
6) 改為歸檔模式並重啟
$ sqlplus / as sysdba
SQL> shutdown immediate;
SQL> startup mount;
SQL> alter database archivelog;
SQL> alter database flashback on; (如果要啟用資料庫閃回功能則執行)
SQL> alter database open;
SQL> execute utl_recomp.recomp_serial(); (重新編譯所有可能失效物件)
SQL> alter system archive log current; (手工歸檔測試)
到此建庫完畢!
7) 預設安裝的資料庫使用者:
SQL> set lines 256 pages 500
SQL> select USER_ID,USERNAME,ACCOUNT_STATUS,DEFAULT_TABLESPACE from dba_users order by 1;
USER_ID USERNAME ACCOUNT_STATUS DEFAULT_TABLESPACE
---------- ------------------------------ -------------------------------- ------------------------------
0 SYS OPEN SYSTEM
5 SYSTEM OPEN SYSTEM
9 OUTLN EXPIRED & LOCKED SYSTEM
14 DIP EXPIRED & LOCKED USERS
21 ORACLE_OCM EXPIRED & LOCKED USERS
30 DBSNMP EXPIRED & LOCKED SYSAUX
31 APPQOSSYS EXPIRED & LOCKED SYSAUX
32 WMSYS EXPIRED & LOCKED SYSAUX
42 EXFSYS EXPIRED & LOCKED SYSAUX
43 CTXSYS EXPIRED & LOCKED SYSAUX
45 XDB EXPIRED & LOCKED SYSAUX
46 ANONYMOUS EXPIRED & LOCKED SYSAUX
53 ORDSYS EXPIRED & LOCKED SYSAUX
54 ORDDATA EXPIRED & LOCKED SYSAUX
55 ORDPLUGINS EXPIRED & LOCKED SYSAUX
56 SI_INFORMTN_SCHEMA EXPIRED & LOCKED SYSAUX
57 MDSYS EXPIRED & LOCKED SYSAUX
61 OLAPSYS EXPIRED & LOCKED SYSAUX
65 MDDATA EXPIRED & LOCKED USERS
67 SPATIAL_WFS_ADMIN_USR EXPIRED & LOCKED USERS
70 SPATIAL_CSW_ADMIN_USR EXPIRED & LOCKED USERS
72 SYSMAN EXPIRED & LOCKED SYSAUX
74 MGMT_VIEW EXPIRED & LOCKED SYSTEM
75 FLOWS_FILES EXPIRED & LOCKED SYSAUX
76 APEX_PUBLIC_USER EXPIRED & LOCKED USERS
78 APEX_030200 EXPIRED & LOCKED SYSAUX
79 OWBSYS EXPIRED & LOCKED SYSAUX
83 OWBSYS_AUDIT EXPIRED & LOCKED SYSAUX
84 SCOTT EXPIRED & LOCKED USERS
2147483638 XS$NULL EXPIRED & LOCKED USERS
30 rows selected.
8) 預設安裝的元件:
SQL> col COMP_ID format a8
col COMP_NAME format a35
col VERSION format a12
col schema format a12
col OTHER_SCHEMAS format a45
SQL> select comp_id,comp_name,version,schema,other_schemas from dba_registry order by 1;
COMP_ID COMP_NAME VERSION SCHEMA OTHER_SCHEMAS
-------- ----------------------------------- ------------ ------------ ---------------------------------------------
AMD OLAP Catalog 11.2.0.1.0 OLAPSYS
APEX Oracle Application Express 3.2.1.00.10 APEX_030200 FLOWS_FILES
APS OLAP Analytic Workspace 11.2.0.1.0 SYS
CATALOG Oracle Database Catalog Views 11.2.0.1.0 SYS
CATJAVA Oracle Database Java Packages 11.2.0.1.0 SYS
CATPROC Oracle Database Packages and Types 11.2.0.1.0 SYS APPQOSSYS,DBSNMP,DIP,ORACLE_OCM,OUTLN,SYSTEM
CONTEXT Oracle Text 11.2.0.1.0 CTXSYS
EM Oracle Enterprise Manager 11.2.0.1.0 SYSMAN
EXF Oracle Expression Filter 11.2.0.1.0 EXFSYS
JAVAVM JServer JAVA Virtual Machine 11.2.0.1.0 SYS
ORDIM Oracle Multimedia 11.2.0.1.0 ORDSYS MDSYS,ORDDATA,ORDPLUGINS,SI_INFORMTN_SCHEMA
OWB OWB 11.2.0.1.0 OWBSYS
OWM Oracle Workspace Manager 11.2.0.1.0 WMSYS
RUL Oracle Rules Manager 11.2.0.1.0 EXFSYS
SDO Spatial 11.2.0.1.0 MDSYS
XDB Oracle XML Database 11.2.0.1.0 XDB ANONYMOUS,XS$NULL
XML Oracle XDK 11.2.0.1.0 SYS
XOQ Oracle OLAP API 11.2.0.1.0 SYS
18 rows selected.
1.3 靜默刪庫(可選)
1) 生成響應檔案模板:
$ vi $DISTRIB/db_delete.rsp
#--------------------------------------------------------------------
#以下引數不能更改
[GENERAL]
RESPONSEFILE_VERSION = "11.2.0"
OPERATION_TYPE = "deleteDatabase"
#以下引數根據實際情況更改
[DELETEDATABASE]
SOURCEDB = "ORCL"
#--------------------------------------------------------------------
2) dbca靜默建庫, 無需手工停庫, 大概1分鐘:
$ $ORACLE_HOME/bin/dbca -silent -responseFile $DISTRIB/db_delete.rsp
Connecting to database
...
47% complete
Updating network configuration files
...
52% complete
Deleting instance and datafiles
...
100% complete
Look at the log file "/u01/app/oracle/cfgtoollogs/dbca/ORCL.log" for further details.
各引數含義如下:
-silent 表示以靜默方式刪除
-responseFile 表示使用哪個響應檔案,必需使用絕對路徑
RESPONSEFILE_VERSION 響應檔案模板的版本,該引數不要更改
OPERATION_TYPE 安裝型別,該引數不要更改
SOURCEDB 資料庫名,不是全域性資料庫名,即不包含db_domain
3) 刪除期間檢視日誌資訊瞭解進度:
$ tail -100f $ORACLE_BASE/cfgtoollogs/dbca/$ORACLE_SID/$ORACLE_SID.log