CentOS 7.5静默安装Oracle 11g

导读 现在linux系统越来越被大家普及,但是linux一般没有桌面想要部署oralce难度很大,今天来给大家介绍一下linux环境部署oracle 11g

CentOS 7.5静默安装Oracle 11g

1.安装前环境准备
1.1.配置本地yum源
#因公司内网环境,没有互联网,所以需要配置本地yum源,安装所需依赖包等。
#挂载ios镜像centos7.5-1804
[root@oracle ~]#mount /dev/cdrom /mnt

#备份原配置文件
[root@oracle ~]#cd /etc/yum.repos.d/
[root@oracle ~]#mkdir bak
[root@oracle ~]#mv * bak

#创建yum配置文件
[root@oracle ~]#vi /etc/yum.repos.d/local.repo 
#添加以下内容
[local]
name=local
baseurl=file:///mnt
gpgcheck=0
enabled=1

#清空yum所有源信息
[root@oracle ~]#yum clean all

#查看本地源的所有软件
[root@oracle ~]#yum list
1.2上传解压oracle 11g安装包
#将下载的linux.x64_11gR2_database_1of2.zip和linux.x64_11gR2_database_2of2.zip解压到/usr/local/apps/oracle目录
[root@oracle ~]# mkdir -p /usr/local/apps/oracle
[root@oracle ~]# cd /usr/local/apps/oracle
[root@oracle oracle]# unzip p13390677_112040_Linux-x86-64_1of7.zip && unzip p13390677_112040_Linux-x86-64_2of7.zip

#没有安装unzip命令工具的安装一下
[root@oracle ~]# yum install unzip –y

#解压后会产生一个database目录,即/usr/local/apps/oracle/database,目录里面是oracle11g企业版的安装文件
1.3.给本机服务IP地址作个映射
#添加本机IP地址和主机名
[root@oracle oracle]# vim /etc/hosts
10.0.0.10 oracle
1.4.关闭selinux
#修改SELINUX=disabled
[root@oracle ~]#vi /etc/selinux/config
SELINUX=disabled

[root@oracle ~]#setenforce 0
setenforce: SELinux is disabled
1.5.关闭防火墙
[root@oracle ~]#service iptables stop
[root@oracle ~]#systemctl stop firewalld
[root@oracle ~]#systemctl disable firewalld
1.6.安装Oracle 11g依赖包
[root@oracle ~]#yum install gcc make  ksh libaio libaio-devel numactl-devel sysstat unixODBC unixODBC-devel pcre-devel –y
1.7.添加安装用户和用户组
#创建用户组
[root@oracle ~]#groupadd oinstall 
[root@oracle ~]#groupadd dba 

#创建oracle用户并指定用户组
[root@oracle ~]#useradd -g oinstall -G dba oracle 

#为oracle用户设置密码
[root@oracle ~]#passwd oracle

#查看用户信息
[root@oracle ~]#id oracle       
uid=1001(oracle) gid=1001(oinstall) 组=1001(oinstall),1002(dba)
#如显示以上类似信息则表示添加用户和用户组成功
1.8.修改内核参数
[root@oracle ~]#vi /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 
#其中shmmax是单个共享内存段的最大值,一般设置为本机物理内存的一半,单位为byte,可根据自己的实际情况做相应调整 

#使新内核参数生效 
[root@oracle ~]#sysctl –p
1.9.修改用户的限制文件
[root@oracle ~]#vi /etc/security/limits.conf 
#添加以下内容 
oracle soft nproc 2047 
oracle hard nproc 16384 
oracle soft nofile 1024 
oracle hard nofile 65536 
oracle soft stack 10240
1.10.修改/etc/pam.d/login文件
[root@oracle ~]#vi /etc/pam.d/login
#添加以下内容
session  required   /lib64/security/pam_limits.so
session  required   pam_limits.so
1.11.修改/etc/profile文件
[root@oracle ~]#vi /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@oracle ~]#source /etc/profile
1.12.创建安装目录和设置文件权限
[root@oracle ~]#mkdir -p /usr/local/apps/oracle/product/11.2.0
[root@oracle ~]#mkdir /usr/local/apps/oracle/oradata
[root@oracle ~]#mkdir /usr/local/apps/oracle/inventory
[root@oracle ~]#mkdir /usr/local/apps/oracle/fast_recovery_area
[root@oracle ~]#chown -R oracle:oinstall /usr/local/apps/oracle
[root@oracle ~]#chmod -R 775 /usr/local/apps/oracle
1.13.设置oracle用户环境变量
[root@oracle ~]#su - oracle
#此处注意,切换用户时切记要加"-",加-会拥有目标用户的环境变量,不加"-"则没有,详细的可自行网上搜索找解答

