1. 程式人生 > 資料庫 >oracle 11.2.0.4靜默安裝

oracle 11.2.0.4靜默安裝

oracle 11.2.0.4靜默安裝

1、安裝包

1.1、上傳安裝包

xshell可用rz命令,選擇安裝包。

mobaxterm可用左側欄上傳功能。

2、安裝準備

2.1、關閉防火牆、SELinux

sed -i 's/=enforcing/=disabled/g' /etc/selinux/config
systemctl stop firewalld

2.2、繫結主機名和主機IP

ifconfig | grep inet		//檢視主機IP
        inet 66.1.30.32  netmask 255.255.255.0  broadcast 66.1.30.255
        inet 127.0.0.1  netmask 255.0.0.0
        inet 192.168.122.1  netmask 255.255.255.0  broadcast 192.168.122.255
vim /etc/hosts		//新增
	66.1.30.32   Oracle		//新增行:IP 機器名(這是我的ip和主機名)

2.3、修改使用者的限制檔案

cat /etc/security/limits.conf                //在該檔案內新增以下內容
	oracle           soft    nproc           2047
	oracle           hard    nproc           16384
	oracle           soft    nofile          1024
	oracle           hard    nofile          65536
	oracle           soft    stack           10240

2.4、修改核心引數

cat /etc/sysctl.conf //在檔案中新增以下內容
	net.ipv4.ip_local_port_range= 9000 65500
	fs.file-max = 6815744
	kernel.shmall = 10523004
	kernel.shmmax = 6465333657
	kernel.shmmni = 4096
	kernel.sem = 250 32000 100128
	net.core.rmem_default=262144
	net.core.wmem_default=262144
	net.core.rmem_max=4194304
	net.core.wmem_max=1048576
	fs.aio-max-nr = 1048576
sysctl –p // 執行這條語句使配置生效

2.5、依賴包安裝

yum install gcc* gcc-* gcc-c++-* glibc-devel-* glibc-headers-* compat-libstdc* libstdc* elfutils-libelf-devel* libaio-devel* sysstat* unixODBC-* pdksh-*

2.6、建立使用者、組,安裝目錄

groupadd oinstall
groupadd dba
useradd –g oinstall -G dba -d /home/oracle oracle
echo "oracle" | passwd --stdin oracle
id oracle //檢視使用者所屬組
	uid=10001(oracle) gid=10001(oinstall) groups=10001(oinstall),10002(dba)

2.7、建立安裝目錄

mkdir -p /var/app
mkdir -p /var/app/oracle
mkdir -p /var/app/oracle/product
mkdir -p /var/app/oracle/product/11.2.0
mkdir -p /var/app/oracle/product/11.2.0/dbhome_1
mkdir -p /home/oracle/backup
mkdir -p /home/oracle/oraInventory
chown -R oracle:oinstall /var/app
chown -R oracle:oinstall /home/oracle/backup
chown -R oracle:oinstall /home/oracle/oraInventory
chmod -R 775 /var/app

2.8、設定並重新整理環境變數

cat /home/oracle/.bash_profile //給該檔案新增以下內容
	umask 022
    export ORACLE_BASE=/var/app
    export ORACLE_HOME=$ORACLE_BASE/oracle/product/11.2.0/dbhome_1
    export ORACLE_SID=orcl
    export PATH=$PATH:$HOME/bin:$ORACLE_HOME/bin
    export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/usr/lib
source /home/oracle/.bash_profile //執行該句使配置生效

3、開始安裝

3.1、切換到oracle使用者,解壓安裝包

su - oracle
cd /var/app/oracle/
unzip p13390677_112040_Linux-x86-64_1of7.zip ./
unzip p13390677_112040_Linux-x86-64_2of7.zip ./

解壓後得到database目錄,其中response目錄裡面有三個rsp檔案,用來作為靜默安裝時應答檔案的模板。分別為:

