#!/bin/sh #http://www.idevelopment.info/data/Oracle/DBA_tips/Oracle11gRAC/CLUSTER_12.shtml#iSCSI SELFE_PRC=$0; export $SELFE_PRC service iptalbes stop service ip6tables stop service ntpd stop service sendmail stop #iscsiadm -m node -p 172.16.1.70 -T iqn.openfiler:70 -l -d 10 #iscsiadm -m discovery -t sendtargets -p 172.16.1.70:3260 chkconfig iptables off chkconfig ip6tables off chkconfig sendmail off chkconfig ntpd off rm /etc/ntp.conf -f mv /etc/ntp.conf to /etc/ntp.conf.org echo '#-------------------------------------------定义参数' RAC=rac1; export $RAC ASM_NAME='+ASM1' ; export $ASM_NAME ORCL_NAME='orcl1' ; export $ORCL_NAME GATEWAY_IP=172.16.1.39; export $GATEWAY_IP RAC_IP1=172.16.1.31; export $RAC_IP1 RAC_IP2=172.16.1.32; export $RAC_IP2 RAC_IP3=172.16.1.33; export $RAC_IP3 RAC_VIP_IP1=172.16.1.41; export $RAC_VIP_IP1 RAC_VIP_IP2=172.16.1.42; export $RAC_VIP_IP2 RAC_VIP_IP3=172.16.1.43; export $RAC_VIP_IP3 RAC_PRIV_IP1=10.0.0.31; export $RAC_PRIV_IP1 RAC_PRIV_IP2=10.0.0.32; export $RAC_PRIV_IP2 RAC_PRIV_IP3=10.0.0.33; export $RAC_PRIV_IP3 echo '#--------------------------------------------禁用SELINUX' sed -i s#SELINUX=enforcing#SELINUX=disabled#g# /etc/selinux/config echo '#--------------------------------------------修改DNS' cat >/etc/hosts<<EOF # Do not remove the following line, or various programs # that require network functionality will fail. 127.0.0.1 localhost.localdomain localhost ::1 localhost6.localdomain6 localhost6 $RAC_IP1 rac1 $RAC_IP2 rac2 $RAC_IP3 rac3 $RAC_VIP_IP1 rac1-vip $RAC_VIP_IP2 rac2-vip $RAC_VIP_IP3 rac3-vip $RAC_PRIV_IP1 rac1-priv $RAC_PRIV_IP2 rac2-priv $RAC_PRIV_IP3 rac3-priv EOF echo '#---------------------------------------------修改HOSTNAME' cat >/proc/sys/kernel/hostname<<EOF $RAC EOF hostname $RAC echo '#---------------------------------------------------------' cat >/etc/resolv.conf<<EOF ; generated by /sbin/dhclient-script nameserver $GATEWAY_IP EOF cat >/etc/sysconfig/network<<EOF NETWORKING_IPV6=no HOSTNAME=$RAC GATEWAY=$GATEWAY_IP EOF groupadd -g 501 oinstall groupadd -g 502 dba groupadd -g 503 oper groupadd -g 504 asmadmin groupadd -g 505 asmoper groupadd -g 506 asmdba useradd -g oinstall -G dba,asmdba,oper oracle useradd -g oinstall -G asmadmin,asmdba,asmoper,oper,dba grid mkdir -p /u01/app/grid chown -R grid:oinstall /u01/app/grid mkdir -p /u01/app/11.2.0/grid/product/db_1 chown -R grid:oinstall /u01/app/11.2.0 mkdir -p /u01/app/oraInventory chown -R grid:oinstall /u01/app/oraInventory mkdir -p /u01/app/oracle mkdir -p /u01/app/oracle/product/11.2.0/db_1 chown -R oracle:oinstall /u01/app/oracle echo '#--------------------------------------------------------修改用户密码passwd grid' echo "111111" | passwd grid --stdin > /dev/null 2>&1 echo "111111" | passwd oracle --stdin > /dev/null 2>&1 chown -R grid:oinstall /usr/local/grid chown -R oracle:oinstall /usr/local/database echo '#----------------------------------------------------------vi /etc/security/limits.conf' cat >>/etc/security/limits.conf<<EOF #ORACLE SETTING 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 echo '#------------------------------------vi /etc/pam.d/login' echo 'session required pam_limits.so' >>/etc/pam.d/login echo '#------------------------------------ vi /etc/sysctl.conf' cat >> /etc/sysctl.conf <<EOF 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 = 1048586 EOF sysctl -p #------------------------------------------------------修改profile cat >> /etc/profile <<EOF if [ \$USER = "oracle" ] || [ \$USER = "grid" ]; then if [ \$SHELL = "/bin/ksh" ]; then ulimit -p 16384 ulimit -n 65536 else ulimit -u 16384 -n 65536 fi umask 022 fi EOF #--------------------------------------------------------修改 csh.login cat >> /etc/csh.login <<EOF if ( \$USER == "oracle" || \$USER == "grid" ) then limit maxproc 16384 limit descriptors 65536 endif EOF echo '#------------------------------------------修改gird 用户的.bash_profile 文件:' cat >> /home/grid/.bash_profile <<EOF # --------------------------------------------------- # ORACLE_SID # --------------------------------------------------- ORACLE_SID=$ASM_NAME; export ORACLE_SID # --------------------------------------------------- # JAVA_HOME # --------------------------------------------------- #JAVA_HOME=/usr/local/java; export JAVA_HOME # --------------------------------------------------- # ORACLE_BASE # --------------------------------------------------- ORACLE_BASE=/u01/app/grid; export ORACLE_BASE # --------------------------------------------------- # ORACLE_HOME # --------------------------------------------------- ORACLE_HOME=/u01/app/11.2.0/grid; export ORACLE_HOME # --------------------------------------------------- # ORACLE_PATH # --------------------------------------------------- ORACLE_PATH=/u01/app/oracle/common/oracle/sql; export ORACLE_PATH # --------------------------------------------------- # SQLPATH # --------------------------------------------------- # Specifies the directory or list of directories that # SQL*Plus searches for a login.sql file. # --------------------------------------------------- # SQLPATH=/u01/app/common/oracle/sql; export SQLPATH # --------------------------------------------------- # ORACLE_TERM # --------------------------------------------------- ORACLE_TERM=xterm; export ORACLE_TERM # --------------------------------------------------- # NLS_DATE_FORMAT # --------------------------------------------------- NLS_DATE_FORMAT="YYYY-MM-DD HH24:MI:SS"; export NLS_DATE_FORMAT # --------------------------------------------------- # TNS_ADMIN # --------------------------------------------------- TNS_ADMIN=\$ORACLE_HOME/network/admin; export TNS_ADMIN # --------------------------------------------------- # ORA_NLS11 # --------------------------------------------------- ORA_NLS11=\$ORACLE_HOME/nls/data; export ORA_NLS11 # --------------------------------------------------- # PATH # --------------------------------------------------- PATH=.:\${JAVA_HOME}/bin:\${PATH}:\$HOME/bin:\$ORACLE_HOME/bin PATH=\${PATH}:/usr/bin:/bin:/usr/bin/X11:/usr/local/bin PATH=\${PATH}:/u01/app/common/oracle/bin export PATH # --------------------------------------------------- # LD_LIBRARY_PATH # --------------------------------------------------- LD_LIBRARY_PATH=\$ORACLE_HOME/lib LD_LIBRARY_PATH=\${LD_LIBRARY_PATH}:\$ORACLE_HOME/oracm/lib LD_LIBRARY_PATH=\${LD_LIBRARY_PATH}:/lib:/usr/lib:/usr/local/lib export LD_LIBRARY_PATH # --------------------------------------------------- # CLASSPATH # --------------------------------------------------- CLASSPATH=\$ORACLE_HOME/JRE CLASSPATH=\${CLASSPATH}:\$ORACLE_HOME/jlib CLASSPATH=\${CLASSPATH}:\$ORACLE_HOME/rdbms/jlib CLASSPATH=\${CLASSPATH}:\$ORACLE_HOME/network/jlib export CLASSPATH # --------------------------------------------------- # THREADS_FLAG # --------------------------------------------------- THREADS_FLAG=native; export THREADS_FLAG # --------------------------------------------------- # TEMP, TMP, and TMPDIR # --------------------------------------------------- export TEMP=/tmp export TMPDIR=/tmp # --------------------------------------------------- # UMASK # --------------------------------------------------- if [ \$USER = "oracle" ] || [ \$USER = "grid" ]; then if [ \$SHELL = "/bin/ksh" ]; then ulimit -p 16384 ulimit -n 65536 else ulimit -u 16384 -n 65536 fi umask 022 fi EOF echo '#-----------------------------oracle 用户配置文件ORACLE_HOSTNAME 请自行设置' # Oracle Settings oracle cat >> /home/oracle/.bash_profile<<EOF # --------------------------------------------------- # ORACLE_SID # --------------------------------------------------- ORACLE_SID=$ORCL_NAME; export ORACLE_SID # --------------------------------------------------- # ORACLE_UNQNAME # --------------------------------------------------- ORACLE_UNQNAME=racdb; export ORACLE_UNQNAME # --------------------------------------------------- # JAVA_HOME # --------------------------------------------------- #JAVA_HOME=/usr/local/java; export JAVA_HOME # --------------------------------------------------- # ORACLE_BASE # --------------------------------------------------- ORACLE_BASE=/u01/app/oracle; export ORACLE_BASE # --------------------------------------------------- # ORACLE_HOME # --------------------------------------------------- ORACLE_HOME=\$ORACLE_BASE/product/11.2.0/dbhome_1; export ORACLE_HOME # --------------------------------------------------- # ORACLE_PATH # --------------------------------------------------- ORACLE_PATH=/u01/app/common/oracle/sql; export ORACLE_PATH # SQLPATH=/u01/app/common/oracle/sql; export SQLPATH # --------------------------------------------------- # ORACLE_TERM # --------------------------------------------------- ORACLE_TERM=xterm; export ORACLE_TERM # --------------------------------------------------- # NLS_DATE_FORMAT # --------------------------------------------------- NLS_DATE_FORMAT="YYYY-MM-DD HH24:MI:SS"; export NLS_DATE_FORMAT # --------------------------------------------------- # TNS_ADMIN # --------------------------------------------------- TNS_ADMIN=\$ORACLE_HOME/network/admin; export TNS_ADMIN # --------------------------------------------------- # ORA_NLS11 # --------------------------------------------------- ORA_NLS11=\$ORACLE_HOME/nls/data; export ORA_NLS11 # --------------------------------------------------- # PATH # --------------------------------------------------- PATH=.:\${JAVA_HOME}/bin:\${PATH}:\$HOME/bin:\$ORACLE_HOME/bin PATH=\${PATH}:/usr/bin:/bin:/usr/bin/X11:/usr/local/bin PATH=\${PATH}:/u01/app/common/oracle/bin export PATH # --------------------------------------------------- # LD_LIBRARY_PATH # --------------------------------------------------- LD_LIBRARY_PATH=\$ORACLE_HOME/lib LD_LIBRARY_PATH=\${LD_LIBRARY_PATH}:\$ORACLE_HOME/oracm/lib LD_LIBRARY_PATH=\${LD_LIBRARY_PATH}:/lib:/usr/lib:/usr/local/lib export LD_LIBRARY_PATH # --------------------------------------------------- # CLASSPATH # --------------------------------------------------- CLASSPATH=\$ORACLE_HOME/JRE CLASSPATH=\${CLASSPATH}:\$ORACLE_HOME/jlib CLASSPATH=\${CLASSPATH}:\$ORACLE_HOME/rdbms/jlib CLASSPATH=\${CLASSPATH}:\$ORACLE_HOME/network/jlib export CLASSPATH # --------------------------------------------------- # THREADS_FLAG # --------------------------------------------------- THREADS_FLAG=native; export THREADS_FLAG # --------------------------------------------------- # TEMP, TMP, and TMPDIR # --------------------------------------------------- export TEMP=/tmp export TMPDIR=/tmp # --------------------------------------------------- # UMASK # --------------------------------------------------- if [ \$USER = "oracle" ] || [ \$USER = "grid" ]; then if [ \$SHELL = "/bin/ksh" ]; then ulimit -p 16384 ulimit -n 65536 else ulimit -u 16384 -n 65536 fi umask 022 fi EOF echo '#------------------------------------------------------------ YUM 环境,安装需要的包' mkdir /mnt/cdrom -p mount /dev/cdrom /mnt/cdrom cat >/etc/yum.repos.d/mycdrom.repo<<EOF [Server] name=rhel6server baseurl=file:///mnt/cdrom/Server enable=1 gpcheck=1 gpgkey=file:///mnt/cdrom/RPM-GPG-KEY-redhat-release #gpgkey=file:///mnt/cdrom/RPM-GPG-KEY-oracle EOF #yum groupinstall -y "gnome desktop environment" #yum groupinstall -y "x window system" yum groupinstall -y "chinese support" yum install -y elfutils-libelf* gcc-* make* binutils* libaio* glibc* compat-libstdc++* libgcc* libstdc++* sysstat* unixODBC* ksh* expect* iscsi* echo '#---------------------------------------------------------ssh-keygen 环境' rm -f /home/oracle/.ssh/*; rm -f /home/grid/.ssh/*; su - grid -c 'ssh-keygen -t rsa -f ~/.ssh/id_rsa -P ""' su - oracle -c 'ssh-keygen -t rsa -f ~/.ssh/id_rsa -P ""' su - grid -c 'cp /home/grid/.ssh/id_rsa.pub /home/grid/.ssh/authorized_keys' su - oracle -c 'cp /home/oracle/.ssh/id_rsa.pub /home/oracle/.ssh/authorized_keys' # 安装 ASM 支持包 rpm -ivh /mnt/hgfs/oracle11g/oracleasm-support-2.1.7-1.el5.x86_64.rpm rpm -ivh /mnt/hgfs/oracle11g/oracleasm-2.6.18-194.el5-2.0.5-1.el5.x86_64.rpm rpm -ivh /mnt/hgfs/oracle11g/oracleasmlib-2.0.4-1.el5.x86_64.rpm echo '#------------------------------------------------拷贝文件,并在RAC上自动执行' auto_scp () { expect -c "set timeout -1; spawn scp -o StrictHostKeyChecking=no ${@:2}; expect { *assword:* {send -- $1\r; expect { *denied* {exit 1;} eof } } eof {exit 1;} } " return $? } auto_ssh () { expect -c "set timeout -1; spawn ssh -o StrictHostKeyChecking=no $2 $3; expect { *assword:* {send -- $1\r; expect { *denied* {exit 2;} eof } } eof {exit 1;} } " return $? } echo '#--------------------------------------------建立可执行文件' cat >/root/s0 <<EOF auto_ssh_copy_id () { expect -c "set timeout -1; spawn ssh-copy-id -i \$1 \$2; expect { *(yes/no)* {send -- yes\r;exp_continue;} *assword:* {send -- 111111\r;exp_continue;} eof {exit 0;} }"; } auto_ssh_copy_id /home/grid/.ssh/id_rsa.pub grid@rac1 auto_ssh_copy_id /home/grid/.ssh/id_rsa.pub grid@rac2 auto_ssh_copy_id /home/grid/.ssh/id_rsa.pub grid@rac3 auto_ssh_copy_id /home/oracle/.ssh/id_rsa.pub oracle@rac1 auto_ssh_copy_id /home/oracle/.ssh/id_rsa.pub oracle@rac2 auto_ssh_copy_id /home/oracle/.ssh/id_rsa.pub oracle@rac3 su - grid -c 'ssh -o StrictHostKeyChecking=no rac1 date' su - grid -c 'ssh -o StrictHostKeyChecking=no rac2 date' su - grid -c 'ssh -o StrictHostKeyChecking=no rac3 date' su - oracle -c 'ssh -o StrictHostKeyChecking=no rac1 date' su - oracle -c 'ssh -o StrictHostKeyChecking=no rac2 date' su - oracle -c 'ssh -o StrictHostKeyChecking=no rac3 date' EOF chmod 755 /root/s0 if [ $RAC = 'rac1' ] ; then rm /root/s2 -f rm /root/s3 -f cp /root/$SELFE_PRC /root/s2 cp /root/$SELFE_PRC /root/s3 sed -i s#RAC=rac1#RAC=rac2#g# /root/s2 sed -i s#RAC=rac1#RAC=rac3#g# /root/s3 sed -i s#ASM1#ASM2#g# /root/s2 sed -i s#ASM1#ASM3#g# /root/s3 sed -i s#orcl1#orcl2#g# /root/s2 sed -i s#orcl1#orcl3#g# /root/s3 chmod 755 /root/s?; auto_scp 111111 /root/s2 root@$RAC_IP2:/root/s2 auto_ssh 111111 root@$RAC_IP2 /root/s2 auto_scp 111111 /root/s3 root@$RAC_IP3:/root/s3 auto_ssh 111111 root@$RAC_IP3 /root/s3 echo '#-------------------------------------------配制 SSH-KEYGEN' auto_ssh 111111 root@$RAC_IP1 /root/s0 auto_ssh 111111 root@$RAC_IP2 /root/s0 auto_ssh 111111 root@$RAC_IP3 /root/s0 rm /root/s2 -f rm /root/s3 -f rm /root/s0 -f fi