[oracle@oracle ~]$vi .bash_profile
#添加如下内容
ORACLE_BASE=/usr/local/apps/oracle
ORACLE_HOME=$ORACLE_BASE/product/11.2.0
ORACLE_SID=orcl
PATH=$PATH:$ORACLE_HOME/bin
export ORACLE_BASE
export ORACLE_HOME
export ORACLE_SID
export PATH

#使配置生效
[oracle@oracle ~]$source .bash_profile
1.14.编辑静默安装响应文件
[oracle@oracle ~]$cp -R /usr/local/apps/oracle/database/response/ /home/oracle
[oracle@oracle ~]$cd /home/oracle/response
[oracle@oracle ~]$vi db_install.rsp
#需要设置的选项如下,注意只修改以下设置,其他设置不变,否则会报错。
oracle.install.option=INSTALL_DB_SWONLY
ORACLE_HOSTNAME=oracle
UNIX_GROUP_NAME=oinstall
INVENTORY_LOCATION=/usr/local/apps/oracle/inventory
SELECTED_LANGUAGES=en,zh_CN
ORACLE_HOME=/usr/local/apps/oracle/product/11.2.0
ORACLE_BASE=/usr/local/apps/oracle
oracle.install.db.InstallEdition=EE
oracle.install.db.DBA_GROUP=dba
oracle.install.db.OPER_GROUP=dba
DECLINE_SECURITY_UPDATES=true
2根据响应文件静默安装Oracle11g Enterprise Edition企业版
[oracle@oracle ~]$cd /usr/local/apps/oracle/database
[oracle@oracle ~]$./runInstaller -silent -responseFile /home/oracle/response/db_install.rsp -ignorePrereq
#Oracle开始在后台静默安装,如果提示Successfully则表示安装成功

#按照要求执行脚本,打开终端,以root用户登录,执行脚本
[root@oracle ~]#/usr/local/apps/oracle/inventory/orainstRoot.sh
[root@oracle ~]#/usr/local/apps/oracle/product/11.2.0/root.sh
3.以静默方式配置监听
#以oracle用户登录,执行
[oracle@oracle ~]$netca /silent /responsefile /home/oracle/response/netca.rsp

#通过netstat命令查看1521端口是否在监听中
[oracle@oracle ~]$ss -tnulp | grep 1521
4.以静默方式建立新库,同时也建立一个对应的实例
4.1.修改dbca.rsp配置文件
[oracle@oracle ~]$vim /home/oracle/response/dbca.rsp
#设置以下参数
[CREATEDATABASE]
GDBNAME = "orcl"
SID = "orcl"
SYSPASSWORD = "123456"
SYSTEMPASSWORD = "123456"
SYSMANPASSWORD = "123456"
DBSNMPPASSWORD = "123456"
DATAFILEDESTINATION =/usr/local/apps/oracle/oradata
RECOVERYAREADESTINATION=/usr/local/apps/oracle/fast_recovery_area
CHARACTERSET = "AL32UTF8"
TOTALMEMORY = "800"
#其中TOTALMEMORY = "800"为800MB,一般设置为物理内存的80%
4.2.进行静默配置创建实例
[oracle@oracle ~]$dbca -silent -responseFile /home/oracle/response/dbca.rsp

#建库后进行实例进程检查
[oracle@oracle ~]$ps -ef | grep ora_ | grep -v grep

#查看监听状态
[oracle@oracle ~]$lsnrctl status

#登录查看实例状态
[oracle@oracle ~]$sqlplus / as sysdba
SQL> select status from v$instance;
#如显示
STATUS
------------
OPEN
#则表示实例是启动状态

#查看数据库编码
SQL> select userenv('language') from dual;

#查看数据库版本
SQL> select * from v$version;
5.Oracle开机自启动设置
5.1.修改启动脚本文件
#修改/usr/local/apps/oracle/product/11.2.0/bin/dbstart
[oracle@oracle ~]$vi /usr/local/apps/oracle/product/11.2.0/bin/dbstart
#将ORACLE_HOME_LISTNER=$1修改为ORACLE_HOME_LISTNER=$ORACLE_HOME

