#!/bin/bash
 
node_num=$1
base_config=./network.conf   网络配置文件
software_config=./software.conf  软件包配置文件
tmp_file=/tmp/autorac.tmp
DISPLAY_ADDR=192.168.8.229
 
if [ ! ${node_num} ];then
echo "specify the node number"
exit 0
fi
 
 
Get_Block()
{
block_name=$1
config_file=$2
begin_line=0
end_line=0
line_num=0
while read line
do
        line_num=`expr ${line_num} + 1`
        is_get=`echo $line | awk "/\[${block_name}]/{print 1;next}{print 0}"`
        if [ ${is_get} -eq 1 ];then
                begin_line=${line_num}
                continue
        fi
 
        if [ ${begin_line} -ne 0 ];then
                is_get=`echo $line | awk "/\[.*]/{print 1;next}{print 0}"`
                if [ ${is_get} -eq 1 ];then
                        end_line=`expr ${line_num} - 1`
                        break
                fi
        fi
 
done < ${config_file}
}
 
 
IP_fun()
{
field_num=`expr $1 + 1`
block_name=$2
tmp_file=/tmp/autorac.tmp
 
Get_Block ${block_name} ${base_config}
 
sed -n "${begin_line},${end_line}p" ${base_config} | grep -v ^$ > ${tmp_file}
 
is_ip=`echo ${block_name} | awk '/IP/{print 1;next}{print 0}'`
 
if [ ${is_ip} -eq 1 ];then
        IPADDR=`awk -F"[:,]" -v num=${field_num} '/IP-LIST/{print $num}' ${tmp_file}`
        HOSTNAME=`awk -F"[:,]" -v num=${field_num} '/HOSTNAME/{print $num}' ${tmp_file}`
        NETMASK=`awk -F"[:,]" '/NETMASK/{print $2}' ${tmp_file}`
        GATEWAY=`awk -F"[:,]" '/GATEWAY/{print $2}' ${tmp_file}`
        DNS1=`awk -F"[:,]" '/DNS1/{print $2}' ${tmp_file}`
        DNS2=`awk -F"[:,]" '/DNS2/{print $2}' ${tmp_file}`
 
 
        if [ "${block_name}" == "PUBLIC-IP" -o "${block_name}" == "PRIVATE-IP" ];then
                if [ "${block_name}" == "PUBLIC-IP" ];then
                        network="ifcfg-eth0"
                        sed -i "s/HOSTNAME=.*/HOSTNAME=${HOSTNAME}/" /etc/sysconfig/network
                        echo "IPADDR:"${IPADDR}
                        echo "HOSTNAME:"${HOSTNAME}
                else
                        network="ifcfg-eth1"
                fi
 
         tmp_ipaddr_file=/tmp/autorac_ipaddr_file.tmp
                 awk '/DEVICE/||/TYPE/||/HWADDR/||/NM_CONTROLLED/{print $1}' /etc/sysconfig/network-scripts/${network} >${tmp_ipaddr_file}
                 echo "IPADDR="${IPADDR} >>${tmp_ipaddr_file}
                 echo "NETMASK="${NETMASK} >>${tmp_ipaddr_file}
                 echo "GATEWAY="${GATEWAY} >>${tmp_ipaddr_file}
                 echo "DNS1="${DNS1} >>${tmp_ipaddr_file}
                 echo "DNS2="${DNS2} >>${tmp_ipaddr_file}
                 echo -e "ARPCHECK=no\nONBOOT=\"yes\"\nBOOTPROTO=static" >>${tmp_ipaddr_file}
 
                 cat ${tmp_ipaddr_file} > /etc/sysconfig/network-scripts/${network}
 
        fi
 
        rac_node_name=/tmp/autorac_node.tmp
        echo >${rac_node_name}
        node_total=`awk -F"[:,]" '/IP-LIST/{print NF}' ${tmp_file}`
        for i in `seq 2 ${node_total}`
        do
                IPADDR=`awk -F"[:,]" -v num=${i} '/IP-LIST/{print $num}' ${tmp_file}`
                HOSTNAME_1=`awk -F"[:,]" -v num=${i} '/HOSTNAME/{print $num}' ${tmp_file}`
        HOSTNAME=${HOSTNAME_1:-${HOSTNAME}}
 
                  echo -e ${IPADDR} ${HOSTNAME} #ORACLE_CONFIG>> /etc/hosts
 
                if [ "${block_name}" == "PUBLIC-IP" -o "${block_name}" == "PRIVATE-IP" ];then
                        echo ${block_name}:${HOSTNAME} >> ${rac_node_name}
                fi
        done
fi
 
#is_storage=`echo ${block_name} | awk '/STORAGE/{print 1;next}{print 0}'`
 
}
 
