1. 程式人生 > >redhat6.9上安裝oracle11g操作手冊(史上最詳細)

redhat6.9上安裝oracle11g操作手冊(史上最詳細)

             第一次在linux系統上安裝oracle資料庫,安裝過程不算順利,遇到各種問題,但是最終還是一一解決了,感覺從這次安裝安裝過程,讓我們對oracle的安裝和使用有更深層次的理解,成就感滿滿!

               不瞎掰,為了讓其它人員也能承擔安裝工作,所以把整個安裝過程及遇到哪些問題、怎麼解決的都記錄下來,專案組其它成員按照我的手冊飛快的就能搞定。詳情往下看

                Oracle資料庫部署手冊

  1. Oracle安裝
  • Linux安裝Oracle系統要求

記憶體 必須高於1G的實體記憶體

交換空間 一般為記憶體的2,例如:1G的記憶體可以設定

swap 分割槽為3G大小

如果8G記憶體,則swap分割槽至少8G

若記憶體空間為16G以上,則swap分割槽至少為16G

  • 修改作業系統核心引數

Root使用者下執行以下步驟:

1)修改使用者的SHELL的限制,修改/etc/security/limits.conf檔案

輸入命令:vi /etc/security/limits.conf,按i鍵進入編輯模式,將下列內容加入該檔案。

oracle   soft    nproc    2047

oracle   hard    nproc    16384

oracle   soft    nofile     1024

oracle   hard    nofile    65536

編輯完成後按Esc鍵,輸入“:wq”存檔退出

2)修改/etc/pam.d/login 檔案,輸入命令:vi  /etc/pam.d/login,按i鍵進入編輯模式,將下列內容加入該檔案。

session   required    /lib/security/pam_limits.so 

session   required    pam_limits.so

編輯完成後按Esc鍵,輸入“:wq”存檔退出

3)修改linux核心,修改/etc/sysctl.conf檔案,輸入命令: vi  /etc/sysctl.conf ,按i鍵進入編輯模式,將下列內容加入該檔案

fs.file-max = 6815744 

fs.aio-max-nr = 1048576 

kernel.shmall = 2097152 

kernel.shmmax = 2147483648 

kernel.shmmni = 4096 

kernel.sem = 250 32000 100 128 

net.ipv4.ip_local_port_range = 9000 65500 

net.core.rmem_default = 4194304 

net.core.rmem_max = 4194304 

net.core.wmem_default = 262144 

net.core.wmem_max = 1048576

編輯完成後按Esc鍵,輸入“:wq”存檔退出

4)要使 /etc/sysctl.conf 更改立即生效,執行以下命令。 輸入:sysctl  -p 顯示如下:

linux:~ # sysctl -p

net.ipv4.ip_forward = 0

net.ipv4.conf.default.rp_filter = 1

net.ipv4.conf.default.accept_source_route = 0

kernel.sysrq = 0

kernel.core_uses_pid = 1

net.ipv4.tcp_syncookies = 1

error: "net.bridge.bridge-nf-call-ip6tables" is an unknown key

error: "net.bridge.bridge-nf-call-iptables" is an unknown key

error: "net.bridge.bridge-nf-call-arptables" is an unknown key

kernel.msgmnb = 65536

kernel.msgmax = 65536

kernel.shmmax = 68719476736

kernel.shmall = 4294967296

fs.file-max = 6815744

fs.aio-max-nr = 1048576

kernel.shmall = 2097152

kernel.shmmax = 2147483648

kernel.shmmni = 4096

kernel.sem = 250 32000 100 128

net.ipv4.ip_local_port_range = 9000 65500

net.core.rmem_default = 4194304

net.core.rmem_max = 4194304

net.core.wmem_default = 262144

net.core.wmem_max = 1048576

5)編輯 /etc/profile ,輸入命令:vi  /etc/profile,按i鍵進入編輯模式,將下列內容加入該檔案。

if [ $USER = "oracle" ]; then 

if [ $SHELL = "/bin/ksh" ]; then 

  ulimit -p 16384 

  ulimit -n 65536 

else 

  ulimit -u 16384 -n 65536 

fi

fi

編輯完成後按Esc鍵,輸入“:wq”存檔退出

  • 建立使用者及使用者組

6)建立相關使用者和組,作為軟體安裝和支援組的擁有者。

建立使用者,輸入命令:

groupadd  oinstall 

groupadd  dba

建立Oracle使用者和密碼,輸入命令:

useradd -g oinstall -g dba -m oracle

passwd  oracle

然後會讓你輸入密碼,密碼任意輸入2次,但必須保持一致,回車確認

  • 安裝前準備

7)建立資料庫軟體目錄和資料檔案存放目錄,目錄的位置,根據自己的情況來定,注意磁碟空間即可,這裡我把其放到oracle使用者下,例如:

