您好,登錄后才能下訂單哦!
最近工作需要安裝oracle 11g R2在阿里云ECS上,因此編寫了一個腳本來完成圖形化安裝界面之前的準備工作,這樣節省時間,shell如下:
#!/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 <<EOF >> $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 <<EOF >> $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 <<EOF >> $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 <<EOF >> $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 <<EOF >> $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 <<EOF >> $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
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。