Linux静默安装Oracle11g


title: Linux静默安装Oracle11g
categories: 数据库
tags:
- Oracle
timezone: Asia/Shanghai
date: 2019-01-06

环境

以下Linux发行版验证通过
REHL6.10 x86_64
REHL7.5 x86_64
CentOS7.5
Oracle Linux 6.10 x86_64
Oracle Linux 7.5 x86_64

使用Oracle版本
Oracle 11g 11.2.0.4

注意

Oracle单机版服务器重启以后监听和实例不会自动启动,需要手动开启。

参考文献

https://www.oracle.com/technetwork/cn/articles/servers-storage-admin/ginnydbinstallonlinux6-1845247-zhs.html

第一步:修改IP为固定IP地址

vim /etc/sysconfig/network-scripts/ifcfg-eno16777736

第二步:配置计算机名

1.redhat7

hostnamectl set-hostname test.com
echo "192.168.0.63 `hostname`" >>/etc/hosts

systemctl restart network

2.redhat6

hostname test.com
sed -i "/HOSTNAME=/c HOSTNAME=`hostname`" /etc/sysconfig/network
echo "192.168.0.63 `hostname`" >>/etc/hosts

第三步:关闭防火墙、修改内核参数、创建用户和组、修改oracle变量、自动使用本地yum安装依赖包

1.有几个包是在RedHat7安装光盘里提供的,需要单独安装
rpm -ivh compat-libstdc++-33-3.2.3-72.el7.x86_64.rpm
rpm -ivh pdksh-5.2.14-37.el5_8.1.x86_64.rpm

compat-libstdc+±33 for CentOS 7.5.1804 for x86_64 https://pan.baidu.com/s/1SJUuIFMEA_j9ZFNDxvMAIQ

compat-libstdc+±33 for CentOS 6.10 for x86_64 https://pan.baidu.com/s/1NHIwJ73_jkixH9Me97mmGg

pdksh-5.2.14-37.el5_8.1.x86_64.rpm https://pan.baidu.com/s/1cK0AZlMlw1A3rrP_ClRDNA

2.执行以下脚本

可以重复执行,已做判断。直接复制到sehll执行即可,建议创建shell脚本后使用

以下脚本已经针对linux6和linux7命令的不同做了判断区分,可以放心执行

################################################## 关闭防火墙和SELinux(OK)

setenforce 0
sed -i -r "/^SELINUX=/c SELINUX=disabled" /etc/selinux/config
which systemctl && systemctl stop firewalld
which systemctl && systemctl disable firewalld
which systemctl && systemctl stop iptables || service iptables stop
which systemctl && systemctl disable iptables || chkconfig iptables off

################################################## 配置内核参数和资源限制(OK)

# 修改/etc/sysctl.conf(修改配置文件之前会自动备份)(OK)
/bin/grep 666666 /etc/sysctl.conf && /bin/cp /etc/sysctl.conf.666666 /etc/sysctl.conf || /bin/cp /etc/sysctl.conf /etc/sysctl.conf.666666
cat <<EOF >>/etc/sysctl.conf
#add by 666666
fs.aio-max-nr = 1048576
fs.file-max = 6815744
kernel.shmall = 2097152
# kernel.shmmax 最低:536870912
# kernel.shmmax 最大值:比物理内存小1个字节的值
# kernel.shmmax 推荐:超过一半的物理内存
kernel.shmmax = 956039168
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
EOF

# 输入以下命令使内核参数马上生效(OK)
/sbin/sysctl -p

# 配置limits.conf文件(修改配置文件之前会自动备份)(OK)
/bin/grep 666666 /etc/security/limits.conf && /bin/cp /etc/security/limits.conf.666666 /etc/security/limits.conf || /bin/cp /etc/security/limits.conf /etc/security/limits.conf.666666
cat <<EOF >>/etc/security/limits.conf
#add by 666666
oracle soft nproc 2047
oracle hard nproc 16384
oracle soft nofile 1024
oracle hard nofile 65536
oracle soft stack 10240
EOF

# 修改/etc/pam.d/login(修改配置文件之前会自动备份)(OK)
/bin/grep 666666 /etc/pam.d/login && /bin/cp /etc/pam.d/login.666666 /etc/pam.d/login || /bin/cp /etc/pam.d/login /etc/pam.d/login.666666
cat <<EOF >>/etc/pam.d/login
#add by 666666
session    required     /lib64/security/pam_limits.so
session    required     pam_limits.so
EOF

# 修改/etc/profile(修改配置文件之前会自动备份)(OK)
/bin/grep 666666 /etc/profile && /bin/cp /etc/profile.666666 /etc/profile || /bin/cp /etc/profile /etc/profile.666666
cat <<EOF >>/etc/profile
#add by 666666
if [ \$USER = "oracle" ]; 
then
	if [ \$SHELL = "/bin/ksh" ]; 
	then
        ulimit -p 16384
        ulimit -n 65536
	else
	ulimit -u 16384 -n 65536
	fi
fi
EOF

# 使配置生效
source /etc/profile