sed -i '/ORACLE_CONFIG/d' /etc/hosts
 
IP_fun ${node_num} PUBLIC-IP
IP_fun ${node_num} PRIVATE-IP
IP_fun ${node_num} VIP
IP_fun ${node_num} SCAN-IP
 
echo '#1.关闭防火墙,selinux'
#shutdown iptables
service iptables stop
chkconfig iptables off
 
#shutdown fireware
setenforce 0
sed -i 's/SELINUX=.*/SELINUX=disable/g' /etc/selinux/config
 
echo '#2.关闭NTP'
#disable ntp server
service ntpd status | grep run && service ntpd stop
chkconfig ntpd off
if [ -e /etc/ntp.conf ];then
mv /etc/ntp.conf /etc/ntp.conf.bak
fi
 
 
echo '#3.安装软件包'
#install package
 
Get_Block()
{
block_name=$1
config_file=$2
begin_line=0
end_line=0
line_num=0
while read line
do
        line_num=`expr ${line_num} + 1`
        is_get=`echo $line | awk "/\[${block_name}]/{print 1;next}{print 0}"`
        if [ ${is_get} -eq 1 ];then
                begin_line=${line_num}
                continue
        fi
 
        if [ ${begin_line} -ne 0 ];then
                is_get=`echo $line | awk "/\[.*]/{print 1;next}{print 0}"`
                if [ ${is_get} -eq 1 ];then
                        end_line=`expr ${line_num} - 1`
                        break
                fi
        fi
 
done < ${config_file}
}
 
 
Install_package_fun()
{
for i in `ls /etc/yum.repos.d/ | grep -v bak$`
do
        mv /etc/yum.repos.d/$i /etc/yum.repos.d/$i.bak
done
 
cat > /etc/yum.repos.d/centos6.repo  <<EOF
[centos6.8]
name=centos6.8
enabled=1
gpgcheck=0
EOF
 
yum clean all
 
 
os_type=`lsb_release -a | awk -F"[:\t]+" '/Distributor ID/{print $2}'`
os_release=`lsb_release -a | awk -F"[:\t]+" '/Release/{printf("%d\n",$2)}'`
echo $os_type
echo $os_release
 
if [ ${os_type} == "CentOS" -o ${os_type} == "Red" ];then
        Get_Block "CentOS${os_release}" ${software_config}
        sed -n "${begin_line},${end_line}p" ${software_config} | grep -v ^$ | awk -F'-[0-9].[0-9]' '! /\[/{print $1}' > ${tmp_file}
        while read line
        do
                yum install -y -q ${line}
      rpm -qa --queryformat "%{NAME}-%{VERSION}-%{RELEASE} (%{ARCH})\n" | grep ${line}
        done < ${tmp_file}
fi
}
echo -e "\033[31mCDROM HAS BEEN MOUNTTED\033[0m" && Install_package_fun
 
echo '#4.清空之前的安装环境'
userdel -rf oracle
userdel -rf grid
groupdel oinstall
groupdel dba
groupdel oper
groupdel asmadmin
groupdel asmdba
groupdel asmoper
rm -rf /u01
rm -rf /home/oracle
rm -rf /home/grid
 
 
echo '#5.创建组和用户'
groupadd -g 501 oinstall
groupadd -g 502 dba
groupadd -g 503 oper
groupadd -g 504 asmadmin
groupadd -g 505 asmdba
groupadd -g 506 asmoper
useradd -u 501 -g oinstall -G dba,asmdba,asmadmin,asmoper grid
useradd -u 502 -g oinstall -G dba,oper,asmdba,asmadmin oracle
echo -n oracle | passwd --stdin oracle
echo -n grid   | passwd --stdin grid
 
echo '#6.创建目录'
mkdir -p /u01/app/oracle
mkdir -p /u01/app/oracle/product/11.2.0/db_1
chown -R oracle:oinstall /u01/app/oracle
 
