#!/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自动化安装脚本-part03-亲试ok
此为 软件包配置文件 software.conf [CentOS6] binutils-2.20.51.0.2-5.11.el6 (x86_64) compat-libcap1-1.10-1 (x8 ...
- Oracle自动化安装脚本-part02-亲试ok
此为网络配置文件 network.conf [PUBLIC-IP] IP-LIST:192.168.7.198,192.168.8.221 HOSTNAME-LIST:mysql-198,RAC2 ...
- mysql自动化安装脚本(二进制安装)
为了日后安装数据库方便,遂写了一个自动安装MySQL的脚本: 测试可以安装mariadb和MySQL-5.7.X 安装前配置好对应的my.cnf文件放在/tmp路径下 将启动脚本mysql3306放在 ...
- oracle 的安装脚本
==[root@oracle ~]# cat 1.preusers.sh ==#!/bin/bash#Purpose:Create 3 groups named 'oinstall','dba','o ...
- oracle rac 安装脚本
1. 配置/etc/hosts 网络 192.168.1.111 rac1 rac1.oracle.com192.168.1.182 rac1-vip 192.168.1.222 rac2 rac2. ...
- linux上安装mysql,亲试成功
安装mysql参考 网址https://blog.csdn.net/a774630093/article/details/79270080 本文更加详细. 1.先检查系统是否装有mysql rpm - ...
- MySQL5.7.18自动化安装脚本
背景 很好的朋友邱启明同学,擅长MySQL,目前任职某大型互联网业MySQL DBA,要来一套MySQL自动安装的Shell脚本,贴出来保存一些. 此版本为 MySQL 5.7.18 ###### 自 ...
- MySQL5.6.36 自动化安装脚本
背景 很好的朋友邱启明同学,擅长MySQL,目前任职某大型互联网业MySQL DBA,要来一套MySQL自动安装的Shell脚本,贴出来保存一些. 此版本为 MySQL 5.6.365 ###### ...
- zabbix指定版本自动化安装脚本shell
安装服务端zabbix 有时候要部署一个zabbix各种配置啊贼烦. #!/bin/sh #sleep 10 zabbix_version=4.2.5 ###这里你自定义版本,我要的是4.2.5 za ...
随机推荐
- socket网络编程 的基本方法:--ongoing
https://blog.csdn.net/shuxiaogd/article/details/50366039在学习网络编程时,我们总是从最简单的Server程序写起:socket -> bi ...
- [转帖]Oracle报错ORA-26563--当重命名表时碰到物化视图
Oracle报错ORA-26563--当重命名表时碰到物化视图 https://www.toutiao.com/i6739137279115133447/ 原创 波波说运维 2019-09-26 00 ...
- Python习题006
作业一:打印10*10 星星 ★☆ 要求一:普通打印★ l = 0 while l <10: h = 0 while h < 9: print("★", end=&q ...
- Yii2 设计模式——单例模式
单例模式 模式定义 单例模式确保一个类只有一个实例,并提供一个全局访问点.当现实中只需要一个对象,或者为了节省系统资源,又或者是为了共享数据的时候可以使用单例模式. 代码实现 我们先来看看单例模式的标 ...
- 数据校验-hibernate-validator
数据校验 在web开发时,对于请求参数,一般上都需要进行参数合法性校验的,原先的写法时一个个字段一个个去判断,这种方式太不通用了,所以java的JSR 303: Bean Validation规范就是 ...
- js文件分段上传
前端代码 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/T ...
- (二)第一个mybatis项目
1. 引包 本例中使用maven构造项目,所以只需配置依赖即可引相应的包. pom.xml <project xmlns="http://maven.apache.org/POM/4. ...
- IdentityServer3 使用记录
官方教程:https://identityserver.github.io/Documentation/docsv2/overview/mvcGettingStarted.html 1.是否启用 SS ...
- 十二、react-reudx之@connect 摆脱redux的繁琐操作
如果对redux的概念和用法掌握的已经不错了 那么现在react-redux会让你的操作更加的得心印手 忘记subscribe,记住reducer,action和dispatch即可 Reac ...
- js大数计算之计算
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...