################################################## 创建所需的组和用户(OK)
# 原始语句
# /usr/sbin/groupadd dba
# /usr/sbin/groupadd oper
# /usr/sbin/groupadd oinstall
# /usr/sbin/useradd -g oinstall -G dba oracle
# 优化以后
/bin/grep "^dba" /etc/group && echo "dba组已存在" || /usr/sbin/groupadd dba
/bin/grep "^oper" /etc/group && echo "dba组已存在" || /usr/sbin/groupadd oper
/bin/grep "^oinstall" /etc/group && echo "oinstall组已存在" || /usr/sbin/groupadd oinstall
/bin/grep "^oracle:" /etc/passwd && echo "oracle账户已存在" || /usr/sbin/useradd -g oinstall -G dba oracle
# 检查oracle用户的的所属组是否正确并修正
GROUPIDTemp=`cat /etc/group | grep oinstall | awk -F ":" '{print $3}'`
id oracle | grep gid=${GROUPIDTemp} && echo "oracle主组检查通过" || usermod --gid ${GROUPIDTemp} oracle
unset GROUPIDTemp
id oracle | grep dba && echo "oracle附属组检查通过" || usermod -aG dba oracle
################################################## 创建所需目录(可根据实际情况更改)(OK)

mkdir -p /u01/app/oracle
mkdir -p /u01/app/oracle/data
mkdir -p /u01/app/oracle/product/11.2.0
chown -R oracle:oinstall /u01/app
chmod -R 775 /u01/app

################################################## 修改oracle用户变量(可根据实际情况更改,对应上边建立目录)(OK)

/bin/grep 666666 /home/oracle/.bash_profile && /bin/cp /home/oracle/.bash_profile.666666 /home/oracle/.bash_profile || /bin/cp /home/oracle/.bash_profile /home/oracle/.bash_profile.666666
cat <<EOF >>/home/oracle/.bash_profile
#add by 666666
ORACLE_BASE=/u01/app/oracle
ORACLE_HOME=\$ORACLE_BASE/product/11.2.0
# 数据库实例名
ORACLE_SID=oracledb
PATH=\$PATH:\$ORACLE_HOME/bin
export ORACLE_BASE ORACLE_HOME ORACLE_SID PATH
EOF
################################################## 配置本地yum源并安装依赖包(OK)
mkdir -p /mnt/cdrom
mount /dev/cdrom /mnt/cdrom

cat <<EOF >/etc/yum.repos.d/local.repo
[local]
name=local
baseurl=file:///mnt/cdrom
gpgcheck=0
enabled=1
EOF

yum clean all       #清理本地缓存
yum clean plugins   #清理插件缓存
yum makecache       #构建缓存

yum install -y binutils* \
compat-libcap1* \
compat-libstdc++* \
gcc* \
gcc-c++* \
glibc* \
glibc-devel* \
ksh* \
libaio* \
libaio-devel* \
libgcc* \
libstdc++* \
libstdc++-devel* \
libXi* \
libXtst* \
make* \
sysstat* \
unixODBC* \
unixODBC-devel* \
elfutils-libelf-devel*

# 检查以上修改是否是执行成功
# 
test `id -u` -eq 0 && echo "当前用户是root用户" || echo -e "\033[31m非root用户,可能会有错误,请注意----------Failed\033[0m"
grep SELINUX=disabled /etc/selinux/config && echo "SELinux成功关闭" || echo -e "\033[31mSELinux----------Failed\033[0m"
grep 666666 /etc/sysctl.conf && echo "/etc/sysctl.conf修改成功" || echo -e "\033[31m/etc/sysctl.conf修改失败----------Failed\033[0m"
grep 666666 /etc/security/limits.conf && echo "/etc/security/limits.conf修改成功" || echo -e "\033[31m/etc/security/limits.conf修改失败----------Failed\033[0m"
grep 666666 /etc/pam.d/login && echo "/etc/pam.d/login修改成功" || echo -e "\033[31m/etc/pam.d/login修改失败----------Failed\033[0m"
grep 666666 /etc/profile && echo "/etc/profile修改成功" || echo -e "\033[31m/etc/profile----------Failed\033[0m"
id oracle && echo "oracle账户创建成功" || echo -e "\033[31moracle账户创建失败----------Failed\033[0m"
ls /u01 > /dev/null 2>&1 && echo "oracle安装目录创建成功" || echo -e "\033[31moracle安装目录创建失败----------Failed\033[0m"
grep 666666 /home/oracle/.bash_profile && echo "oracle用户变量修改成功" || echo -e "\033[31moracle用户变量修改失败---------Failed\033[0m"

第四步:静默方式安装Oracle Database(使用oracle用户)

1.修改自动应答文件(在database/response目录)

cd /home/oracle/database/response
cp db_install.rsp db_install.rsp.bak

