1. 程式人生 > 其它 >cento7靜默安裝oracle11g

cento7靜默安裝oracle11g

安裝硬體要求

1、記憶體 要求:記憶體最小1G,推薦2G或者更高。檢視命令:

grep MemTotal /proc/meminfo

2、swap
|RAW|Swap|
|:—- |:—— |
|1G至2G|1.5倍|
|2G至16G|同RAW相等|
|16G以上|16G|
檢視命令:

grep SwapTotal /proc/meminfo

環境準備

安裝包:

安裝Oracle前的準備

1、建立執行oracle資料庫的系統使用者和使用者組

[root@localhost ~]# groupadd oinstall #建立使用者組oinstall
[root@localhost ~]# groupadd dba  #建立使用者組dba
[root@localhost ~]# useradd -g oinstall -g dba -m oracle  #建立oracle使用者,並加入到oinstall和dba使用者組
[root@localhost ~]# passwd oracle  #設定使用者oracle的登陸密碼,不設定密碼,在CentOS的圖形登陸介面沒法登陸
[root@localhost ~]# id oracle # 檢視新建的oracle使用者

2、建立oracle資料庫安裝目錄
檢視每個目錄容量大小

[root@localhost ~]# df -h 
|檔案系統                 |容量  |已用  |可用 |已用% |掛載點|
|:---- 	|:------ |:------ |:------ |:------ |:------ |
|/dev/mapper/centos-root   |50G   |13G   |38G   |26% |/
|devtmpfs                 |7.8G     |0  |7.8G    |0% |/dev
|tmpfs                    |7.8G     |0  |7.8G    |0% |/dev/shm
|tmpfs                    |7.8G  |138M  |7.6G    |2% |/run
|tmpfs                    |7.8G     |0  |7.8G    |0% |/sys/fs/cgroup
|/dev/sda1               |1014M  |223M  |792M   |22% |/boot
|/dev/mapper/centos-home  |1.8T  |144G  |1.7T    |8% |/home
|tmpfs                    |1.6G     |0  |1.6G    |0% |/run/user/0
|tmpfs                    |1.6G   |12K  |1.6G    |1% |/run/user/42
[root@localhost ~]# cd /home/oracle # 進入到 /home/oracle目錄
[root@localhost ~]# mkdir data #oracle資料庫安裝目錄
[root@localhost ~]# mkdir database #oracle資料庫配置檔案目錄
[root@localhost ~]# mkdir oraInventory #oracle資料庫軟體包解壓目錄
[root@localhost ~]# chown -R oracle:oinstall data 	#設定目錄所有者為oinstall使用者組的oracle使用者
[root@localhost ~]# chown -R oracle:oinstall database #設定目錄所有者為oinstall使用者組的oracle使用者
[root@localhost ~]# chown -R oracle:oinstall oraInventory  #設定目錄所有者為oinstall使用者組的oracle使用者

3、修改OS系統標識(oracle預設不支援CentOS系統安裝,但是centos其實就是redhat)

