天天看點

1、Centos7下安裝Oracle11gR2及多執行個體

實驗環境:

系統:2核8G記憶體60G硬碟,centos7.4;

優化操作:已經關閉了防火牆、selinux,/etc/hosts檔案中以添加"172.16.1.92 slave-node2"的主機解析記錄;

設定umask檔案權限:[root@slave-node2 ~]# echo 'umask 022' >>/etc/profile && source /etc/profile

yum的base和epel源倉庫已經更改為阿裡雲的yum倉庫;

1.1、oracle軟體包下載下傳:

1、下載下傳位址:

​​ https://www.oracle.com/technetwork/database/enterprise-edition/downloads/index.html​​

2、軟體包選擇:

1、Centos7下安裝Oracle11gR2及多執行個體

#官方手冊:https://docs.oracle.com/cd/E11882_01/install.112/e24326/toc.htm#BHCJCBAF

3、使用xftp上傳軟體包:

[root@slave-node2 ~]# mkdir -p /tools/

1、Centos7下安裝Oracle11gR2及多執行個體

1.2、建立oracle使用者和使用者組:

[root@slave-node2 ~]# groupadd oinstall

[root@slave-node2 ~]# groupadd dba

[root@slave-node2 ~]# useradd -g oinstall -G dba oracle

[root@slave-node2 ~]# id oracle

uid=1000(oracle) gid=1000(oinstall) 組=1000(oinstall),1001(dba)

1.3、建立oracle工作目錄:

[root@slave-node2 tools]# cd /tools/

[root@slave-node2 tools]# unzip linux.x64_11gR2_database_1of2.zip 1>/dev/null

[root@slave-node2 tools]# unzip linux.x64_11gR2_database_2of2.zip 1>/dev/null

[root@slave-node2 tools]# cd ~

[root@slave-node2 ~]# ls -ld /tools/database/ #解壓包目錄;

drwxr-xr-x 8 root root 128 8月 21 2009 /tools/database/

[root@slave-node2 ~]# mkdir /application/{Oracle11gR2,oraInventory} -p

#Oracle11gR2是oracle的安裝目錄,oraInventory是oracle的配置檔案目錄;

[root@slave-node2 ~]# ln -s /application/Oracle11gR2/ /application/oracle

[root@slave-node2 ~]# chown -R oracle:oinstall /tools/database/

[root@slave-node2 ~]# chown -R oracle:oinstall /application/Oracle11gR2/

[root@slave-node2 ~]# chown -R oracle:oinstall /application/oraInventory/

#上面三行是授權;

1.4、修改系統辨別:

oracle預設是不支援CentOS系統安裝的,是以要修改OS辨別檔案;

[root@slave-node2 ~]# cp -a /etc/redhat-release{,.ori}

#備份檔案;

[root@slave-node2 ~]# vim /etc/redhat-release

redhat-7

1.5、安裝oracle所需的依賴包:

[root@slave-node2 ~]# yum -y install binutils compat-libcap1 compat-libstdc++-33 compat-libstdc++-33*i686 \

compat-libstdc++-33*.devel compat-libstdc++-33 compat-libstdc++-33*.devel gcc gcc-c++ glibc glibc*.i686 \

glibc-devel glibc-devel*.i686 ksh libaio libaio*.i686 libaio-devel libaio-devel*.devel libgcc libgcc*.i686 libstdc++ \

libstdc++*.i686 libstdc++-devel libstdc++-devel*.devel libXi libXi*.i686 libXtst libXtst*.i686 make sysstat unixODBC \

unixODBC*.i686 unixODBC-devel unixODBC-devel*.i686

1.6、修改核心參數:

[root@slave-node2 ~]# vim /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

#限制未完成的并發請求,避免I/O系統故障

kernel.shmall = 2097152

##########################################################################

#共享記憶體分頁總量,應不小于shmmax/page_size預設值就是2097152,8G(2097152*4k/1024/1024)

