侧边栏壁纸
博主头像
与晚风述往事博主等级

万般皆下品,唯有读书高。

  • 累计撰写 149 篇文章
  • 累计创建 29 个标签
  • 累计收到 7 条评论

目 录CONTENT

文章目录

Oracle安装前自动配置脚本

与晚风述往事
2022-01-10 / 0 评论 / 1 点赞 / 212 阅读 / 5,826 字 / 正在检测是否收录...
温馨提示:
本文最后更新于 2022-04-21,若内容或图片失效,请留言反馈。部分素材来自网络,若不小心影响到您的利益,请联系我们删除。

介绍

为了加快安装Oracle的速度,也为了能够偷个懒,不用再手动复制大量的命令去执行,我就写了个简单的Shell的脚本,自动执行Oracle安装前所需要执行的命令。

说明

脚本首先会检查oracle用户是否存在,如果存在,则直接退出,否则,会执行以下步骤:

  • 创建oracle用户
  • 配置redhat-release
  • 检查firewalld的状态。如果firewalld是运行状态,则开放指定的端口并重启;反之,则不执行任何操作。
  • 检查selinux的状态。如果selinux状态不是disable,则立即改为disable状态,并配置到/etc/selinux/config中。
  • 配置内核参数
  • 配置用户资源限制
  • 配置oracle用户的环境变量

注意,在脚本执行后,需要手动去安装oracle所需要的依赖。否则,在安装时先决条件检查会出现大量的错误。

CentOS 7 安装依赖

[root@localhost home]# yum install binutils* compat* gcc* glibc* ksh* libaio* libgcc* libstdc* libXi* libXtst* make* sysstat* elfutils*

参数

脚本有以下需要根据实际环境手动去配置的参数:

  • HOME 指定安装Oracle的目录位置,会在此目录创建oracle、database和oraInventory目录
  • ORACLE_PASSWD 指定创建oracle用户的密码
  • ORACLE_SID 指定配置到oracle用户环境变量的SID
  • PORT 指定要开放的端口号,通常是1521
  • MEM_PERCENTAGE 指定内核参数kernel.shmall和kernel.shmmax的大小,大小会基于操作系统的内存的百分比计算。例如指定80,则会指定成内存的80%。单实例建议设置为85%

脚本

#!/bin/bash

#Date:2021-01-10
#Author:Created by b
#Version:1.0
#Describe:Automatically configure the configuration required for Oracle installation

HOME="/home"
ORACLE_PASSWD="123456"
ORACLE_SID=orcl
PORT=1521
MEM_PERCENTAGE=85

function User_Create(){
  groupadd oinstall
  groupadd dba
  useradd -g oinstall -g dba -m oracle
  groups oracle > /dev/null
  echo ${ORACLE_PASSWD} | passwd --stdin oracle > /dev/null
  echo "=============== User created success ==============="
}

function Directory_Create(){

  mkdir -p ${HOME}/oracle
  mkdir -p ${HOME}/oraInventory
  mkdir -p ${HOME}/database
  chown -R oracle:oinstall ${HOME}/oracle
  chown -R oracle:oinstall ${HOME}/oraInventory
  chown -R oracle:oinstall ${HOME}/database
  echo "=============== Directory created successfully ==============="

}

function System_Version_Update(){
  echo "redhat-7" > /etc/redhat-release

}

function Port_Configure(){
  local temp_parameter=$(systemctl status firewalld | grep Active |awk '{printf($2)}')

  if [ $temp_parameter == "active" ]
    then
      firewall-cmd --permanent --zone=public --add-port=1521/tcp > /dev/null
      systemctl restart firewalld

      echo "=============== port ${PORT} configure successfully ==============="
    else
      echo "---------- Firewalld has been disabled  ----------"
  fi

}

function Selinux_Configure(){
  local temp_parameter=$(getenforce)

  if [ ${temp_parameter} == "Enforcing" ] || [ ${temp_parameter} == "Permissive" ]
    then
      setenforce 0
      sed -i 's#SELINUX=.*#SELINUX=disabled#' /etc/selinux/config
      echo "=============== selinux configure successfully ==============="
    else
      echo "---------- selinux does not require configuration ----------"
  fi

}

