Centos7下安装Oracle11g

一、安装文件下载

1、VMware上安装centos7系统(可以固定centos7的IP,也可以不固定)
百度云:
链接:https://pan.baidu.com/s/1-TrXkdmOa4dfMhSHY13NjA
提取码:s3pp
注:我这里的centos7是最精简的安装包
2、下载oracle11g安装包
百度云:
链接:https://pan.baidu.com/s/14pC6FnjLpIUF-5a97xoLwA
提取码:xlv9
3、下载Xshell7及Xftp工具,将安装包由本地上传到centos上
百度云:
链接:https://pan.baidu.com/s/1jrOB8p-WycShij66cmTJ9Q
提取码:g4qx

二、安装环境搭建(root账号登录)

1、安装oracle的目录磁盘空间要充足,否则会安装oracle失败(大于4G)
在这里插入图片描述

2、安装解压工具unzip

[root@localhost ~]# yum -y install unzip

3、切换到oracle压缩包所在的目录,解压压缩包(我这里放在了/home下)

[root@localhost ~]# cd /home
[root@localhost ~]# unzip linux.x64_11gR2_database_1of2.zip
[root@localhost ~]# unzip linux.x64_11gR2_database_2of2.zip
解压完成后会在/home目录下生成一个database文件夹,这个就是oracle的安装文件

4、安装vim编辑器

[root@localhost ~]# yum -y install vim

5、添加主机名

[root@localhost ~]# hostname  查看主机名为:localhost.localdomain
[root@localhost ~]# vim etc/hosts

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.230.128 localhost.localdomain #添加改行,IP是当前获取的IP或者固定的IP

6、关掉selinux

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

# 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=enforcing
# SELINUXTYPE= can take one of three values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected. 
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted

根据注释,将SELINUX=enforcing 改为:SELINUX=disabled

[root@localhost ~]# setenforce 0

使上面的配置文件生效

7、关闭防火墙以免发生不必要的错误

[root@localhost ~]# systemctl stop firewalld.service    停止防火墙服务
[root@localhost ~]# systemctl disable firewalld.service 永久关闭防火墙
[root@localhost ~]# systemctl status firewalld.service  查看防火墙状态

8、安装oracle11g依赖包

[root@localhost ~]# 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

9、添加安装用户和组

[root@localhost home]# groupadd oinstall
[root@localhost home]# groupadd dba
[root@localhost home]# useradd -g oinstall -G dba oracle
[root@localhost home]# passwd oracle
更改用户 oracle 的密码 。
新的密码:
无效的密码: 密码少于 8 个字符
重新输入新的 密码:
passwd:所有的身份验证令牌已经成功更新。

10、修改内核参数配置文件

[root@localhost home]# vim /etc/sysctl.conf 

# sysctl settings are defined through files in
# /usr/lib/sysctl.d/, /run/sysctl.d/, and /etc/sysctl.d/.
#
# Vendors settings live in /usr/lib/sysctl.d/.
# To override a whole file, create a new file with the same in
# /etc/sysctl.d/ and put new settings there. To override
# only specific settings, add a file with a lexically later
# name in /etc/sysctl.d/ and put new settings there.
#
# For more information, see sysctl.conf(5) and sysctl.d(5).
fs.aio-max-nr = 1048576
fs.file-max = 6815744
kernel.shmall = 2097152
kernel.shmmax = 536870912
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
其中kernel.shmmax = 536870912为本机物理内存(1G)的一半,单位为byte

11、修改用户的限制文件

[root@localhost home]# vim /etc/security/limits.conf

#ftp             hard    nproc           0
#@student        -       maxlogins       4
oracle soft nproc 2047
oracle hard nproc 16384
oracle soft nofile 1024
oracle hard nofile 65536
oracle soft stack 10240

12、修改用户验证选项

[root@localhost ~]# vim /etc/pam.d/login 

添加一下内容(注意此处别出错,否则你的系统将不能正常登陆):

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

13、设置oracle安装目录和设置文件权限

[root@localhost ~]# mkdir -p /data/oracle/product/11.2.0
[root@localhost ~]# mkdir -p /data/oracle/oradata
[root@localhost ~]# mkdir /data/oracle/inventory
[root@localhost ~]# mkdir /data/oracle/fast_recovery_area
[root@localhost ~]# chown -R oracle:oinstall /data/oracle
[root@localhost ~]# chmod -R 777 /data/oracle
[root@localhost ~]# 

