oracle11gr2一键配置脚本-创新互联
最近工作需要安装oracle 11g R2在阿里云ECS上,因此编写了一个脚本来完成图形化安装界面之前的准备工作,这样节省时间,shell如下:
网站建设公司,为您提供网站建设,网站制作,网页设计及定制网站建设服务,专注于
成都定制网页设计,高端网页制作,对
楼梯护栏等多个行业拥有丰富的网站建设经验的网站建设公司。专业网站设计,网站优化推广哪家好,专业
成都网站营销优化,H5建站,响应式网站。#!/bin/bash
SYSCTL="/etc/sysctl.conf"
LIMITS="/etc/security/limits.conf"
PAM="/etc/pam.d/login"
PROFILE="/etc/profile"
BASH_PROFILE="/home/oracle/.bash_profile"
oracle_passwd='oracle'
SID=orcl
lang="AMERICAN_AMERICA.AL32UTF8"
#ora_install_dir=/u01
#ora_database_dir=/u02
ORACLE_BASE=$ora_install_dir/app/oracle
ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db
#初始化检查,OS版本、内存、磁盘情况
check_init()
{
OS=`cat /etc/redhat-release`
MEM=`free -m |grep 'Mem' | awk '{print $2}'`
CPUS=`grep -i "processor" /proc/cpuinfo | wc -l`
echo "系统版本:$OS"
echo "内存:${MEM}M"
echo "CPU核数:$CPUS"
}
#检查swap空间是否分配
check_swap()
{
mem=`free -g |grep 'Mem' | awk '{print $2}'`
mem_temp=$(($mem%2))
swap_all=`free -m |grep 'Swap' |awk '{print $2}'`
if [ $mem_temp == 1 ];then
mem=$(($mem+1))
swap=$(($mem/2))
echo -e "\n\e[1;32m 系统内存为 ${mem}GB \e[0m"
fi
swap_check="`grep -i 'swaptotal' /proc/meminfo |awk '{print $2}'`"
if [[ $swap_check = "0" ]];then
read -p " swap分区没有设置,请进行设置,输入[y] or [n]:" temp
if [ $temp == "y" ];then
COUNT=$(($swap * 1024))
echo -e "\n\e[1;31m 开始设置swap分区,/mnt/swap=${swap}GB \e[0m"
dd if=/dev/zero of=/mnt/swap bs=1M count=${COUNT}
mkswap /mnt/swap
swapon /mnt/swap
echo "/mnt/swap swap swap defaults 0 0" >> /etc/fstab
else
echo "请检查或手工设置swap分区后运行该脚本!"
exit 1
fi
else
echo -e "\n\e[1;31m系统内存为${mem}GB 当前swap分区已经配置,大小为${swap_all}MB \e[0m"
fi
}
#检查是否root用户执行脚本
isroot()
{
if [ $USER != "root" ];then
echo -e "\n\e[1;31m The user must be root,and you user is $USER,please su to root.\e[0m"
exit 4
fi
}
#创建oracle用户
oracle_useradd()
{
if [[ `grep "oracle" /etc/passwd` != "" ]];then
echo -e "\e[1;31m User oracle exits, delete and create oracle! \e[0m" && sleep 2
userdel -rf oracle
fi
if [[ `grep "oinstall" /etc/group` = "" ]];then
groupadd oinstall
fi
if [[ `grep "dba" /etc/group` = "" ]];then
groupadd dba
fi
useradd oracle -g oinstall -G dba && echo $oracle_passwd |passwd oracle --stdin
if [ $? -eq 0 ];then
echo -e "\n\e[1;32m oracle's password update successfully ---OK! \e[0m"
else
echo -e "\n\e[1;31m oracle's password set failed. ---NO! \e[0m"
fi
}
#创建oracle使用的目录
oracle_dirs()
{
read -p "please input oracle install dirname,default /u01": ora_install_dir
read -p "please input oracle database dirname,default /u02": ora_database_dir
mkdir -p $ora_install_dir/app/oracle/{oraInventory,product/11.2.0/db}
mkdir -p "$ora_database_dir/oradata/oradb"
chown -R oracle:oinstall $ora_install_dir
chown -R oracle.oinstall $ora_database_dir
chmod -R 755 $ora_install_dir $ora_database_dir
if [ $? == 0 ];then
echo "$ora_install_dir create sucessfully!"
echo "$ora_database_dir create sucessfully!"
else
echo "$ora_install_dir or $ora_database_dir create Failed,please check!"
exit 2
fi
}
#配置profile文件
oracle_profile()
{
if [ -f "/etc/profile.bak" ];then
rm -rf /etc/profile >/dev/null
cp /etc/profile.bak /etc/profile
cat << EOF >>$PROFILE
if [ $USER = "oracle" ];then
if [ $SHELL = "/bin/ksh" ];then
ulimit -p 16384
ulimit -n 65536
else
ulimit -u 16384 -n 65536
fi
fi
EOF
else
cp /etc/profile /etc/profile.bak
cat << EOF >>$PROFILE
if [ $USER = "oracle" ];then
if [ $SHELL = "/bin/ksh" ];then
ulimit -p 16384
ulimit -n 65536
else
ulimit -u 16384 -n 65536
fi
fi
EOF
fi
if [ $? -eq 0 ];then
echo -e "\n\e[1;32m $PROFILE update successfully... OK! \e[0m"
fi
}
#配置.bash_profile()
oracle_bash()
{
if [ -f "/home/oracle/.bash_profile.bak" ];then
rm -rf $BASH_PROFILE>/dev/null
cp /home/oracle/.bash_profile.bak $BASH_PROFILE
cat <
> $BASH_PROFILE
export ORACLE_BASE=$ORACLE_BASE
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db
export ORACLE_SID=$SID
export ORACLE_TERM=xterm
export ORACLE_OWNER=oracle
export TNS_ADMIN=$ORACLE_HOME/network/admin
export ORA_NLS33=$ORACLE_HOME/ocommon/nls/admin/data
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$ORACLE_HOME/network/lib:/lib:/usr/lib:/usr/local/lib
export LIBPATH=$ORACLE_HOME/lib:$ORACLE_HOME/network/lib:/lib:/usr/lib:/usr/local/lib
export PATH=$PATH:/sbin:/usr/bin:/usr/sbin:$JAVA_HOME/bin:$ORACLE_HOME/bin:$ORACLE_HOME/lib:$HOME/bin:$ORACLE_HOME/OPatch:.
umask 022
export NLS_LANG=$lang
EOF
else
cp $BASH_PROFILE /home/oracle/.bash_profile.bak
cat <> $BASH_PROFILE
export ORACLE_BASE=$ORACLE_BASE
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db
export ORACLE_SID=$SID
export ORACLE_TERM=xterm
export ORACLE_OWNER=oracle
export TNS_ADMIN=$ORACLE_HOME/network/admin
export ORA_NLS33=$ORACLE_HOME/ocommon/nls/admin/data
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$ORACLE_HOME/network/lib:/lib:/usr/lib:/usr/local/lib
export LIBPATH=$ORACLE_HOME/lib:$ORACLE_HOME/network/lib:/lib:/usr/lib:/usr/local/lib
export PATH=$PATH:/sbin:/usr/bin:/usr/sbin:$JAVA_HOME/bin:$ORACLE_HOME/bin:$ORACLE_HOME/lib:$HOME/bin:$ORACLE_HOME/OPatch:.
umask 022
export NLS_LANG=$lang
EOF
fi
if [ $? -eq 0 ];then
echo -e "\n\e[1;32m $BASH_PROFILE update successfully...OK! \e[0m"
fi
}
#设置limit资源限制
oracle_limit()
{
if [ -f "/etc/security/limits.conf.bak" ];then
rm -rf $LIMITS>/dev/null
cp /etc/security/limits.conf.bak $LIMITS
cat <> $LIMITS
oracle soft nproc 8192
oracle hard nproc 16384
oracle soft nofile 8192
oracle hard nofile 65536
EOF
else
cp $LIMITS /etc/security/limits.conf.bak
cat <> $LIMITS
oracle soft nproc 8192
oracle hard nproc 16384
oracle soft nofile 8192
oracle hard nofile 65536
EOF
fi
if [ $? -eq 0 ];then
echo -e "\n\e[1;32m $LIMITS update sucessfully...OK! \e[0m"
fi
}
#设置内核参数
oracle_kernal()
{
if [ -f /etc/sysctl.conf.bak ];then
rm -rf $SYSCTL>/dev/null
cp /etc/sysctl.conf.bak $SYSCTL
sed -i 's/kernel.msgmnb.*/#kernel.msgmnb = 65536/g' $SYSCTL
sed -i 's/kernel.msgmax.*/#kernel.msgmax = 65536/g' $SYSCTL
sed -i 's/kernel.shmmax.*/#kernel.shmmax = 68719476736/g' $SYSCTL
sed -i 's/kernel.shmall.*/#kernel.shmall = 4294967296/g' $SYSCTL
cat <> $SYSCTL
kernel.shmall = 2097152
kernel.shmmax = 2147483648
kernel.shmmni = 40960
kernel.sem = 250 32000 100 128
kernel.msgmni = 4096
kernel.msgmax = 65536
kernel.msgmnb = 84000
fs.file-max = 6815744
net.ipv4.ip_local_port_range = 9000 65500
fs.file-max = 6815744
net.core.rmem_default = 262144
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 1048576
fs.aio-max-nr = 1048576
net.ipv4.tcp_wmem = 262144 262144 262144
net.ipv4.tcp_rmem = 4194304 4194304 4194304
EOF
else
cp $SYSCTL /etc/sysctl.conf.bak
sed -i 's/kernel.msgmnb.*/#kernel.msgmnb = 65536/g' $SYSCTL
sed -i 's/kernel.msgmax.*/#kernel.msgmax = 65536/g' $SYSCTL
sed -i 's/kernel.shmmax.*/#kernel.shmmax = 68719476736/g' $SYSCTL
sed -i 's/kernel.shmall.*/#kernel.shmall = 4294967296/g' $SYSCTL
cat <> $SYSCTL
kernel.shmall = 2097152
kernel.shmmax = 2147483648
kernel.shmmni = 40960
kernel.sem = 250 32000 100 128
kernel.msgmni = 4096
kernel.msgmax = 65536
kernel.msgmnb = 84000
fs.file-max = 6815744
net.ipv4.ip_local_port_range = 9000 65500
fs.file-max = 6815744
net.core.rmem_default = 262144
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 1048576
fs.aio-max-nr = 1048576
net.ipv4.tcp_wmem = 262144 262144 262144
net.ipv4.tcp_rmem = 4194304 4194304 4194304
EOF
fi
if [ $? -eq 0 ];then
echo -e "\n\e[1;32m $SYSCTL update sucessfully...OK! \e[0m"
fi
}
#关闭iptables and selinux
iptables_selinux()
{
service iptables stop && chkconfig iptables off
setenforce 0 &>/dev/null
sed -i '/SELINUX/s/enforcing/disabled/;/SELINUX/s/permissive/disabled/' /etc/selinux/config
}
#下载oracle安装文件
get_oracle()
{
wget http://10.139.96.23:8080/p13390677_112040_Linux-x86-64_1of7.zip -P /home/oracle && wget http://10.139.96.23:8080/p13390677_112040_Linux-x86-64_2of7.zip -P /home/oracle
}
#oracle安装准备主程序
main()
{
isroot
check_init && sleep 1
check_swap && sleep 1
oracle_useradd && sleep 1
oracle_dirs && sleep 1
oracle_profile && sleep 1
oracle_bash && sleep 1
oracle_limit && sleep 1
oracle_kernal && sleep 1
iptables_selinux && sleep 1
get_oracle && sleep 1
if [ $? -eq 0 ] ;then
echo -e "\n\e[1;32m oracle初始化配置已经完成,请确保图形化界面正常工作,执行./database安装程序! \e[0m"
fi
}
main另外有需要云服务器可以了解下创新互联cdcxhl.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。
网站标题:oracle11gr2一键配置脚本-创新互联
链接地址:http://myzitong.com/article/ejgps.html