#推薦設定為實體記憶體大小除以分頁大小,分頁預設大小是4k;

##########################################################################

kernel.shmmax = 4294967296

#最大共享記憶體段大小,不小于實體記憶體的一半(推薦70%),且大于資料庫執行個體的SGA,機關是位元組

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

#發送緩沖區最大值

[root@slave-node2 ~]# sysctl -p

#使核心參數生效;

1.7、對oracle使用者設定限制:

[root@slave-node2 ~]# vim /etc/security/limits.conf

#@student - maxlogins 4

oracle soft nproc 2047

oracle hard nproc 16384

oracle soft nofile 1024

oracle hard nofile 65536

oracle soft stack 10240

oracle hard stack 32768

# End of file

1.8、配置oracle環境變量:

[root@slave-node2 ~]# vim /home/oracle/.bash_profile

export ORACLE_BASE=/application/oracle

#oracl安裝目錄

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=en_US.UTF-8

#防止安裝過程出現亂碼

export NLS_LANG=AMERICAN_AMERICA.AL32UTF8

#設定Oracle用戶端字元集,必須和oracle安裝時的字元集保持一緻

[root@slave-node2 ~]# source /home/oracle/.bash_profile

#使環境變量生效;

1.9、安裝oracle:

1、使用Xbrower中的Xstart連接配接linux:

1、Centos7下安裝Oracle11gR2及多執行個體
1、Centos7下安裝Oracle11gR2及多執行個體

#具體的關于Xstart的相關配置,請參考“linux架構_02-1(1、如何通過xstart遠端連接配接桌面)”;

2、安裝:

(1)切換使用者:

[root@slave-node2 ~]# su - oracle

上一次登入:四 8月 1 01:43:49 CST 2019pts/2 上

(2)設定DISPLAY環境變量:

[oracle@slave-node2 ~]$ export DISPLAY=172.16.1.254:0.0

[oracle@slave-node2 ~]$ echo $DISPLAY

172.16.1.254:0.0

(3)啟動oracle安裝程式:

[oracle@slave-node2 ~]$ cd /tools/database/

[oracle@slave-node2 database]$ ./runInstaller

#提示:啟動oracle安裝程式後會在windows中跳出oracle安裝圖形界面;

(4)oracle圖形界面安裝步驟:

1)

1、Centos7下安裝Oracle11gR2及多執行個體

2)

1、Centos7下安裝Oracle11gR2及多執行個體

3)

1、Centos7下安裝Oracle11gR2及多執行個體

4)

1、Centos7下安裝Oracle11gR2及多執行個體

5)

1、Centos7下安裝Oracle11gR2及多執行個體

6)

1、Centos7下安裝Oracle11gR2及多執行個體

7)

1、Centos7下安裝Oracle11gR2及多執行個體

8)

1、Centos7下安裝Oracle11gR2及多執行個體

9)

1、Centos7下安裝Oracle11gR2及多執行個體

10)

1、Centos7下安裝Oracle11gR2及多執行個體

11)

1、Centos7下安裝Oracle11gR2及多執行個體

12)

1、Centos7下安裝Oracle11gR2及多執行個體

13)

1、Centos7下安裝Oracle11gR2及多執行個體

14)

1、Centos7下安裝Oracle11gR2及多執行個體

15)

1、Centos7下安裝Oracle11gR2及多執行個體

16)

1、Centos7下安裝Oracle11gR2及多執行個體

17)

1、Centos7下安裝Oracle11gR2及多執行個體

18)

1、Centos7下安裝Oracle11gR2及多執行個體

19)

1、Centos7下安裝Oracle11gR2及多執行個體

20)

1、Centos7下安裝Oracle11gR2及多執行個體

#檢查時出現swap分區不足的解決辦法如下:

[root@slave-node2 ~]# dd if=/dev/zero of=/root/swap bs=1024 ‬count=8500000

#建立一個8G的swap分區;