mkdir -p /u01/app/grid
mkdir -p /u01/app/grid/product/11.2.0/db_1
chown -R grid:oinstall /u01/app/grid
chown -R grid:oinstall /u01/app/grid/product/11.2.0/db_1
 
chmod -R 775 /u01/
 
echo '#7.修改用户grid的初始化参数文件'
is_modified=`awk 'BEGIN{a=0}/grid_config/{a+=1}END{print a}' /home/grid/.bash_profile`
 
if [ ${is_modified} -eq 0 ];then
cat>> /home/grid/.bash_profile<< EOF
#grid_config
export TMP=/tmp;
export TMPDIR=\$TMP;
export ORACLE_SID=+ASM1;
export ORACLE_BASE=/u01/app/grid;
export ORACLE_HOME=/u01/app/grid/product/11.2.0/db_1/;
export NLS_DATE_FORMAT="yyyy-mm-dd HH24:MI:SS";
export PATH=\$ORACLE_HOME/BIN:\$PATH;
export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK;
EOF
fi
 
 
 
echo '#8.修改用户oracle的初始化参数文件'
is_modified=`awk 'BEGIN{a=0}/oracle_config/{a+=1}END{print a}' /home/oracle/.bash_profile`
 
if [ ${is_modified} -eq 0 ];then
cat>> /home/oracle/.bash_profile<< EOF
#oracle_config
export TMP=/tmp;
export TMPDIR=\$TMP;
export ORACLE_BASE=/u01/app/oracle;
export ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1;
export ORACLE_UNQNAME=prod;
export ORACLE_SID=prod1;
export ORACLE_TERM=xterm;
export PATH=/usr/sbin:\$PATH;
export PATH=\$ORACLE_HOME/bin:\$PATH;
export LD_LIBRARY_PATH=\$ORACLE_HOME/lib:/lib:/usr/lib;
export CLASSPATH=\$ORACLE_HOME/JRE:\$ORACLE_HOME/jlib:\$ORACLE_HOME/rdbms/jlib;
export NLS_DATE_FORMAT="yyyy-mm-dd HH24:MI:SS";
export NLS_LANG="SIMPLIFIED CHINESE_CHINA.ZHS16GBK";
EOF
fi
 
echo '#9.网络参数调整'
is_modified=`awk 'BEGIN{a=0}/sysctl_config/{a+=1}END{print a}' /etc/sysctl.conf`
 
if [ ${is_modified} -eq 0 ];then
sed -i 's/^kernel.shmmax/#kernel.shmmax/g' /etc/sysctl.conf
sed -i 's/^kernel.shmall/#kernel.shmall/g' /etc/sysctl.conf
cat>> /etc/sysctl.conf<<EOF
#sysctl_config
fs.aio-max-nr = 1048576 fs.file-max = 6815744 kernel.shmall = 2097152
kernel.shmmax = 1417529344
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 = 1048586
EOF
fi
 
 
echo '#10.资源限制参数调整'
is_modified=`awk '/oracle/||/grid/{a+=1}END{print a}' /etc/security/limits.conf`
if [ ${is_modified} -en 0 ];then
    cat>> /etc/security/limits.conf<<EOF
    oracle soft nproc 2047
    oracle hard nproc 16384
    oracle soft nofile 1024
    oracle hard nofile 65536
    oracle soft stack 10240
    grid soft nproc 2047
    grid hard nproc 16384
    grid soft nofile 1024
    grid hard nofile 65536
    grid soft stack 10240
EOF
fi
 
echo '#11.修改主机参数文件'
is_modified=`awk 'BEGIN{a=0}/profile_config/{a+=1}END{print a}' /etc/profile`
 
if [ ${is_modified} -eq 0 ];then
cat >>/etc/profile<<EOF
#ORACLE_CONFIG
if [ \$USER = "oracle" ]; then
        if [ \$SHELL = "/bin/ksh" ]; then
              ulimit -p 16384
              ulimit -n 65536
        else
              ulimit -u 16384 -n 65536
        fi
fi
alias grep='grep --color=auto'
export PATH=\$PATH:/u01/app/11.2.0/grid/bin
export DISPLAY=$DISPLAY_ADDR
EOF
fi
 