cd /var/app/oracle/database/response
ls -l
    -rwxrwxr-x 1 oracle oinstall 44637 Oct 31 02:18 dbca.rsp      //安裝應答
    -rwxrwxr-x 1 oracle oinstall 25333 Oct 31 01:42 db_install.rsp      //建立資料庫應答
    -rwxrwxr-x 1 oracle oinstall  5871 Aug 27  2013 netca.rsp		//建立監聽,本地服務名等網路設定

3.2、修改配置檔案

cp /var/app/oracle/database/response/ /home/oracle/		//備份
cat db_install.rsp | grep -v '^#' | grep -v '^$'

輸出如下:

oracle.install.responseFileVersion=/oracle/install/rspfmt_dbinstall_response_schema_v11_2_0
oracle.install.option=INSTALL_DB_SWONLY
ORACLE_HOSTNAME=oracle
UNIX_GROUP_NAME=oinstall
INVENTORY_LOCATION=/var/app/oracle/oraInventory
SELECTED_LANGUAGES=en,zh_CN
ORACLE_HOME=/var/app/oracle/product/11.2.0/dbhome_1
ORACLE_BASE=/var/app/oracle
oracle.install.db.InstallEdition=EE
oracle.install.db.EEOptionsSelection=false
oracle.install.db.optionalComponents=oracle.rdbms.partitioning:11.2.0.4.0,oracle.oraolap:11.2.0.4.0,oracle.rdbms.dm:11.2.0.4.0,oracle.rdbms.dv:11.2.0.4.0,oracle.rdbms.lbac:11.2.0.4.0,oracle.rdbms.rat:11.2.0.4.0
oracle.install.db.DBA_GROUP=dba
oracle.install.db.OPER_GROUP=oinstall
oracle.install.db.CLUSTER_NODES=
oracle.install.db.isRACOneInstall=
oracle.install.db.racOneServiceName=
oracle.install.db.config.starterdb.type=GENERAL_PURPOSE
oracle.install.db.config.starterdb.globalDBName=ora11g
oracle.install.db.config.starterdb.SID=ora11g
oracle.install.db.config.starterdb.characterSet=AL32UTF8
oracle.install.db.config.starterdb.memoryOption=true
oracle.install.db.config.starterdb.memoryLimit=1500
oracle.install.db.config.starterdb.installExampleSchemas=false
oracle.install.db.config.starterdb.enableSecuritySettings=true
oracle.install.db.config.starterdb.password.ALL=oracle
oracle.install.db.config.starterdb.password.SYS=
oracle.install.db.config.starterdb.password.SYSTEM=
oracle.install.db.config.starterdb.password.SYSMAN=
oracle.install.db.config.starterdb.password.DBSNMP=
oracle.install.db.config.starterdb.control=DB_CONTROL
oracle.install.db.config.starterdb.gridcontrol.gridControlServiceURL=
oracle.install.db.config.starterdb.automatedBackup.enable=false
oracle.install.db.config.starterdb.automatedBackup.osuid=
oracle.install.db.config.starterdb.automatedBackup.ospwd=
oracle.install.db.config.starterdb.storageType=FILE_SYSTEM_STORAGE
oracle.install.db.config.starterdb.fileSystemStorage.dataLocation=
oracle.install.db.config.starterdb.fileSystemStorage.recoveryLocation=
oracle.install.db.config.asm.diskGroup=
oracle.install.db.config.asm.ASMSNMPPassword=
[email protected]
MYORACLESUPPORT_PASSWORD=password
SECURITY_UPDATES_VIA_MYORACLESUPPORT=
DECLINE_SECURITY_UPDATES=true
PROXY_HOST=
PROXY_PORT=
PROXY_USER=
PROXY_PWD=
PROXY_REALM=
COLLECTOR_SUPPORTHUB_URL=
oracle.installer.autoupdates.option=
oracle.installer.autoupdates.downloadUpdatesLoc=
AUTOUPDATES_MYORACLESUPPORT_USERNAME=
AUTOUPDATES_MYORACLESUPPORT_PASSWORD=

3.3、靜默安裝

cd /var/app/oracle/database
./runInstaller -silent -responseFile /var/app/oracle/database/response/db_install.rsp