[root@slave-node2 ~]# mkswap /root/swap

#格式化swap分區;

[root@slave-node2 ~]# chmod 0600 /root/swap

#賦權swap分區;

[root@slave-node2 ~]# swapon /root/swap

#挂載swap分區;

[root@slave-node2 ~]# free -m | grep Swap

Swap: 10348 0 10348

#檢視現在swap分區量;

[root@slave-node2 ~]# chmod +x /etc/rc.d/rc.local

[root@slave-node2 ~]# echo 'swapon /root/swap' >>/etc/rc.local

#将swap分區挂載加入到開機自啟動;

#重新檢測

21)

1、Centos7下安裝Oracle11gR2及多執行個體

22)

1、Centos7下安裝Oracle11gR2及多執行個體

#當安裝到68%時會出現上圖所示報錯,解決辦法如下:

[root@slave-node2 ~]# vim /application/oracle/product/11.2.0/db_1/ctx/lib/ins_ctx.mk +11

-static/usr/lib64/libc.a

#修改第11行的參數;

#再點選"Retry"時會出現如下報錯;

1、Centos7下安裝Oracle11gR2及多執行個體

#解決上圖報錯的方法如下:

[root@slave-node2 ~]# vim /application/oracle/product/11.2.0/db_1/sysman/lib/ins_emagent.mk +190

$(MK_EMAGENT_NMECTL) -lnnz11

#修改第190行的參數;

#再點選"Retry"後安裝正常進行;

1、Centos7下安裝Oracle11gR2及多執行個體

23)安裝完成:

1、Centos7下安裝Oracle11gR2及多執行個體

24)執行腳本:

1、Centos7下安裝Oracle11gR2及多執行個體

[root@slave-node2 ~]# sh /application/oraInventory/orainstRoot.sh

[root@slave-node2 ~]# sh /application/oracle/product/11.2.0/db_1/root.sh

………………………………………………………………………………………………………………………………

Enter the full pathname of the local bin directory: [/usr/local/bin]: #此處直接回車;

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

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

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

………………………………………………………………………………………………………………………………

#到此處oracle安裝成功,關閉oracle安裝界面,以上建立了一個'orcl'全局資料庫和其下面的'orcl'執行個體;

[root@slave-node2 ~]# netstat -tunlp | grep 1521

tcp6 0 0 :::1521 :::* LISTEN 1241/tnslsnr

1.10、啟動資料庫:

1、登入到伺服器,切換到oracle使用者;

[root@slave-node2 ~]# su - oracle

上一次登入:四 8月 1 14:15:24 CST 2019pts/3 上

[oracle@slave-node2 ~]$

2、打開oracle的監聽服務:

(1)開啟服務:

[oracle@slave-node2 ~]$ lsnrctl start

(2)檢視監聽服務:

[oracle@slave-node2 ~]$ lsnrctl status

LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 01-AUG-2019 16:11:45

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 01-AUG-2019 16:11:20

Uptime 0 days 0 hr. 0 min. 24 sec

Trace Level off

Security ON: Local OS Authentication

SNMP OFF

Listener Parameter File /application/oracle/product/11.2.0/db_1/network/admin/listener.ora

Listener Log File /application/oracle/diag/tnslsnr/slave-node2/listener/alert/log.xml

Listening Endpoints Summary...

(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))

(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=slave-node2)(PORT=1521)))

The listener supports no services

The command completed successfully

3、啟動oracle執行個體:

[oracle@slave-node2 ~]$ sqlplus system/123456 as sysdba

……………………………………………………………………………………

SQL> startup

ORACLE instance started.

Total System Global Area 3340451840 bytes

Fixed Size 2217952 bytes

Variable Size 1811941408 bytes

Database Buffers 1509949440 bytes

Redo Buffers 16343040 bytes

Database mounted.

Database opened.

SQL>

4、通過sqldeveloper連接配接oracle:

