RAC环境部署自动化shell脚本

下面是一个rac搭建时候的一个环境自动部署脚本,这个脚本可以自动帮你完成安装数据库需要的包,创建oracle,grid用户,并且配置环境变量,已经配置操作系统参数,大部分工作都可以完成,可以根据自己需要修改该脚本。该脚本运行选择(2) ios,指定.iso镜像文件的绝对路径就可以自动部署环境了(.ios文件需要你手动上传到服务器上面)。(该脚本可以根据自己需要来修改)
#!/bin/bash
# This program configure the enviroment for oracle database(version 11.2.0.4 64bit) on your system
# 2013-10-21 zfsoft First release
 
export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
 
#variables
service=oradb
orapwd=oracle
gridpwd=grid
 
rac1=$rac1
rac1priv=$rac1-priv
rac2=$rac2
rac2priv=$rac2-priv
scan=scan

cat >> /etc/hosts <<EOF
10.1.70.158    $rac1
10.1.70.161    $rac1-vip
11.1.1.1       $rac1-priv

10.1.70.159    $rac2
10.1.70.162    $rac2-vip
11.1.1.2       $rac2-priv
10.1.70.163    $scan
EOF
 
isdvd=no
function alert() {
        echo -e "$1"
        exit -1
}
 
echo "*******************************************************************"
echo "                     System environment check                      "
neededPackage="binutils compat-libstdc++-33 compat-libstdc++-296 elfutils-libelf elfutils-libelf-devel gcc gcc-c++ glibc glibc-common glibc-devel glibc-headers libaio libaio-devel libgcc libstdc++ libstdc++-devel make openmotif sysstat unixODBC unixODBC-devel compat-libcap1"
missing=$(rpm -q $neededPackage| grep "not installed")
 
#test -z "$missing" && echo "package check passed" || alert "${missing} \\n please install the package above then rerun this program"
 
if [ -z "$missing" ]; then
        echo "package check passed"
else
        echo -e "${missing} \\n Please insert the os install Disc or upload the iso."
        echo "Where is your operation system installation media?"
        select media in "dvd Disc" "iso" ;do
        if [ "$media" == "dvd Disc" ] || [ "$media" == "iso" ];  then
        break
        fi;
        done
        echo "You have selected $media"
 
        mkdir /mnt/dvd
        if [ "$media" == "dvd Disc" ]; then
                isdvd=yes
                mount /dev/cdrom /mnt/dvd
        else
                read -p "Where is the iso?(in absolute path,e.g., /u01/rhel-server-6.4-x86_64-dvd.iso)" isopath
                mount "$isopath" -o loop /mnt/dvd
        fi;
 
        test $? != 0 && alert "Error occured while mounting the media,please check and try again!"
            
        test -d /etc/yum.repos.d/bak && mv -f /etc/yum.repos.d/*.repo /etc/yum.repos.d/bak || mkdir /etc/yum.repos.d/bak
cat >/etc/yum.repos.d/rhel6.repo<<EOF
[dvd]
name=dvd
baseurl=file:///mnt/dvd
enabled=1
gpgcheck=0
EOF
 
        yum install $neededPackage -y
fi
 
groupadd -g 600 oinstall
groupadd -g 601 asmadmin
groupadd -g 602 asmdba
groupadd -g 603 asmoper
useradd -u 600 -g oinstall -G asmadmin,asmdba,asmoper grid
id grid
 
echo "$gridpwd" | passwd grid --stdin
 
groupadd -g 604 dba
groupadd -g 605 oper
useradd -u 601 -g oinstall -G dba,oper,asmdba oracle
id oracle
echo "$orapwd" | passwd oracle --stdin
 
#[ $? != 0 ] && alert "Error occured where create oracle users,please check"
 
echo "Disable the iptables and selinux"
service iptables stop
chkconfig iptables off
sed -i 's/^SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
 
#modify the size of /dev/shm(default is half of physical memory,11g auto memory management need the /dev/shm greater or equal memory_target) 
[ -f /etc/fstab.bak ] || cp /etc/fstab /etc/fstab.bak
[ -f /etc/rc.d/rc.sysinit.bak ] || cp /etc/rc.d/rc.sysinit /etc/rc.d/rc.sysinit.bak
#num=`cat -n /etc/fstab | grep /dev/shm | awk '{ print $1 }'`
tootalMem=`free -m | grep Mem: |sed 's/^Mem:\s*//'| awk '{print $1}'`
[ $tootalMem -lt 1000 ] && alert "The physical memory is ${tootalMem}M,oracle requires at least 1G" || echo "Your physical memory is ${tootalMem} (in MB)"
num=`grep -n /dev/shm /etc/fstab | awk -F: '{ print $1 }'`
declare -i newSize=$tootalMem*80/100+400 #at least plus 10
sed -i "${num}s/defaults.*/defaults,size=${newSize}M     0 0/" /etc/fstab
 