#修改/usr/local/apps/oracle/product/11.2.0/bin/dbshut
[oracle@oracle ~]$vi /usr/local/apps/oracle/product/11.2.0/bin/dbshut
#将ORACLE_HOME_LISTNER=$1修改为ORACLE_HOME_LISTNER=$ORACLE_HOME
5.2.修改/etc/oratab文件
[oracle@oracle ~]$vi /etc/oratab
#将orcl:/usr/local/apps/oracle/product/11.2.0:N中最后的N改为Y,成为orcl:/usr/local/apps/oracle/product/11.2.0:Y

#输入dbshut和dbstart测试
[oracle@oracle ~]$dbshut
#Oracle监听停止,进程消失
[oracle@oracle ~]$dbstart
#Oracle监听启动,进程启动
5.3.切换到root账户建立自启动脚本
[oracle@oracle ~]$su -
[root@oracle ~]#vim /etc/rc.d/init.d/oracle
#添加以下内容(有些值如ORA_HOME和ORA_USER等根据实际情况可以修改):
#!/bin/sh
# chkconfig: 35 80 10
# description: Oracle auto start-stop script.
#
# Set ORA_HOME to be equivalent to the $ORACLE_HOME
# from which you wish to execute dbstart and dbshut;
#
# Set ORA_OWNER to the user id of the owner of the
# Oracle database in ORA_HOME.
ORA_HOME=/usr/local/apps/oracle/product/11.2.0
ORA_OWNER=oracle
if [ ! -f $ORA_HOME/bin/dbstart ]
then
    echo "Oracle startup: cannot start"
    exit
fi
case "$1" in
'start')
# Start the Oracle databases:
echo "Starting Oracle Databases ... "
echo "-------------------------------------------------" >> /var/log/oracle
date +" %T %a %D : Starting Oracle Databases as part of system up." >> /var/log/oracle
echo "-------------------------------------------------" >> /var/log/oracle
su - $ORA_OWNER -c "$ORA_HOME/bin/dbstart" >>/var/log/oracle
echo "Done"

# Start the Listener:
echo "Starting Oracle Listeners ... "
echo "-------------------------------------------------" >> /var/log/oracle
date +" %T %a %D : Starting Oracle Listeners as part of system up." >> /var/log/oracle
echo "-------------------------------------------------" >> /var/log/oracle
su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl start" >>/var/log/oracle
echo "Done."
echo "-------------------------------------------------" >> /var/log/oracle
date +" %T %a %D : Finished." >> /var/log/oracle
echo "-------------------------------------------------" >> /var/log/oracle
touch /var/lock/subsys/oracle
;;

'stop')
# Stop the Oracle Listener:
echo "Stoping Oracle Listeners ... "
echo "-------------------------------------------------" >> /var/log/oracle
date +" %T %a %D : Stoping Oracle Listener as part of system down." >> /var/log/oracle
echo "-------------------------------------------------" >> /var/log/oracle
su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl stop" >>/var/log/oracle
echo "Done."
rm -f /var/lock/subsys/oracle

# Stop the Oracle Database:
echo "Stoping Oracle Databases ... "
echo "-------------------------------------------------" >> /var/log/oracle
date +" %T %a %D : Stoping Oracle Databases as part of system down." >> /var/log/oracle
echo "-------------------------------------------------" >> /var/log/oracle
su - $ORA_OWNER -c "$ORA_HOME/bin/dbshut" >>/var/log/oracle
echo "Done."
echo ""
echo "-------------------------------------------------" >> /var/log/oracle
date +" %T %a %D : Finished." >> /var/log/oracle
echo "-------------------------------------------------" >> /var/log/oracle
;;

'restart')
$0 stop
$0 start
;;
esac
5.4.修改/etc/init.d/oracle服务文件权限
[root@oracle ~]#chmod 755 /etc/init.d/oracle
5.5.添加开机自启服务
[root@oracle ~]#chkconfig oracle on
5.6.需要在关机或重启机器之前停止数据库,做一下操作
#关机
[root@oracle ~]ln -s /etc/init.d/oracle /etc/rc0.d/K01oracle 

#重启
[root@oracle ~]ln -s /etc/init.d/oracle /etc/rc6.d/K01oracle  

#进行测试
[root@oracle ~]# service oracle start       #启动oracle
[root@oracle ~]# service oracle stop        #关闭oracle
5.7.重启查看Oracle监听和实例进程是否均能自动启动
[root@oracle ~]#reboot

原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/125753.html

(0)
上一篇 2021年8月29日
下一篇 2021年8月29日

相关推荐

发表回复

登录后才能评论