环境准备

操作系统 centos7

oracle11g

终端软件 MobaXterm

192.168.46.61 oracleMaster

一、安装前准备

1、关闭selinux

[root@oracleMaster ~]# vim /etc/selinux/config

修改 SELINUX 为 disabled

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled #此处修改为disable
# SELINUXTYPE= can take one of three two values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected.
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted
[root@oracleMaster ~]# setenforce 0
setenforce: SELinux is disabled

2、防火墙设置

2.1、关闭防火墙,一劳永逸,生产环境禁止使用,仅测试

systemctl stop firewalld.service

2.2、开放端口

查看端口是否开放:
firewall-cmd --query-port=1521/tcp

永久开放1521端口号:
firewall-cmd --permanent --zone=public --add-port=1521/tcp

重启防火墙:
systemctl restart firewalld.service

查看防火墙状态
systemctl status firewalld.service

3、安装oracle11g依赖

yum install gcc make binutils gcc-c++ compat-libstdc++-33elfutils-libelf-devel elfutils-libelf-devel-static ksh libaio libaio-develnumactl-devel sysstat unixODBC unixODBC-devel pcre-devel –y

4、添加安装用户及用户组

groupadd oinstall

groupadd dba

useradd -g oinstall -G dba oracle

# 为oracle用户设置密码
passwd oracle

# 查看 oracle 用户
[root@oracleMaster ~]# id oracle
uid=1001(oracle) gid=1001(oinstall) 组=1001(oinstall),1002(dba)

5、修改linux 内核参数

[root@oracleMaster ~]# vim /etc/sysctl.conf

在文件末尾增加如下参数

fs.aio-max-nr = 1048576
fs.file-max = 6815744
kernel.shmall = 2097152
kernel.shmmax = 1073741824
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
net.ipv4.ip_local_port_range = 9000 65500
net.core.rmem_default = 262144
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 1048576

检查一下配置是否已经写入文件

sysctl -p

6、修改 limits.conf

vim /etc/security/limits.conf

在文件末尾增加配置

#oracle config date 2023-07-12
oracle           soft    nproc           2047
oracle           hard    nproc           16384
oracle           soft    nofile          1024
oracle           hard    nofile          65536
oracle           soft    stack           10240

7、修改/etc/pam.d/login文件

vim /etc/pam.d/login

文件末尾增加如下配置

session required  /lib64/security/pam_limits.so
session required   pam_limits.so

8、修改环境变量

vim /etc/profile

文件末尾增加如下配置

##oracle config date 2023-07-12
if [ $USER = "oracle" ]; then
  if [ $SHELL = "/bin/ksh" ]; then
      ulimit -p 16384
      ulimit -n 65536
  else
      ulimit -u 16384 -n 65536
  fi
fi

9、创建安装目录并且设置文件权限

mkdir -p /data/oracle/product/11.2.0/db_01

mkdir /data/oracle/oradata

mkdir /data/oracle/inventory

mkdir /data/oracle/fast_recovery_area

chown -R oracle:oinstall /data/oracle

chmod -R 775 /data/oracle

10、修改hosts文件

vim /etc/hosts

在文件末尾增加如下配置,对应两台机器的ip和用户名

192.168.46.61 oracleMaster
192.168.46.62 oracleSlave

11、解压安装包

创建安装包存放目录

[root@oracleMaster ~]# mkdir -p /opt/oracle
[root@oracleMaster oracle]# pwd
/opt/oracle

将 2个安装包放到此目录下

[root@oracleMaster oracle]# ls
linux.x64_11gR2_database_1of2.zip  linux.x64_11gR2_database_2of2.zip

解压安装包,会得到一个 database 文件夹

[root@oracleMaster oracle]# ls
database  linux.x64_11gR2_database_1of2.zip  linux.x64_11gR2_database_2of2.zip

这个目录会在安装时使用

/opt/oracle/database

12、为oracle设置环境变量

切换到 oracle 用户