輸入命令:

mkdir /home/oracle/app

mkdir /home/oracle/app/oracle

mkdir /home/oracle/app/oradata

mkdir /home/oracle/app/oracle/product

8)更改目錄屬主為Oracle使用者所有,輸入命令:

chown -R oracle:oinstall /home/oracle/app

9)配置oracle使用者的環境變數,首先,切換到新建立的oracle使用者下,

輸入:su – oracle  ,然後直接在輸入 vi .bash_profile

i編輯 .bash_profile,進入編輯模式,增加以下內容:

umask 022

export ORACLE_BASE=/home/oracle/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

編輯完成後按Esc鍵,輸入“:wq”存檔退出

測試環境變數是否有效:

[[email protected] ~]$ echo $ORACLE_HOME

發現為空。執行下面命令

[[email protected] ~]$ . ./.bash_profile

再次測試,ok

[[email protected] ~]$ echo $ORACLE_HOME

/home/oracle/app/oracle/product/11.2.0/dbhome_1

安裝過程

上傳安裝包到目錄/home/oracle/app,並使用cksum命令檢查包的完整性,與oracle官網上對應的包cksum值比對(下載包路徑那都會有cksum值),如果匹配不上,則需要重新下載按照包。我就因為包不完整折騰了我一整天。

注:如果包不完整,在按照到圖形化介面會彈出異常:valid entry size(expected ….

也可以直接拷貝:

-bash-4.1$ ls -l

-rw-r--r-- 1 oracle oinstall 1111416131 Mar 22 15:44 linux.x64_11gR2_database_2of2.zip

-rw-r--r-- 1 oracle oinstall 1239269270 Mar 23 10:05 linux.x64_11gR2_database_1of2.zip

-bash-4.1$

-bash-4.1$ cksum linux.x64_11gR2_database_1of2.zip

3152418844 1239269270 linux.x64_11gR2_database_1of2.zip

-bash-4.1$ cksum linux.x64_11gR2_database_2of2.zip

3669256139 1111416131 linux.x64_11gR2_database_2of2.zip

解壓安裝包到 database資料夾

-bash-4.1$ unzip linux.x64_11gR2_database_1of2.zip

-bash-4.1$ unzip linux.x64_11gR2_database_2of2.zip

  • 安裝過程

進入目錄/home/oracle/app/database目錄,執行命令 ./runnInstaller

注意:此處一定要用oracle使用者登入的視窗執行(用root使用者登入切換到oracle使用者執行可能會報錯。)例如:

正確的要用oracle登陸執行.

-bash-4.1$ ./runInstaller

Starting Oracle Universal Installer...

Checking Temp space: must be greater than 120 MB.   Actual 15390 MB    Passed

Checking swap space: must be greater than 150 MB.   Actual 17611 MB    Passed

Checking monitor: must be configured to display at least 256 colors.    Actual 16777216    Passed

#如果此處檢查不過,解決方法:

#su – root  切換到root使用者

#xhost 執行xhost命令

#su – oracle 切換到oracle使用者

#export DISPLAY=:0.0

Preparing to launch Oracle Universal Installer from /tmp/OraInstall2018-03-23_10-23-20AM. Please wait ...-bash-4.1$

注意:如果缺少按照包或者其它條件不符合,不會跳轉到此頁面

此處check點包括

  1. 環境變數是否已經設定,比如:net.ipv4.ip_local_port_range = 9000 65500 如果範圍不對,會要求修改
  2. Swap空間大小是否符合要求,增加swap的方法:

一、檢視系統當前的分割槽情況:

>free -m

             total       used       free     shared    buffers     cached

Mem:           438        432          6          0          8        141

-/+ buffers/cache:        282        156

Swap:         2047       1375        671

二、建立用於交換分割槽的檔案:如果要增加2G大小的交換分割槽,則命令寫法如下,其中的 count 等於想要的塊大小

>dd if=/dev/zero of=/home/swap bs=block_size count=number_of_block

dd if=/dev/zero of=/home/swap bs=1024 count=2048000

2048000+0 records in

2048000+0 records out

2097152000 bytes (2.1 GB) copied, 60.4492 seconds, 34.7 MB/s

三、設定交換分割槽檔案:

>mkswap /home/swap

四、立即啟用交換分割槽檔案:

>swapon /home/swap

五、若要想使開機時自啟用,則需修改檔案/etc/fstab中的swap行:

/home/swap swap swap defaults 0 0

  1. rpm安裝包

下載缺少的rpm包,上傳到指定目錄,用root使用者登入,併到指定目錄執行以下命令:

      rpm -ivh 包名 --nodeps --force

[[email protected] Downloads]# rpm  -ivh  unixODBC-2.2.11-7.1.i386.rpm  --nodeps --force

warning: unixODBC-2.2.11-7.1.i386.rpm: Header V3 DSA/SHA1 Signature, key ID 37017186: NOKEY

Preparing...                ########################################### [100%]

   1:unixODBC               ########################################### [100%]

[[email protected] dbhome_1]# ./root.sh

Running Oracle 11g root.sh script...

The following environment variables are set as:

    ORACLE_OWNER= oracle

    ORACLE_HOME=  /home/oracle/app/product/11.2.0/dbhome_1

Enter the full pathname of the local bin directory: [/usr/local/bin]: /usr/local/bin

   Copying dbhome to /usr/local/bin ...

   Copying oraenv to /usr/local/bin ...

   Copying coraenv to /usr/local/bin ...

Creating /etc/oratab file...

Entries will be added to the /etc/oratab file as needed by

Database Configuration Assistant when a database is created

Finished running generic part of root.sh script.

Now product-specific root actions will be performed.

Finished product-specific root actions

至此,oracle已經安裝完成。

 使用sqlplus測試下。

安裝完成。

啟動資料庫

-bash-4.1$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.1.0 Production on Fri Mar 23 11:26:17 2018

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

Connected to an idle instance.

SQL> startup

ORA-00845: MEMORY_TARGET not supported on this system

SQL>

ORA-00845: MEMORY_TARGET not supported on this system 解決方法

Root使用者登入,編輯/etc/fstab 修改記錄成以下,增加size=8G

tmpfs                   /dev/shm                tmpfs   defaults,size=8G        0 0

重啟生效,或者重新掛載

掛載命令:mount -o remount,size=16G /dev/shm

一般Size大小跟機器記憶體保持一致。

SQL> startup

ORACLE instance started.

Total System Global Area 1.3429E+10 bytes

Fixed Size            2217992 bytes

Variable Size          6845106168 bytes

Database Buffers    6576668672 bytes

Redo Buffers              4661248 bytes

ORA-01102: cannot mount database in EXCLUSIVE mode

SQL>

ORA-01102: cannot mount database in EXCLUSIVE mode解決方法:

[[email protected] dbhome_1]# ipcs -s

------ Semaphore Arrays --------

key        semid      owner      perms      nsems    

0x00000000 0          root       600        1        

0x00000000 65537      root       600        1        

0x01ad2954 655362     oracle     660        154      

0x62052f41 131075     root       644        1        

0xaea4f7b4 786436     oracle     660        154      

[[email protected] dbhome_1]# ipcrm -s 655362

[[email protected] dbhome_1]# ipcrm -s 655362

ipcrm: invalid id (655362)

[[email protected] dbhome_1]# ipcrm -s 786436

[[email protected] dbhome_1]#

再次啟動,啟動成功。

-bash-4.1$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.1.0 Production on Fri Mar 23 11:41:03 2018

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

Connected to an idle instance.

SQL> startup

ORACLE instance started.

Total System Global Area 1.3429E+10 bytes

Fixed Size            2217992 bytes

Variable Size          6845106168 bytes

Database Buffers    6576668672 bytes

Redo Buffers              4661248 bytes

Database mounted.

Database opened.

SQL>

-bash-4.1$ lsnrctl start

LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 23-MAR-2018 11:48:28

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

TNS-01106: Listener using listener name LISTENER has already been started

-bash-4.1$

  1. 建立oracle資料庫例項

 Oracle資料庫建立成功,預設的資料庫例項為orcl,如何實現一個數據庫多例項執行.?下面是建立資料庫例項的步驟

  1. oracle使用者登入(一定是oracle使用者登入,不能su – oracle方式dengl)
  2. 修改.bash_profile中SID的值為要增加的例項名,比如:bipdb
  3. 執行命令dbca,彈出圖形化介面

上圖彈出介面亂碼 ,檢視LANG的值。執行export LANG=C,後再執行dbca命令。

注意:此處需要修改預設的資料庫編碼,預設的資料庫編碼格式不支援中文字元.

後面全部預設按鈕就好。

  1. 啟動多個數據庫例項

迴圈執行下列命令:

export SID=例項名

sqlplus / as sysdba

startup

  1. 刪除資料庫例項

orace使用者登入,執行命令:dbca

注意:有可能會遇到dbca命令執行後,“DELETE A DATABASE”,是灰色的,無法選擇,這時候需要堅持/etc/oratab檔案中是否存在“SID:ORACLE_HOME:N” 如:esbdb:/home/oracle/app/oracle/database/11g........:N。

以上就是我們在安裝oracle資料的整個過程所有操作和遇到的一些問題,當然作業系統版本不同和oracle安裝版本不同可能遇到的問題也會不同,我後面用centenos7.5作業系統來安裝oracle,遇到又是另外一些問題,這個在下篇再介紹。