1. 程式人生 > >CentOS7安裝Oracle 11gR2 圖文詳解

CentOS7安裝Oracle 11gR2 圖文詳解


一、環境準備

安裝包:

1.VMware-workstation-full-11.1.0-2496824.exe
2.CentOS-7-x86_64-DVD-1511.iso
3.linux.x64_11gR2_database_1of2.zip
  linux.x64_11gR2_database_2of2.zip

以上覺得不是重點,不給下載地址,不描述安裝過程,安裝完CentOS 7,截圖如下:

 

第一次安裝防坑,沒有進行任何操作之前,先在VMware中建立該虛擬機器快照,後期搞鬱悶了,可以迴歸到該快照版本。特麼還是不放心,又把該虛擬機器完整克隆一份(強迫症)。

二、安裝Oracle前準備

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

[[email protected] ~]$ su root  #切換到root
Password: 
[[email protected] sonny]# groupadd oinstall  #建立使用者組oinstall
[[email protected] sonny]# groupadd dba  #建立使用者組dba
[[email protected] sonny]# useradd -g oinstall -g dba -m oracle  #建立oracle使用者,並加入到oinstall和dba使用者組
[[email protected] sonny]#
passwd oracle  #設定使用者oracle的登陸密碼,不設定密碼,在CentOS的圖形登陸介面沒法登陸 Changing password for user oracle. New password:   # 密碼 BAD PASSWORD: The password is shorter than 8 characters Retype new password:   # 確認密碼 passwd: all authentication tokens updated successfully. [[email protected]
sonny]#
id oracle # 檢視新建的oracle使用者 uid=1001(oracle) gid=1002(dba) groups=1002(dba) [[email protected] sonny]#

理論上單例按照需要3種使用者組,實際只建兩個oinstall和dba,後面再安裝oracle資料庫的時候把OSOPER組也設定是dba組。

a.oracle 清單組(一般為oinstall):
 OINSTALL 組的成員被視為 Oracle 軟體的“所有者”,擁有對 Oracle 中央清單 (oraInventory) 的寫入許可權。在一個 Linux 系統上首次安裝 Oracle 軟體時,
 OUI 會建立 /etc/oraInst.loc 檔案。該檔案指定 Oracle 清單組的名稱(預設為 oinstall)以及 Oracle 中央清單目錄的路徑。
b.資料庫管理員(OSDBA,一般為 dba):
 OSDBA 組的成員可通過作業系統身份驗證使用 SQL 以 SYSDBA 身份連線到一個 Oracle 例項。該組的成員可執行關鍵的資料庫管理任務,如建立資料庫、啟動和關
 閉例項。該組的預設名稱為dba。SYSDBA 系統許可權甚至在資料庫未開啟時也允許訪問資料庫例項。對此許可權的控制完全超出了資料庫本身的範圍。不要混淆 SYSDBA 
 系統許可權與資料庫角色 DBA。DBA 角色不包括 SYSDBA 或 SYSOPER 系統許可權。
c.資料庫操作員組(OSOPER,一般為 oper):
 OSOPER 組的成員可通過作業系統身份驗證使用 SQL 以 SYSOPER 身份連線到一個 Oracle 例項。這個可選組的成員擁有一組有限的資料庫管理許可權,如管理和執行備份。
 該組的預設名稱為oper。SYSOPER 系統許可權甚至在資料庫未開啟時也允許訪問資料庫例項。對此許可權的控制完全超出了資料庫本身的範圍。要使用該組,選擇 Advanced 安裝型別來安裝 Oracle 資料庫軟體。 

2.建立oracle資料庫安裝目錄

[[email protected] ~]$ su root
Password: 
[[email protected] sonny]# mkdir -p /data/oracle  #oracle資料庫安裝目錄
[[email protected] sonny]# mkdir -p /data/oraInventory  #oracle資料庫配置檔案目錄
[[email protected] sonny]# mkdir -p /data/database  #oracle資料庫軟體包解壓目錄
[[email protected] sonny]# cd /data
[[email protected] data]# ls  #建立完畢檢查一下(強迫症)
database  oracle  oraInventory
[[email protected] data]# chown -R oracle:oinstall /data/oracle  #設定目錄所有者為oinstall使用者組的oracle使用者
[[email protected] data]# chown -R oracle:oinstall /data/oraInventory
[[email protected] data]# chown -R oracle:oinstall /data/database
[[email protected] data]#  

3.修改OS系統標識

 我安裝是64位資料庫,On Linux x86-64:Red Hat Enterprise Linux 7  (RHEL 7)

 修改檔案 /etc/RedHat-release 