function Kernel_Configure(){
  local kernel_shmmax=$(cat /proc/meminfo | grep "MemTotal:" |awk -v mem=${MEM_PERCENTAGE} '{printf($2*1024/100*mem)}' |awk '{printf("%d",$0)}')
  local kernel_shmall=$(cat /proc/meminfo | grep "MemTotal:" |awk -v mem=${MEM_PERCENTAGE} '{printf($2*1024/100*mem)/4096}' |awk '{printf("%d",$0)}')


  if [ ${kernel_shmall} -le 2097152 ]; then
    kernel_shmall=2097152
  fi

  echo "net.ipv4.icmp_echo_ignore_broadcasts = 1" >> /etc/sysctl.conf
  echo "net.ipv4.conf.all.rp_filter = 1" >> /etc/sysctl.conf
  echo "fs.file-max = 6815744" >> /etc/sysctl.conf
  echo "fs.aio-max-nr = 1048576" >> /etc/sysctl.conf
  echo "kernel.shmall = ${kernel_shmall}" >> /etc/sysctl.conf
  echo "kernel.shmmax = ${kernel_shmmax}" >> /etc/sysctl.conf
  echo "kernel.shmmni = 4096" >> /etc/sysctl.conf
  echo "kernel.sem = 250 32000 100 128" >> /etc/sysctl.conf
  echo "net.ipv4.ip_local_port_range = 9000 65500" >> /etc/sysctl.conf
  echo "net.core.rmem_default = 262144" >> /etc/sysctl.conf
  echo "net.core.rmem_max= 4194304" >> /etc/sysctl.conf
  echo "net.core.wmem_default= 262144" >> /etc/sysctl.conf
  echo "net.core.wmem_max= 1048576" >> /etc/sysctl.conf

  sysctl -p > /dev/null

  echo "=============== kernel configure successfully ==============="

}

function User_Resource_Configure(){

  echo "session required /lib/security/pam_limits.so" >>/etc/pam.d/login
  echo "oracle soft nproc 2047" >> /etc/security/limits.conf
  echo "oracle hard nproc 16384" >> /etc/security/limits.conf
  echo "oracle soft nofile 1024" >> /etc/security/limits.conf
  echo "oracle hard nofile 65536" >> /etc/security/limits.conf
  
  echo 'if [ $USER = "oracle" ] || [ $USER = "grid" ] ; then' >>  /etc/profile
  echo ' if [ $SHELL = "/bin/ksh" ]; then' >> /etc/profile
  echo '  ulimit -p 16384' >> /etc/profile
  echo '  ulimit -n 65536' >> /etc/profile
  echo ' else' >> /etc/profile
  echo '  ulimit -u 16384 -n 65536' >> /etc/profile
  echo ' fi' >> /etc/profile
  echo 'fi' >> /etc/profile

  echo "=============== user resource configure successfully ==============="
}

function Oracle_Env_Configure(){

  echo "export ORACLE_BASE=${HOME}/oracle">> /home/oracle/.bash_profile
  echo "export ORACLE_HOME=${HOME}/oracle/app/oracle/product/11.2.0/dbhome_1">> /home/oracle/.bash_profile
  echo "export ORACLE_SID=${ORACLE_SID}">> /home/oracle/.bash_profile
  echo "export ORACLE_TERM=xterm">> /home/oracle/.bash_profile
  echo "export PATH=\$ORACLE_HOME/bin:/usr/sbin:\$PATH">> /home/oracle/.bash_profile
  echo "export LD_LIBRARY_PATH=\$ORACLE_HOME/lib:/lib:/usr/lib">> /home/oracle/.bash_profile
  echo "export LANG=C">> /home/oracle/.bash_profile
  echo "export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK">> /home/oracle/.bash_profile
  source /home/oracle/.bash_profile

  echo "=============== configure oracle environment successfully ==============="

}

function main(){
  if [ "$(grep -o "^oracle" /etc/passwd)" = oracle ]
    then
      echo "User already exists ! "
    else
      User_Create
      Directory_Create
      System_Version_Update
      Port_Configure
      Selinux_Configure
      Kernel_Configure
      User_Resource_Configure
      Oracle_Env_Configure
      echo "After the initial configuration is complete, install Oracle dependencies"  
  fi

}

main
1

评论区