内存调整后Oracle相关配置
echo '#!/bin/bash'>/tmp/shm.sh
cat >>/tmp/shm.sh<<shm
echo "# 设置 /dev/shm:\$(hostname),如小于内存的60%,则调整到等同内存大小"
shmsizegb=\$(echo "scale=0;\$(df -PmT /dev/shm | grep shm | awk '{print \$3}')/1024" | bc)
swapgb=\$(grep SwapTotal /proc/meminfo | awk '{printf "%.0f",\$2/1024/1024}')
memgb=\$(grep MemTotal /proc/meminfo | awk '{printf "%.0f",\$2/1024/1024}')
mingb=\$((\$memgb*6/10))
if [ \$shmsizegb -lt \$mingb ]; then
echo "# resize /dev/shm to \${memgb}G"
sed -i '/\/dev\/shm/d' /etc/fstab
echo "tmpfs /dev/shm tmpfs defaults,size=\${memgb}G,noatime,nodiratime 0 0" >>/etc/fstab
mount -o remount /dev/shm
else
echo "# /dev/shm equal to MemTotal(${memgb}GB), Now \$(df -h | grep /dev/shm | awk '{print $2}')"
fi
shm
chmod +x /tmp/shm.sh;sh /tmp/shm.sh
memTotal=$(grep MemTotal /proc/meminfo | awk '{print $2}')
MEM=$((($memTotal - 1) * 1024))
SHMALL=$(($MEM / $(getconf PAGE_SIZE)))
SHMMAX=$(($MEM))
min_free_kbytes=$(($memTotal*4/1000))
if [ $SHMALL -lt 2097152 ]; then
SHMALL=2097152
fi
SHMMAX=$((memTotal * 1024 - 1))
if [ "$SHMMAX" -lt 4294967295 ]; then
SHMMAX=4294967295
fi
sed -i '/kernel.shmall/d' /etc/sysctl.conf
sed -i '/kernel.shmmax/d' /etc/sysctl.conf
sed -i '/vm.min_free_kbytes/d' /etc/sysctl.conf
echo "kernel.shmall = $SHMALL
kernel.shmmax = $SHMMAX
vm.min_free_kbytes = $min_free_kbytes">>/etc/sysctl.conf
sed -i '/memlock/d' /etc/security/limits.conf
echo "@oinstall soft memlock unlimited
@oinstall hard memlock unlimited" >>/etc/security/limits.conf
sysctl -p
sysctl --system
huge=
if [ -z $huge ];then
exit 1
fi
sed -i '/vm.nr_hugepages/Id' /etc/sysctl.conf
echo "vm.nr_hugepages = $huge" >> /etc/sysctl.conf
sysctl -p
sysctl --system