3.4、出現如下輸出即為成功:

Starting Oracle Universal Installer...
Checking Temp space: must be greater than 120 MB.   Actual 30447 MB    Passed
Checking swap space: must be greater than 150 MB.   Actual 8063 MB    Passed
Preparing to launch Oracle Universal Installer from /tmp/OraInstall2020-10-31_01-46-54AM. Please wait ...
[WARNING] [INS-32055] The Central Inventory is located in the Oracle base.
   CAUSE: The Central Inventory is located in the Oracle base.
   ACTION: Oracle recommends placing this Central Inventory in a location outside the Oracle base directory.
You can find the log of this install session at: /var/app/oracle/oraInventory/logs/installActions2020-10-31_01-46-54AM.log
The installation of Oracle Database 11g was successful.
Please check '/var/app/oracle/oraInventory/logs/silentInstall2020-10-31_01-46-54AM.log' for more details.

As a root user, execute the following script(s):
        1. /var/app/oracle/oraInventory/orainstRoot.sh
        2. /var/app/oracle/product/11.2.0/dbhome_1/root.sh

3.5、按照提示操作

開啟新的客戶端使用root身份執行以下指令碼

開啟新的ssh視窗
sh /var/app/oracle/oraInventory/orainstRoot.sh
sh /var/app/oracle/product/11.2.0/dbhome_1/root.sh

3.6、執行完上面的指令碼後回到安裝介面按下Enter繼續

3.7、配置Oracle監聽

cd /var/app/oracle/database/response
netca /silent /responsefile /var/app/oracle/database/response/netca.rsp

執行成功之後,在/var/app/oracle/product/11.2.0/dbhome_1/network/admin目錄下會生成sqlnet.ora和listener.ora兩個檔案。

ls /var/app/oracle/product/11.2.0/dbhome_1/network/admin
	listener.ora  samples  shrept.lst  sqlnet.ora  tnsnames.ora
netstat -tlnp | grep 1521
    tcp    0	0	0.0.0.0:1521	0.0.0.0:*	LISTEN	2101099/tnslsnr

如果監聽沒有啟動,則手動啟動監聽器。

cd /var/app/oracle/database/response
lsnrctl start

3.8、配置Oracle資料庫

cd /var/app/oracle/database/response
vim dbca.rsp
GDBNAME = "orcl11g.us.oracle.com"     //78 行 全域性資料庫的名字=SID+主機域名
SID = "ora11g"    //170行 SID
SYSPASSWORD = "oracle"    //211行
SYSTEMPASSWORD = "oracle"   //221行
CHARACTERSET="AL32UTF8" //418行 編碼
NATIONALCHARACTERSET="UTF8" //429行 編碼

3.9、建立oracle資料庫

$ORACLE_HOME/bin/dbca -silent -responseFile /var/app/oracle/database/response/dbca.rsp

4、啟動資料庫

sqlplus / as sysdba		//oracle使用者執行
SQL> startup
ORA-01078: failure in processing system parameters
LRM-00109: could not open parameter file '/var/app/oracle/product/11.2.0/dbhome_1/dbs/initora11g.ora'
啟動時會出現以上錯誤,解決方法如下:找到init.ora.78201817526檔案,將其複製到/var/app/oracle/product/11.2.0/dbhome_1/dbs目錄下
[oracle@Oracle admin]$ locate init.ora           //定位尋找目標檔案
/var/app/admin/orcl11g/pfile/init.ora.78201817526               //目標檔案
/var/app/oracle/product/11.2.0/dbhome_1/dbs/init.ora
/var/app/oracle/product/11.2.0/dbhome_1/srvm/admin/init.ora
[oracle@Oracle admin]$ cd /var/app/admin/orcl11g/pfile/
[oracle@Oracle pfile]$ ls
init.ora.78201817526
[oracle@Oracle pfile]$ cp init.ora.78201817526  /var/app/oracle/product/11.2.0/dbhome_1/dbs/
[oracle@Oracle dbs]$ mv init.ora.78201817526 initora11g.ora    //將目標檔案改成所需檔名

