Centos7靜默安裝Oracle11g
目錄
1、環(huán)境及準(zhǔn)備工作
1.1 環(huán)境及配置調(diào)整
1.2 常用參數(shù)
1.3 其他準(zhǔn)備
2、oracle安裝
2.1 基本配置
2.2 解壓安裝包
2.3 正式安裝
2.4 靜默創(chuàng)建數(shù)據(jù)庫
2.5 登錄數(shù)據(jù)庫啟動(dòng)監(jiān)聽
2.6 激活scott用戶(可選)
3、設(shè)置開機(jī)啟動(dòng)

本文是去年十月在公司有需求安裝Oracle數(shù)據(jù)庫,復(fù)盤時(shí)整理的,部分內(nèi)容參考自網(wǎng)絡(luò)和官方文檔,親測(cè)無坑~
1、環(huán)境及準(zhǔn)備工作
1.1 環(huán)境及配置調(diào)整
操作系統(tǒng)版本、內(nèi)核版本、系統(tǒng)CPU、RAM、硬盤配置如下
[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.7.1908 (Core)
[root@localhost ~]# uname -r
3.10.0-1062.el7.x86_64
[root@localhost ~]# cat /proc/cpuinfo| grep "processor"| wc -l
8
[root@localhost ~]# cat /proc/meminfo| grep MemTotal
MemTotal: 131826144 kB
[root@localhost ~]# cat /proc/meminfo| grep SwapTotal
SwapTotal: 1835004 kB
[root@localhost ~]# fdisk -l|grep Disk
Disk /dev/vda: 21.5 GB, 21474836480 bytes, 41943040 sectors
Disk label type: dos
Disk identifier: 0x000e4fd0
Disk /dev/vdb: 2199.0 GB, 2199023255552 bytes, 4294967296 sectors
Disk /dev/mapper/centos-root: 18.5 GB, 18513657856 bytes, 36159488 sectors
Disk /dev/mapper/centos-swap: 1879 MB, 1879048192 bytes, 3670016 sectors
如下表所示
| 項(xiàng)目 | 值 |
|---|---|
| 操作系統(tǒng) | CentOS Linux release 7.7.1908 (Core) |
| 內(nèi)核版本 | 3.10.0-1062.el7.x86_64 |
| CPU | 8C |
| RAM | 128GB |
| SWAP | 1GB |
| 磁盤 | /dev/vda 20G + /dev/vdb 2TB |
數(shù)據(jù)盤未做格式化分區(qū)(這里僅格式化并掛載到單獨(dú)目錄,不做分區(qū))
根據(jù)內(nèi)存大小需要對(duì)此操作系統(tǒng)重新分配合適的swap空間(這里增加到16G),關(guān)于swap分區(qū)大小可參考紅帽官方說明
[root@localhost ~]# mkfs.xfs /dev/vdb
[root@localhost ~]# mkdir /data && mount /dev/vdb /data
[root@localhost ~]# df -h | grep "data"
/dev/vdb 2.0T 33M 2.0T 1% /data
[root@localhost ~]# blkid |grep vdb|awk '{print $2}'|cut -d '=' -f 2
"11eda493-b248-4ce0-91fb-e28e1b8164a9"
[root@localhost ~]# echo "UUID=11eda493-b248-4ce0-91fb-e28e1b8164a9 /data xfs defaults 0 0" >> /etc/fstab # 開機(jī)自動(dòng)掛載數(shù)據(jù)盤
[root@localhost ~]# sed -ri '/^[^#]*swap/s@^@#@' /etc/fstab # 關(guān)掉原來的swap開機(jī)自動(dòng)掛載
[root@localhost ~]# dd if=/dev/zero of=/data/swapfile bs=1G count=16
[root@localhost ~]# mkswap /data/swapfile
[root@localhost ~]# chmod 600 /data/swapfile
[root@localhost ~]# swapon /data/swapfile
[root@localhost ~]# echo "/data/swapfile swap swap defaults 0 0" >> /etc/fstab # 開機(jī)自動(dòng)掛載swap分區(qū)
1.2 常用參數(shù)
修改主機(jī)名、關(guān)閉selinux、時(shí)間同步等
[root@localhost ~]# hostnamectl set-hostname oracledb-01
[root@localhost ~]# echo "127.0.0.1 oracledb-01" >> /etc/hosts
[root@oracledb-01 ~]# sestatus
SELinux status: disabled
1.3 其他準(zhǔn)備
安裝依賴
[root@oracledb-01 ~]# yum -y install binutils compat-libcap1 compat-libstdc++-33 gcc gcc-c++ glibc glibc-devel ksh libaio libaio-devel libgcc libstdc++ libstdc++-dev libXi libXtst make sysstat unixODBC unixODBC-devel下載
oracle安裝包從官網(wǎng)下載
linux64位安裝包,下載后兩個(gè)文件如下[root@oracledb-01 ~]# ls linux.x64_11gR2_database_2of2
linux.x64_11gR2_database_1of2.zip linux.x64_11gR2_database_2of2.zip創(chuàng)建用戶:安裝
Oracle數(shù)據(jù)庫,需要以下本地操作系統(tǒng)組和用戶[root@oracledb-01 ~]# groupadd oinstall
[root@oracledb-01 ~]# groupadd dba
[root@oracledb-01 ~]# groupadd oper
[root@oracledb-01 ~]# useradd -g oinstall -G dba oracleOracle inventory組(通常為 oinstall) OSDBA組 (通常為 dba) OSOPER組 (通常為 oper) Oracle軟件所有者(通常為 oracle) 修改oracle用戶的密碼
[root@oracledb-01 ~]# echo "oracle" | passwd --stdin oracle
Changing password for user oracle.
passwd: all authentication tokens updated successfully.配置資源限制和內(nèi)核參數(shù)
在
/etc/sysctl.conf添加如下參數(shù),如果系統(tǒng)中某個(gè)參數(shù)高于下面的參數(shù)的值,保留較大的值,下面的數(shù)值只是官方要求的最小值,可以根據(jù)系統(tǒng)調(diào)整數(shù)值,以優(yōu)化系統(tǒng)性能fs.aio-max-nr = 1048576 # 同時(shí)可以擁有的的異步IO請(qǐng)求數(shù)目
fs.file-max = 6815744 # 指定可以分配的文件句柄的最大數(shù)目
kernel.shmall = 2097152 # 共享內(nèi)存總量
kernel.shmmax = 536870912 # 共享內(nèi)存段的最大尺寸
kernel.shmmni = 4096 # 系統(tǒng)范圍內(nèi)共享內(nèi)存段的最大數(shù)量
kernel.sem = 250 32000 100 128
net.ipv4.ip_local_port_range = 9000 65500
net.core.rmem_default = 262144 # 接收緩沖區(qū)大小
net.core.rmem_max = 4194304 # 接收緩沖區(qū)最大值
net.core.wmem_default = 262144 # 默認(rèn)的發(fā)送緩沖區(qū)大小
net.core.wmem_max = 1048576 # 發(fā)送緩沖區(qū)最大值使內(nèi)核參數(shù)生效
[root@oracledb-01 ~]# sysctl -p編輯
/etc/security/limits.conf(用戶限制配置文件),添加如下參數(shù)oracle soft nproc 2047
oracle hard nproc 16384
oracle soft nofile 1024
oracle hard nofile 65536編輯
/etc/pam.d/login文件,將配置文件加入到登錄驗(yàn)證模塊#Add for Install Oracle Database 11g
session required /lib64/security/pam_limits.so
session required pam_limits.so編輯
/etc/profile文件(環(huán)境變量文件)[root@oracledb-01 ~]# vim /etc/profile
if [ $USER = "oracle" ]; then
if [ $SHELL = "/bin/ksh" ]; then
ulimit -p 16384
ulimit -n 65536
else
ulimit -u 16384 -n 65536
fi
fi
[root@oracledb-01 ~]# source /etc/profile禁用使用
Transparent HugePages(啟用Transparent HugePages,可能會(huì)導(dǎo)致造成內(nèi)存在運(yùn)行時(shí)的延遲分配,Oracle官方建議使用標(biāo)準(zhǔn)的HugePages)[root@oracledb-01 ~]# cat /sys/kernel/mm/transparent_hugepage/enabled
[always] madvise never
[root@oracledb-01 ~]# echo never > /sys/kernel/mm/transparent_hugepage/enabled重新啟動(dòng)系統(tǒng)以使上述更改成為永久更改
查看是否啟用 如果顯示
[always]說明啟用了禁用Transparent HugePages,在/etc/grub.conf添加如下內(nèi)容
2、oracle安裝
2.1 基本配置
創(chuàng)建
oracle安裝目錄[root@oracledb-01 ~]# mkdir -p /data/app/
[root@oracledb-01 ~]# chown -R oracle:oinstall /data/app/
[root@oracledb-01 ~]# chmod -R 775 /data/app/配置
oracle用戶環(huán)境變量在文件/home/oracle/.bash_profile里添加下面內(nèi)容umask 022
export ORACLE_HOSTNAME=oracledb-01 # 修改成主機(jī)名
export ORACLE_BASE=/data/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/
export ORACLE_SID=ORCL
export ORACLE_UNQNAME=orcl
export PATH=.:$ORACLE_HOME/bin:$ORACLE_HOME/OPatch:$ORACLE_HOME/jdk/bin:$PATH
export LC_ALL="en_US"
export LANG="en_US"
export NLS_LANG="AMERICAN_AMERICA.ZHS16GBK"
export NLS_DATE_FORMAT="YYYY-MM-DD HH24:MI:SS"由于新增了環(huán)境變量,再次重啟系統(tǒng)
2.2 解壓安裝包
[root@oracledb-01 ~]# cd linux.x64_11gR2_database_2of2/
[root@oracledb-01 linux.x64_11gR2_database_2of2]# ls
linux.x64_11gR2_database_1of2.zip linux.x64_11gR2_database_2of2.zip
[root@oracledb-01 linux.x64_11gR2_database_2of2]# unzip -q linux.x64_11gR2_database_1of2.zip -d /data
[root@oracledb-01 linux.x64_11gR2_database_2of2]# unzip -q linux.x64_11gR2_database_2of2.zip -d /data
[root@oracledb-01 linux.x64_11gR2_database_2of2]# mkdir -p /data/etc
[root@oracledb-01 linux.x64_11gR2_database_2of2]# cp /data/database/response/* /data/etc/
2.3 正式安裝
修改文件/data/etc/db_install.rsp中以下變量的值
oracle.install.option=INSTALL_DB_SWONLY
DECLINE_SECURITY_UPDATES=true
UNIX_GROUP_NAME=oinstall
INVENTORY_LOCATION=/data/app/oracle/inventory
SELECTED_LANGUAGES=en,zh_CN
ORACLE_HOSTNAME=oracledb-01 # 修改成主機(jī)名
ORACLE_HOME=/data/app/oracle/product/11.2.0
ORACLE_BASE=/data/app/oracle
oracle.install.db.InstallEdition=EE
oracle.install.db.isCustomInstall=true
oracle.install.db.DBA_GROUP=dba
oracle.install.db.OPER_GROUP=dba
執(zhí)行安裝腳本
[root@oracledb-01 ~]# su - oracle
[oracle@oracledb-01 ~]$ cd /data/database/
[oracle@oracledb-01 database]$ ./runInstaller -silent -responseFile /data/etc/db_install.rsp -ignorePrereq
安裝時(shí)可以根據(jù)安裝提示查看日志
[root@oracledb-01 ~]# tail -f /data/app/oracle/inventory/logs/installActions2020-10-31_09-40-21PM.log
安裝完成后會(huì)有如下提示
You can find the log of this install session at:
/data/app/oracle/inventory/logs/installActions2020-10-31_09-40-21PM.log
The following configuration scripts need to be executed as the "root" user.
#!/bin/sh
#Root scripts to run
/data/app/oracle/inventory/orainstRoot.sh
/data/app/oracle/product/11.2.0/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.
按照上述提示進(jìn)行操作,使用root用戶運(yùn)行腳本
[oracle@oracledb-01 ~]$ su - root
Password:
[root@oracledb-01 ~]# sh /data/app/oracle/inventory/orainstRoot.sh
Changing permissions of /data/app/oracle/inventory.
Adding read,write permissions for group.
Removing read,write,execute permissions for world.
Changing groupname of /data/app/oracle/inventory to oinstall.
The execution of the script is complete.
[root@oracledb-01 ~]# sh /data/app/oracle/product/11.2.0/root.sh
Check /data/app/oracle/product/11.2.0/install/root_oracledb-01_2020-10-31_09-46-20.log for the output of root script
配置監(jiān)聽
[root@oracledb-01 ~]# su - oracle
[oracle@oracledb-01 ~]$ netca /silent /responsefile /data/etc/netca.rsp
Parsing command line arguments:
Parameter "silent" = true
Parameter "responsefile" = /data/etc/netca.rsp
Done parsing command line arguments.
Oracle Net Services Configuration:
Profile configuration complete.
Oracle Net Listener Startup:
Running Listener Control:
/data/app/oracle/product/11.2.0/bin/lsnrctl start LISTENER
Listener Control complete.
Listener started successfully.
Listener configuration complete.
Oracle Net Services configuration successful. The exit code is 0
查看監(jiān)聽端口
[oracle@oracledb-01 database]$ netstat -tnpl | grep 1521
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
tcp6 0 0 :::1521 :::* LISTEN 6064/tnslsnr
2.4 靜默創(chuàng)建數(shù)據(jù)庫
2.4.1 編輯應(yīng)答文件
編輯應(yīng)答文件/data/etc/dbca.rsp
[GENERAL]
RESPONSEFILE_VERSION = "11.2.0"
OPERATION_TYPE = "createDatabase"
[CREATEDATABASE]
GDBNAME = "orcl"
SID = "orcl"
SYSPASSWORD = "oracle"
SYSTEMPASSWORD = "oracle"
SYSMANPASSWORD = "oracle"
DBSNMPPASSWORD = "oracle"
DATAFILEDESTINATION = /data/app/oracle/oradata
RECOVERYAREADESTINATION=/data/app/oracle/fast_recovery_area
CHARACTERSET = "AL32UTF8" # 字符集,根據(jù)需求設(shè)置,建議前期確定好需要什么字符集,后期不建議更改
TOTALMEMORY = "102400" # 分配給Oracle的內(nèi)存總量,根據(jù)服務(wù)器內(nèi)存總量進(jìn)行分配
2.4.2 執(zhí)行靜默建庫
su - oracle
dbca -silent -responseFile /data/etc/dbca.rsp
執(zhí)行時(shí)控制臺(tái)輸出如下
Copying database files
1% complete
3% complete
11% complete
18% complete
26% complete
37% complete
Creating and starting Oracle instance
40% complete
45% complete
50% complete
55% complete
56% complete
60% complete
62% complete
Completing Database Creation
66% complete
70% complete
73% complete
85% complete
96% complete
100% complete
Look at the log file "/data/app/oracle/cfgtoollogs/dbca/orcl/orcl.log" for further details.
2.4.3 檢查
查看進(jìn)程
[oracle@oracledb-01 ~]$ ps -ef | grep ora_ | grep -v grep
oracle 8113 1 0 12:03 ? 00:00:00 ora_pmon_orcl
oracle 8115 1 0 12:03 ? 00:00:00 ora_vktm_orcl
oracle 8119 1 0 12:03 ? 00:00:00 ora_gen0_orcl
oracle 8121 1 0 12:03 ? 00:00:00 ora_diag_orcl
oracle 8123 1 0 12:03 ? 00:00:00 ora_dbrm_orcl
oracle 8125 1 0 12:03 ? 00:00:00 ora_psp0_orcl
oracle 8127 1 0 12:03 ? 00:00:00 ora_dia0_orcl
oracle 8129 1 0 12:03 ? 00:00:00 ora_mman_orcl
oracle 8131 1 0 12:03 ? 00:00:00 ora_dbw0_orcl
oracle 8133 1 0 12:03 ? 00:00:00 ora_lgwr_orcl
oracle 8135 1 0 12:03 ? 00:00:00 ora_ckpt_orcl
oracle 8137 1 0 12:03 ? 00:00:00 ora_smon_orcl
oracle 8139 1 0 12:03 ? 00:00:00 ora_reco_orcl
oracle 8141 1 0 12:03 ? 00:00:00 ora_mmon_orcl
oracle 8143 1 0 12:03 ? 00:00:00 ora_mmnl_orcl
oracle 8145 1 0 12:03 ? 00:00:00 ora_d000_orcl
oracle 8147 1 0 12:03 ? 00:00:00 ora_s000_orcl
oracle 8161 1 0 12:03 ? 00:00:00 ora_qmnc_orcl
oracle 8178 1 0 12:03 ? 00:00:00 ora_cjq0_orcl
oracle 8188 1 0 12:03 ? 00:00:00 ora_q000_orcl
oracle 8190 1 0 12:03 ? 00:00:00 ora_q001_orcl
查看監(jiān)聽狀態(tài)
[oracle@oracledb-01 ~]$ lsnrctl status
LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 03-NOV-2020 12:06:10
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 03-NOV-2020 11:37:14
Uptime 0 days 0 hr. 28 min. 56 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /data/app/oracle/product/11.2.0/network/admin/listener.ora
Listener Log File /data/app/oracle/diag/tnslsnr/oracledb-01/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=oracledb-01)(PORT=1521)))
Services Summary...
Service "orcl" has 1 instance(s).
Instance "orcl", status READY, has 1 handler(s) for this service...
Service "orclXDB" has 1 instance(s).
Instance "orcl", status READY, has 1 handler(s) for this service...
The command completed successfully
2.5 登錄數(shù)據(jù)庫啟動(dòng)監(jiān)聽
[root@oracledb-01 ~]# su - oracle
[oracle@oracledb-01 ~]$ sqlplus / as sysdba
SQL> startup
ORA-01078: failure in processing system parameters
LRM-00109: could not open parameter file '/data/app/oracle/product/11.2.0/dbs/initORCL.ora'
按照提示操作
[oracle@oracledb-01 ~]$ cp /data/app/oracle/admin/orcl/pfile/init.ora.103202012323 /data/app/oracle/product/11.2.0/dbs/initORCL.ora
再次啟動(dòng)監(jiān)聽
SQL> shutdown immediate;
SQL> startup;
ORACLE instance started.
Total System Global Area 534462464 bytes
Fixed Size 2215064 bytes
Variable Size 163578728 bytes
Database Buffers 360710144 bytes
Redo Buffers 7958528 bytes
Database mounted.
Database opened.
2.6 激活scott用戶(可選)
SQL> alter user scott account unlock;
SQL> alter user scott identified by tiger;
SQL> select username,account_status from dba_users;
3、設(shè)置開機(jī)啟動(dòng)
修改/data/app/oracle/product/11.2.0/bin/dbstart
ORACLE_HOME_LISTNER=$ORACLE_HOME
修改/data/app/oracle/product/11.2.0/bin/dbshut
ORACLE_HOME_LISTNER=$ORACLE_HOME
修改vi /etc/oratab
orcl:/data/app/oracle/product/11.2.0:Y
新建服務(wù)文件/etc/rc.d/init.d/oracle
#! /bin/bash
# oracle: Start/Stop Oracle Database 11g R2
#
# chkconfig: 345 90 10
# description: The Oracle Database is an Object-Relational Database Management System.
#
# processname: oracle
. /etc/rc.d/init.d/functions
LOCKFILE=/var/lock/subsys/oracle
ORACLE_HOME=/data/app/oracle/product/11.2.0
ORACLE_USER=oracle
case "$1" in
'start')
if [ -f $LOCKFILE ]; then
echo $0 already running.
exit 1
fi
echo -n $"Starting Oracle Database:"
su - $ORACLE_USER -c "$ORACLE_HOME/bin/lsnrctl start"
su - $ORACLE_USER -c "$ORACLE_HOME/bin/dbstart $ORACLE_HOME"
su - $ORACLE_USER -c "$ORACLE_HOME/bin/emctl start dbconsole"
touch $LOCKFILE
;;
'stop')
if [ ! -f $LOCKFILE ]; then
echo $0 already stopping.
exit 1
fi
echo -n $"Stopping Oracle Database:"
su - $ORACLE_USER -c "$ORACLE_HOME/bin/lsnrctl stop"
su - $ORACLE_USER -c "$ORACLE_HOME/bin/dbshut"
su - $ORACLE_USER -c "$ORACLE_HOME/bin/emctl stop dbconsole"
rm -f $LOCKFILE
;;
'restart')
$0 stop
$0 start
;;
'status')
if [ -f $LOCKFILE ]; then
echo $0 started.
else
echo $0 stopped.
fi
;;
*)
echo "Usage: $0 [start|stop|status]"
exit 1
esac
exit 0
添加執(zhí)行權(quán)限和開機(jī)啟動(dòng)
[root@oracledb-01 ~]# chmod +x /etc/init.d/oracle
[root@oracledb-01 ~]# chkconfig oracle on
[root@oracledb-01 ~]# chkconfig --list|grep oracle
Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by native
systemd configuration.
If you want to list systemd services use 'systemctl list-unit-files'.
To see services enabled on particular target use
'systemctl list-dependencies [target]'.
oracle 0:off 1:off 2:on 3:on 4:on 5:on 6:off
修改啟動(dòng)相關(guān)文件的權(quán)限
[root@oracledb-01 ~]# cd /data/app/oracle/product/11.2.0/bin/
[root@oracledb-01 bin]# chmod 6751 oracle
[root@oracledb-01 bin]# cd /var/tmp
[root@oracledb-01 tmp]# chown -R oracle:oinstall .oracle
關(guān)機(jī)重啟測(cè)試
reboot
關(guān)機(jī)重啟后登陸進(jìn)入數(shù)據(jù)庫后,再執(zhí)行startup啟動(dòng)數(shù)據(jù)庫
安裝完成~
內(nèi)容參考:
https://blog.csdn.net/chenghuikai/article/details/85776622
https://www.cnblogs.com/hftian/p/6944133.html
https://www.cnblogs.com/xiaofeng666/p/13702197.html