[root@localhost ~]# cat /proc/version
Linux version 3.10.0-514.26.2.el7.x86_64 ([email protected]) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-11) (GCC) ) #1 SMP Tue Jul 4 15:04:05 UTC 2017
[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.3.1611 (Core)
[root@localhost ~]# vi /etc/redhat-release
[root@localhost ~]# cat /etc/redhat-release
redhat-7

4、安裝oracle資料庫所需要的軟體包

[root@localhost ~]# yum -y install binutils* compat-libcap1* compat-libstdc++* gcc* gcc-c++* glibc* glibc-devel* ksh* libaio* libaio-devel* libgcc* libstdc++* libstdc++-devel* libXi* libXtst* make* sysstat* elfutils*
[root@localhost ~]# yum -y install unixODBC-2.3.1-11.el7.i686
[root@localhost ~]# yum -y install unixODBC-devel-2.3.1-11.el7.i686

5、關閉防火牆

[root@localhost ~]# systemctl status firewalld.service    #檢視防火牆狀態(執行中)
[root@localhost ~]# systemctl stop firewalld.service    #關閉防火牆
[root@localhost ~]# systemctl disable firewalld.service   #禁止使用防火牆(重啟也是禁止的) 如果是內網無所謂,如果是阿里雲或者其他雲建議不要這樣做,開啟防火牆策略即可 其他防火牆命令 請參考我的 linux防火牆策略文章

6、修改核心引數

[root@localhost ~]# vi /etc/sysctl.conf
# 加入以下部分
net.ipv4.icmp_echo_ignore_broadcasts = 1
net.ipv4.conf.all.rp_filter = 1
fs.file-max = 6815744 #設定最大開啟檔案數
fs.aio-max-nr = 1048576
kernel.shmall = 2097152 #共享記憶體的總量,8G記憶體設定:2097152*4k/1024/1024
kernel.shmmax = 2147483648 #最大共享記憶體的段大小
kernel.shmmni = 4096 #整個系統共享記憶體端的最大數
kernel.sem = 250 32000 100 128
net.ipv4.ip_local_port_range = 9000 65500 #可使用的IPv4埠範圍
net.core.rmem_default = 262144
net.core.rmem_max= 4194304
net.core.wmem_default= 262144
net.core.wmem_max= 1048576

7、使配置修改核心的引數生效

[root@localhost  ~]# sysctl -p

8、對oracle使用者設定限制,提高軟體執行效能

[root@localhost ~]# vi /etc/security/limits.conf
# 加入以下部分
oracle soft nproc 2047
oracle hard nproc 16384
oracle soft nofile 1024
oracle hard nofile 65536

9、配置使用者的環境變數

[root@localhost ~]# vi /home/oracle/.bash_profile

export ORACLE_BASE=/home/oracle/data #oracle資料庫安裝目錄
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/ #oracle資料庫路徑
export ORACLE_SID=orcl #oracle啟動資料庫例項名
export PATH=$ORACLE_HOME/bin:/usr/sbin:$PATH #新增系統環境變數
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
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"

10、將安裝包移動到 /home/oracle/src 目錄下面

[root@localhost ~]# mkdir /home/oracle/src. # 在oracle 目錄下面建立src 目錄
[root@localhost oracle]# chown -R oracle:oinstall src  # 切換到oracle 目錄,並更改目錄的使用者和使用者組
[root@localhost oracle]# mv /root/soft/linux.x64_11gR2_database_* ./ # 移動安裝包到這兩個目錄
[root@localhost src]# ll
總用量 2295592
-rwxr-xr-x 1 root root 1239269270 11月 27 09:37 linux.x64_11gR2_database_1of2.zip
-rwxr-xr-x 1 root root 1111416131 11月 27 09:39 linux.x64_11gR2_database_2of2.zip
[root@localhost src]#

11、解壓 檔案至 /home/oracle/database/ 目錄下

[root@localhost src]# unzip linux.x64_11gR2_database_1of2.zip /home/oracle/database
[root@localhost src]# unzip linux.x64_11gR2_database_2of2.zip /home/oracle/database

#檢視解壓檔案
[oracle@localhost database]$ ls
doc  install  response  rpm  runInstaller  sshsetup  stage  welcome.html
[oracle@localhost database]$ pwd
/home/oracle/database/database。 # 在此目錄下

12、進入管理員許可權,設定目錄所有者為oinstall使用者組的oracle使用者,執行安裝指令碼

[root@localhost src]#  su root
# 設定目錄所有者為 oinstall使用者組的oracle使用者
[root@localhost src]# chown -R oracle:oinstall /home/oracle/database/database/
[root@localhost oracle]# ll
總用量 0
drwxr-xr-x 2 oracle oinstall  6 11月 27 10:03 data
drwxr-xr-x 3 oracle oinstall 22 11月 27 11:00 database
drwxr-xr-x 2 oracle oinstall  6 11月 27 10:04 oraInventory
drwxr-xr-x 2 oracle dba       6 11月 27 10:47 perl5
drwxr-xr-x 2 oracle oinstall 88 11月 27 11:00 src

[root@localhost src]#  su oracle # 許可權設定完成後 切換回oracle 使用者 在oracle 使用者下執行以下命令
[oracle@localhost database]# ls
doc  install  response  rpm  runInstaller  sshsetup  stage  welcome.html
[oracle@localhost database]# pwd
/home/oracle/database/database。 # 進入安裝目錄
[oracle@localhost database]# ./runInstaller  #執行命令

13、修改db_install.rsp 值 以下操作請使用 root 使用者

[root@localhost src]#  cd /home/oracle/database/database/response # 切換到此目錄
[root@localhost response]# ls
dbca.rsp  db_install.rsp  netca.rsp
[root@localhost response]# pwd
/home/oracle/database/database/response
[root@localhost response]#  mkdir -p /home/oracle/data/etc #建立etc目錄
[root@localhost response]# cp * /home/oracle/data/etc   # 複製檔案到 etc 目錄
[root@localhost response]# cd  /home/oracle/data/etc。 # 切換目錄
[root@localhost etc]# ll  # 檢視檔案
total 76
-rw-r--r-- 1 root root 44969 Nov 27 11:45 dbca.rsp
-rw-r--r-- 1 root root 22557 Nov 27 11:45 db_install.rsp
-rwxr-xr-x 1 root root  5740 Nov 27 11:45 netca.rsp

#修改db_install.rsp 值
[root@localhost etc]# vim db_install.rsp
# 修改以下變數的值
oracle.install.option=INSTALL_DB_SWONLY
DECLINE_SECURITY_UPDATES=true
UNIX_GROUP_NAME=oinstall
INVENTORY_LOCATION=/home/oracle/data/oraInventory
SELECTED_LANGUAGES=en,zh_CN
ORACLE_HOSTNAME=oracle
ORACLE_HOME=/home/oracle/data/product/11.2.0
ORACLE_BASE=/home/oracle/data
oracle.install.db.InstallEdition=EE
oracle.install.db.isCustomInstall=true
oracle.install.db.DBA_GROUP=dba
oracle.install.db.OPER_GROUP=dba

安裝oracle

1、安裝

[root@localhost etc]$ su - oracle  # 切換到oracle 使用者
[oracle@localhost ~]$ /home/oracle/database/database # 切換到database 目錄
[oracle@localhost database]$ ./runInstaller -silent -responseFile /home/oracle/data/etc/db_install.rsp -ignorePrereq   # 執行命令

2、安裝期間可以使用tail命令監看oracle的安裝日誌

 tail -f /home/oracle/app/oraInventory/logs/installActions2019-11-27_12-05-14PM.log

# 出現以下命令則說明安裝完成
 The following configuration scripts need to be executed as the "root" user.
 #!/bin/sh
 #Root scripts to run

/home/oracle/data/product/11.2.0/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.

3、使用root使用者執行指令碼
重新開啟一個視窗,使用root 使用者執行上面所說的指令碼。

[oracle@localhost ~]$ sh /home/oracle/data/product/11.2.0/root.sh

4、配置監聽程式

[oracle@localhost ~]$ su - oracle
[oracle@localhost ~]$ netca /silent /responsefile /home/oracle/data/etc/netca.rsp

# 以下為輸出內容
Parsing command line arguments:
    Parameter "silent" = true
    Parameter "responsefile" = /home/oracle/data/etc/netca.rsp
Done parsing command line arguments.
Oracle Net Services Configuration:
Profile configuration complete.
Oracle Net Listener Startup:
    Running Listener Control:
      /home/oracle/data/product/11.2.0/bin/lsnrctl start LISTENER
    Listener Control complete.
    Listener started successfully.
Listener configuration complete.
Oracle Net Services configuration successful. The exit code is 0

5、檢視監聽埠

netstat -tnpl | grep 1521

(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
tcp6       0      0 :::1521                 :::*                    LISTEN      16453/tnslsnr

靜默建立資料庫

1、編輯應答檔案。/home/oracle/data/etc/dbca.rsp

[oracle@localhost ~]$ vim /home/oracle/data/etc/dbca.rsp

# 更改以下內容
[GENERAL]
RESPONSEFILE_VERSION = "11.2.0"
OPERATION_TYPE = "createDatabase"
[CREATEDATABASE]
GDBNAME = "orcl"
SID = "orcl"
SYSPASSWORD = "oracle"
SYSTEMPASSWORD = "oracle"
SYSMANPASSWORD = "oracle"
DBSNMPPASSWORD = "oracle"
DATAFILEDESTINATION =/home/oracle/data/oradata  # 預設是 $ORACLE_BASE/oradata
RECOVERYAREADESTINATION=/home/oracle/data/fast_recovery_area  # 預設是 $ORACLE_BASE/fast_recovery_area
CHARACTERSET = "AL32UTF8"
TOTALMEMORY = "1638"

2、執行靜默建庫

[oracle@localhost ~]$ su - oracle
[oracle@localhost ~]$ dbca -silent -responseFile /home/oracle/data/etc/dbca.rsp
# 輸出日誌如下
Copying database files
1% complete
3% complete
11% complete
18% complete
26% complete
37% complete
Creating and starting Oracle instance
40% complete
45% complete

[root@localhost ~]# ps -ef | grep ora_ | grep -v grep   # 檢視程序
oracle   21722     1  0 13:00 ?        00:00:00 ora_pmon_orcl
oracle   21724     1  0 13:00 ?        00:00:00 ora_vktm_orcl
oracle   21728     1  0 13:00 ?        00:00:00 ora_gen0_orcl
oracle   21730     1  0 13:00 ?        00:00:00 ora_diag_orcl
oracle   21732     1  0 13:00 ?        00:00:00 ora_dbrm_orcl
oracle   21734     1  0 13:00 ?        00:00:00 ora_psp0_orcl
oracle   21736     1  0 13:00 ?        00:00:00 ora_dia0_orcl
oracle   21738     1  0 13:00 ?        00:00:00 ora_mman_orcl
oracle   21740     1  0 13:00 ?        00:00:00 ora_dbw0_orcl
oracle   21742     1  0 13:00 ?        00:00:00 ora_dbw1_orcl
oracle   21744     1  0 13:00 ?        00:00:00 ora_lgwr_orcl
oracle   21746     1  0 13:00 ?        00:00:00 ora_ckpt_orcl
oracle   21748     1  0 13:00 ?        00:00:00 ora_smon_orcl
oracle   21750     1  0 13:00 ?        00:00:00 ora_reco_orcl
oracle   21752     1  0 13:00 ?        00:00:00 ora_mmon_orcl
oracle   21754     1  0 13:00 ?        00:00:00 ora_mmnl_orcl
oracle   21756     1  0 13:00 ?        00:00:00 ora_d000_orcl
oracle   21758     1  0 13:00 ?        00:00:00 ora_s000_orcl
oracle   21838     1  0 13:00 ?        00:00:00 ora_qmnc_orcl
oracle   21855     1  0 13:00 ?        00:00:00 ora_cjq0_orcl
oracle   21867     1  0 13:00 ?        00:00:00 ora_q000_orcl
oracle   21869     1  0 13:00 ?        00:00:00 ora_q001_orcl

[oracle@localhost data]$ lsnrctl status   # 檢視監聽狀態 在oracle 使用者下執行

LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 27-NOV-2019 13:07:09

Copyright (c) 1991, 2009, Oracle.  All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 11.2.0.1.0 - Production
Start Date                27-NOV-2019 12:21:15
Uptime                    0 days 0 hr. 45 min. 54 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /home/oracle/data/product/11.2.0/network/admin/listener.ora
Listener Log File         /home/oracle/data/diag/tnslsnr/localhost/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521)))
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

3、至此資料庫就安裝成功了,下面我們登入下資料庫

su - oracle
[oracle@localhost data]$ sqlplus / as sysdba
SQL> select status from v$instance;

SQL> select status from v$instance;
select status from v$instance
*
ERROR at line 1:
ORA-01034: ORACLE not available
Process ID: 0
Session ID: 0 Serial number: 0
# 報錯 解決方式 可參考 https://www.cnblogs.com/kerrycode/p/3656655.html
# 我的問題是 刪除了 /home/oracle/data/product/11.2.0/dbs/lkORCL 檔案即可正常使用
# 通過以下命令可以檢視具體的錯誤 日誌
如果找不到日誌 通過 find / -name alert*.log 搜尋即可
[root@localhost data]$  tail -f /home/oracle/data/diag/rdbms/orcl/orcl/trace/alert_orcl.log

4、檢視資料庫編碼

SQL> select userenv('language') from dual;

USERENV('LANGUAGE')
--------------------------------------------------------------------------------
AMERICAN_AMERICA.US7ASCII

5、檢視資料庫版本

SQL> select * from v$version;

BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
PL/SQL Release 11.2.0.1.0 - Production
CORE	11.2.0.1.0	Production
TNS for Linux: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production

6、啟用scott使用者

SQL> alter user scott account unlock;
alter user scott account unlock
*
ERROR at line 1:
ORA-01109: database not open