#num=`cat -n /etc/rc.d/rc.sysinit | grep "mount -f /dev/shm" | awk '{ print $1 }'`
num=`grep -n "mount -f /dev/shm" /etc/rc.d/rc.sysinit | awk -F: '{ print $1 }'`
sed -i "${num}s/mount/#mount/" /etc/rc.d/rc.sysinit
mount -o remount tmpfs
test $? != 0 && alert "Error occured while remounting the tmpfs,please check!!!"
sed -i 's/\-t nonfs,nfs4/\-t tmpfs,nonfs,nfs4/' /etc/rc.d/rc.sysinit
 
cat >>/etc/sysctl.conf<<EOF
#required by oracle
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
#10g is 65536
fs.file-max = 6815744
#10g is 1024 65000
net.ipv4.ip_local_port_range = 9000 65500
net.core.rmem_default = 262144
#10g is 262144
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
#10g is 262144
net.core.wmem_max = 1048576
#no need by 10g 
fs.aio-max-nr = 1048576
EOF
sysctl -p
 
cat >> /etc/security/limits.conf <<EOF
grid soft nproc 2047
grid hard nproc 16384
grid soft nofile 1024
grid hard nofile 65536
oracle soft nproc 2047
oracle hard nproc 16384
oracle soft nofile 1024
oracle hard nofile 65536
EOF
 
#print
chkconfig cups off
chkconfig hplip off
#selinux
chkconfig mcstrans off
chkconfig setroubleshoot off
#bluetooth
chkconfig hidd off
chkconfig bluetooth off
 
chkconfig ip6tables off
chkconfig iptables off
chkconfig sendmail off
chkconfig yum-updatesd off
 
#check the node number
[ $(hostname | grep 1$) ] && nodenum=1 || nodenum=2 && echo number $nodenum node
 
 
sed -i '10,$d' ~grid/.bash_profile
cat >>~grid/.bash_profile<<EOF
export ORACLE_BASE=/u01/app/grid
export ORACLE_HOME=/u01/app/11.2.0/grid
export ORACLE_SID=+ASM$nodenum
export JAVA_HOME=\$ORACLE_HOME/jdk
 
export LD_LIBRARY_PATH=\$ORACLE_HOME/lib:\$ORACLE_HOME/ctx/lib:\$ORACLE_HOME/oracm/lib
export CLASSPATH=\$ORACLE_HOME/JRE:\$ORACLE_HOME/jlib:\$ORACLE_HOME/rdbms/jlib:\$ORACLE_HOME/network/jlib
 
export PATH=\$PATH:\$ORACLE_HOME/bin
EOF
 
sed -i '10,$d' ~oracle/.bash_profile
cat >>~oracle/.bash_profile<<EOF
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=\$ORACLE_BASE/product/11.2.0/db_1
export ORACLE_SID=$service$nodenum
 
export LD_LIBRARY_PATH=\$ORACLE_HOME/lib:\$ORACLE_HOME/oracm/lib:/lib:/usr/lib:/usr/local/lib
export CLASSPATH=\$ORACLE_HOME/JRE:\$ORACLE_HOME/jlib:\$ORACLE/rdbms/jlib:\$ORACLE_HOME/network/jlib
 
export PATH=\$PATH:\$ORACLE_HOME/bin
EOF
 
mkdir -p /u01/app/oracle
mkdir -p /u01/app/grid
mkdir -p /u01/app/11.2.0/grid
chown -R oracle:oinstall /u01
chown -R grid:oinstall /u01/app
chown oracle:oinstall /u01/app/oracle
chown -R grid:oinstall /u01/app/11.2.0/grid
 
[ "$nodenum" == 1 ] && exit
echo "---------------Configure ssh conectivity----------------"
 
cat >/u01/sshUserSetup.sh<<EOF
#!/bin/bash
 
ssh-keygen -f ~/.ssh/id_rsa -N ''
ssh-copy-id $rac1
cp .ssh/id_rsa.pub .ssh/authorized_keys
ssh $rac1 "ssh-keygen -f ~/.ssh/id_rsa -N ''"
ssh $rac1 cat .ssh/id_rsa.pub>>.ssh/authorized_keys
scp .ssh/authorized_keys $rac1:.ssh
ssh $rac1 date;ssh $rac1priv date;ssh $rac2 date;ssh $rac2priv date;
scp .ssh/known_hosts $rac1:.ssh
 
echo -e "Run the following command as the user(you have just executed /u01/sshUserSetup.sh) on rac1 to test ssh conectivity\n ssh $rac1 date;ssh $rac1priv date;ssh $rac2 date;ssh $rac2priv date"
EOF
 
chmod o+x /u01/sshUserSetup.sh
echo  -e "Run the following command as grid and oracle user on rac2 to setup ssh conectivity\n /u01/sshUserSetup.sh"

[root@ASMTEST u01]# chmod 777 en.sh

[root@ASMTEST u01]# ./en.sh 
*******************************************************************
                     System environment check                      
package compat-libstdc++-296 is not installed
package openmotif is not installed 
 Please insert the os install Disc or upload the iso.
Where is your operation system installation media?
1) dvd Disc
2) iso
#? 2
You have selected iso
Where is the iso?(in absolute path,e.g., /u01/rhel-server-6.4-x86_64-dvd.iso)/u01/rhel6.4.iso

记住这里将服务器上的镜像文件位置写上,后面环境就自动部署了。

 

 

 

 

 

 

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值