1、Centos7下安裝Oracle11gR2及多執行個體

5、補充:如何關閉oracle資料庫:

(1)關閉執行個體:

[oracle@slave-node2 ~]$ sqlplus system/123456 as sysdba

SQL> shutdown immediate;

(2)關閉監聽:

[oracle@slave-node2 ~]$ lsnrctl stop

1.11、設定oracle開機自啟動:

1、檢視dbstart和dbshut指令:

[oracle@slave-node2 ~]$ dbstart

ORACLE_HOME_LISTNER is not SET, unable to auto-start Oracle Net Listener

Usage: /application/oracle/product/11.2.0/db_1/bin/dbstart ORACLE_HOME

[oracle@slave-node2 ~]$ dbshut

ORACLE_HOME_LISTNER is not SET, unable to auto-stop Oracle Net Listener

Usage: /application/oracle/product/11.2.0/db_1/bin/dbshut ORACLE_HOME

#錯誤原因是dbstart和dbshut腳本檔案中ORACLE_HOME_LISTNER設定有問題;

2、修改dbstart和dbshut腳本:

(1)修改dbstart腳本:

[oracle@slave-node2 ~]$ vim $ORACLE_HOME/bin/dbstart +80

ORACLE_HOME_LISTNER=$ORACLE_HOME

#修改第80行處如上:

(2)修改dbshut腳本:

[oracle@slave-node2 ~]$ vim $ORACLE_HOME/bin/dbshut +50

ORACLE_HOME_LISTNER=$ORACLE_HOME

#修改第50行處如上;

3、修改/etc/oratab檔案開啟oracle執行個體開機自啟動功能:

[oracle@slave-node2 ~]$ vim /etc/oratab

orcl:/application/oracle/product/11.2.0/db_1:Y

#将N改為Y如上,格式為:"$ORACLE_SID:$ORACLE_HOME:<N|Y>"

4、自啟動方法:

(1)登入到root使用者:

[oracle@slave-node2 ~]$ su - root

Password:

Last login: Thu Aug 1 17:08:50 CST 2019 on pts/0

(2)方法一:将dbstart加入/etc/rc.local開機自啟動檔案中:

[root@slave-node2 ~]# chmod +x /etc/rc.d/rc.local

[root@slave-node2 ~]# echo 'su - oracle /application/oracle/product/11.2.0/db_1/bin/dbstart' >>/etc/rc.local

(3)方法二:建立oracle自啟動腳本:

1)編寫腳本:

[root@slave-node2 ~]# cat /etc/init.d/oracled

#!/bin/sh

#chkconfig: 2345 61 61

#description: Oracle 11g R2 AutoRun Servimces

#location: /etc/init.d/oracle

#Run-level Startup script for the Oracle Instance, Listener

#ORACLE_SID="orcl"

#AUTHOR:LIUCHANG

ORACLE_BASE="/application/oracle"

ORACLE_HOME="$ORACLE_BASE/product/11.2.0/db_1"

ORA_OWNR="oracle"

PORT=`netstat -tunlp | grep 1521 | awk -F '[ :]+' '{print $4}'`

[ $UID -eq 0 ] || {

echo "This Shell only root execute"

exit 1

}

if [ ! -f $ORACLE_HOME/bin/dbstart -o ! -d $ORACLE_HOME ]; then

echo "Oracle startup: cannot start"

exit 1

fi

RETVAL=0

function check() {

RETVAL=$?

if [ $RETVAL -eq 0 ]; then

echo -e "$1\033[1;32m Success! \033[0m"

else

echo -e "$1\033[1;31m Faild! \033[0m"

fi

}

function start() {

PORT=`netstat -tunlp | grep 1521 | awk -F '[ :]+' '{print $4}'`

if [ "$PORT" = "1521" ]; then

echo "Oracle already Start!"

else

su - $ORA_OWNR $ORACLE_HOME/bin/dbstart &>/dev/null

check "Oracle Start"

fi

}