5、oracle安裝問題彙總

為方便區別使用者,用#代表root使用者、$代表oracle使用者。

5.1、[INS-13013]

[FATAL] [INS-13013] Target environment do not meet some mandatory requirements.
   CAUSE: Some of the mandatory prerequisites are not met. See logs for details. /tmp/OraInstall2018-11-07_10-29-35PM/installActions2018-11-07_10-29-35PM.log
   ACTION: Identify the list of failed prerequisite checks from the log: /tmp/OraInstall2018-11-07_10-29-35PM/installActions2018-11-07_10-29-35PM.log. Then either from the log file or from installation manual find the appropriate configuration to meet the prerequisites and fix it manually.
解決:增加忽略
加上-ignorePrereq命令,就可以了。
$ ./runInstaller -silent -force -noconfig -ignorePrereq -responseFile /var/app/oracle/oracle/database/response/db_install.rsp

5.2、[INS-32038]

[FATAL] [INS-32038] The operating system group specified for central inventory (oraInventory) ownership is invalid.
   CAUSE: User performing installation is not a member of the operating system group specified for central inventory(oraInventory) ownership.
   ACTION: Specify an operating system group that the installing user is a member of. All the members of this operating system group will have write permission to the central inventory directory (oraInventory).
解決:三種情況,自行檢視
對oraInventory目錄沒有寫許可權
原因:
1、oraInventory目錄許可權設定不對
$ chown -R oracle:oinstall /var/app/oracle/oraInventory
2、Oracle所屬組不對
系統安裝時主動新增的Oracle使用者,則會導致這個情況
$ id oracle
錯誤:
uid=504(oracle) gid=500(oracle) groups=500(oracle),501(wheel)
正常輸出:
uid=504(oracle) gid=500(oinstall) groups=500(oinstall),501(dba)
# userdel oracle
# useradd –g oinstall -G dba -d /home/oracle oracle
# chown -R oracle:oinstall /u01/app/oracle
# chown -R oracle:oinstall /u01/app/oraInventory
思路就是:刪除現在這個Oracle使用者,重新建立一個新的Oracle使用者,並且將需要的目錄重新授予新Oracle使用者
3、缺少/etc/oraInst.loc檔案(這個問題我沒遇到過暫時)
# vim /etc/oraInst.loc
UNIX_GROUP_NAME=oinstall
INVENTORY_LOCATION=/var/app/oracle/oraInventory

5.3、[PRVF-0002]

[FATAL] [PRVF-0002] : Could not retrieve local nodename
A log of this session is currently saved as: /tmp/OraInstall2017-09-29_11-43-52AM/installActions2017-09-29_11-43-52AM.log. Oracle recommends that if you want to keep this log, you should move it from the temporary location to a more permanent location.
解決:繫結主機名和主機IP
# hostname
oracle
# ifconfig | grep inet		//檢視主機IP
        inet 66.1.30.32  netmask 255.255.255.0  broadcast 66.1.30.255
        inet 127.0.0.1  netmask 255.0.0.0
        inet 192.168.122.1  netmask 255.255.255.0  broadcast 192.168.122.255
# vim /etc/hosts		//新增
	66.1.30.32   Oracle		//新增行:IP 機器名(這是我的ip和主機名

5.4、重新安裝時,沒有orainstRoot.sh檔案

$ ./runInstaller -silent -force -noconfig -responseFile /var/app/oracle/database/response/db_install_dtstack.rsp
Starting Oracle Universal Installer...
·
·
·
As a root user, execute the following script(s):

  \1. /var/app/oracle/product/11.2.4/db_1/root.sh