while [ ${exitcode:=0} -eq 0 ]
do
times=`expr ${times:=0} + 1`
is_install_multipath=`rpm -qa | grep -E "device-mapper-[0-9]|multipath" |wc -l`
if [ ${is_install_multipath} -ge 2 ];then
    if [ ! -e /etc/multipath.conf ];then
        cp /usr/share/doc/device-mapper-multipath-0.4.9/multipath.conf /etc/multipath.conf && service multipathd restart || echo -e "\033[31mMultipath ERROR\033[0m"
    fi
 
    is_modified=`awk 'BEGIN{a=0}/ORACLE_CONFIG/{a+=1}END{print a}' /etc/multipath.conf`
    if [ ${is_modified} -eq 0 ];then
        echo '#ORACLE_CONFIG' >> /etc/multipath.conf
        awk -F'[ \t]+' 'BEGIN{print "multipaths '{'";a=0}NF==2&&/mpath/{a+=1;printf("\tmultipath '{'\n\t\twwid\t%s\n\t\talias\tlun%d\n\t'}'\n",$2,a)} \
            END{print "'}'"}' /etc/multipath/bindings >> /etc/multipath.conf
    fi
 
    service multipathd restart
    sleep 5
    if [ $? -ne 0 ];then
        echo -e "\033[31mMultipath ERROR\033[0m"
    else        
        is_multipath=`multipath -ll | awk -F'[ \t]' '/lun/{print $3}'|wc -l`
    fi
    exitcode=1
