oracle安装脚本

#!/bin/bash
echo "此脚本在CentOS7.5上测试"
echo "CentOS7.5是最小化安装"
echo "运行脚本前先yum -y update;yum -y groupinstall \"Development tools\""
echo "运行脚本前先将linux.x64_11gR2_database_1of2.zip和linux.x64_11gR2_database_2of2.zip下载后上传到/tmp目录下"
read -p "是否继续?" y
[ "$y" != "y" ]&&exit 1
. /etc/rc.d/init.d/functions
#FreeMem=`free -m|grep 'Mem'|awk '{print $4}'|grep -o '[0-9]*'`
FreeSwp=`free -m|grep 'Swap'|awk '{print $4}'|grep -o '[0-9]*'`
#[ $FreeMem -gt 512 ]&&action "FreeMem  :"$FreeMem"M"  /bin/true||action "FreeMem  :"$FreeMem"M"  /bin/false||exit 1
[ $FreeSwp -gt 1024 ]&&action "FreeSwap :"$FreeSwp"M"  /bin/true||action "FreeSwap :"$FreeSwp"M"  /bin/false||exit 1
exit 99
sleep 5
echo "`hostname -I|awk '{print $1}'` `hostname`" >> /etc/hosts;

grep "=disabled" /etc/selinux/config >/dev/null 2>&1;
[ $? -ne 0 ]&&sed -i "s/`grep ^SELINUX= \/etc\/selinux\/config`/SELINUX=disabled/" /etc/selinux/config;

systemctl stop firewalld;
systemctl disable firewalld;

yum -y install gcc make binutils gcc-c++ compat-libstdc++-33 elfutils-libelf-devel elfutils-libelf-devel-static elfutils-libelf-devel ksh libaio libaio-devel numactl-devel sysstat unixODBC unixODBC-devel pcre-devel libXp.i686 libXp*;

groupadd oinstall;
groupadd dba;
useradd oracle -g oinstall -G dba;
echo 0|passwd --stdin oracle;

cp /etc/sysctl.conf /etc/sysctl.conf.ori;
cat >>/etc/sysctl.conf< io-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
EOF

sysctl -p;

cp /etc/security/limits.conf /etc/security/limits.conf.ori
cat >> /etc/security/limits.conf < oracle           soft    nproc           2047
oracle           hard    nproc           16384
oracle           soft    nofile          1024
oracle           hard    nofile          65536
oracle           soft    stack           10240
EOF

cp /etc/pam.d/login /etc/pam.d/login.ori;
cat >> /etc/pam.d/login << EOF
session  required   /lib64/security/pam_limits.so
session  required   pam_limits.so
EOF

cp /etc/profile /etc/profile.ori;
cat >> /etc/profile << EOF
if [ \$USER = "oracle" ]; then
      if [ \$SHELL = "/bin/ksh" ]; then
       ulimit -p 16384
       ulimit -n 65536
      else
       ulimit -u 16384 -n 65536
      fi
fi
EOF

mkdir -p /u01/app/oracle/product/11.2.0;
mkdir /u01/app/oracle/oradata;
mkdir /u01/app/oracle/inventory;
mkdir /u01/app/oracle/fast_recovery_area;
chown -R oracle:oinstall /u01/app/oracle;
chmod -R 775 /u01/app/oracle;

cd /tmp;
[ ! -d database ]&&unzip linux.x64_11gR2_database_1of2.zip && unzip linux.x64_11gR2_database_2of2.zip;

cat >> /home/oracle/.bash_profile < ORACLE_BASE=/u01/app/oracle
ORACLE_HOME=\$ORACLE_BASE/product/11.2.0
ORACLE_SID=orcl
PATH=\$PATH:\$ORACLE_HOME/bin
export ORACLE_BASE ORACLE_HOME ORACLE_SID PATH
EOF

cd /tmp/database/response/;
cp db_install.rsp db_install.rsp.ori;