[[email protected] data]$ su root
Password: 
[[email protected] data]# cat /proc/version 
Linux version 3.10.0-327.el7.x86_64 ([email protected]) (gcc version 4.8.3 20140911 (Red Hat 4.8.3-9) (GCC) ) #1 SMP Thu Nov 19 22:10:57 UTC 2015
[[email protected] data]# cat /etc/redhat-release  
CentOS Linux release 7.2.1511 (Core) 
[[email protected] data]# vi /etc/redhat-release
[[email protected] data]# cat /etc/redhat-release 
redhat-7 
[[email protected] data]#  

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

重複一遍,我安裝時Oracle Database 11g Release 2 64位資料庫。

rpm -qa binutils compat-libstdc++-33 elfutils-libelf elfutils-libelf-devel elfutils-libelf-devel-static gcc gcc-c++ glibc glibc-common glibc-devel glibc-headers glibc-static kernel-headers pdksh libaio libaio-devel libgcc libgomp libstdc++ libstdc++-devel libstdc++-static make numactl-devel sysstat unixODBC unixODBC-devel // 驗證命令26個包
  • kernel-headers-3.10.0-123.el7.x86_64
  • gcc-c++-4.8.2-16.el7.x86_64
  • numactl-devel-2.0.9-2.el7.x86_64
  • glibc-headers-2.17-55.el7.x86_64
  • glibc-common-2.17-55.el7.x86_64
  • binutils-2.23.52.0.1-16.el7.x86_64
  • unixODBC-devel-2.3.1-10.el7.x86_64
  • libaio-0.3.109-12.el7.x86_64
  • make-3.82-21.el7.x86_64
  • elfutils-libelf-0.158-3.el7.x86_64
  • elfutils-libelf-devel-0.158-3.el7.x86_64
  • sysstat-10.1.5-4.el7.x86_64
  • glibc-static-2.17-55.el7.x86_64
  • glibc-devel-2.17-55.el7.x86_64
  • glibc-2.17-55.el7.x86_64
  • elfutils-libelf-devel-static-0.158-3.el7.x86_64
  • libaio-0.3.109-12.el7.i686
  • gcc-4.8.2-16.el7.x86_64
  • libgcc-4.8.2-16.el7.i686
  • libstdc++-static-4.8.2-16.el7.x86_64
  • libaio-devel-0.3.109-12.el7.x86_64
  • libstdc++-4.8.2-16.el7.x86_64
  • libaio-devel-0.3.109-12.el7.i686
  • unixODBC-2.3.1-10.el7.x86_64
  • libstdc++-devel-4.8.2-16.el7.x86_64
  • compat-libstdc++-33-3.2.3-71.el7.x86_64
  • libgcc-4.8.2-16.el7.x86_64
  • libgomp-4.8.2-16.el7.x86_64

 老實人,第一次搞,一個一個的安裝,命令也很簡單,反正文件要求高版本也可以:

[[email protected] data]$ su root
Password: 
[[email protected] data]# yum install binutils
省略...

5.關閉防火牆 CentOS 7.2預設使用的是firewall作為防火牆

[[email protected] /]$ su root
Password: 
[[email protected] /]# systemctl status firewalld.service  #檢視防火牆狀態,執行中
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
   Active: active (running) since Thu 2016-04-07 18:54:29 PDT; 2h 20min ago
 Main PID: 802 (firewalld)
   CGroup: /system.slice/firewalld.service
           └─802 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid

Apr 07 18:54:25 localhost.localdomain systemd[1]: Starting firewalld - dynamic firewall daemon...
Apr 07 18:54:29 localhost.localdomain systemd[1]: Started firewalld - dynamic firewall daemon.
[[email protected] /]# systemctl stop firewalld.service  #關閉防火牆
[[email protected] /]# systemctl status firewalld.service  #再次檢視防火牆狀態,發現已關閉
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
   Active: inactive (dead) since Thu 2016-04-07 21:15:34 PDT; 9s ago
 Main PID: 802 (code=exited, status=0/SUCCESS)

Apr 07 18:54:25 localhost.localdomain systemd[1]: Starting firewalld - dynamic firewall daemon...
Apr 07 18:54:29 localhost.localdomain systemd[1]: Started firewalld - dynamic firewall daemon.
Apr 07 21:15:33 localhost systemd[1]: Stopping firewalld - dynamic firewall daemon...
Apr 07 21:15:34 localhost systemd[1]: Stopped firewalld - dynamic firewall daemon.
[[email protected] /]# systemctl disable firewalld.service  #禁止使用防火牆(重啟也是禁止的)
Removed symlink /etc/systemd/system/dbus-org.Fedoraproject.FirewallD1.service.
Removed symlink /etc/systemd/system/basic.target.wants/firewalld.service.
[[email protected] /]# 

 防火牆先禁用,搞好之後再配置,個人虛擬機器,要毛線防火牆~~