[root@oracleMaster ~]# su -l oracle
上一次登录:三 7月 12 10:28:39 CST 2023pts/0 上
[oracle@oracleMaster ~]$ vim .bash_profile
ORACLE_BASE=/data/oracle
ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_01
ORACLE_SID=orcl
PATH=$PATH:$ORACLE_HOME/bin
export  ORACLE_BASE ORACLE_HOME ORACLE_SID PATH

使环境变量生效

source .bash_profile

二、开始安装

登录 oracle 用户,在 oracle 用户下面操作

1、复制安装文件到当前用户 oracle 根目录下面

[oracle@oracleMaster ~]$ cp -R /opt/oracle/database/response .

安装文件在一、安装前准备 第11部那个目录下面

[oracle@oracleMaster ~]$ cd response
[oracle@oracleMaster response]$ vim  db_install.rsp

修改如下配置

oracle.install.option=INSTALL_DB_SWONLY

ORACLE_HOSTNAME=CentOS

UNIX_GROUP_NAME=oinstall

INVENTORY_LOCATION=/data/oracle/inventory

SELECTED_LANGUAGES=en,zh_CN

ORACLE_HOME=/data/oracle/product/11.2.0/db_01

ORACLE_BASE=/data/oracle

oracle.install.db.InstallEdition=EE

oracle.install.db.DBA_GROUP=dba

oracle.install.db.OPER_GROUP=dba

DECLINE_SECURITY_UPDATES=true

2、静默安装oracle

cd /opt/oracle/database
./runInstaller -silent -responseFile /home/oracle/response/db_install.rsp -ignorePrereq

安装时会遇到一些问题,运气好的话全程不会报错,主要看机器的环境

在我安装时,根目录的磁盘空间不足导致安装无法进行下去,需要扩展磁盘空间

当出现:

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

/data/oracle/inventory/orainstRoot.sh
/data/oracle/product/11.2.0/db_01/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.

Successfully Setup Software表示安装成功,中间提示warning不需要理会,当提示成功以后可以退出当前窗口了,然后根据提示执行脚本切换到root用户继续执行一下操作

3、切换到root用户执行操作

sh /data/oracle/inventory/orainstRoot.sh

sh /data/oracle/product/11.2.0/db_01/root.sh

4、配置监听程序

监听命令

启动监听:lsnrctl start

停止监听:lsnrctl stop

重启监听:lsnrctl reload

查看监听:lsnrctl status

切换到oracle 用户

su -l oracle

4.1、配置监听

$ORACLE_HOME/bin/netca /silent /responseFile /home/oracle/response/netca.rsp

查看是否监听成功

lsnrctl status

5、静默dbca建库

vim /home/oracle/response/dbca.rsp

填写下面的参数,SYSTEMPASSWORD 和 SYSTEMPASSWORD 必须设置不然不会安装,在ssh软件中安装会清屏,在 vmware esxi 中安装才会提示输入这两个用户的密码,坑

GDBNAME = "orcl" # 78 行

SID="orcl" # 149行

# Description   : Password for SYS user
# SYS管理员密码
SYSTEMPASSWORD = "123456"

# Description   : Password for SYSTEM user
# SYSTEM管理员密码
SYSTEMPASSWORD = "123456"

CHARACTERSET="AL32UTF8" # 415行

NATIONALCHARACTERSET="UTF8" # 425行

TOTALMEMORY = "1638"

5.1、配置解释

[GENERAL]

# oracle版本,不能更改
RESPONSEFILE_VERSION = "11.2.0"

# Description   : Type of operation
OPERATION_TYPE = "createDatabase"

[CREATEDATABASE]

# Description   : Global database name of the database
# 全局数据库的名字=SID+主机域名# 第三方工具链接数据库的时候使用的service名称
GDBNAME = "orcl.myorcl"

# Description   : System identifier (SID) of the database
# 对应的实例名字
SID = "orcl"

# Description   : Name of the template
# 建库用的模板文件
TEMPLATENAME = "General_Purpose.dbc"

