說明:原創,經過一天的折騰,終于搞清楚centos7.2上靜默安裝oracle數據庫,并且經過安裝驗證。由于之前都是在桌面環境中安裝,一般依賴包安裝完,安裝過程和Windows上相似。但是如果服務器中的Linux安裝了桌面環境,因為桌面環境運行還是比較占用資源,會拖慢服務器的速度,所以現在大多數Linux服務器都是無桌面版的,安裝都是最小化環境。
當然,可以在安裝最小化環境中的Linux中安裝桌面環境,安裝好后再次安裝oracle數據庫。最后又將桌面環境卸載。但是這種方法麻煩費時。
今天,花了一天時間,折騰安裝桌面再次安裝數據庫,系統都做了好幾次了。最后決定嘗試靜默安裝數據庫,終于嘗試兩次之后安裝成功。
只要嘗試,不斷總結,肯定會成功的。原來,靜默安裝步驟也就比較簡單。主要還是在響應文件的配置。其他的配置基本和桌面環境安裝一樣。
說明:為了安裝方便,最好使用Xshell類似的工具連接到centos終端
1、創建用戶及組
groupadd oinstall #創建oinstall
groupadd dba # 創建dba組
useradd -g oinstall -G dba oracle #創建oracle用戶
passwd oracle # 修改oracle用戶的登錄密碼
[root@rainbow oracle]# id oracle #查看oracle用戶信息
uid=1000(oracle) gid=1000(oinstall) groups=1000(oinstall),1001(dba)
2、創建目錄
mkdir -p /u01/app/oracle
chown -R oracle:oinstall /u01/app/oracle
chmod -R 775 /u01/app/oracle
3、安裝依賴包
依賴包是安裝oracle的必須,如果某些需要的依賴包沒有安裝上,安裝過程中會出現各種各樣的錯誤。所以,依賴包安裝完整,安裝過程一般會比較順利。
直接執行如下命令,安裝依賴包。
yum -y install binutils compat-libcap1 compat-libstdc++-33 compat-libstdc++-33*i686 compat-libstdc++-33*.devel compat-libstdc++-33 compat-libstdc++-33*.devel gcc gcc-c++ glibc glibc*.i686 glibc-devel glibc-devel*.i686 ksh libaio libaio*.i686 libaio-devel libaio-devel*.devel libgcc libgcc*.i686 libstdc++ libstdc++*.i686 libstdc++-devel libstdc++-devel*.devel libXi libXi*.i686 libXtst libXtst*.i686 make sysstat unixODBC unixODBC*.i686 unixODBC-devel unixODBC-devel*.i686
- 參考官方:http://docs.oracle.com/cd/E11882_01/install.112/e24326/toc.htm#BHCCADGD
- The following or later version of packages for Oracle Linux 7, and Red Hat Enterprise Linux 7 must be installed:
binutils-2.23.52.0.1-12.el7.x86_64 compat-libcap1-1.10-3.el7.x86_64 compat-libstdc++-33-3.2.3-71.el7.i686 compat-libstdc++-33-3.2.3-71.el7.x86_64 gcc-4.8.2-3.el7.x86_64 gcc-c++-4.8.2-3.el7.x86_64 glibc-2.17-36.el7.i686 glibc-2.17-36.el7.x86_64 glibc-devel-2.17-36.el7.i686 glibc-devel-2.17-36.el7.x86_64 ksh libaio-0.3.109-9.el7.i686 libaio-0.3.109-9.el7.x86_64 libaio-devel-0.3.109-9.el7.i686 libaio-devel-0.3.109-9.el7.x86_64 libgcc-4.8.2-3.el7.i686 libgcc-4.8.2-3.el7.x86_64 libstdc++-4.8.2-3.el7.i686 libstdc++-4.8.2-3.el7.x86_64 libstdc++-devel-4.8.2-3.el7.i686 libstdc++-devel-4.8.2-3.el7.x86_64 libXi-1.7.2-1.el7.i686 libXi-1.7.2-1.el7.x86_64 libXtst-1.2.2-1.el7.i686 libXtst-1.2.2-1.el7.x86_64 make-3.82-19.el7.x86_64 sysstat-10.1.5-1.el7.x86_64 unixODBC-2.3.1-6.el7.x86_64 or later unixODBC-2.3.1-6.el7.i686 or later unixODBC-devel-2.3.1-6.el7.x86_64 or later unixODBC-devel-2.3.1-6.el7.i686 or later
4、更改hosts文件
hosts文件中,要講主機名添加到配置文件中,及添加到127.0.0.1后面,如果沒有加,安裝過程中會出錯。
- 首先查看主機名:使用hostname命令
[root@rainbow oracle]# hostname rainbow
- 主機名為rainbow,則把rainbow添加到/etc/hosts文件中:
[root@rainbow oracle]# vi /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 rainbow ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
- 將自己的主機名添加到文件中,保存退出。
5、配置內核參數/etc/sysctl.conf
編輯sysctl.conf文件
`[root@rainbow oracle]# vi /etc/sysctl.conf
加入如下配置
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 = 1048576
vm.hugetlb_shm_group = 1001 #此處與id oracle中的dba中一致讓內核參數生效,執行:/sbin/sysctl -p
6、修改用戶限制
vi /etc/secruity/limits.conf
#在末尾添加
oracle soft nproc 2047
oracle hard nproc 16384
oracle soft nofile 1024
oracle hard nofile 65536
oracle soft stack 10240
- 保存退出。
7、修改 /etc/pam.d/login
vi /etc/pam.d/login
打開編輯此文件,在末尾加入如下配置:
session required /lib64/security/pam_limits.so session required pam_limits.so
說明:此處,要使用lib64,如果使用lib,則可能會出現無法登陸系統的情況,使用lib是在32位的情況下,如果是64位系統,則應該使用lib64
- 保存退出。
8、修改系統配置文件/etc/profile
vi /etc/profile
加入如下配置:
if [[ $USER = "oracle" ]]; then if [[ $SHELL = "/bin/ksh" ]]; then ulimit -p16384 ulimit -n65536 else ulimit -u16384 -n 65536 fi fi
- 注意空格
- 保存退出
- 使其生效 source /etc/profile
9、修改oracle用戶環境變量
vi /home/oracle/.bash_profile
加入如下配置文件:
`#oracle
export TMP=/tmp;
export TMPDIR=$TMP;
export ORACLE_BASE=/u01/app/oracle;
export ORACLE_HOME=$ORACLE_BASE/product/12.1.0/db_1;
export ORACLE_SID=orcl;
export ORACLE_TERM=xterm;
export PATH=/usr/sbin:$PATH;
export PATH=$ORACLE_HOME/bin:$PATH;
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib;
export CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib;`
- 保存退出。
- 使其生效:source /home/oracle/.bash_profile
10、上傳、解壓oracle安裝文件
使用sftp將安裝文件上傳至服務器。
- 解壓文件夾
[root@rainbow oracle]# unzip linuxamd64_12102_database_1of2.zip [root@rainbow oracle]# unzip linuxamd64_12102_database_2of2.zip
加壓之后,得到一個database的文件夾,將其移動到/u01/app/oracle目錄下
mv database /u01/app/oracle - 對文件授權
chown -R oracle:oinstall /u01/app/oracle/database
11、編輯、安裝數據庫響應文件db_install.rsp
最終的安裝主要在與三個響應文件的配置:dbca.rsp,netca.rsp,db_install.rsp,分別對應于創建數據庫,創建監聽,安裝數據庫。三個文件的路徑在database/response 文件夾下。
為了防止出錯,我們把三個響應文件復制到oracle用戶路徑下,出錯之后可以刪除再復制更改即可。
在oracle用戶目錄下,創建一個etc文件夾
[oracle@rainbow /]$ mkdir /home/oracle/etc
復制響應文件
[oracle@rainbow /]$ cp /u01/app/oracle/database/response/* /home/oracle/etc
[oracle@rainbow /]$ ls /home/oracle/etc/ dbca.rsp db_install.rsp netca.rsp
授權
[oracle@rainbow /]$ su - root [root@rainbow ~]# chmod 700 /home/oracle/etc/*.rsp
編輯安裝響應文件
[root@rainbow ~]# vi /home/oracle/etc/db_install.rsp
找到如下的配置,將配置更改如下:
`oracle.install.option=INSTALL_DB_SWONLY // 安裝類型
ORACLE_HOSTNAME=rainbow // 主機名稱(hostname查詢)
UNIX_GROUP_NAME=oinstall // 安裝組
INVENTORY_LOCATION=/u01/app/oracle/oraInventory //INVENTORY目錄(不填就是默認值)
SELECTED_LANGUAGES=en // 選擇語言
ORACLE_HOME=/u01/app/oracle/product/12.1.0/db_1 //oracle_home
ORACLE_BASE=/u01/app/oracle //oracle_base
oracle.install.db.InstallEdition=EE // oracle版本
oracle.install.db.isCustomInstall=false //自定義安裝,否,使用默認組件
oracle.install.db.DBA_GROUP=dba // dba用戶組
oracle.install.db.OPER_GROUP=dba // oper用戶組
oracle.install.db.config.starterdb.type=GENERAL_PURPOSE //數據庫類型
oracle.install.db.config.starterdb.globalDBName=orcl //globalDBName
oracle.install.db.config.starterdb.SID=orcl //SID
oracle.install.db.config.starterdb.password.ALL=admin123 //設定所有數據庫用戶使用同一個密碼
SECURITY_UPDATES_VIA_MYORACLESUPPORT=false //(手動寫了false)
DECLINE_SECURITY_UPDATES=true //設置安全更新(貌似是有bug,這個一定要選true,否則會無限提醒郵件地址有問題,終止安裝。PS:不管地址對不對)`
- 配置好后。保存退出。
- 開始安裝數據庫。切換到oracle用戶下
[root@rainbow ~]# su - oracle [oracle@rainbow database]$ /u01/app/oracle/database/runInstaller -silent -responseFile /home/oracle/etc/db_install.rsp
- 安裝過程如下,出現如下結果,說明安裝成功
Starting Oracle Universal Installer...
Checking Temp space: must be greater than 500 MB. Actual 17997 MB Passed
Checking swap space: must be greater than 150 MB. Actual 2999 MB Passed
Preparing to launch Oracle Universal Installer from /tmp/OraInstall2017-06-04_07-51-31PM. Please wait ...[oracle@rainbow database]$ [WARNING] [INS-32055] The Central Inventory is located in the Oracle base.
ACTION: Oracle recommends placing this Central Inventory in a location outside the Oracle base directory.
[WARNING] [INS-13014] Target environment does not meet some optional requirements.
CAUSE: Some of the optional prerequisites are not met. See logs for details. /tmp/OraInstall2017-06-04_07-51-31PM/installActions2017-06-04_07-51-31PM.log
ACTION: Identify the list of failed prerequisite checks from the log: /tmp/OraInstall2017-06-04_07-51-31PM/installActions2017-06-04_07-51-31PM.log. Then either from the log file or from installation manual find the appropriate configuration to meet the prerequisites and fix it manually.
You can find the log of this install session at:
/u01/app/oracle/oraInventory/logs/installActions2017-06-04_07-51-31PM.log
The installation of Oracle Database 12c was successful.
Please check '/u01/app/oracle/oraInventory/logs/silentInstall2017-06-04_07-51-31PM.log' for more details.
As a root user, execute the following script(s):
1. /u01/app/oracle/oraInventory/orainstRoot.sh
2. /u01/app/oracle/product/12.1.0/db_1/root.sh
Successfully Setup Software
- 使用root用戶登錄 ,分別執行
/u01/app/oracle/oraInventory/orainstRoot.sh /u01/app/oracle/product/12.1.0/db_1/root.sh
- 到此,數據庫已成功安裝上。
12、配置、啟動監聽
監聽器配置響應文件為:/home/oracle/etc/netca.rsp,此文件使用默認即可。
執行配置監聽
[oracle@rainbow database]$ /u01/app/oracle/product/12.1.0/db_1/bin/netca -silent -responseFile /home/oracle/etc/netca.rsp
出現如下信息,說明監聽配置成功。
[oracle@rainbow database]$ /u01/app/oracle/product/12.1.0/db_1/bin/netca -silent -responseFile /home/oracle/etc/netca.rsp
Parsing command line arguments:
Parameter "silent" = true
Parameter "responsefile" = /home/oracle/etc/netca.rsp
Done parsing command line arguments.
Oracle Net Services Configuration:
Profile configuration complete.
Oracle Net Listener Startup:
Running Listener Control:
/u01/app/oracle/product/12.1.0/db_1/bin/lsnrctl start LISTENER
Listener Control complete.
Listener started successfully.
Listener configuration complete.
Oracle Net Services configuration successful. The exit code is 0
[oracle@rainbow database]$啟動監聽
[oracle@rainbow database]$ lsnrctl start
- 查看監聽狀態
[oracle@rainbow database]$ lsnrctl status
LSNRCTL for Linux: Version 12.1.0.2.0 - Production on 04-JUN-2017 20:15:07
Copyright (c) 1991, 2014, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521)))
STATUS of the LISTENER
Alias LISTENER
Version TNSLSNR for Linux: Version 12.1.0.2.0 - Production
Start Date 04-JUN-2017 20:08:08
Uptime 0 days 0 hr. 7 min. 0 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/app/oracle/product/12.1.0/db_1/network/admin/listener.ora
Listener Log File /u01/app/oracle/diag/tnslsnr/rainbow/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
The listener supports no services
The command completed successfully
- 重啟監聽
[oracle@rainbow database]$ lsnrctl reload
13、靜默創建數據庫實例
編輯應答文件
[oracle@rainbow database]$ vi /home/oracle/etc/dbca.rsp
將其更改如下:
[GENERAL] RESPONSEFILE_VERSION = "12.1.0" OPERATION_TYPE = "createDatabase" [CREATEDATABASE] GDBNAME = "dbsrv2" SID = "dbsrv2" TEMPLATENAME = "General_Purpose.dbc" CHARACTERSET = "AL32UTF8"
保存退出
執行安裝數據庫實例
[oracle@rainbow database]$ /u01/app/oracle/product/12.1.0/db_1/bin/dbca -silent -responseFile /home/oracle/etc/dbca.rsp
- 執行安裝后,依次輸入sys和system的密碼,然后耐性等待,會顯示安裝的進度。
- 查看日志信息:
`[oracle@rainbow database]$ cat /u01/app/oracle/cfgtoollogs/dbca/orcl/orcl.log
Unique database identifier check passed.
/ has enough space. Required space is 6140 MB , available space is 12658 MB.
File Validations Successful.
Copying database files
DBCA_PROGRESS : 1%
DBCA_PROGRESS : 3%
DBCA_PROGRESS : 11%
DBCA_PROGRESS : 18%
DBCA_PROGRESS : 26%
DBCA_PROGRESS : 37%
Creating and starting Oracle instance
DBCA_PROGRESS : 40%
DBCA_PROGRESS : 45%
DBCA_PROGRESS : 50%
DBCA_PROGRESS : 55%
DBCA_PROGRESS : 56%
DBCA_PROGRESS : 60%
DBCA_PROGRESS : 62%
Completing Database Creation
DBCA_PROGRESS : 66%
DBCA_PROGRESS : 70%
DBCA_PROGRESS : 73%
DBCA_PROGRESS : 85%
DBCA_PROGRESS : 96%
DBCA_PROGRESS : 100%
Database creation complete. For details check the logfiles at:
/u01/app/oracle/cfgtoollogs/dbca/orcl.
Database Information:
Global Database Name:orcl
System Identifier(SID):orcl
`
- 日志顯示,數據庫實例已經成功創建。
- 此時,查看監聽,orcl數據庫實例已經正常運行。
`[oracle@rainbow database]$ lsnrctl status
LSNRCTL for Linux: Version 12.1.0.2.0 - Production on 04-JUN-2017 20:54:52
Copyright (c) 1991, 2014, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521)))
STATUS of the LISTENER
Alias LISTENER
Version TNSLSNR for Linux: Version 12.1.0.2.0 - Production
Start Date 04-JUN-2017 20:08:08
Uptime 0 days 0 hr. 46 min. 44 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/app/oracle/product/12.1.0/db_1/network/admin/listener.ora
Listener Log File /u01/app/oracle/diag/tnslsnr/rainbow/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
Services Summary...
Service "orcl" has 1 instance(s).
Instance "orcl", status READY, has 1 handler(s) for this service...
Service "orclXDB" has 1 instance(s).
Instance "orcl", status READY, has 1 handler(s) for this service...
The command completed successfully
`
14、數據庫的啟動與停止
進入到oracle安裝目錄的bin目錄下,執行 dbstop即可停止數據庫。
15、開放端口(使用root用戶)
由于數據庫安裝了一般需要外網訪問,所以需要開放數據庫連接端口。
[root@rainbow /]# firewall-cmd --zone=public --add-port=1521/tcp --permanent
success
[root@rainbow /]# firewall-cmd --zone=public --add-port=5500/tcp --permanent
success
[root@rainbow /]# firewall-cmd --reload
success
- 命令含義:
--zone #作用域
--add-port=80/tcp #添加端口,格式為:端口/通訊協議
--permanent #永久生效,沒有此參數重啟后失效 - 重啟防火墻
firewall-cmd --reload
16、設置oracle數據庫隨系統開機自啟動。
大多數情況下,我們都需要讓oracle數據庫隨服務器開機自啟動。
- 1、編輯/etc/oratab
orcl:/u01/app/oracle/product/12.1.0/db_1:N - 將以上配置改為:
orcl:/u01/app/oracle/product/12.1.0/db_1:Y - 保存退出
- 2、編輯/etc/rc.d/rc.local
vi /etc/rc.d/rc.local - 加入如下配置:
su oracle -lc "/u01/app/oracle/product/12.1.0/db_1/bin/lsnrctl start"
su oracle -lc /u01/app/oracle/product/12.1.0/db_1/bin/dbstart - 保存退出
- 重啟系統,再次連接數據庫,將正常連接上。
說明:本人水平有限,有些地方可能不完善,望大家多多知道俺