最近工作需要安裝oracle 11g R2在阿里云ECS上,因此編寫了一個腳本來完成圖形化安裝界面之前的準(zhǔn)備工作,這樣節(jié)省時間,shell如下:
金寨ssl適用于網(wǎng)站、小程序/APP、API接口等需要進(jìn)行數(shù)據(jù)傳輸應(yīng)用場景,ssl證書未來市場廣闊!成為成都創(chuàng)新互聯(lián)公司的ssl證書銷售渠道,可以享受市場價格4-6折優(yōu)惠!如果有意向歡迎電話聯(lián)系或者加微信:13518219792(備注:SSL證書合作)期待與您的合作!
#!/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版本、內(nèi)存、磁盤情況 check_init() { OS=`cat /etc/redhat-release` MEM=`free -m |grep 'Mem' | awk '{print $2}'` CPUS=`grep -i "processor" /proc/cpuinfo | wc -l` echo "系統(tǒng)版本:$OS" echo "內(nèi)存:${MEM}M" echo "CPU核數(shù):$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 系統(tǒng)內(nèi)存為 ${mem}GB \e[0m" fi swap_check="`grep -i 'swaptotal' /proc/meminfo |awk '{print $2}'`" if [[ $swap_check = "0" ]];then read -p " swap分區(qū)沒有設(shè)置,請進(jìn)行設(shè)置,輸入[y] or [n]:" temp if [ $temp == "y" ];then COUNT=$(($swap * 1024)) echo -e "\n\e[1;31m 開始設(shè)置swap分區(qū),/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 "請檢查或手工設(shè)置swap分區(qū)后運行該腳本!" exit 1 fi else echo -e "\n\e[1;31m系統(tǒng)內(nèi)存為${mem}GB 當(dāng)前swap分區(qū)已經(jīng)配置,大小為${swap_all}MB \e[0m" fi } #檢查是否root用戶執(zhí)行腳本 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 } #創(chuàng)建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 } #創(chuàng)建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 } #設(shè)置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 } #設(shè)置內(nèi)核參數(shù) 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 } #關(guān)閉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安裝準(zhǔn)備主程序 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初始化配置已經(jīng)完成,請確保圖形化界面正常工作,執(zhí)行./database安裝程序! \e[0m" fi } main
新聞名稱:oracle11gr2一鍵配置腳本
當(dāng)前URL:http://jinyejixie.com/article8/ghoiop.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供外貿(mào)建站、電子商務(wù)、靜態(tài)網(wǎng)站、ChatGPT、網(wǎng)站維護(hù)、域名注冊
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)