1. 程式人生 > 實用技巧 >【Oracle】手動安裝和解除安裝Oracle,這是最全的一篇了!!

【Oracle】手動安裝和解除安裝Oracle,這是最全的一篇了!!

寫在前面

之前寫過一篇在CentOS 7/8上安裝Oracle的文章,按照我寫的文章安裝成功了,但是解除安裝Oracle時出現了問題。今天,我就整理一篇手動安裝和解除安裝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

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

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資料庫,如下所示。

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

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

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

手動解除安裝Oracle

1.停止監聽

[oracle@binghe101 ~]$ lsnrctl stop
[oracle@binghe101 ~]$ lsnrctl status

2.停止資料庫

[oracle@binghe101 ~]$ sqlplus / as sysdba
SQL> shutdown immediate

3.刪除oracle的inventory 目錄

[root@binghe101 app]# rm -rf /home/oracle/tools/oraInventory/

4.刪除Oracle的base目錄下所有的目錄

[root@binghe101 oracle]# rm -rf /home/oracle/tools/oracle11g/*

5.刪除臨時目錄/tmp

[root@binghe101 tmp]# rm -rf /tmp/*

6.刪除Oracle的配置檔案

[root@binghe101 tmp]# rm -f /etc/ora*

7.刪除oracle產生命令

[root@binghe101 tmp]# rm -f /usr/local/bin/*

8.其他的檔案

[root@binghe101 .oracle]# rm -rf /usr/tmp/.oracle/

9.刪除使用者和組

[root@binghe101 tmp]# userdel -r oracle
[root@binghe101 tmp]# groupdel oper
[root@binghe101 tmp]# groupdel dba    
[root@binghe101 tmp]# groupdel oinstall
[root@binghe101 tmp]# groupdel asmadmin

10.撤銷oracle的資源限制檔案

[root@binghe101 tmp]# vi /etc/security/limits.conf

11.核心引數

[root@binghe101 tmp]# vi /etc/sysctl.conf 
[root@binghe101 tmp]# sysctl -p

12.刪除oracle base

[root@binghe101 ~]# rm -rf /home/oracle/tools/oracle11g

重磅福利

關注「 冰河技術 」微信公眾號,後臺回覆 “設計模式” 關鍵字領取《深入淺出Java 23種設計模式》PDF文件。回覆“Java8”關鍵字領取《Java8新特性教程》PDF文件。回覆“限流”關鍵字獲取《億級流量下的分散式限流解決方案》PDF文件,三本PDF均是由冰河原創並整理的超硬核教程,面試必備!!

好了,今天就聊到這兒吧!別忘了點個贊,給個在看和轉發,讓更多的人看到,一起學習,一起進步!!

寫在最後

如果你覺得冰河寫的還不錯,請微信搜尋並關注「 冰河技術 」微信公眾號,跟冰河學習高併發、分散式、微服務、大資料、網際網路和雲原生技術,「 冰河技術 」微信公眾號更新了大量技術專題,每一篇技術文章乾貨滿滿!不少讀者已經通過閱讀「 冰河技術 」微信公眾號文章,吊打面試官,成功跳槽到大廠;也有不少讀者實現了技術上的飛躍,成為公司的技術骨幹!如果你也想像他們一樣提升自己的能力,實現技術能力的飛躍,進大廠,升職加薪,那就關注「 冰河技術 」微信公眾號吧,每天更新超硬核技術乾貨,讓你對如何提升技術能力不再迷茫!