function stop() {

PORT=`netstat -tunlp | grep 1521 | awk -F '[ :]+' '{print $4}'`

if [ "$PORT" = "1521" ]; then

su - $ORA_OWNR $ORACLE_HOME/bin/dbshut &>/dev/null

check "Oracle Stop"

else

echo "Oracle already Stop!"

fi

}

function status() {

PORT=`netstat -tunlp | grep 1521 | awk -F '[ :]+' '{print $4}'`

if [ "$PORT" = "1521" ]; then

echo "Oracle is Running!"

else

echo "Oracle is Stop!"

fi

}

function Usage() {

echo "Usage:$0{start|stop|status|reload|reload}"

exit 1

}

function main() {

if [ $# -eq 1 ]; then

case "$1" in

start)

start

;;

stop)

stop

;;

status)

status

;;

reload|restart)

stop

sleep 30

start

;;

*)

Usage

esac

else

Usage

fi

}

main $*

2)将腳本加入到開機自啟動:

[root@slave-node2 ~]# chmod u+x /etc/init.d/oracled

[root@slave-node2 ~]# chkconfig --add oracled

[root@slave-node2 ~]# chkconfig --list oracled

oracled 0:關 1:關 2:開 3:開 4:開 5:開 6:關

#在linux7版本上會報建議使用Systemctl指令的提示,忽略即可;

1.12、設定oracle監聽:

oracle監聽分為服務端和用戶端兩部分,服務端監聽必須在安裝oracle資料庫的伺服器上,而用戶端網絡服務可以配置在

任何一台能連接配接到oracle伺服器的伺服器上,也可以将兩者都配置在oracle伺服器上,本實驗使用的是将兩者都配置了oracle

伺服器上;

上面的實驗在建資料庫"orcl"執行個體的時候已經建立好了服務端監聽和用戶端"orcl"資料庫執行個體的網絡

服務,這裡我将其删除重新配置;

1、使用xstart登入到oracle使用者:

[root@slave-node2 ~]# su - oracle

上一次登入:五 8月 2 23:17:46 CST 2019pts/2 上

[oracle@slave-node2 ~]$ export DISPLAY=172.16.1.254:0.0

[oracle@slave-node2 ~]$ netca

2、配置服務端監聽:

(1)

1、Centos7下安裝Oracle11gR2及多執行個體

(2)

1、Centos7下安裝Oracle11gR2及多執行個體

(3)

1、Centos7下安裝Oracle11gR2及多執行個體

(4)

1、Centos7下安裝Oracle11gR2及多執行個體

(5)

1、Centos7下安裝Oracle11gR2及多執行個體

(6)

1、Centos7下安裝Oracle11gR2及多執行個體

(7)

1、Centos7下安裝Oracle11gR2及多執行個體

#當oracle監聽配置完成後,在控制台會輸出"Listener started successfully"的提示;

1、Centos7下安裝Oracle11gR2及多執行個體

3、配置用戶端網絡服務:

(1)

1、Centos7下安裝Oracle11gR2及多執行個體

(2)

1、Centos7下安裝Oracle11gR2及多執行個體

(3)

1、Centos7下安裝Oracle11gR2及多執行個體

(4)

1、Centos7下安裝Oracle11gR2及多執行個體

(5)

1、Centos7下安裝Oracle11gR2及多執行個體

(6)

1、Centos7下安裝Oracle11gR2及多執行個體

(7)

1、Centos7下安裝Oracle11gR2及多執行個體

(8)

1、Centos7下安裝Oracle11gR2及多執行個體

(9)

1、Centos7下安裝Oracle11gR2及多執行個體

(10)

1、Centos7下安裝Oracle11gR2及多執行個體

(11)

1、Centos7下安裝Oracle11gR2及多執行個體

#控制端輸出配置成功資訊如下:

1、Centos7下安裝Oracle11gR2及多執行個體

(12)

1、Centos7下安裝Oracle11gR2及多執行個體

1.13、添加新的oracle執行個體:

1、使用xstart登入到oracle使用者:

[root@slave-node2 ~]# su - oracle

上一次登入:五 8月 2 23:20:34 CST 2019pts/2 上

[oracle@slave-node2 ~]$ export DISPLAY=172.16.1.254:0.0

[oracle@slave-node2 ~]$ dbtca

2、添加執行個體:

(1)

1、Centos7下安裝Oracle11gR2及多執行個體

(2)

1、Centos7下安裝Oracle11gR2及多執行個體

(3)

1、Centos7下安裝Oracle11gR2及多執行個體

(4)

1、Centos7下安裝Oracle11gR2及多執行個體

(5)

1、Centos7下安裝Oracle11gR2及多執行個體

(6)

1、Centos7下安裝Oracle11gR2及多執行個體

(7)

1、Centos7下安裝Oracle11gR2及多執行個體

(8)

1、Centos7下安裝Oracle11gR2及多執行個體

(9)

1、Centos7下安裝Oracle11gR2及多執行個體

(10)

1、Centos7下安裝Oracle11gR2及多執行個體

使用自動記憶體管理,當點選Sizing設定時會報如下錯誤,原因是預設的/dev/shm空間不足;

1、Centos7下安裝Oracle11gR2及多執行個體

解決辦法如下:

[oracle@slave-node2 ~]$ su - root

Password:

Last login: Sat Aug 3 00:11:21 CST 2019 on pts/2

[root@slave-node2 ~]# df -h /dev/shm

檔案系統 容量 已用 可用 已用% 挂載點

tmpfs 3.9G 1.9G 2.1G 49% /dev/shm

#/dev/shm使用的是記憶體的空間,預設大小是實體記憶體的一半,最大不超過實體記憶體的80%,可以看到/dev/shm可用

#大小隻有2.1G(2068M),而警告的要求是3185M,是以(8*0.8-1.9)*1024M>3185M,我這裡将tmpfs設定為6G;

[root@slave-node2 ~]# vim /etc/fstab

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

#在/etc/fstab配置檔案中添加如上配置;

[root@slave-node2 ~]# mount -o remount /dev/shm

#将/dev/shm重新挂載;

[root@slave-node2 ~]# df -h /dev/shm

檔案系統 容量 已用 可用 已用% 挂載點

tmpfs 6.0G 1.9G 4.2G 32% /dev/shm

#可以看到/dev/shm的空間已經增大了;

點選"ok"繼續配置;

(11)

1、Centos7下安裝Oracle11gR2及多執行個體

(12)

1、Centos7下安裝Oracle11gR2及多執行個體

(13)

1、Centos7下安裝Oracle11gR2及多執行個體

(14)

1、Centos7下安裝Oracle11gR2及多執行個體

(15)

1、Centos7下安裝Oracle11gR2及多執行個體

(16)安裝完成:

1、Centos7下安裝Oracle11gR2及多執行個體

3、提示:

"oa"資料庫執行個體安裝完成後使用的是服務端預設監聽(1521),會根據預設伺服器監聽自動配置"oa"數

據庫執行個體的用戶端網絡服務,如果想使用新的端口号通路建立的"oa"資料庫執行個體,可以添加新的服務端

監聽,然後删除用戶端網絡服務重新配置;

4、修改資料庫執行個體開機自啟動"/etc/oratab"檔案如下,将"oa"資料庫執行個體開機自啟服務打開:

[root@slave-node2 ~]# vim /etc/oratab

oa:/application/oracle/product/11.2.0/db_1:Y

到此,oracle資料庫多執行個體操作就完成了;

#oracle是通過端口号來區分不同的資料庫執行個體的,而oracle是通過不同的資料庫執行個體名來區分不同的資料庫執行個體的;

1、Centos7下安裝Oracle11gR2及多執行個體