6.關閉selinux(需重啟生效)

[[email protected] /]# vi /etc/selinux/config
[[email protected] /]# cat /etc/selinux/config

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled   #此處修改為disabled
# SELINUXTYPE= can take one of three two values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected. 
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted 


[[email protected] /]# 

為啥要關閉selinux?因為selinux太高深,非專業人士搞不懂~~

7.修改核心引數

紅色部分為新增程式碼

[[email protected] /]$ su root
Password: 
[[email protected] /]# vi /etc/sysctl.conf 
[[email protected] /]# cat /etc/sysct.conf
cat: /etc/sysct.conf: No such file or directory
[[email protected] /]# cat /etc/sysctl.conf 
# System default settings live in /usr/lib/sysctl.d/00-system.conf.
# To override those settings, enter new settings here, or in an /etc/sysctl.d/<name>.conf file
#
# For more information, see sysctl.conf(5) and sysctl.d(5).
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
[[email protected] /]# 

使配置引數生效

[[email protected] /]# sysctl -p
net.ipv4.icmp_echo_ignore_broadcasts = 1
net.ipv4.conf.all.rp_filter = 1
sysctl: setting key "fs.file-max": Invalid argument
fs.file-max = 6815744 #設定最大開啟檔案數
fs.aio-max-nr = 1048576
sysctl: setting key "kernel.shmall": Invalid argument
kernel.shmall = 2097152 #共享記憶體的總量,8G記憶體設定:2097152*4k/1024/1024
sysctl: setting key "kernel.shmmax": Invalid argument
kernel.shmmax = 2147483648 #最大共享記憶體的段大小
sysctl: setting key "kernel.shmmni": Invalid argument
kernel.shmmni = 4096 #整個系統共享記憶體端的最大數
kernel.sem = 250 32000 100 128
sysctl: setting key "net.ipv4.ip_local_port_range": Invalid argument
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
[[email protected] /]#  

8.對oracle使用者設定限制,提高軟體執行效能(紅色為新增部分)

[[email protected] /]$ su root
Password: 
[[email protected] /]# vi /etc/security/limits.conf 
[[email protected] /]# cat /etc/security/limits.conf
# /etc/security/limits.conf
#
#This file sets the resource limits for the users logged in via PAM.
#It does not affect resource limits of the system services.
#
#Also note that configuration files in /etc/security/limits.d directory,
#which are read in alphabetical order, override the settings in this
#file in case the domain is the same or more specific.
#That means for example that setting a limit for wildcard domain here
#can be overriden with a wildcard setting in a config file in the
#subdirectory, but a user specific setting here can be overriden only
#with a user specific setting in the subdirectory.
#
#Each line describes a limit for a user in the form:
#
#<domain>        <type>  <item>  <value>
#
#Where:
#<domain> can be:
#        - a user name
#        - a group name, with @group syntax
#        - the wildcard *, for default entry
#        - the wildcard %, can be also used with %group syntax,
#                 for maxlogin limit
#
#<type> can have the two values:
#        - "soft" for enforcing the soft limits
#        - "hard" for enforcing hard limits
#
#<item> can be one of the following:
#        - core - limits the core file size (KB)
#        - data - max data size (KB)
#        - fsize - maximum filesize (KB)
#        - memlock - max locked-in-memory address space (KB)
#        - nofile - max number of open file descriptors
#        - rss - max resident set size (KB)
#        - stack - max stack size (KB)
#        - cpu - max CPU time (MIN)
#        - nproc - max number of processes
#        - as - address space limit (KB)
#        - maxlogins - max number of logins for this user
#        - maxsyslogins - max number of logins on the system
#        - priority - the priority to run user process with
#        - locks - max number of file locks the user can hold
#        - sigpending - max number of pending signals
#        - msgqueue - max memory used by POSIX message queues (bytes)
#        - nice - max nice priority allowed to raise to values: [-20, 19]
#        - rtprio - max realtime priority
#
#<domain>      <type>  <item>         <value>
#

#*               soft    core            0
#*               hard    rss             10000
#@student        hard    nproc           20
#@faculty        soft    nproc           20
#@faculty        hard    nproc           50
#ftp             hard    nproc           0
#@student        -       maxlogins       4
oracle soft nproc 2047
oracle hard nproc 16384
oracle soft nofile 1024
oracle hard nofile 65536