sed -i 's/oracle.install.option=/oracle.install.option=INSTALL_DB_SWONLY/' db_install.rsp;
sed -i 's/ORACLE_HOSTNAME=/ORACLE_HOSTNAME=r/' db_install.rsp;
sed -i 's/UNIX_GROUP_NAME=/UNIX_GROUP_NAME=oinstall/' db_install.rsp;
sed -i 's/INVENTORY_LOCATION=/INVENTORY_LOCATION=\/u01\/app\/oracle\/inventory/' db_install.rsp;
sed -i 's/SELECTED_LANGUAGES=/SELECTED_LANGUAGES=en,zh_CN/' db_install.rsp;
sed -i 's/ORACLE_HOME=/ORACLE_HOME=\/u01\/app\/oracle\/product\/11.2.0/' db_install.rsp;
sed -i 's/ORACLE_BASE=/ORACLE_BASE=\/u01\/app\/oracle/' db_install.rsp;
sed -i 's/oracle.install.db.InstallEdition=/oracle.install.db.InstallEdition=EE/' db_install.rsp;
sed -i 's/oracle.install.db.DBA_GROUP=/oracle.install.db.DBA_GROUP=dba/' db_install.rsp;
sed -i 's/oracle.install.db.OPER_GROUP=/oracle.install.db.OPER_GROUP=dba/' db_install.rsp;
sed -i 's/DECLINE_SECURITY_UPDATES=/DECLINE_SECURITY_UPDATES=true/' db_install.rsp;

su -l - oracle -c "cd /tmp/database;./runInstaller -silent -ignorePrereq -ignoreSysPrereqs -responseFile /tmp/database/response/db_install.rsp;";

read;
sleep 0;
    
sh /u01/app/oracle/inventory/orainstRoot.sh;
sh /u01/app/oracle/product/11.2.0/root.sh;

su -l - oracle -c "export DISPLAY=localhost:0.0;netca -silent -responseFile /tmp/database/response/netca.rsp";

sed -i 's/GDBNAME = "orcl11g.us.oracle.com"/GDBNAME = "orcl"/' /tmp/database/response/dbca.rsp;
sed -i 's/SID = "orcl11g"/SID = "orcl"/' /tmp/database/response/dbca.rsp;
sed -i 's/#SYSPASSWORD = "password"/SYSPASSWORD = "oracle"/' /tmp/database/response/dbca.rsp;
sed -i 's/#SYSTEMPASSWORD = "password"/SYSTEMPASSWORD = "oracle"/' /tmp/database/response/dbca.rsp;
sed -i 's/#SYSMANPASSWORD = "password"/SYSMANPASSWORD = "oracle"/' /tmp/database/response/dbca.rsp;
sed -i 's/#DBSNMPPASSWORD = "password"/DBSNMPPASSWORD = "oracle"/' /tmp/database/response/dbca.rsp;
sed -i 's/#DATAFILEDESTINATION =/DATAFILEDESTINATION =\/u01\/app\/oracle\/oradata/' /tmp/database/response/dbca.rsp;
sed -i 's/#RECOVERYAREADESTINATION=/RECOVERYAREADESTINATION=\/u01\/app\/oracle\/fast_recovery_area/' /tmp/database/response/dbca.rsp;
sed -i 's/#CHARACTERSET = "US7ASCII"/CHARACTERSET = "ZHS16GBK"/' /tmp/database/response/dbca.rsp;
sed -i 's/#TOTALMEMORY = "800"/TOTALMEMORY = "1638"/' /tmp/database/response/dbca.rsp;
cd /tmp;
rpm -ivh rlwrap-0.42-1.1.x86_64.rpm;
su -l - oracle -c 'echo alias sqlplus=\"rlwrap sqlplus\" >>.bash_profile;. .bash_profile';
su -l - oracle -c "dbca -silent -responseFile /tmp/database/response/dbca.rsp;lsnrctl status;sqlplus / as sysdba;"
 

你可能感兴趣的:(数据库)