话不多说,直接上脚本,此脚本适用于oracle 11g,以静默的方式安装,其他版本数据库大家可以根据自己实际情况进行修改。
直接执行1.sh
#! /bin/bash
#一键安装oracle数据库
#修改主机名
hostnamectl set-hostname myoracledemo
#添加主机名与IP对应记录
cat <<EOF >/etc/hosts
192.168.59.138 myoracledemo
EOF
#关闭Selinux
sed -i "s/SELINUX=enforcing/SELINUX=disabled/" /etc/selinux/config
setenforce 0
#添加yum源
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
#添加用户组及用户
groupadd oinstall
groupadd dba
useradd -g oinstall -G dba oracle
echo oracle | passwd --stdin oracle
chmod 644 /etc/sysctl.conf
#修改环境变量
cat <<EOF >>/etc/sysctl.conf
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
EOF
sysctl -p
chmod 644 /etc/security/limits.conf
cat <<EOF >>/etc/security/limits.conf
oracle soft nproc 2047
oracle hard nproc 16384
oracle soft nofile 1024
oracle hard nofile 65536
oracle soft stack 10240
oracle hard stack 10240
EOF
chmod 644 /etc/pam.d/login
cat <<EOF >>/etc/pam.d/login
session required /lib64/security/pam_limits.so
session required pam_limits.so
EOF
chmod 644 /etc/profile
cat <<EOF >>/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
EOF
source /etc/profile
mkdir -p /u01/app/
chown -R oracle:oinstall /u01/app/
chmod -R 775 /u01/app/
mkdir -p /usr/local/src
cd /usr/local/src
#解压oracle安装包
unzip p13390677_112040_Linux-x86-64_1of7.zip
unzip p13390677_112040_Linux-x86-64_2of7.zip
mkdir /home/oracle/etc
chown -R oracle.oinstall /home/oracle/etc
cp /usr/local/src/database/response/* /home/oracle/etc/
chmod 777 /home/oracle/etc/*.rsp
chown -R oracle:oinstall /home/oracle/etc/
. /etc/profile
su - oracle -s /bin/bash /usr/local/src/shell.sh
. /etc/profile
下面是shell.sh的内容
需要编辑db_install.rsp,都是默认内容,大家自行修改。
然后执行db_install.rsp
cd /usr/local/src/database/
./runInstaller -silent -responseFile /home/oracle/etc/db_install.rsp
sleep 3000
/u01/app/oraInventory/orainstRoot.sh
/u01/app/oracle/product/11.2.0/db_1/root.sh
cat <<EOF >>~/.bash_profile
#for oracle
export ORACLE_BASE=/u01/app/oracle
export ORACLE_SID=orcl11g
export ORACLE_PID=ora11g
#export NLS_LANG=AMERICAN_AMERICA.AL32UTF8
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/usr/lib
export ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1
export PATH=$PATH:$ORACLE_HOME/bin
export LANG="zh_CN.UTF-8"
export NLS_LANG="SIMPLIFIED CHINESE_CHINA.AL32UTF8"
export NLS_DATE_FORMAT='yyyy-mm-dd hh24:mi:ss'
EOF
####使配置文件生效###
source ~/.bash_profile
echo $ORACLE_HOME
/u01/app/oracle/product/11.2.0/db_1/bin/netca /silent /responsefile /home/oracle/etc/netca.rsp
chmod 644 /home/oracle/etc/dbca.rsp
cat <<EOF >>/home/oracle/etc/dbca.rsp
[GENERAL]
RESPONSEFILE_VERSION = "11.2.0"
OPERATION_TYPE = "createDatabase"
[CREATEDATABASE]
GDBNAME = "dbsrv2"
SID = "dbsrv2"
TEMPLATENAME = "General_Purpose.dbc"
CHARACTERSET = "AL32UTF8"
EOF
sleep 3000
/u01/app/oracle/product/11.2.0/db_1/bin/dbca -silent -responseFile /home/oracle/etc/dbca.rsp
以下是oracle数据库各个版本的依赖包、补丁包和安装包,大家有需要的可以下载
注意:整个脚本在执行过程,需要二次输入管理员的密码,其余的等执行完脚本即可,此脚本的缺陷是得重新配置环境变量,如安装成功后,执行sqlplus,需要绝对路径。当然脚本还有很多不足之处,还需继续完善。