# End of file
[[email protected] /]#  

9.配置使用者的環境變數(紅色部分為新增程式碼)

[[email protected] /]# vi /home/oracle/.bash_profile 
[[email protected] /]# cat /home/oracle/.bash_profile 
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
    . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/.local/bin:$HOME/bin

export PATH

export ORACLE_BASE=/data/oracle #oracle資料庫安裝目錄
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1 #oracle資料庫路徑
export ORACLE_SID=orcl #oracle啟動資料庫例項名
export ORACLE_TERM=xterm #xterm視窗模式安裝
export PATH=$ORACLE_HOME/bin:/usr/sbin:$PATH #新增系統環境變數
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib #新增系統環境變數
export LANG=C #防止安裝過程出現亂碼
export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK  #設定Oracle客戶端字符集,必須與Oracle安裝時設定的字符集保持一致,如:ZHS16GBK,否則出現數據匯入匯出中文亂碼問題
[[email protected] /]#  

使上述配置立即生效:

[[email protected] /]$ su root
Password: 
[[email protected] /]# source /home/oracle/.bash_profile 
[[email protected] /]# 

10.上述都搞定了,上傳安裝包我喜歡xftp,將oracle安裝包上傳到/usr/local/src

11.解壓安裝包

[[email protected] /]$ cd /usr/local/src  #進入/usr/local/src目錄
[[email protected] src]$ ls
linux.x64_11gR2_database_1of2.zip  linux.x64_11gR2_database_2of2.zip
[[email protected] src]$ unzip linux.x64_11gR2_database_1of2.zip -d /data/database/  #解壓
(省略...)
[[email protected] src]$ unzip linux.x64_11gR2_database_2of2.zip -d /data/database/  #解壓
(省略...)
[[email protected] src]$ su root
Password: 
[[email protected] src]# chown -R oracle:oinstall /data/database/database/
[[email protected] src]#  

三、oracle安裝 

1.圖形介面登陸oracle使用者:

2.啟動oralce安裝,到/data/database/database/目錄下,執行runInstaller

3.去掉勾,懶得填,個人使用環境不需要自動接收Oracle的安全更新。

4.下一步,只安裝資料庫軟體,這一步貌似是有點問題的,重灌了幾遍都有問題,建議選第一個!!!

5.選擇DESKTOP安裝

6.新增語言

7.預設安裝版本企業版-Enterprise Edition --圖沒了。

8.確定資料軟體的安裝路徑,自動讀取前面Oracle環境變數中配置的值。

9.理論上要建立Database Operation(OSOPER)Group:oper ,個人用,懶得建,就使用dba使用者組

10.安裝檢查,按照提示資訊一個一個解決。

swap空間不足解決 :(要求2.67G 實際2G)

[[email protected] oracle]# free -m  #檢視當前虛擬記憶體
              total        used        free      shared  buff/cache   available
Mem:           1824        1369          93          10         361         250
Swap:          2048          20        2028
[[email protected] oracle]# dd if=/dev/zero of=/home/swap bs=1024 count=1024000  #將當前swap空間由2048M 增加到 3048M 新增一個2014的swap檔案
1024000+0 records in
1024000+0 records out
1048576000 bytes (1.0 GB) copied, 29.4051 s, 35.7 MB/s
[[email protected] oracle]# mkswap /home/swap
Setting up swapspace version 1, size = 1023996 KiB
no label, UUID=5e3d39d7-285e-4c74-b321-1e2b3ffabf83
[[email protected] oracle]# free -m
              total        used        free      shared  buff/cache   available
Mem:           1824        1275          95          10         454         342
Swap:          2048         141        1907
[[email protected] oracle]# swapon /home/swap  #增加並啟用虛擬內容
swapon: /home/swap: insecure permissions 0644, 0600 suggested.
[[email protected] oracle]# free -m  #再次檢視
              total        used        free      shared  buff/cache   available
Mem:           1824        1275          94          10         454         342
Swap:          3048         141        2907 

11.一個一個檢查package,在準備階段中漏掉的,此處再安裝,有些系統報錯是因為現有的包的版本比檢測要高,最後忽略即可。(點選Check_Again 多檢查幾次)

12.準備完畢,fuck “Finish”開始安裝。

13.安裝過程是一個漫長的過程,中間有幾次卡住,沒有出現任何畫面,螢幕中間有條小線,嘗試多次,發現游標在該線上,右鍵點選Closed,不知道關閉了啥,又能繼續安裝了。先裝吧,到時看安裝日誌再說。

 14.提示安裝成功。安裝日誌懶得看,再說。

四、配置監聽listener

1.執行netca 報錯

