oracle安装脚本

插2个脚本,安装oracle配置环境变量用得到,第一个是静默安装需要的配置。第二个需要图形化连接安装。

附:第一个脚本其实没写完,最后没时间写了。先放上来,免得忘记了,有时间在写。

#!/bin/bash
#encoding:utf-8
#auto install oralce
oracle_env(){
yum -y install binutils compat-libstdc++-33 compat-libstdc++-33.i686 elfutils-libelf elfutils-libelf-devel gcc gcc-c++ glibc glibc.i686 glibc-common glibc-devel glibc-devel.i686 glibc-headers ksh libaio libaio.i686 libaio-devel libaio-devel.i686 libgcc libgcc.i686 libstdc++ libstdc++.i686 libstdc++-devel make sysstat
}
oracle_user(){
read -t 5  -p "请输入安装oracle的用户名,默认的用户名是oracle:" user
echo
read -t 5 -s -p "请输入为了oracle用户设置的密码,默认的密码是oracle:" password
if  test -z $user
then
        echo "开始创建ORACLE用户"
        /usr/sbin/groupadd oinstall
        /usr/sbin/groupadd dba
        /usr/sbin/useradd -g oinstall -G dba oracle
        echo "oracle" |passwd --stdin oracle
else
        echo "检测此用户是否被创建----------------------"
        if cat /etc/passwd | awk -F: '{print $1}'| grep  $user >/dev/null 2>&1
                then
                        echo "用户已经存在--------------"
        else
                echo "用户不存在,检测用户组是否存在后创建!"
                user_exist=0
        fi
        if cat /etc/group | awk -F: '{print $1}' | grep dba >/dev/null 2>&1
                then
                        echo "dba用户组已存在--------------"
        else
                echo "dba用户组不存在!"
                dba_exist=0
        fi
        if cat /etc/group | awk -F: '{print $1}'| grep oinstall > /dev/null 2>&1
                then
                        echo "oinstall用户组已存在----------"
        else
                echo "oinstall 用户组不存在!"
                oinstall_exist=0
        fi
        if [[ "$user_exist" -eq "0" ]] && [[ "$dba_exist" -eq "0" ]] && [[ "$oinstall_exist" -eq "0" ]]
                then
                        /usr/sbin/groupadd dba
                        /usr/sbin/groupadd oinstall
                        /usr/sbin/useradd -g oinstall -G dba $user
        elif [[ "$user_exist" -ne "0" ]] && [[ "$dba_exist" -eq "0" ]] && [[ "$oinstall_exist" -eq "0" ]]
                then
                        /usr/sbin/groupadd dba
                        /usr/sbin/groupadd oinstall
                        /usr/sbin/usermod -G dba,oinstall $user
        elif [[ "$user_exist" -ne "0" ]] && [[ "$dba_exist" -eq "0" ]] && [[ "$oinstall_exist" -eq "0" ]]
                then
                        /usr/sbin/groupadd dba
                        /usr/sbin/groupadd oinstall
                        /usr/sbin/usermod -G dba,oinstall $user
        elif [[ "$user_exist" -eq "0" ]] && [[ "$dba_exist" -ne "0" ]] && [[ "$oinstall_exist" -ne "0" ]]
                then
                        /usr/sbin/useradd -g oinstall -G dba $user
        elif [[ "$user_exist" -ne "0" ]] && [[ "$dba_exist" -ne "0" ]] && [[ "$oinstall_exist" -ne "0" ]]
                then
                        /usr/sbin/usermod -G oinstall,dba $user
        fi
fi
}
add_sysctl(){
echo "添加内核参数!"
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
echo "添加完成,使生效!"
sleep 3
sysctl -p
sleep 3
echo "更改用户文件限制!"
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
EOF
echo "更改完成!"
}
create_dir(){
echo "创建oracle安装目录!"
read -t 5 -p "请输入oracle的安装目录(默认安装在opt下):" dir
if test -z $dir
    then   
        mkdir -p /opt/oracle /opt/oraInventory /opt/oradata/;
        chown -R oracle:oinstall /opt/oracle /dopt/oraInventory /opt/oradata/;
        chmod -R 775 /opt/oracle /opt/oraInventory /opt/oradata/;
    else
        mkdir -p $dir/oracle/ $dir/oraInventory/ $dir/oradata/;
        chown -R $user.oinstall $dir/oracle $dir/oraInventory $dir/oradata;
        chmod -R 775 $dir/oracle/$dir/oraInventory $dir/oradata/;
fi
su - $user -c "cat >> ~/.bash_profile << "EOF"
export ORACLE_BASE=$dir/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1
export ORACLE_SID=orcl
export ORALCE_OWNER=oracle
export PATH=$PATH:$ORACLE_HOME/bin:$HOME/bin
EOF"
su - $user -c "source ~/.bash_profile"
}
cd /usr/src
unzip $1
unzip -o  $2
chmod 777 /data/database;
chown -R oracle.oinstall /data/database
#create oraInst file
cat >> /etc/oraInst.loc << "EOF"
inventory_loc=/data/oraInventory
inst_group=oinstall
EOF
#End
chown oracle.oinstall /etc/oraInst.loc
chmod 664 /etc/oraInst.loc
#create Response file
#backup ResponseFile file
cp $ResponseFile /data/database/response/db_install.bak;
sed -i '32s/$/INSTALL_DB_AND_CONFIG/' $ResponseFile;
sed -i '37s#$#oracledb#' $ResponseFile;
sed -i '42s#$#oinstall#' $ResponseFile;
sed -i '47s#$#/data/oraInventory#' $ResponseFile;
sed -i '78s#$#en,zh_CN#' $ResponseFile;
sed -i '83s#$#/data/oracle/product/11.2.0/db_1#' $ResponseFile
sed -i '88s#$#/data/oracle#' $ResponseFile
sed -i '99s/$/EE/' $ResponseFile
sed -i '142s/$/oinstall/' $ResponseFile
sed -i '147s/$/oinstall/' $ResponseFile
sed -i '160s/$/GENERAL_PURPOSE/' $ResponseFile
sed -i '165s/$/oracle/' $ResponseFile
sed -i '170s/$/oracl/'  $ResponseFile
sed -i '200s/$/512/' $ResponseFile
sed -i '233s/$/Oracle123/' $ResponseFile
sed -i '324s#$#FILE_SYSTEM_STORAGE#' $ResponseFile
sed -i '332s#$#/data/oradata/ora11g/ORA11G#' $ResponseFile
sed -i '385s/$/true/' $ResponseFile
#End Edit
echo -e "-------------------------------------------------------------------------------------------------------End Edit-----------------------------------------------------------------------------------------------------------------------"#Start install oracle
echo -e "Start install oracle"
su - oracle -c "/data/database/runInstaller -silent -responseFile /data/database/response/db_install.rsp"
#installing
echo -e "oracle is installing"
#Run the oracle script
echo -e "Run of the oracle script"
sh /data/oracle/product/11.2.0/db_1/root.sh
echo -e "Oracle is installed"
echo -e "Please look the /etc/oratab file,have no SID!!!"