# Description   : Password for SYS user
# SYS管理员密码
SYSPASSWORD = "123456"

# Description   : Password for SYSTEM user
# SYSTEM管理员密码
SYSTEMPASSWORD = "123456"

# Description   : Password for SYSMAN user
# SYSMAN管理员密码
SYSMANPASSWORD = "123456"

# Description   : Password for DBSNMP user
# DBSNMP管理员密码
DBSNMPPASSWORD = "123456"

# Description   : Location of the data file's
# 数据文件存放目录 Default value : $ORACLE_BASE/oradata
DATAFILEDESTINATION =/data/oracle/oradata

# Description   : Location of the data file's
# 恢复数据存放目录 $ORACLE_BASE/flash_recovery_area
RECOVERYAREADESTINATION=/data/oracle/fast_recovery_area

# Description   : Character set of the database
# 字符集,重要!!! 建库后一般不能更改,所以建库前要确定清楚。
# (CHARACTERSET = "AL32UTF8" NATIONALCHARACTERSET= "UTF8")
CHARACTERSET = "AL32UTF8"

NATIONALCHARACTERSET="UTF8" # 425行

# Description   : total memory in MB to allocate to Oracle
# oracle内存1638MB,物理内存2G*80%
TOTALMEMORY = "1638"

5.2、静默建库

保持在oracle 用户下面

$ORACLE_HOME/bin/dbca -silent -responseFile /home/oracle/response/dbca.rsp

6、启动数据库

sqlplus / as sysdba
startup

--创建表空间
CREATE TABLESPACE NNC_DATA01 DATAFILE '/data/oracle/oradata/orcl/nnc_data01.dbf' SIZE 500M AUTOEXTEND ON NEXT 50M EXTENT MANAGEMENT LOCAL UNIFORM SIZE 256K ;
CREATE TABLESPACE NNC_DATA02 DATAFILE '/data/oracle/oradata/orcl/nnc_data02.dbf' SIZE 300M AUTOEXTEND ON NEXT 50M EXTENT MANAGEMENT LOCAL UNIFORM SIZE 256K ;
CREATE TABLESPACE NNC_DATA03 DATAFILE '/data/oracle/oradata/orcl/nnc_data03.dbf' SIZE 500M AUTOEXTEND ON NEXT 100M EXTENT MANAGEMENT LOCAL UNIFORM SIZE 512K ;
CREATE TABLESPACE NNC_INDEX01 DATAFILE '/data/oracle/oradata/orcl/nnc_index01.dbf' SIZE 500M AUTOEXTEND ON NEXT 50M EXTENT MANAGEMENT LOCAL UNIFORM SIZE 128K ;
CREATE TABLESPACE NNC_INDEX02 DATAFILE '/data/oracle/oradata/orcl/nnc_index02.dbf' SIZE 300M AUTOEXTEND ON NEXT 50M EXTENT MANAGEMENT LOCAL UNIFORM SIZE 128K ;
CREATE TABLESPACE NNC_INDEX03 DATAFILE '/data/oracle/oradata/orcl/nnc_index03.dbf' SIZE 500M AUTOEXTEND ON NEXT 100M EXTENT MANAGEMENT LOCAL UNIFORM SIZE 256K ;

7、配置开机自动启动监听、启动Oracle

切换到root 用户

7.1、设置oratab

su - root
vim /etc/oratab
其中:  

*:/home/oracle/oracle92:N

这一行中 * 改为数据库的SID orcl, 第三段的N改为Y

改后如下:

orcl:/home/oracle/oracle92:Y 务必是大写的Y
保存并退出

7.2、设置 rc.local

vim /etc/rc.local

在文件末尾增加如下内容

su - oracle -c 'dbstart'
su - oracle -c 'lsnrctl start'

设置权限

chmod +x /etc/rc.local

8、远程连接oracle

sqlplus /nolog
SQL> connect / as sysdba
SQL> create user sync identified by 123456;//创建用户 sync,密码为123456
SQL> grant connect, resource to sync;//将connect和resource权限授予 sync