14、以oracle身份登陆系统,设置oracle用户环境变量

[root@localhost ~]# su - oracle
[oracle@localhost ~]$ vim .bash_profile 

添加如下内容:

ORACLE_BASE=/data/oracle; export ORACLE_BASE

ORACLE_HOME=ORACLE_BASE/product/11.2.0; export ORACLE_HOME

NLS_LANG=american; export NLS_LANG

ORACLE_SID=orcl; export ORACLE_SID

PATH=PATH:ORACLE_HOME/bin:ORACLE_HOME/jdk/bin:/sbin;

export PATH

BIN=ORACLE_HOME/bin; export BIN

LD_LIBRARY_PATH=ORACLE_HOME/lib; export LD_LIBRARY_PATH

export LANG=en_US.UTF-8

注:a)ORACLE_SID=orcl与创建的数据库实例名称一致,否则数据库启动后无法访问
b)这里语言我设置为American,设置为中文执行以下命令不生效

配置完后使用命令使配置生效

[oracle@localhost ~]source .bash_profile 
[oracle@localhost ~] 

退出在登录,使得环境变量的配置生效

[oracle@localhost ~]exit
logout
[root@localhost ~]# su - oracle
上一次登录:三 11月 24 21:42:21 CST 2021pts/0 上
[oracle@localhost ~] env | grep ORA
ORACLE_SID=orcl
ORACLE_BASE=/data/oracle
ORACLE_HOME=/data/oracle/product/11.2.0

15、安装前的最后准备工作

a. 将响应文件复制到oracle用户家目录 即/home/oracle

[oracle@localhost ~]cp -R /home/database/response/ .
[oracle@localhost ~] ls
response

b. 编辑相应文件,“=”后面加上如下内容

oracle.install.option=INSTALL_DB_SWONLY

ORACLE_HOSTNAME=localhost

UNIX_GROUP_NAME=oinstall

INVENTORY_LOCATION=/data/oracle/inventory

SELECTED_LANGUAGES=en,zh_CN

ORACLE_HOME=/data/oracle/product/11.2.0

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

三、根据相应文件静默安装oracle11g

[oracle@localhost response]cd /home/database/
[oracle@localhost database] 
[oracle@localhost database][oracle@localhost database] ./runInstaller -silent -responseFile /home/oracle/response/db_install.rsp -ignorePrereq
Starting Oracle Universal Installer...

Checking Temp space: must be greater than 120 MB.   Actual 12372 MB    Passed
Checking swap space: must be greater than 150 MB.   Actual 1023 MB    Passed

出现warning不必理会,当出现以successfully Setup Software提示时,代表安装成功

安装完成后,执行以下脚本

[root@localhost ~]# sh /data/oracle/inventory/orainstRoot.sh 
Changing permissions of /data/oracle/inventory.
Adding read,write permissions for group.
Removing read,write,execute permissions for world.

Changing groupname of /data/oracle/inventory to oinstall.
The execution of the script is complete.
[root@localhost ~]# sh /data/oracle/product/11.2.0/root.sh 
Check /data/oracle/product/11.2.0/install/root_localhost.localdomain_2021-11-24_22-18-00.log for the output of root script
[root@localhost ~]# 

四、静默方式配置监听

使用oracle用户登录安装

[oracle@localhost ~]$ netca /silent /responseFile /home/oracle/response/netca.rsp

成功运行后,在/data/oracle/product/11.2.0/network/admin目录下生成listener.ora和sqlnet.ora

修改监听文件listener.ora

# listener.ora Network Configuration File: /data/oracle/product/11.2.0/network/admin/listener.ora

# Generated by Oracle configuration tools.

LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.230.128)(PORT = 1521))
) 
)

SID_LIST_LISTENER= 

(SID_LIST= 

(SID_DESC= 

(GLOBAL_DBNAME=orcl)

(SID_NAME=orcl)

(ORACLE_HOME=/data/oracle/product/11.2.0)

(PRESPAWN_MAX=20)

(PRESPAWN_LIST=

(PRESPAWN_DESC=(PROTOCOL=tcp)(POOL_SIZE=2)(TIMEOUT=1))

)

)

)

ADR_BASE_LISTENER = /data/oracle

yum安装netstat软件,软件包是在net-tools中

通过netstat命令可以查看1521端口正在监听

[root@localhost ~]# yum install net-tools

[root@localhost ~]# netstat -tnulp | grep 1521
tcp6       0      0 :::1521                 :::*                    LISTEN      14704/tnslsnr       