Successfully Setup Software.
重新安裝 [Oracle](http://lib.csdn.net/base/oracle) 時,沒有orainstRoot.sh檔案。
重新安裝RAC時,到excute configuration scripts時,只提示執行:root.sh這個檔案,不提示orainstRoot.sh;這個檔案,是為什麼?
解決:刪除/etc/oraInst.loc檔案
原因:沒刪除/etc/oraInst.loc檔案
[oracle@iz2zec57gfl6i9vbtdksl1z database]$ ./runInstaller -silent -force -noconfig -responseFile /var/app/oracle/database/response/db_install_dtstack.rsp
Starting Oracle Universal Installer...
·
·
·
As a root user, execute the following script(s):
  \1. /home/u01/app/oraInventory/orainstRoot.sh
  \2. /home/u01/app/oracle/product/11.2.4/db_1/root.sh
Successfully Setup Software.

5.5、啟動Oracle出現:MEMORY_TARGET not supported

# su - oracle
# sqlplus / as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Wed Sep 13 19:33:17 2017
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to an idle instance.
SQL> startup
ORA-00845: MEMORY_TARGET not supported on this system
解決:增加掛載盤大小
# df -h | grep shm
	tmpfs      497M 205M 292M 42% /dev/shm
# cat /etc/fstab | grep tmpfs
# mount -o remount,size=4G /dev/shm
# df -h | grep shm
	tmpfs      4.0G 205M 3.9G  5% /dev/shm
刪除其他使用者登入oracle程序

5.6、啟動Oracle出現:cannot mount

# su - oracle
# sqlplus / as sysdba
SQL> startup
ORACLE instance started.
Total System Global Area 413372416 bytes
Fixed Size      2253784 bytes
Variable Size     327158824 bytes
Database Buffers    79691776 bytes
Redo Buffers      4268032 bytes
ORA-01102: cannot mount database in EXCLUSIVE mode
解決:
# su - oracle
$ cd /var/app/oracle/database
$ ipcs -s
------ Semaphore Arrays --------
key    semid   owner   perms   nsems
0xbcf2a624 491520   oracle   640    154
0x50f506b0 884737   oracle   640    154
$ ipcrm -s 491520
$ ipcrm -s 884737
$ ipcs -s
------ Semaphore Arrays --------
key    semid   owner   perms   nsems
$ ipcs -s

5.7、記憶體問題

$ sqlplus monitor/monitor123
SQL*Plus: Release 11.2.0.4.0 Production on Thu Aug 31 18:51:59 2017
Copyright (c) 1982, 2013, Oracle. All rights reserved.
ERROR:
ORA-01034: ORACLE not available
ORA-27102: out of memory
Linux-x86_64 Error: 12: Cannot allocate memory
Additional information: 26
Additional information: 229378
Additional information: 1619001344
Process ID: 0
Session ID: 0 Serial number: 0
Enter user-name:
解決:清理記憶體並重啟資料庫
1、首先檢查linux伺服器的當前記憶體使用情況:
# free -m
發現已經沒有空閒記憶體
2、檢視核心允許的最大共享記憶體段大小
# /proc/sys/kernel/shmmax
發現設定的足夠大
3、使用top 檢視當前消耗記憶體大的程序
發現oracle有好幾個程序消耗了大量的資源
4、kill掉這幾個程序
# kill -s 9  11111(程序號)
5、清理記憶體
# echo 1 > /proc/sys/vm/drop_caches
6、重啟資料庫
$ sqlplus / as sysdba
SQL> shutdown immediate
SQL> startup

5.8、鎖賬號(原因是密碼錯誤次數過多)

$ sqlplus monitor/monitor123
SQL*Plus: Release 11.2.0.4.0 Production on Thu Aug 31 18:57:23 2017
Copyright (c) 1982, 2013, Oracle. All rights reserved.
ERROR:
ORA-28000: the account is locked
解決:
# su - oracle
# sqlplus / as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Thu Aug 31 18:50:39 2017
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, Oracle Label Security, OLAP, Data Mining,
Oracle Database Vault and Real Application Testing options
SQL> alter user monitor account unlock;
User altered.

5.9、ORA-01045沒有建立會話的許可權

$ sqlplus monitor/monitor123
ERROR:
ORA-01045: user CUSTOMERCHAT lacks CREATE SESSION privilege; logon denied
解決:重新賦建立會話的許可權
# su - oracle
# sqlplus / as sysdba
SQL> grant create session to monitor;

6、oracle使用

6.1、建立例項

# su - oracle
$ sqlplus / as sysdba
6.1.1、建立表空間
SQL> select name from v$datafile;		//查詢使用者表空間檔案的路徑
NAME
--------------------------------------------------------------------------------
/var/app/oradata/orcl11g/system01.dbf
/var/app/oradata/orcl11g/sysaux01.dbf
/var/app/oradata/orcl11g/undotbs01.dbf
/var/app/oradata/orcl11g/users01.dbf
SQL> CREATE TABLESPACE test datafile '/var/app/oradata/orcl11g/htest.dbf' size 600M autoextend on next 50m maxsize unlimited;		//建立使用者表空間
Tablespace created.
SQL> CREATE USER htest IDENTIFIED BY htest DEFAULT TABLESPACE test;		//建立使用者,指定密碼和上邊建立的使用者表空間
User created.
SQL> grant connect,resource,dba to htest;		//賦予許可權
Grant succeeded.
常用oracle命令
select username from dba_users;		//查詢已建立的使用者
alter user customerchat identified by 123456;		//修改使用者密碼
alter user customerchat account unlock;		//解鎖使用者
drop user 使用者名稱 cascade;		//刪除使用者
drop tablespace tablespace_name;		//刪除空的表空間,但是不包含物理檔案
drop tablespace tablespace_name including contents;		//刪除非空表空間,但是不包含物理檔案
drop tablespace tablespace_name including datafiles;		//刪除空表空間,包含物理檔案
drop tablespace tablespace_name including contents and datafiles;		//刪除非空表空間,包含物理檔案
drop tablespace tablespace_name including contents and datafiles CASCADE CONSTRAINTS;		//如果其他表空間中的表有外來鍵等約束關聯到了本表空間中的表的欄位,就要加上CASCADE CONSTRAINTS
6.1.2、建表
sqlplus htest/htest		//用建立的使用者名稱、密碼(usernmae/password)登陸
SELECT * FROM ALL_TABLES WHERE OWNER= 'HTEST';		//查詢使用者下所有表
CREATE TABLE TEST1031
(
  ID                VARCHAR(20) 		NOT NULL,                             
  NAME              VARCHAR(20) 	NOT NULL,                              
  CREATE_TIME       DATE      NOT NULL,
  UPDATE_TIME 	    DATE 		NOT NULL,                        
CONSTRAINT TEST1031 PRIMARY KEY(ID) USING INDEX TABLESPACE TEST
) TABLESPACE TEST;
INSERT  INTO  TEST1031  VALUES  ( '1','123',to_date ( '2020-11-01' , 'YYYY-MM-DD'), to_date ( '2020-11-02' , 'YYYY-MM-DD') ) ;
commit

select * from all_tab_comments;		//查詢所有使用者的表,檢視等
select * from user_tab_comments;		//查詢本使用者的表,檢視等
select * from all_col_comments;		//查詢所有使用者的表的列名和註釋.
select * from user_col_comments;		//查詢本使用者的表的列名和註釋
select * from all_tab_columns;		//查詢所有使用者的表的列名等資訊(詳細但是沒有備註).
select * from user_tab_columns;		//查詢本使用者的表的列名等資訊(詳細但是沒有備註).

登入新建的customerchat使用者匯入sql檔案

sqlplus customerchat/customerchat		//--sqlplus登入

匯入sql檔案:@路徑名/檔名

報如下錯誤:

ORA-01031: insufficient privileges

這是因為沒有建表的許可權

登入dba使用者匯入

sqlplus / as sysdba

匯入sql檔案報如下錯誤:

ORA-01950: no privileges on tablespace 'CUSTOMERCHAT'

這是由於建立表空間時設定了有限的大小,兩種方法:

方法1: 授予使用者對該表空間的UNLIMITED配額

ALTER USER CUSTOMERCHAT  QUOTA UNLIMITED ON customerchat;

方法2: 重新授權resource角色給使用者之後,便可以建立表

GRANT RESOURCE TO CUSTOMERCHAT;