-------------+-----------------------------
# * Filename : selinux.
sh
# * Date :
2020-
07-
16
# *
Author : wangjianxiong
# * Description : oracle silent
install
# -------------+-----------------------------
#
# bin conf file log readme share tmp
#
os=
""
ip=
"192.168.64.131"
myhostname=
"oracle.daxiong.com"
myhostname_alias=
"oracle"
num=
$RANDOM
mymem=`
free |
grep Mem |
awk ‘{print $2}‘`
myswap=`
free |
grep Swap |
awk ‘{print $2}‘`
Ora_Installation_Position=/u01/
app
INSTALLATION_FAILURE=/tmp/
oracle_installation_failure_exit_code
ORACLE_INSTALL_LOG=/tmp/
oracle_install.log
STEP=
"1"
show_spinner()
{
$* &
PID=$!
local delay=
0.1
local spinstr=
‘|/-\‘
spin[
0]=
"-"
spin[1]=
"\\"
spin[2]=
"|"
spin[3]=
"/"
sleep 0.05
echo -n
" ... "
while kill -
0 $PID
2>/dev/
null
do
if [ -z $DEBUG ];
then
for i
in "${spin[@]}"
do
echo -ne
"$i"
sleep 0.1
echo -ne
"\b"
done
else
sleep 0.1
fi
done
if [ -f $INSTALLATION_FAILURE ];
then
failure_reason=`
cat $INSTALLATION_FAILURE`
if [ -z $DEBUG ];
then
echo -e
"$(tput setaf 1)\nFAIL\n$(tput sgr0)"|
tee -
a $ORACLE_INSTALL_LOG
echo -e
"$(tput setaf 1)Reason: $failure_reason\n$(tput sgr0)"|
tee -
a $ORACLE_INSTALL_LOG
else
echo "FAIL"
echo "Reason: $failure_reason"
fi
exit 1
else
if [ -z $DEBUG ];
then
echo -e
"$(tput setaf 2)PASS$(tput sgr0)"|
tee -
a $ORACLE_INSTALL_LOG
else
echo "PASS"
fi
fi
}
echo_title(){
echo "\n================">>
$ORACLE_INSTALL_LOG
echo ""|
tee -
a $ORACLE_INSTALL_LOG
echo -n
" ${STEP}. $*:" |
tee -
a $ORACLE_INSTALL_LOG
STEP=`
expr $STEP +
1`
}
echo_subtitle(){
echo "\n----------------" >>
$ORACLE_INSTALL_LOG
echo -n
" $*:"|
tee -
a $ORACLE_INSTALL_LOG
}
fail(){
tput cub 6
#echo -e
"$(tput setaf 1) \nFAIL\n$(tput sgr0)"|
tee -
a $ORACLE_INSTALL_LOG
echo -e
"$(tput setaf 1) Reason: $*\n$(tput sgr0)"|
tee -
a $ORACLE_INSTALL_LOG
echo "$* \n\nThe detailed installation log could be found in $ORACLE_INSTALL_LOG " >
$INSTALLATION_FAILURE
exit 1
}
# Set the host name
set_hostname()
{
echo_subtitle "设置主机名,修改/etc/hosts"
sleep 1
hostnamectl set-
hostname $myhostname
cat >>/etc/hosts <<
EOF
$ip $myhostname $myhostname_alias
EOF
}
# Set the swap size
# If the physical memory is 2GB or less, swap should be
1.5 times the physical memory.
# If there is between 2GB and 16GB of physical memory, then swap size should be equal to physical memory.
# If the physical memory is greater than 16GB, then 16GB is sufficient
for SWAP.
set_swap()
{
echo_subtitle "设置swap交互分区"
sleep 1
if [ $mymem -le
2048000 ];
then
let addswap=
3072000-
$myswap
elif [ $mymem -gt
2048000 ] && [ $mymem -lt
16384000 ];
then
let addswap=$mymem-
$myswap
elif [ $mymem -gt
16384000 ];
then
let addswap=
16384000-
$myswap
fi
if [ $addswap -lt
40 ];
then # Swap area needs to be at least
40 KiB
echo "Swap area needs to be at least 40 KiB" >> $ORACLE_INSTALL_LOG
2>&
1
echo "Swap now size [ $myswap ], No need to expand." >> $ORACLE_INSTALL_LOG
2>&
1
else
# Add a SWAP partition under /
var to randomly generate a directory ending with the number beginning swap.
dd if=/dev/zero of=/var/swap_$num bs=
1024 count=$addswap >> $ORACLE_INSTALL_LOG
2>&
1
mkswap /var/swap_$num >> $ORACLE_INSTALL_LOG
2>&
1
swapon /var/swap_$num >> $ORACLE_INSTALL_LOG
2>&
1
if [ $? -eq
0 ];
then
echo "/var/swap_$num swap swap defaults 0 0" >> /etc/
fstab
else
fail "swap设置失败,请查看日志文件 : $ORACLE_INSTALL_LOG"
fi
# Add all swap partitions, or free.
ret=`
cat /proc/swaps |
grep ^/ |
awk ‘{print $3}‘ |
awk ‘{sum+=$1}END{print sum}‘`
echo "Swap is set to $ret" >> $ORACLE_INSTALL_LOG
2>&
1
fi
}
# check sys
check_sys()
{
echo_subtitle "检查系统"
sleep 1
# 2>&
1 >/dev/
null : Standard output enters /dev/
null and error output is printed to the screen.
# >/dev/
null 2>&
1 : Both standard output and error output enter /dev/
null.
rpm -q centos-release >/dev/
null 2>&
1
if [ $? -eq
0 ];
then
v=`
cat /etc/redhat-release|
sed -r
‘s/.* ([0-9]+)\..*/\1/‘`
if [ $v -eq
6 ];
then
os=
"centos6"
fail "这个系统不是 Centos7."
elif [ $v -eq
7 ];
then
os=
"centos7"
mv /etc/centos-release ../
file
echo "redhat-7" > /etc/centos-
release
fi
else
fail "这个系统不是 Centos."
fi
t_mem=`
grep MemTotal /proc/meminfo |
awk ‘{print $2}‘`
if [ $t_mem -le
2048000 ];
then
fail "系统内存需要大于2G."
fi
tmp_s=`
df -h /tmp |
grep /dev |
awk ‘{print $2}‘ |
tr -cd
"[0-9]"`
if [ $tmp_s -le
1 ];
then
fail "/tmp 空间需要大于1G"
fi
}
# set selinux=
disabled
set_selinux()
{
echo_subtitle "设置selinux=disabled"
sleep 1
setenforce 0
sed -i
‘/SELINUX/s/enforcing/disabled/‘ /etc/selinux/
config
if [ $? -eq
0 ];
then
echo "Current set seliunx=permissive, restart system after selinux=disabled." >> $ORACLE_INSTALL_LOG
2>&
1
else
fail "设置 selinux 失败."
fi
}
# Checking the Software Requirements
# Oracle‘s website : https://docs.oracle.com/cd/E11882_01/install.112/e24326/toc.htm#CIHFICFD
# The following or later version of packages
for Oracle Linux
4 and Red Hat Enterprise Linux
4 must be installed:
# Remove the version number and use yum to
install.
must_pkg()
{
echo_subtitle "安装oracle所需依赖包"
yum -y
install bc binutils compat-
libcap1 compat-libstdc++
33 elfutils-
libelf elfutils-libelf-
devel fontconfig-
devel glibc glibc-
devel ksh libaio libaio-
devel libX11 libXau libXi libXtst libXrender libXrender-
devel libgcc libstdc++
libstdc++-
devel libxcb make smartmontools sysstat ipmiutil net-
tools nfs-
utils python python-
configshell python-
rtslib python-
six targetcli dtrace-
modules dtrace-modules-
headers dtrace-modules-provider-
headers dtrace-
utils gcc gcc-c++
libdtrace-ctf-
devel librdmacm-
devel unixODBC >> $ORACLE_INSTALL_LOG
2>&
1
if [ $? -ne
0 ];
then
fail "安装oracle所需依赖失败."
fi
}
create_orauser()
{
echo_subtitle "创建oracle用户"
# Create group : oinstall dba oper backupdba dgdba kmdba asmdba asmoper racdba
for i
in oinstall dba oper backupdba dgdba kmdba asmdba asmoper racdba
do
egrep "^$i" /etc/group >& /dev/
null
if [ $? -ne
0 ];
then
/usr/sbin/
groupadd $i
fi
done
# Creating an Oracle user
egrep "^oracle" /etc/
passwd >& /dev/
null
if [ $? -ne
0 ];
then
/usr/sbin/useradd -g oinstall -
G dba,oper,backupdba,dgdba,kmdba,asmdba,asmoper,racdba oracle
if [ $? -ne
0 ];
then
fail "创建oracle用户失败"
fi
fi
echo oracle |
passwd --stdin oracle >& /dev/
null
if [ $? -eq
0 ];
then
echo "oracle用户的密码: oracle" >> $ORACLE_INSTALL_LOG
2>&
1
else
fail "设置oracle用户密码失败"
fi
}
# Configuring Kernel Parameters and Resource Limits
# Oracle‘s website : https://docs.oracle.com/cd/E11882_01/install.112/e24326/toc.htm#BHCCADGD
conf_kernel()
{
echo_subtitle "设置内核参数"
sleep 1
tmem=`
echo "scale=1; $mymem/1024/1024/2" | bc |
awk -F.
‘{if(substr($2,1,1)>=5)$1+=1;print $1}‘`
let my_shmall=tmem*
1024*
256
let my_shmmax=tmem*
1024*
1024*
1024
cat >>/etc/sysctl.conf <<
EOF
net.ipv4.icmp_echo_ignore_broadcasts =
1
net.ipv4.conf.all.rp_filter =
1
fs.aio-max-nr =
1048576
fs.file-max =
6815744
kernel.shmall =
$my_shmall
kernel.shmmax =
$my_shmmax
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 =
1048576
EOF
/sbin/sysctl -p >> $ORACLE_INSTALL_LOG
2>&
1
}
set_limit()
{
echo_subtitle "修改用户限制"
sleep 1
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
oracle hard stack 10240
EOF
cat >>/etc/pam.d/
login <<
EOF
session required /lib64/security/
pam_limits.so
session required pam_limits.so
EOF
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
source /etc/
profile
}
# Create installation directory.
create_dir()
{
echo_subtitle "创建安装目录"
[ ! -d $Ora_Installation_Position ] &&
mkdir -
p $Ora_Installation_Position
[ ! -d $Ora_Installation_Position/oracle/product/
19.3.
0/db_1 ] &&
mkdir -p $Ora_Installation_Position/oracle/product/
19.3.
0/
db_1
[ ! -d $Ora_Installation_Position/oracle/oradata ] &&
mkdir -p $Ora_Installation_Position/oracle/
oradata
[ ! -d $Ora_Installation_Position/oracle/oraInventory ] &&
mkdir -p $Ora_Installation_Position/oracle/
oraInventory
[ ! -d $Ora_Installation_Position/oracle/flash_recovery_area ] &&
mkdir -p $Ora_Installation_Position/oracle/
flash_recovery_area
chown -
R oracle:oinstall $Ora_Installation_Position
chmod -R
775 $Ora_Installation_Position
cat >/etc/oraInst.loc <<
EOF
inventory_loc=$Ora_Installation_Position/oracle/
oraInventory
inst_group=
oinstall
EOF
chown oracle:oinstall /etc/
oraInst.loc
chmod 664 /etc/
oraInst.loc
}
# Configure The Oracle environment variables.
conf_ora_env()
{
echo_subtitle "设置oracle用户环境变量"
cat >>/home/oracle/.bash_profile <<
EOF
umask 022
export ORACLE_BASE=/u01/app/
oracle
export ORACLE_HOME=$ORACLE_BASE/product/
19.3.
0/
db_1
export ORACLE_SID=
orcl
NLS_DATE_FORMAT=
"YYYY:MM:DDHH24:MI:SS"
export PATH=$ORACLE_HOME/bin:/usr/
sbin:$PATH
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/
lib
export LANG=en_US.UTF-
8
export NLS_LANG=
AMERICAN_AMERICA.UTF8
EOF
su - oracle -c
"source /home/oracle/.bash_profile"
}
unzip_oracle()
{
echo_subtitle "解压安装介质"
which unzip >> $ORACLE_INSTALL_LOG
2>&
1
if [ $? -ne
0 ];
then
yum -y
install zip unzip >> $ORACLE_INSTALL_LOG
2>&
1
fi
ORACLE_HOME=/u01/app/oracle/product/
19.3.
0/
db_1
unzip -q ../share/LINUX.X64_193000_db_home.
zip -d $ORACLE_HOME >> $ORACLE_INSTALL_LOG
2>&
1
chown -
R oracle:oinstall $ORACLE_HOME
}
set_etc()
{
echo_subtitle "设置响应文件"
sleep 1
sed -i
‘/ORACLE_HOSTNAME/s/oracle.daxiong.com/ORACLE_HOSTNAME=$myhostname/‘ ../
file/etc/
db_install.rsp
cp -r ../
file/etc /home/
oracle
chown -R oracle:oinstall /home/oracle/
etc
chmod -R
755 /home/oracle/
etc
}
Initialize_db()
{
echo_subtitle "初始化Oracle数据库"
su - oracle -c
"/u01/app/oracle/product/19.3.0/db_1/runInstaller -silent -force -responseFile /home/oracle/etc/db_install.rsp -ignorePrereq" >> $ORACLE_INSTALL_LOG
2>&
1
while true
do
ret=`
grep ^Successfully /tmp/
oracle_install.log`
if [
"$ret" ==
"Successfully Setup Software with warning(s)." ];
then
/u01/app/oracle/product/
19.3.
0/db_1/root.
sh >> $ORACLE_INSTALL_LOG
2>&
1
break
fi
done
}
oracle_netca()
{
echo_subtitle "配置监听"
su - oracle -c
"/u01/app/oracle/product/19.3.0/db_1/bin/netca /silent /responsefile /home/oracle/etc/netca.rsp" >> $ORACLE_INSTALL_LOG
2>&
1
if [ $? -ne
0 ];
then
fail "oracle 配置监听失败"
fi
}
oracle_dbca()
{
echo_subtitle "创建数据库"
su - oracle -c
"/u01/app/oracle/product/19.3.0/db_1/bin/dbca -silent -createDatabase -responseFile /home/oracle/etc/dbca.rsp" >> $ORACLE_INSTALL_LOG
2>&
1
if [ $? -ne
0 ];
then
fail "创建数据库失败"
fi
}
clear
echo -
e
echo "======================================="
echo "Oracle 19c silent installation"
echo "======================================="
echo_title "检查系统"
echo -
e
show_spinner check_sys
echo_title "基本系统设置"
echo -
e
show_spinner set_hostname
show_spinner set_swap
show_spinner set_selinux
echo_title "安装依赖包"
echo -
e
show_spinner must_pkg
echo_title "创建oracle用户"
echo -
e
show_spinner create_orauser
echo_title "配置内核参数和资源限制"
echo -
e
show_spinner conf_kernel
show_spinner set_limit
echo_title "创建安装目录"
echo -
e
show_spinner create_dir
echo_title "解压安装介质"
echo -
e
show_spinner unzip_oracle
show_spinner conf_ora_env
echo_title "开始安装oracle"
echo -
e
show_spinner set_etc
show_spinner Initialize_db
echo_title "配置监听创建数据库"
echo -
e
show_spinner oracle_netca
show_spinner oracle_dbca
View Code
效果截图:
查看实例状态
基于centos7.x之上oracle 19c 静默安装-脚本
标签:截图 $* cto color installer libaio awk http rod