----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------



#!/bin/bash
function swapfile
{
dd if=/dev/zero of=/home/swap bs=1M count=$mem
mkswap /home/swap
echo "/home/swap         swap    swap    defaults        0 0">> /etc/fstab
swapon -a
}
phymem=`free -m | grep Mem | awk  '{ printf $2 }'`
swapmem=`free -m | grep Swap | awk  '{ printf $2 }'`
if [ $phymem -lt 1024 ];then
       {
       echo "RAM is too small , oracle install faild !"
       exit 1
       }
       else
                if [ $phymem -lt 2048 ];then
                   {
#2swap
                            mem=`expr $phymem \* 2 - $swapmem + 15`
                            swapfile
                   }
                   else
                            if [ $phymem -lt 16384 ];then
                                     {
                                               mem=`expr $phymem - $swapmem + 15`
                                               swapfile $mem
                                     }
                            else
                                     {
                                               mem=`expr 16384 - $swapmem + 15`
                                               swapfile $mem
                                     }
                            fi
                   fi
fi
unzip linux_11gR2_database_1of2.zip
unzip -o linux_11gR2_database_2of2.zip
groupadd dba
groupadd oinstall
useradd -g oinstall -G dba oracle
echo oracle | passwd oracle --stdin
mkdir /opt/oracle
chmod 777 /opt
chmod 777 /opt/oracle/
chmod 777 /var
chmod 777 /var/opt
mkdir -p /opt/oracle/product
mkdir -p /opt/oracle/product/OraHome
mkdir -p /opt/oraInventory                  
mkdir -p /opt/oracle/oradata               
mkdir -p /var/opt/oracle
chown oracle:oinstall /opt
chown -R oracle:oinstall /opt/oracle
chown -R oracle:dba /opt/oraInventory
chown oracle:dba /var/opt/oracle
chmod -R 777 /opt/oracle
chmod -R 777 /var/opt/oracle
mkdir -p /oracle
mv database /oracle/database
chown oracle -R /oracle
chown oracle.oinstall /oracle
yum -y install binutils compat-libstdc++-33 elfutils-libelf elfutils-libelf-devel gcc gcc-c++ glibc glibc-common glibc-devel glibc-headers libaio libaio-devel libgcc libstdc++ libstdc++-devel make sysstat unixODBC unixODBC-devel ksh numactl-devel kernel-headers pdksh jre
cat >> /home/oracle/.bash_profile <<EOF
export ORACLE_BASE=/opt/oracle
export ORACLE_HOME=/opt/oracle/product/OraHome
export ORACLE_SID=orcl
export ORACLE_OWNER=oracle
export ORACLE_TERM=vt100
export PATH=\$PATH:\$ORACLE_HOME/bin:\$HOME/bin
export PATH=\$ORACLE_HOME/bin:\$ORACLE_HOME/Apache/Apache/bin:\$PATH
LD_LIBRARY_PATH=\$ORACLE_HOME/lib:/lib:/usr/lib:/usr/local/lib
export LD_LIBRARY_PATH
CLASSPATH=\$ORACLE_HOME/JRE:\$ORACLE_HOME/jlib:\$ORACLE_HOME/rdbms/jlib
CLASSPATH=\$CLASSPATH:\$ORACLE_HOME/network/jlib
export CLASSPATH
ORA_NLS33=\$ORACLE_HOME/nls/admin/data
EOF
cat >> /etc/security/limits.conf <<EOF
oracle soft nofile 65536
oracle hard nofile 65536
oracle soft nproc 16384
oracle hard nproc 16384
EOF
echo "session required /lib/security/pam_limits.so" >> /etc/pam.d/login
echo "session required pam_limits.so" >> /etc/pam.d/login
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
export DISPLAY=:0.0
xhost +
cat >> /etc/sysctl.conf <<EOF
fs.aio-max-nr = 1048576
kernel.shmall = 2097152
kernel.shmmax = 536870912
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
fs.file-max = 6815744
net.ipv4.ip_local_port_range = 9000 65500
net.core.rmem_default = 262144
net.core.rmem_max = 4194304
net.core.wmem_max = 1048576
net.core.wmem_default = 262144
EOF
sysctl -p
echo "IS OK! 10s will be reboot!"
sleep 10
reboot


你可能感兴趣的:(oracle,安装脚本)