[Oracle@localhost ~]$ netca

Oracle Net Services Configuration:
#
# An unexpected error has been detected by HotSpot Virtual Machine:
#
#  SIGSEGV (0xb) at pc=0x00007f69a69fcb9d, pid=8033, tid=140092892297024
#
# Java VM: Java HotSpot(TM) 64-Bit Server VM (1.5.0_17-b03 mixed mode)
# Problematic frame:
# C  [libclntsh.so.11.1+0x62ab9d]  snlinGetAddrInfo+0x1b1
#
# An error report file with more information is saved as hs_err_pid8033.log
#
# If you would like to submit a bug report, please visit:
#   http://java.sun.com/webapps/bugreport/crash.jsp
#
/data/oracle/product/11.2.0/db_1/bin/netca: line 178:  8033 Aborted                 (core dumped) $JRE $JRE_OPTIONS -classpath $CLASSPATH oracle.net.ca.NetCA $*
[[email protected] ~]$  

錯誤原因:安裝作業系統是預設主機名localhost造成錯誤

解決辦法:

racle]# cat /etc/sysconfig/network
# Created by anaconda

[[email protected] oracle]# vi /etc/sysconfig/network  #增加HOSTNAME
[[email protected] oracle]# cat /etc/sysconfig/network
# Created by anaconda
HOSTNAME=odb-sonny
[[email protected] oracle]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
[[email protected] oracle]# vi /etc/hosts  #增加HOSTNAME
[[email protected] oracle]# cat /etc/hosts     
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4 odb-sonny
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
[[email protected] oracle]# hostname odb-sonny  #執行
[[email protected] oracle]#  

最後登出當前oracle使用者,重新登陸即可!!這次發現開啟配置介面正常,安裝windows下面配置即可。

五、建立Oracle資料例項Orcl

執行dbca命令,啟動oracle例項安裝介面,剩下的與Windows上安裝一樣,不廢話了:

注意:必須先建立監聽,並且監聽是啟動中,否則報錯。

六、檢查安裝日誌檢查

發現有幾個錯誤(原因未知,後續再看):

錯誤1:

INFO: /lib64/libstdc++.so.5: undefined reference to `[email protected]_2.14'
collect2: error: ld returned 1 exit status

INFO: make: *** [ctxhx] Error 1

INFO: End output from spawned process.
INFO: ----------------------------------
INFO: Exception thrown from action: make
Exception Name: MakefileException
Exception String: Error in invoking target 'install' of makefile '/data/oracle/product/11.2.0/db_1/ctx/lib/ins_ctx.mk'. 
See '/data/oraInventory/logs/installActions2016-04-07_10-38-06PM.log' for details.
Exception Severity: 1 

錯誤2:

INFO: /usr/bin/ld: warning: -z lazyload ignored.
/usr/bin/ld: warning: -z nolazyload ignored.
/usr/bin/ld: /data/oracle/product/11.2.0/db_1/sysman/lib//libnmectl.a(nmectlt.o): undefined reference to symbol 'B_DestroyKeyObject'
/usr/bin/ld: note: 'B_DestroyKeyObject' is defined in DSO /data/oracle/product/11.2.0/db_1/lib/libnnz11.so so try adding it to the linker command line
/data/oracle/product/11.2.0/db_1/lib/libnnz11.so: could not read symbols: Invalid operation

INFO: collect2: error: ld returned 1 exit status

INFO: make[1]: *** [/data/oracle/product/11.2.0/db_1/sysman/lib/emdctl] Error 1

INFO: make[1]: Leaving directory `/data/oracle/product/11.2.0/db_1/sysman/lib'

INFO: make: *** [emdctl] Error 2

INFO: End output from spawned process.
INFO: ----------------------------------
INFO: Exception thrown from action: make
Exception Name: MakefileException
Exception String: Error in invoking target 'agent nmhs' of makefile '/data/oracle/product/11.2.0/db_1/sysman/lib/ins_emagent.mk'. 
See '/data/oraInventory/logs/installActions2016-04-07_10-38-06PM.log' for details.
Exception Severity: 1
INFO: Calling Action unixActions10.2.0.3.0  make
    registerOnly = false
    installMakePath = /usr/bin/make
    installMakeFileName = /data/oracle/product/11.2.0/db_1/rdbms/lib/ins_rdbms.mk
    installTarget = all_no_orcl
    undoMakeFileName = 
    installArguments = ORACLE_HOME=/data/oracle/product/11.2.0/db_1
    logFile = /data/oracle/product/11.2.0/db_1/install/make.log
    undoTarget = 
    progMsg = Linking RDBMS Executables