解決:
檢視共享記憶體
[root@localhost dbs]# ipcs -map

--------- 訊息佇列 PID -----------
msqid      擁有者  lspid      lrpid

-------- 共享記憶體 建立者/上次修改者 PID ----------
shmid      擁有者  cpid       lpid
294912     oracle     21676      26322
622593     oracle     26199      26301

移除共享記憶體
ipcrm -m 294912
ipcrm -m 294912


SQL> shutdown
ORA-01507: database not mounted

# 依然報錯,繼續解決
ORA-27120: unable to removed shared memory segment
Linux-x86_64 Error: 22: Invalid argument
Additional information: 622593
Additional information: 11
SQL> startup
ORA-00600: internal error code, arguments: [SKGMBUSY], [1], [0], [0], [0], [], [], [], [], [], [], []
ORA-27123: unable to attach to shared memory segment
SQL>

以上報錯執行以下命令即可解決,執行完成後,重啟
[root@localhost data]$  mount -o remount rw / 

# 重啟完成後進入oracle 使用者
[oracle@localhost ~]$sqlplus / as sysdba

SQL> startup    # 啟動oracle 例項
ORACLE instance started.

Total System Global Area 1720328192 bytes
Fixed Size		    2214056 bytes
Variable Size		 1006634840 bytes
Database Buffers	  704643072 bytes
Redo Buffers		    6836224 bytes
Database mounted.
Database opened.