# 只安装数据库软件 Install database software only
sed -i -r "/^oracle.install.option=/c oracle.install.option=INSTALL_DB_SWONLY" db_install.rsp
# 主机名--------------------重点注意
sed -i -r "/^ORACLE_HOSTNAME=/c ORACLE_HOSTNAME=`hostname`" db_install.rsp
# oraInventory Group Name
sed -i -r "/^UNIX_GROUP_NAME=/c UNIX_GROUP_NAME=oinstall" db_install.rsp
# Inventory Directory
sed -i -r "/^INVENTORY_LOCATION=/c INVENTORY_LOCATION=/u01/app/oraInventory" db_install.rsp
# 语言 Selected Languages----------
sed -i -r "/^SELECTED_LANGUAGES=/c SELECTED_LANGUAGES=en,zh_CN" db_install.rsp
# Software Location
sed -i -r "/^ORACLE_HOME=/c ORACLE_HOME=/u01/app/oracle/product/11.2.0" db_install.rsp
# Oracle Base
sed -i -r "/^ORACLE_BASE=/c ORACLE_BASE=/u01/app/oracle" db_install.rsp
# 数据库版本为企业版 Enterprise Edition
sed -i -r "/^oracle.install.db.InstallEdition=/c oracle.install.db.InstallEdition=EE" db_install.rsp
# Database Administrator(OSDBA) Group
sed -i -r "/^oracle.install.db.DBA_GROUP=/c oracle.install.db.DBA_GROUP=dba" db_install.rsp
# Database Operator(OSOPEF) Group(Optional)
sed -i -r "/^oracle.install.db.OPER_GROUP=/c oracle.install.db.OPER_GROUP=oper" db_install.rsp
# 执行创建的数据库类型为:一般用途(选择"单实例数据库安装"自动修改,默认为空)
sed -i -r "/^oracle.install.db.isRACOneInstall=/c oracle.install.db.isRACOneInstall=false" db_install.rsp
# 执行创建的数据库类型为:一般用途(选择"单实例数据库安装"自动修改,默认为空)
sed -i -r "/^oracle.install.db.config.starterdb.type=/c oracle.install.db.config.starterdb.type=GENERAL_PURPOSE" db_install.rsp
# 不填写Oracle Support凭证 Oracle Support credentials----------
sed -i -r "/^SECURITY_UPDATES_VIA_MYORACLESUPPORT=/c SECURITY_UPDATES_VIA_MYORACLESUPPORT=false" db_install.rsp
# 指定用户是否不想配置安全更新。(=true是跳过更新)----------
sed -i -r "/^DECLINE_SECURITY_UPDATES=/c DECLINE_SECURITY_UPDATES=true" db_install.rsp
# 跳过更新 Skip software updates
sed -i -r "/^oracle.installer.autoupdates.option=/c oracle.installer.autoupdates.option=SKIP_UPDATES" db_install.rsp

2.使用刚才创建的自动应答脚本开始安装数据库

./runInstaller -silent -ignorePrereq -ignoreSysPrereqs -showProgress -responseFile /home/oracle/database/response/db_install.rsp

-silent                     对于无提示模式下的操作, 输入内容可以是一个响应文件, 也可以是命令行变量值对的列表。
-ignorePrereq               忽略运行先决条件检查。
-ignoreSysPrereqs           忽略系统先决条件检查的结果。
-showProgress               用于在控制台上显示安装进度。仅在无提示安装下才支持此选项。
-responseFile <Path>        指定要使用的响应文件和路径。

第五步:静默方式创建数据库(使用oracle用户)

dbca  -silent -createDatabase -templateName General_Purpose.dbc -gdbName oracledb -sid oracledb -sysPassword xiaoliu -systemPassword xiaoliu -characterSet ZHS16GBK 

-silent 静默方式创建数据库
-templateName <默认位置或完整模板路径中现有模板的名称>
-gdbName <全局数据库名>
[-sid <数据库系统标识符>]
[-sysPassword <SYS 用户口令>]
[-systemPassword <SYSTEM 用户口令>]
[-characterSet <数据库的字符集>]
[-nationalCharacterSet  <数据库的国家字符集>]

第六步:静默方式创建监听(使用oracle用户)

监听默认配置文件路径在$ORACLE_HOME/assistants/netca/下

netca -silent -responseFile /u01/app/oracle/product/11.2.0/assistants/netca/netca.rsp

附录:出错1:CentOS7在安装到80%左右的时候出现下边错误提示
Error in invoking target 'agent nmhs' of makefile'/u01/app/oracle/product/11.2.0/db_1/sysman/lib/ins_emagent.mk'.

官方解释

Unpublished bug 19692824 
During installation of Oracle Database or Oracle RAC on OL7, the following linking error may be encountered:
Error in invoking target 'agent nmhs' of makefile '<ORACLE_HOME>/sysman/lib/ins_emagent.mk'. See '<installation log>' for details.

If this error is encountered, the user should select Continue. Then, after the installation has completed, the user must download Patch 19692824 from My Oracle Support and apply it per the instructions included in the patch README. 
官方的解释说是先继续安装,然后再打补丁,这个bug19692824是在创建数据库的时候引发的。如果你在安装
数据库软件的时候就报错,建议使用下面的解决方法。

建议的解决方案

在makefile中添加链接libnnz11库的参数 
修改$ORACLE_HOME/sysman/lib/ins_emagent.mk,找到下面这行

$(MK_EMAGENT_NMECTL)
修改为:
$(MK_EMAGENT_NMECTL) -lnnz11
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值