Centos7.0無桌面環境上靜默安裝oracle 11g
Centos7.0無桌面環境上靜默安裝oracle 11g
1 配置基礎環境
1.1 創建用戶及組
groupadd oinstall #創建oinstall
groupadd dba # 創建dba組
useradd -g oinstall -G dba oracle #創建oracle用戶
passwd oracle # 修改oracle用戶的登錄密碼
[[email protected] oracle]# id oracle #查看oracle用戶信息
uid=1000(oracle) gid=1000(oinstall)groups=1000(oinstall),1001(dba)
1.2 創建目錄
mkdir -p /mnt/app/oracle
chown -R oracle:oinstall /mnt/app/oracle
chmod -R 775 /mnt/app/oracle
1.3 安裝依賴包
依賴包是安裝oracle的必須,如果某些需要的依賴包沒有安裝上,安裝過程中會出現各種各樣的錯誤。所以,依賴包安裝完整,安裝過程一般會比較順利。
直接執行如下命令,安裝依賴包。
yum -y install binutils compat-libcap1compat-libstdc++-33 compat-libstdc++-33*i686 compat-libstdc++-33*.develcompat-libstdc++-33 compat-libstdc++-33*.devel gcc gcc-c++ glibc glibc*.i686glibc-devel glibc-devel*.i686 ksh libaio libaio*.i686 libaio-devellibaio-devel*.devel libgcc libgcc*.i686 libstdc++ libstdc++*.i686libstdc++-devel libstdc++-devel*.devel libXi libXi*.i686 libXtst libXtst*.i686make 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 packagesfor 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
1.4 更改hosts文件
hosts文件中,要講主機名添加到配置文件中,及添加到127.0.0.1後面,如果沒有加,安裝過程中會出錯。
首先查看主機名:使用hostname命令
[[email protected] oracle]# hostname
test-1
主機名為test-1,則把test-1添加到/etc/hosts文件中:
[[email protected] oracle]# vi /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4test-1
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
將自己的主機名添加到文件中,保存退出。
1.5 配置內核參數/etc/sysctl.conf
編輯sysctl.conf文件
`[[email protected] 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
1.6 修改用戶限制
vi /etc/security/limits.conf
#在末尾添加
oracle soft nproc 2047
oracle hard nproc 16384
oracle soft nofile 1024
oracle hard nofile 65536
oracle soft stack 10240
保存退出。
1.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
保存退出。
1.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
1.9 修改oracle用戶環境變量
vi /home/oracle/.bash_profile
加入如下配置文件:
#oracle
export TMP=/tmp;
export TMPDIR=$TMP;
export ORACLE_BASE=/mnt/app/oracle;
exportORACLE_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;
exportCLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib;
保存退出。
使其生效:source /home/oracle/.bash_profile
2 開始安裝oracle
2.1 上傳、解壓oracle安裝文件
使用sftp將安裝文件上傳至服務器。
解壓文件夾
[[email protected] oracle]# unziplinuxamd64_12102_database_1of2.zip
[[email protected] oracle]# unziplinuxamd64_12102_database_2of2.zip
加壓之後,得到一個database的文件夾,將其移動到/mnt/app/oracle目錄下
mv database /mnt/app/oracle
對文件授權
chown -R oracle:oinstall/mnt/app/oracle/database
2.2 編輯、安裝數據庫響應文件db_install.rsp
最終的安裝主要在與三個響應文件的配置:dbca.rsp,netca.rsp,db_install.rsp,分別對應於創建數據庫,創建監聽,安裝數據庫。三個文件的路徑在database/response 文件夾下。
為了防止出錯,我們把三個響應文件復制到oracle用戶路徑下,出錯之後可以刪除再復制更改即可。
在oracle用戶目錄下,創建一個etc文件夾
[[email protected] /]$ mkdir /home/oracle/etc
復制響應文件
[[email protected] /]$ cp /mnt/app/oracle/database/response/*/home/oracle/etc
[[email protected] /]$ ls /home/oracle/etc/
dbca.rsp db_install.rsp netca.rsp
授權
[[email protected] /]$ su - root
[[email protected] ~]# chmod 777 /home/oracle/etc/*.rsp
編輯安裝響應文件
[[email protected] ~]# vi /home/oracle/etc/db_install.rsp
找到如下的配置,將配置更改如下:
`oracle.install.option=INSTALL_DB_SWONLY //安裝類型
ORACLE_HOSTNAME=test-1 // 主機名稱(hostname查詢)
UNIX_GROUP_NAME=oinstall // 安裝組
INVENTORY_LOCATION=/mnt/app/oracle/oraInventory//INVENTORY目錄(不填就是默認值)
SELECTED_LANGUAGES=en // 選擇語言
ORACLE_HOME=/mnt/app/oracle/product/12.1.0/db_1//oracle_home
ORACLE_BASE=/mnt/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
[email protected]#@!//設定所有數據庫用戶使用同一個密碼
SECURITY_UPDATES_VIA_MYORACLESUPPORT=false//(手動寫了false)
DECLINE_SECURITY_UPDATES=true //設置安全更新(貌似是有bug,這個一定要選true,否則會無限提醒郵件地址有問題,終止安裝。PS:不管地址對不對)`
配置好後。保存退出。
2.3 開始安裝數據庫。切換到oracle用戶下
[[email protected] ~]# su - oracle
[[email protected] database]$/mnt/app/oracle/database/runInstaller -silent -responseFile /home/oracle/etc/db_install.rsp
安裝過程如下,出現如下結果,說明安裝成功
Starting Oracle Universal Installer...
Checking Temp space: must be greater than500 MB. Actual 17997 MB Passed
Checking swap space: must be greater than150 MB. Actual 2999 MB Passed
Preparing to launch Oracle UniversalInstaller from /tmp/OraInstall2017-06-04_07-51-31PM. Please wait...[[email protected] database]$ [WARNING] [INS-32055] The Central Inventory is locatedin the Oracle base.
ACTION: Oracle recommends placing thisCentral Inventory in a location outside the Oracle base directory.
[WARNING] [INS-13014] Target environmentdoes not meet some optional requirements.
CAUSE: Some of the optional prerequisitesare 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 failedprerequisite 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 appropriateconfiguration to meet the prerequisites and fix it manually.
You can find the log of this installsession at:
/mnt/app/oracle/oraInventory/logs/installActions2017-06-04_07-51-31PM.log
The installation of Oracle Database 12c wassuccessful.
Please check‘/mnt/app/oracle/oraInventory/logs/silentInstall2017-06-04_07-51-31PM.log‘ formore details.
As a root user, execute the followingscript(s):
1. /mnt/app/oracle/oraInventory/orainstRoot.sh
2. /mnt/app/oracle/product/12.1.0/db_1/root.sh
Successfully Setup Software
2.4 使用root用戶登錄 ,分別執行
/mnt/app/oracle/oraInventory/orainstRoot.sh
/mnt/app/oracle/product/12.1.0/db_1/root.sh
到此,數據庫已成功安裝上。
2.5 配置、啟動監聽
監聽器配置響應文件為:/home/oracle/etc/netca.rsp,此文件使用默認即可。
執行配置監聽
[[email protected] database]$ netca /silent/responsefile /home/oracle/etc/netca.rsp
出現如下信息,說明監聽配置成功。
[[email protected] oracle]$ netca /silent/responsefile /home/oracle/etc/netca.rsp
正在對命令行參數進行語法分析:
參數"silent" = true
參數"responsefile" =/home/oracle/etc/netca.rsp
完成對命令行參數進行語法分析。
Oracle Net Services 配置:
完成概要文件配置。
Oracle Net 監聽程序啟動:
正在運行監聽程序控制:
/mnt/app/oracle/product/12.1.0/db_1/bin/lsnrctl start LISTENER
監聽程序控制完成。
監聽程序已成功啟動。
監聽程序配置完成。
成功完成 Oracle Net Services 配置。退出代碼是0
成功運行後,在/mnt/app/oracle/product/12.1.0/db_1/network/admin/中生成listener.ora和sqlnet.ora
通過netstat命令可以查看1521端口正在監聽。
Yum安裝netstat軟件,軟件包是在net-tools中
[[email protected] ~]# yum install net-tools
[[email protected] ~]# netstat -lntup|grep 1521
tcp6 0 0 :::1521 :::* LISTEN 14496/tnslsnr
2.5.1啟動監聽
[[email protected] database]$ lsnrctl start
查看監聽狀態
[[email protected] 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. Allrights reserved.
Connecting to(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521)))
STATUS of the LISTENER
Alias LISTENER
Version TNSLSNR for Linux: Version12.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/mnt/app/oracle/product/12.1.0/db_1/network/admin/listener.ora
Listener Log File/mnt/app/oracle/diag/tnslsnr/test-1/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
2.5.2重啟監聽
[[email protected] database]$ lsnrctl reload
2.6 靜默創建數據庫實例
2.6.1編輯應答文件
[[email protected] /]$ su - root
[[email protected] ~]# vim/home/oracle/etc/dbca.rsp
設置以下參數:
GDBNAME = "orcl"
SID = "orcl"
SYSPASSWORD = "oracle"
SYSTEMPASSWORD = "oracle"
SYSMANPASSWORD = "oracle"
DBSNMPPASSWORD = "oracle"
DATAFILEDESTINATION=/mnt/app/oracle/oradata
RECOVERYAREADESTINATION=/mnt/app/oracle/fast_recovery_area
CHARACTERSET = "ZHS16GBK"
TOTALMEMORY = "1638"
其中TOTALMEMORY = "1638" 為1638MB,物理內存2G*80%。執行安裝數據庫實例
切換到oracle用戶
[[email protected] ~]# su - oracle
[[email protected] ~]$ dbca -silent-responseFile /home/oracle/etc/dbca.rsp
日誌顯示,數據庫實例已經成功創建。
2.6.2建庫後進行實例進程檢查:
[[email protected] ~]$ ps -ef | grep ora_ |grep -v grep
2.6.3查看監聽狀態:
[[email protected]~]$ lsnrctl status
2.6.4登錄查看實例狀態:
[[email protected] ~]$ sqlplus / as sysdba
SQL> select status from v$instance;
2.7 數據庫的啟動與停止
進入到oracle安裝目錄的bin目錄下,執行 dbstop即可停止數據庫。
2.8 開放端口(使用root用戶)
由於數據庫安裝了一般需要外網訪問,所以需要開放數據庫連接端口。
[[email protected] /]# firewall-cmd --zone=public--add-port=1521/tcp --permanent
success
[[email protected] /]# firewall-cmd --zone=public--add-port=5500/tcp --permanent
success
[[email protected] /]# firewall-cmd --reload
success
命令含義:
--zone #作用域
--add-port=80/tcp #添加端口,格式為:端口/通訊協議
--permanent #永久生效,沒有此參數重啟後失效
重啟防火墻
firewall-cmd --reload
2.9 設置oracle數據庫隨系統開機自啟動。
1、修改/mnt/app/oracle/product/12.1.0/db_1/bin/dbstart
[[email protected] ~]$ vim/mnt/app/oracle/product/12.1.0/db_1/bin/dbstart
將ORACLE_HOME_LISTNER=$1修改為ORACLE_HOME_LISTNER=$ORACLE_HOME
2、修改/mnt/app/oracle/product/12.1.0/db_1/bin/dbshut
[[email protected] ~]$ vim /mnt/app/oracle/product/12.1.0/db_1/bin/dbshut
將ORACLE_HOME_LISTNER=$1修改為ORACLE_HOME_LISTNER=$ORACLE_HOME
3、修改/etc/oratab文件
[[email protected]~]$ vim /etc/oratab
將orcl:/mnt/app/oracle/product/11.2.0:N中最後的N改為Y,成為orcl:/mnt/app/oracle/product/11.2.0:Y
2.9.1輸入命令dbshut和dbstart測試
[[email protected]~]$ dbshut
Oracle監聽停止,進程消失。
Oracle監聽啟動,進程啟動。
2.9.2、編輯/etc/rc.d/rc.local
2.9.2.1 方案一:自啟動
vi /etc/rc.d/rc.local
加入如下配置:
su oracle -lc "/mnt/app/oracle/product/12.1.0/db_1/bin/lsnrctlstart"
su oracle -lc /mnt/app/oracle/product/12.1.0/db_1/bin/dbstart
保存退出
重啟系統,再次連接數據庫,將正常連接上。
2.9.2.2 方案二:切換到root賬戶建立自啟動腳本
[[email protected]~]$ su -
[[email protected]~]# vim /etc/rc.d/init.d/oracle
添加以下內容(有些值如ORACLE_HOME和ORACLE_USER等根據實際情況可以修改):
[[email protected] ~]# cat/etc/rc.d/init.d/oracle
#!/bin/bash
# oracle: Start/Stop Oracle Database 11g R2
# chkconfig: 345 90 10
# description: The Oracle Database is anObject-Relational Database Management System.
#
. /etc/rc.d/init.d/functions
LOCKFILE=/mnt/app/oracle/var/lock/subsys/oracle
ORACLE_HOME=/mnt/app/oracle/product/12.1.0/db_1/
ORACLE_USER=oracle
case "$1" in
‘start‘)
if[ ! -f $LOCKFILE ];
then
touch "$LOCKFILE"
else
exit 1
fi
su- $ORACLE_USER -c "$ORACLE_HOME/bin/lsnrctl start"
su- $ORACLE_USER -c "$ORACLE_HOME/bin/dbstart"
su- $ORACLE_USER -c "$ORACLE_HOME/bin/emctl start dbconsole"
echo -n $"Starting Oracle Database:"
;;
‘stop‘)
if[ ! -f $LOCKFILE ]; then
echo $0 already stopping.
exit 1
fi
echo-n $"Stopping Oracle Database:"
su- $ORACLE_USER -c "$ORACLE_HOME/bin/lsnrctl stop"
su- $ORACLE_USER -c "$ORACLE_HOME/bin/dbshut"
su- $ORACLE_USER -c "$ORACLE_HOME/bin/emctl stop dbconsole"
rm-f "$LOCKFILE"
;;
‘restart‘)
$0stop
$0start
;;
‘status‘)
if[ -e $LOCKFILE ];
then
echo $0 started.
else
echo $0 stopped.
fi
;;
*)
echo "Usage: $0 [start|stop|status]"
exit 1
esac
exit 0
2.9.2.3 修改/etc/init.d/oracle服務文件權限
[[email protected] ~]# chmod 755 /etc/init.d/oracle
[[email protected] ~]# ll /etc/init.d/oracle
-rwxr-xr-x 1 root root 1203 6月 29 10:59 /etc/init.d/oracle
2.9.2.4 設置開機啟動
[[email protected] ~]# chkconfig oracle on
2.9.2.5 進行serviceoracle start/stop/restart測試
本文出自 “隨心所欲” 博客,請務必保留此出處http://scajy.blog.51cto.com/9547185/1948571
Centos7.0無桌面環境上靜默安裝oracle 11g