#重新執行 sql 語音
# 檢視資料庫編碼方式
SQL> select userenv('language') from dual;

USERENV('LANGUAGE')
--------------------------------------------------------------------------------
AMERICAN_AMERICA.AL32UTF8

#例項狀態
SQL> select status from v$instance;

STATUS
------------------------
OPEN

#資料庫版本
SQL> select * from v$version;

BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
PL/SQL Release 11.2.0.1.0 - Production
CORE	11.2.0.1.0	Production
TNS for Linux: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production

#啟用sofft 使用者
SQL> alter user scott account unlock;

User altered.

SQL> alter user scott identified by tiger;

User altered.

SQL> select username,account_status from dba_users;

USERNAME
------------------------------------------------------------
ACCOUNT_STATUS
----------------------------------------------------------------
SYS
OPEN

SYSTEM
OPEN

SCOTT
OPEN
。。。。。。省略

設定Oracle開機啟動

1、修改 /home/oracle/data/product/11.2.0/bin/dbstart

[root@localhost bin]# vim dbstart
#更改以下內容
將 ORACLE_HOME_LISTNER=$1  更改為 ORACLE_HOME_LISTNER=$ORACLE_HOME

2、修改 /home/oracle/data/product/11.2.0/bin/dbshut

[root@localhost bin]# vim dbshut
#更改以下內容
將 ORACLE_HOME_LISTNER=$1  更改為 ORACLE_HOME_LISTNER=$ORACLE_HOME

3、修改 /etc/oratab

[root@localhost bin]# vim /etc/oratab
將 orcl:/home/oracle/data/product/11.2.0:N 修改為 orcl:/home/oracle/data/product/11.2.0:Y

4、新建檔案 /etc/rc.d/init.d/oracle

#! /bin/bash
# oracle: Start/Stop Oracle Database 11g R2
#
# chkconfig: 345 90 10
# description: The Oracle Database is an Object-Relational Database Management System.
#
# processname: oracle
./etc/rc.d/init.d/functions
LOCKFILE=/var/lock/subsys/oracle
ORACLE_HOME=/home/oracle/data/product/11.2.0
ORACLE_USER=oracle
case "$1" in
'start')
   if [ -f $LOCKFILE ]; then
      echo $0 already running.
      exit 1
   fi
   echo -n $"Starting Oracle Database:"
   su - $ORACLE_USER -c "$ORACLE_HOME/bin/lsnrctl start"
   su - $ORACLE_USER -c "$ORACLE_HOME/bin/dbstart $ORACLE_HOME"
   su - $ORACLE_USER -c "$ORACLE_HOME/bin/emctl start dbconsole"
   touch $LOCKFILE
   ;;
'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')
   $0 stop
   $0 start
   ;;
'status')
   if [ -f $LOCKFILE ]; then
      echo $0 started.
      else
      echo $0 stopped.
   fi
   ;;
*)
   echo "Usage: $0 [start|stop|status]"
   exit 1
esac
exit 0

5、給/etc/init.d/oracle新增執行許可權

chmod +x /etc/init.d/oracle

6、開機啟動oracle

[root@localhost init.d]# systemctl enable oracle
或
[root@localhost init.d]# chkconfig oracle on

# 如;
[root@localhost init.d]# systemctl enable oracle
oracle.service is not a native service, redirecting to /sbin/chkconfig.
Executing /sbin/chkconfig oracle on
[root@localhost init.d]# chkconfig oracle on
[root@localhost init.d]#

7、防火牆配置放開Oracle的埠

# 防火牆更多資料請參考我另一篇文章
firewall-cmd --zone=public --add-port=1521/tcp --permanent
firewall-cmd --reload

參考文獻

1、https://blog.csdn.net/chenghuikai/article/details/85776622
2、https://blog.csdn.net/lvtao0519/article/details/51135101