五、以静默方式建立新库,同时也建立一个对应的实例

以oracle用户登录,再次进去响应文件夹

[oracle@localhost ~]$ vim /home/oracle//response/dbca.rsp 

设置以下参数:

GDBNAME= “orcl”

SID =” orcl” #自己设置一个数据库实例名

SYSPASSWORD= “ 123”

SYSTEMPASSWORD= “123”

SYSMANPASSWORD= “ 1237”

DBSNMPPASSWORD= “ 123” #自己设置的密码

DATAFILEDESTINATION=/data/oracle/oradata

RECOVERYAREADESTINATION=/data/oracle/fast_recovery_area

CHARACTERSET= “ZHS16GBK”

TOTALMEMORY= “819”

进行静默配置

[oracle@localhost ~]$ dbca -silent -responseFile /home/oracle/response/dbca.rsp

注意:监听文件的格式一定要正确,比如空格、对齐等,否则监听无法启动

[oracle@localhost ~]lsnrctl start   启动监听
[oracle@localhost ~] lsnrctl stop    停止监听
[oracle@localhost ~]lsnrctl status  查看监听状态

登录数据库

[oracle@localhost ~] sqlplus / as sysdba

SQL*Plus: Release 11.2.0.1.0 Production on Wed Nov 24 23:07:21 2021

Copyright (c) 1982, 2009, Oracle.  All rights reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> 

六、设置oracle开机自启动

1.>修改/data/oracle/product/11.2.0/bin/dbstart

[oracle@localhost ~]vim /data/oracle/product/11.2.0/bin/dbstart 
将ORACLE_HOME_LISTNER=1修改为ORACLE_HOME_LISTNER=ORACLE_HOME(大约在12%行左右)

2.>修改/data/oracle/product/11.2.0/bin/dbshut

[oracle@localhost ~] vim /data/oracle/product/11.2.0/bin/dbshut 
将ORACLE_HOME_LISTNER=1修改为ORACLE_HOME_LISTNER=ORACLE_HOME(大约12%左右)

3>修改/etc/oratab文件

[oracle@localhost ~]vim /etc/oratab 
将orcl:/data/oracle/product/11.2.0:N中最后的N改为Y,成为orcl:/data/oracle/product/11.2.0:Y

4>输入命令dbshut和dbstart测试
4.1 测试dbshut,监听停止

[oracle@localhost ~] dbshut
Processing Database instance "orcl": log file /data/oracle/product/11.2.0/shutdown.log
[oracle@localhost ~]lsnrctl status

LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 24-NOV-2021 23:22:28

Copyright (c) 1991, 2009, Oracle.  All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521)))
TNS-12541: TNS:no listener
 TNS-12560: TNS:protocol adapter error
  TNS-00511: No listener
   Linux Error: 2: No such file or directory
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.230.128)(PORT=1521)))
TNS-12541: TNS:no listener
 TNS-12560: TNS:protocol adapter error
  TNS-00511: No listener
   Linux Error: 111: Connection refused

4.2测试dbstart:监听启动

[oracle@localhost ~] dbstart
Processing Database instance "orcl": log file /data/oracle/product/11.2.0/startup.log
^[[A^[[A[oracle@localhost ~]lsnrctl status

LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 24-NOV-2021 23:24:11

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                24-NOV-2021 23:24:01
Uptime                    0 days 0 hr. 0 min. 9 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /data/oracle/product/11.2.0/network/admin/listener.ora
Listener Log File         /data/oracle/diag/tnslsnr/localhost/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.230.128)(PORT=1521)))
Services Summary...
Service "orcl" has 1 instance(s).
  Instance "orcl", status UNKNOWN, has 3 handler(s) for this service...
The command completed successfully

5.配置rc.local (root用户执行)

[root@localhost ~]# vim /etc/rc.d/rc.local 

# that this script will be executed during boot.

touch /var/lock/subsys/local
su - oracle -lc "/data/oracle/product/11.2.0/bin/dbstartORACLE_HOME"
#加上这个语句

最后运行以下语句授权

[root@localhost ~]# chmod 777 /etc/rc.d/rc.local

至此,Oracle随Linux自动启动设置完毕!

https://blog.csdn.net/m0_53166211/article/details/121524069

  • 我的微信
  • 这是我的微信扫一扫
  • weinxin
  • 我的微信公众号
  • 我的微信公众号扫一扫
  • weinxin
avatar

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: