天天看點

【Oracle】CentOS7/CentOS8指令行安裝Oracle 11G R2

寫在前面

很長一段時間内,國内網際網路公司都在提倡“去IOE”,但是很多企業還是願意為昂貴的Oracle資料庫買單,不少讀者所在的公司也在用Oracle,很多讀者自行安裝Oracle資料庫時,多多少少遇到了些問題,苦惱于幾天下來還是沒能解決問題。這不,不少讀者跑來問我,讓我輸出一篇如何在實體機上安裝Oracle的文章,最好是安裝過程中不會出現各種“疑難雜症”。哈哈,這要求不過分,我周末也着實搗鼓了一番,不過我是安裝在CentOS 7/ CentOS 8虛拟機中的,效果和在實體機中一樣,整個過程也算是小有所成吧!輸出此文,記錄搗鼓的過程,與各位Oracle開發者共勉。

環境準備

1.CentOS7 / CentOS8 64位最小化安裝的虛拟機環境(這裡的安裝步驟,我就直接省略了,大家自行安裝虛拟機環境)

2.Oracle 11gR2 64位 Linux版安裝包(關注【冰河技術】微信公衆号,回複“oracle”關鍵字即可擷取Oracle資料庫安裝包下載下傳連結)。

linux.x64_11gR2_database_1of2.zip

linux.x64_11gR2_database_2of2.zip

安裝過程

1.關閉防火牆

操作使用者:root

systemctl stop firewalld.service
systemctl disable firewalld.service
           

2.安裝依賴包

操作使用者為:root。

執行如下指令安裝依賴包。

yum install -y automake autotools-dev binutils bzip2 elfutils expat \
gawk gcc gcc-multilib g++-multilib lib32ncurses5 lib32z1 \
ksh less lib32z1 libaio1 libaio-dev libc6-dev libc6-dev-i386 \
libc6-i386 libelf-dev libltdl-dev libodbcinstq4-1 libodbcinstq4-1:i386 \
libpth-dev libpthread-stubs0-dev libstdc++5 make openssh-server rlwrap \
rpm sysstat unixodbc unixodbc-dev unzip x11-utils zlibc unzip cifs-utils \
libXext.x86_64  glibc.i686
           

如果上述指令報錯,則使用如下指令安裝

yum -y install xz wget gcc-c++ ncurses ncurses-devel \
cmake make perl openssl openssl-devel gcc* libxml2 \
libxml2-devel curl-devel libjpeg* libpng* freetype* \
make gcc-c++ cmake bison perl perl-devel  perl perl-devel \
glibc-devel.i686 glibc-devel libaio readline-devel \
zlib.x86_64 zlib-devel.x86_64 libcurl-* net-tool*  \
sysstat lrzsz dos2unix telnet.x86_64 iotop unzip \
ftp.x86_64 xfs* expect vim psmisc openssh-client* \
libaio bzip2  epel-release automake binutils bzip2 \
elfutils expat gawk gcc  ksh less make openssh-server \
rpm sysstat unzip unzip cifs-utils libXext.x86_64  \
glibc.i686 binutils compat-libstdc++-33 \
elfutils-libelf elfutils-libelf-devel \
expat gcc gcc-c++ glibc glibc-common \
glibc-devel glibc-headers libaio \
libaio-devel libgcc libstdc++ libstdc++-devel \
make sysstat unixODBC unixODBC-devel libnsl
           

3.建立oracle使用者

操作使用者為:root

groupadd -g 502 oinstall
groupadd -g 503 dba
groupadd -g 504 oper
groupadd -g 505 asmadmin
useradd -u 502 -g oinstall -G oinstall,dba,asmadmin,oper -s /bin/bash -m oracle
passwd oracle
           

上述指令執行完畢後,為oracle使用者設定密碼,例如,我這裡設定的密碼為oracle

4.解壓Oracle資料庫安裝包

操作使用者:oracle

操作目錄:/home/oracle

将Oracle 11gR2安裝檔案上傳(可以使用sftp上傳)到該操作目錄下面,然後順序解壓安裝檔案到該目錄。

unzip linux.x64_11gR2_database_1of2.zip
unzip linux.x64_11gR2_database_2of2.zip
           

5.修改作業系統配置

操作使用者:root

操作檔案:/etc/security/limits.conf

vim /etc/security/limits.conf
           

在檔案的末尾添加如下配置項。

oracle          soft      nproc   2047
oracle          hard      nproc   16384
oracle          soft      nofile  1024
oracle          hard      nofile  65536
oracle          soft      stack   10240
           

6.建立Oracle安裝目錄

操作使用者:oracle

mkdir ~/tools/oracle11g
           

7.修改環境變量

操作使用者:oracle

操作目錄:/home/oracle

vim ~/.bash_profile
           

在檔案末尾添加如下配置項

export ORACLE_BASE=/home/oracle/tools/oracle11g
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/dbhome_1
export ORACLE_SID=orcl
export ORACLE_UNQNAME=orcl
export NLS_LANG=.AL32UTF8
export PATH=${PATH}:${ORACLE_HOME}/bin/:$ORACLE_HOME/lib64
           

使得環境變量生效。

source ~/.bash_profile
           

8.修改Oracle配置檔案

操作使用者:oracle

操作目錄:/home/oracle

複制檔案模闆

cp /home/oracle/database/response/db_install.rsp .
           

注意:複制指令的最後一個 . 不能省略,表示将db_install.rsp檔案從/home/oracle/database/response目錄拷貝到目前目錄。

對db_install.rsp檔案進行編輯。

vim db_install.rsp
           

需要修改的配置項如下所示,這裡,我将修改後的配置項列舉出來。

oracle.install.option=INSTALL_DB_AND_CONFIG
ORACLE_HOSTNAME=localhost #實際上可以修改成你自己的主機名或者域名(IP)
UNIX_GROUP_NAME=oinstall
INVENTORY_LOCATION=/home/oracle/tools/oraInventory
SELECTED_LANGUAGES=en,zh_CN
ORACLE_HOME=/home/oracle/tools/oracle11g/product/11.2.0/dbhome_1
ORACLE_BASE=/home/oracle/tools/oracle11g
oracle.install.db.InstallEdition=EE
oracle.install.db.DBA_GROUP=dba
oracle.install.db.OPER_GROUP=oper
oracle.install.db.config.starterdb.type=GENERAL_PURPOSE
oracle.install.db.config.starterdb.globalDBName=orcl
oracle.install.db.config.starterdb.SID=orcl
oracle.install.db.config.starterdb.characterSet=AL32UTF8
oracle.install.db.config.starterdb.memoryOption=true
oracle.install.db.config.starterdb.memoryLimit=1024
oracle.install.db.config.starterdb.installExampleSchemas=false
oracle.install.db.config.starterdb.password.ALL=Oracle#123456
oracle.install.db.config.starterdb.control=DB_CONTROL
oracle.install.db.config.starterdb.dbcontrol.enableEmailNotification=false
oracle.install.db.config.starterdb.dbcontrol.emailAddress=test@qq.com #可以填寫你自己的郵箱位址
oracle.install.db.config.starterdb.automatedBackup.enable=false
oracle.install.db.config.starterdb.storageType=FILE_SYSTEM_STORAGE
oracle.install.db.config.starterdb.fileSystemStorage.dataLocation=/home/oracle/tools/oracle11g/oradata
oracle.install.db.config.starterdb.fileSystemStorage.recoveryLocation=/home/oracle/tools/oracle11g/fast_recovery_area
oracle.install.db.config.starterdb.automatedBackup.enable=false
DECLINE_SECURITY_UPDATES=true
           

9.靜默安裝Oracle 11gR2

操作使用者:oracle

操作目錄:/home/oracle/database

./runInstaller -silent -ignoreSysPrereqs -responseFile /home/oracle/db_install.rsp
           

接下來,就是默默的等待Oracle自行安裝了,等待一段時間後,如果輸出如下資訊,則表明Oracle資料庫已經安裝成功。

The following configuration scripts need to be executed as the "root" user.
#!/bin/sh
#Root scripts to run

/home/oracle/tools/oraInventory/orainstRoot.sh
/home/oracle/tools/oracle11g/product/11.2.0/dbhome_1/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.
           

10.安裝完成

操作使用者:root

根據上一步完成資訊提示,執行以下兩行指令,具體位置需要根據你的安裝位置決定:

/home/oracle/tools/oraInventory/orainstRoot.sh
/home/oracle/tools/oracle11g/product/11.2.0/dbhome_1/root.sh
           

11.建立連接配接使用者

操作使用者:oracle

sqlplus /nolog
conn /as sysdba
startup
           

接下來,執行如下指令。

alter user system identified by system;
alter user sys identified by sys;
           

建立連接配接使用者。

create user SYNC identified by SYNC;
grant connect,resource,dba to SYNC;
           

驗證安裝結果

1.啟動資料庫

啟動已經安裝的資料庫orcl。

操作使用者oracle

啟動監聽

lsnrctl  start
           

啟動資料庫過程如下:

sqlplus /nolog
           

使用dba權限連接配接Oralce

connect / as sysdba
           

啟動資料庫

startup
           

确認啟動結果:

ORACLE instance started.

Total System Global Area  534462464 bytes
Fixed Size                  2215064 bytes
Variable Size            373293928 bytes
Database Buffers          150994944 bytes
Redo Buffers                7958528 bytes
Database mounted.
Database opened.
           

2.驗證資料庫

這裡,我們使用Navicat連接配接Oracle資料庫,如下所示。

【Oracle】CentOS7/CentOS8指令行安裝Oracle 11G R2

這裡,輸入的使用者名為SYNC,密碼為SYNC。

接下來,點選“連接配接測試”,如下所示。

【Oracle】CentOS7/CentOS8指令行安裝Oracle 11G R2

可以看到,Oracle資料庫連接配接成功。

寫在最後

如果覺得文章對你有點幫助,請掃描下方二維碼或微信搜尋并關注「 冰河技術 」微信公衆号,跟冰河學習網際網路程式設計技術。公衆号回複“oracle”關鍵字領取Oracle資料庫安裝包下載下傳連結。