1. 程式人生 > >CentOS 7虛擬機器安裝Oracle11g詳解

CentOS 7虛擬機器安裝Oracle11g詳解

一、安裝Oracle前準備

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

[[email protected]~]$ su root  #切換到root

Password:

[[email protected]]# groupadd oinstall  #建立使用者組oinstall

[[email protected]]# groupadd dba  #建立使用者組dba

[[email protected]]# useradd -g oinstall -g dba -m oracle  #建立oracle使用者,並加入到oinstall和dba使用者組

[[email protected]]# passwd oracle  #設定使用者oracle的登陸密碼,不設定密碼,在CentOS的圖形登陸介面沒法登陸

Changing password for user oracle.

New password:   # 密碼

BAD PASSWORD: Thepassword is shorter than 8 characters

Retype new password:   #確認密碼

passwd: all authentication tokens updatedsuccessfully.

[[email protected]

]# id oracle#檢視新建的oracle使用者

uid=1001(oracle) gid=1002(dba)groups=1002(dba)

[[email protected]]#

理論上單例按照需要3種使用者組,實際只建兩個oinstalldba,後面再安裝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]]# mkdir -p /data/oracle  #oracle資料庫安裝目錄

[[email protected]]# mkdir -p /data/oraInventory  #oracle資料庫配置檔案目錄

[[email protected]]# mkdir -p /data/database  #oracle資料庫軟體包解壓目錄

[[email protected]]# cd /data

[[email protected]]# ls    #建立完畢檢查一下(強迫症)

database  oracle oraInventory

[[email protected]]# chown -R oracle:oinstall /data/oracle  #設定目錄所有者為oinstall使用者組的oracle使用者

[[email protected]]# chown -R oracle:oinstall /data/oraInventory

[[email protected]]# chown -R oracle:oinstall /data/database

[[email protected] data]#

3.修改OS系統標識

修改檔案 /etc/RedHat-release 

[[email protected]]$ su root

Password:

[[email protected]]# cat /proc/version

Linux version 3.10.0-327.el7.x86_64([email protected]) (gcc version 4.8.320140911 (Red Hat4.8.3-9) (GCC) ) #1 SMPThu Nov1922:10:57 UTC2015

[[email protected]]# cat /etc/redhat-release  

CentOS Linux release 7.2.1511 (Core)

[[email protected]]# vi /etc/redhat-release

[[email protected]]# cat /etc/redhat-release

redhat-7

[[email protected]]#

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

The following packages (or later versions) must be installed:
binutils-2.23.52.0.1-12.el7.x86_64 
compat-libcap1-1.10-3.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 
[[email protected] data]$ su root
Password: 
[[email protected] data]# yum install binutils* gcc* ….(圖方便,就全給它裝了)

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-0718: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 0718:54:25 localhost.localdomain systemd[1]: Starting firewalld - dynamic firewall daemon...
Apr 0718: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-0721:15:34 PDT; 9s ago
 Main PID: 802 (code=exited, status=0/SUCCESS)
Apr 0718:54:25 localhost.localdomain systemd[1]: Starting firewalld - dynamic firewall daemon...
Apr 0718:54:29 localhost.localdomain systemd[1]: Started firewalld - dynamic firewall daemon.
Apr 0721:15:33 localhost systemd[1]: Stopping firewalld - dynamic firewall daemon...
Apr 0721: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 = 25032000100128
sysctl: setting key "net.ipv4.ip_local_port_range": Invalid argument
net.ipv4.ip_local_port_range = 900065500 #可使用的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
#fileincase 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 filein 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.上述都搞定了,上傳安裝包,將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.後面步驟與window下相似

可能遇到的問題

1.swap空間不足解決(要求2.67G實際2G

[[email protected] oracle]# free -m  #檢視當前虛擬記憶體
              total        used        free      shared  buff/cache   available
Mem:           182413699310361250
Swap:          2048202028
[[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:           182412759510454342
Swap:          20481411907
[[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:           182412759410454342
Swap:          3048141