else
    rm -rf /var/lib/yum/history/*.sqlite&&yum install -y -q *multipath*&& echo -e "\033[31mInstall device-mapper-* Complete\033[0m"
    if [ ${times} -ge 3 ];then
        echo -e "\033[31mInstall Package device-mpper-* ERROR\033[0m"
        break
    fi
fi
done
 
if [ ${is_multipath:=0} -ge 1 ];then
   sed -i '/^[^#]/d' /etc/udev/rules.d/60-raw.rules
   for i in `multipath -ll | grep lun | sort| awk -F'[ \t]' '{print $2}'|sed -e 's/(//g' -e 's/)//g'`
   do
        num=`expr ${num:=0} + 1`
        echo "KERNEL==\"sd*\", ACTION==\"add\", PROGRAM==\"/lib/udev/scsi_id --whitelisted --device=/dev/\$name\", \
        RESULT==\"$i\", NAME=\"raw${num}\"" >> /etc/udev/rules.d/60-raw.rules
   done
   echo "NAME==\"raw[0-9]*\",OWNER=\"grid\", GROUP=\"asmadmin\", MODE=\"0660\"" >> /etc/udev/rules.d/60-raw.rules
   start_udev
else
   echo -e "\033[31mNO STORAGE DEVICE BE FOUND\033[0m"
fi
 
 
 
echo '12.配置节点间的信任关系'
ssh_keygen()
{
for user in oracle grid
do
        awk -F':' '/PUBLIC-IP/{print $2}' ${rac_node_name} | while read line
        do
                node_name=${line}
                ssh root@${node_name} su - ${user} -c "
                rm -f ~/.ssh/id_rsa\r
                rm -f ~/.ssh/id_dsa\r
                rm -f ~/.ssh/authorized_keys\r
                ssh-keygen -t rsa -q -f ~/.ssh/id_rsa -N 099q4naefadfasfdadfAADF8W0309QERQSDQ97FGJH\r
                ssh-keygen -t dsa -q -f ~/.ssh/id_rsa -N 099q4naefadf0w323346ssd0ADF8WsdRQSDQ97FGJH\r"
 
                ssh root@${node_name} su - ${user} -c "cat ~/.ssh/*.pub" >> all_node_authorized_keys
        done
 
        awk -F: '/PUBLIC-IP/{print $2}' ${rac_node_name}| while read line
        do
                node_name=${line}
                scp all_node_authorized_keys ${user}@${node_name}:~/.ssh/authorized_keys
 
        done
done
 
 
for user in oracle grid
do
        awk -F':' '/PUBLIC-IP/{print $2}' ${rac_node_name} |while read line
        do
                node_name=${line}
                awk -F':' '{print $2}' ${rac_node_name} | while read line
                do
                        host_name=${line}
                        ssh root@${node_name} su - ${user} -c "ssh ${host_name} date"
                done
        done
done
}
 
if [ ${node_num} -eq 1 ];then
    ssh_keygen
fi

Oracle自动化安装脚本-part01-亲试ok的更多相关文章

  1. Oracle自动化安装脚本-part03-亲试ok

     此为 软件包配置文件 software.conf [CentOS6] binutils-2.20.51.0.2-5.11.el6 (x86_64) compat-libcap1-1.10-1 (x8 ...

  2. Oracle自动化安装脚本-part02-亲试ok

     此为网络配置文件  network.conf [PUBLIC-IP] IP-LIST:192.168.7.198,192.168.8.221 HOSTNAME-LIST:mysql-198,RAC2 ...

  3. mysql自动化安装脚本(二进制安装)

    为了日后安装数据库方便,遂写了一个自动安装MySQL的脚本: 测试可以安装mariadb和MySQL-5.7.X 安装前配置好对应的my.cnf文件放在/tmp路径下 将启动脚本mysql3306放在 ...

  4. oracle 的安装脚本

    ==[root@oracle ~]# cat 1.preusers.sh ==#!/bin/bash#Purpose:Create 3 groups named 'oinstall','dba','o ...

  5. oracle rac 安装脚本

    1. 配置/etc/hosts 网络 192.168.1.111 rac1 rac1.oracle.com192.168.1.182 rac1-vip 192.168.1.222 rac2 rac2. ...

  6. linux上安装mysql,亲试成功

    安装mysql参考 网址https://blog.csdn.net/a774630093/article/details/79270080 本文更加详细. 1.先检查系统是否装有mysql rpm - ...

  7. MySQL5.7.18自动化安装脚本

    背景 很好的朋友邱启明同学,擅长MySQL,目前任职某大型互联网业MySQL DBA,要来一套MySQL自动安装的Shell脚本,贴出来保存一些. 此版本为 MySQL 5.7.18 ###### 自 ...

  8. MySQL5.6.36 自动化安装脚本

    背景 很好的朋友邱启明同学,擅长MySQL,目前任职某大型互联网业MySQL DBA,要来一套MySQL自动安装的Shell脚本,贴出来保存一些. 此版本为 MySQL 5.6.365 ###### ...

  9. zabbix指定版本自动化安装脚本shell

    安装服务端zabbix 有时候要部署一个zabbix各种配置啊贼烦. #!/bin/sh #sleep 10 zabbix_version=4.2.5 ###这里你自定义版本,我要的是4.2.5 za ...

随机推荐

  1. CentOS使用yum安装jdk

    1.查看系统版本命令 cat /etc/issue 2.查看yum包含的jdk版本 yum search java 或者 yum list java* 版本 jre jdk 1.8 java-1.8. ...

  2. 1.1Spring Boot 环境配置和常用注解

    Spring Boot常用注解:@Service: 注解在类上,表示这是一个业务层bean@Controller:注解在类上,表示这是一个控制层bean@Repository: 注解在类上,表示这是一 ...

  3. C++经典类库

    现实中,C++的库门类繁多,解决的问题也是极其广泛,库从轻量级到重量级的都有.本文为你介绍了十一种类库,有我们常见的,也有不常见的,一起来看. C++类库介绍 再次体现了C++保持核心语言的效率同时大 ...

  4. 下载GDB调试工具peda

    命令: 1.git clone https://github.com/longld/peda.git ~/peda 2.echo "source ~/peda/peda.py" & ...

  5. jq勾选

    1.取消勾选 $("box").attr("checked", false); 2.勾选 $("kbox").attr("chec ...

  6. 在oracle表中增加、修改、删除字段,表的重命名,字段顺序调整

    增加字段语法:alter table tablename add (column datatype [default value][null/not null],….); 说明:alter table ...

  7. IDEA报错: Clone failed: Authentication failed for 'http://10.70.XXXXXXXXXXXXXXXXX'

    今天从git上导入公司的项目,总是报错Clone failed: Authentication failed for 'http://10.70.XXXXXXXXXXXXXX' 在网上百度了一下,大致 ...

  8. (三十)JSP标签之自定义标签

    创建一个类,引入外部jsp-api.jar包(在tomcat 下lib包里有),这个类继承SimpleTagSupport 重写doTag()方法. jspprojec包下的helloTag类: 1 ...

  9. (一)Maven基础及第一个Maven工程

    一.Maven介绍 ANT/Maven/gradle是一个项目管理工具,它包含了一项目对象模型(Project Object Model),一组标准集合,一个项目生命周期(Project Lifecy ...

  10. (五)Redis之List

    一.List常用命令 两端添加 两端弹出 1.2. 两端添加和两端弹出 package myRedis01; import java.util.HashMap; import java.util.Li ...