0%

CentOS7 命令行安装Oracle 11G R2

环境准备

  • 1.CentOS7 64位最小化安装

  • 2.Oracle 11gR2 64位 Linux版安装包

    1
    2
    linux.x64_11gR2_database_1of2.zip
    linux.x64_11gR2_database_2of2.zip

安装过程

关闭防火墙

操作用户:root

1
2
systemctl stop firewalld.service
systemctl disable firewalld.service

安装依赖包

操作用户为:root

执行如下命令安装依赖包。

1
2
3
4
5
6
7
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

如果上述命令报错,则直接直接下面的命令。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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

修改内核

操作用户为:root

修改sysctl.conf文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
kernel.shmmax = 277495689510912
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
net.core.rmem_default = 262144
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 1048586
fs.file-max = 6815744

# Controls the maximum number of shared memory segments, in pages
kernel.shmall = 4294967296
net.ipv4.tcp_max_tw_buckets = 6000
net.ipv4.ip_local_port_range = 9000 65500
net.ipv4.tcp_tw_recycle = 0
net.ipv4.tcp_tw_reuse = 1
net.core.somaxconn = 262144
net.core.netdev_max_backlog = 262144
net.ipv4.tcp_max_orphans = 262144
net.ipv4.tcp_max_syn_backlog = 262144
net.ipv4.tcp_synack_retries = 2
net.ipv4.tcp_syn_retries = 1
net.ipv4.tcp_fin_timeout = 1
net.ipv4.tcp_keepalive_time = 30
net.ipv4.tcp_keepalive_probes = 6
net.ipv4.tcp_keepalive_intvl = 5
net.ipv4.tcp_timestamps = 0
fs.aio-max-nr = 1048576

使参数生效

1
sysctl -p

创建oracle用户

操作用户为:root

1
2
3
4
5
6
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
操作目录:/home/oracle

将Oracle 11gR2安装文件上传(可以使用sftp上传)到该操作目录下面,然后顺序解压安装文件到该目录。

1
2
unzip linux.x64_11gR2_database_1of2.zip
unzip linux.x64_11gR2_database_2of2.zip

修改操作系统配置

操作用户:root
操作文件:/etc/security/limits.conf

1
vim /etc/security/limits.conf

在文件的末尾添加如下配置项。

1
2
3
4
5
oracle          soft      nproc   2047
oracle hard nproc 16384
oracle soft nofile 1024
oracle hard nofile 65536
oracle soft stack 10240

创建Oracle安装目录

操作用户:oracle

1
mkdir ~/tools/oracle11g -p

修改环境变量

操作用户:oracle
操作目录:/home/oracle

1
vim ~/.bash_profile

在文件末尾添加如下配置项

1
2
3
4
5
6
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

使得环境变量生效。

1
source ~/.bash_profile

修改Oracle配置文件

操作用户:oracle
操作目录:/home/oracle

复制文件模板

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

注意:复制命令的最后一个 . 不能省略,表示将db_install.rsp文件从/home/oracle/database/response目录拷贝到当前目录。

对db_install.rsp文件进行编辑。

1
vim db_install.rsp

需要修改的配置项如下所示,这里,我将修改后的配置项列举出来。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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
DECLINE_SECURITY_UPDATES=true

静默安装Oracle 11gR2

操作用户:oracle
操作目录:/home/oracle/database

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

等待一段时间后,如果输出如下信息,则表明Oracle数据库已经安装成功。

1
2
3
4
5
6
7
8
9
10
11
12
13
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.

安装完成

操作用户:root

根据上一步完成信息提示,执行以下两行命令,具体位置需要根据你的安装位置决定:

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

创建连接用户

操作用户:oracle

1
2
sqlplus /nolog
conn /as sysdba

接下来,执行如下命令。

1
2
alter user system identified by system;
alter user sys identified by sys;

创建连接用户。

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

验证安装结果

启动数据库

启动已经安装的数据库orcl。

操作用户oracle

启动监听

1
lsnrctl  start

启动数据库过程如下:

1
sqlplus /nolog

使用dba权限连接Oralce

1
connect / as sysdba

启动数据库

1
startup

确认启动结果:

1
2
3
4
5
6
7
8
9
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.