摘要:這是自己曾經寫的一個在服務器上,一鍵配置安裝環境的腳本,能快速完成安裝前環境的配置。
這是自己曾經寫的一個oracle 11gR2在CentOS6 x86_64服務器上,一鍵配置安裝環境的腳本,能快速完成安裝前環境的配置。
具體完成以下工作:
備份系統配置文件,以防出錯
添加oracle用戶和用戶組
創建安裝目錄
關閉selinux
在.bash_profile中修改環境變量
修改sysctl.conf文件
修改limits.conf文件
修改PAM的login文件
安裝必要的依賴包
使用注意事項:
root的用戶執行,chmod +x oraclePreInstCheck.sh
./oraclePreInstCheck.sh運行后,請仔細閱讀說明,再決定是否使用該腳本
該腳本默認參數適用于2核4G內存的環境,你可以根據需要修改kernelset()部分
執行完后,你檢查一下你的安裝目錄及權限(默認/db/oracle)
該腳本會有提示輸入的地方,請不要挑戰它的健壯性,比如輸入安裝根目錄時,不要帶入空格
腳本只需執行一次,修改系統參數如sysctl.conf之前,都有備份成xxx.ora_bak
請確保可以通過yum方式安裝軟件包(使用掛載DVD鏡像或聯網)
建議結合tee將執行過程記錄在日志文件中,./oraclePreInstCheck.sh | tee oraclePreInstCheck.log
#!/bin/bash # author zhouxiao # date 2014-03-07 # description oracle 11g R2 for linux 6.0+ x86_64 安裝輔助腳本 #定義常量 SYSCTL=/etc/sysctl.conf LIMITS=/etc/security/limits.conf PAM=/etc/pam.d/login PROFILE=/etc/profile BASH_PROFILE=/home/oracle/.bash_profile #循環變量 i=1 #定義顯示顏色 #顏色定義 信息(33黃色) 警示(31紅色) 過程(36淺藍) usage() { echo "Scripts: initialize the required env settings for Oracle 11gR2 installation on Linux 6.0+ x86_64" echo "Make sure you have prepared conditions list bellow:" echo -e " e[1;33m yum, hosts, user oracle"s passwd, oralce SID, DISPLAY location e[0m" echo "The Script will backup config files with .ora_bak in case failure " echo "The Script will set the following change:" echo " - add user oracle and group oinstall/dba/oper, etc." echo " - make directory ORACLE_HOME and change owner" echo " - modify oracle .bash_profile" echo " - modify /etc/sysctl.conf kernel parameters like shmall/shmmax" echo " - modify /etc/security/limits.conf " echo " - install necessary packages like libgcc/libaio/unixODBC, etc." echo " - IF anything goes wrong, you need to recover ora_bak files manually." echo -e " e[1;33m Continue? (y/n [n]): e[0m" read singal if [ $singal != "y" ]; then exit 0 else echo "God Bless you! Settings started." echo "" echo "" fi } #判斷執行用戶是否root isroot() { if [ $USER != "root" ];then echo -e " e[1;31m the user must be root,and now you user is $USER,please su to root. e[0m" exit4 else echo -e " e[1;36m check root ... OK! e[0m" fi } #掛在光盤到/mnt/cdrom目錄下 mount_cdrom() { echo -e " e[1;31m please insert RHEL to CDROM,press any key ...e[0m" read -n 1 if [ -d /mnt/cdrom ];then mount -t auto -o ro /dev/cdrom /mnt/cdrom else mkdir -p /mnt/cdrom mount -t auto -o ro /dev/cdrom /mnt/cdrom fi if [ $? -eq 0 ];then echo -e " e[1;36m CDROM mount on /mnt/cdrom ... OK! e[0m" fi } #設置yum本地光盤源 yum_repo() { rm -rf /etc/yum.repos.d/* && cat <> /etc/yum.repos.d/Server.repo [Server] name=MyRPM baseurl=file:///mnt/cdrom/Server enabled=1 gpgkey=file:///mnt/cdrom/RPM-GPG-KEY-redhat-release EOF if [ $? -eq 0 ];then echo -e " e[1;36m /etc/yum.repos.d/Server.repo ... OK! e[0m" fi } #添加oracle用戶,添加oracle用戶所屬組oinstall及附加組dba ouseradd() { if [[ `grep "oracle" /etc/passwd` != "" ]];then userdel -r oracle fi if [[ `grep "oinstall" /etc/group` = "" ]];then groupadd -g 501 oinstall fi if [[ `grep "dba" /etc/group` = "" ]];then groupadd -g 502 dba groupadd -g 503 oper groupadd -g 504 asmadmin groupadd -g 506 asmdba groupadd -g 505 asmoper fi useradd oracle -g oinstall -G dba,asmdba,oper && echo $1 |passwd oracle --stdin if [ $? -eq 0 ];then echo -e " e[1;36m oracle"s password updated successfully --- OK! e[0m" else echo -e " e[1;31m oracle"s password set faild. --- NO!e[0m" fi } #檢查oracle所需軟件包并安裝 packagecheck() { for package in binutils compat-libcap1 compat-libstdc++-33 compat-libstdc++-33*i686 gcc gcc-c++ glibc glibc-2*i686 glibc-devel glibc-devel-2*i686 glibc-headers-2.* libgcc libgcc-4*i686 libstdc++ libstdc++-4*i686 libstdc++-devel libstdc++-devel-4*i686 libaio-0* libaio-0*i686 libaio-devel libaio-devel-0*i686 unixODBC unixODBC-2*i686 unixODBC-devel unixODBC-devel-2*i686 make sysstat ksh do rpm -q $package 2> /dev/null if [ $? != 0 ];then yum -y install $package 2> /dev/null echo -e " e[1;36m $package is installed ... OK! e[0m" fi done } #安裝桌面套件 X Window System / Desktop xdesk() { LANG=C yum -y groupinstall "X Window System" "Desktop" if [ $? -eq 0 ];then echo -e " e[1;36m $package is already installed ... OK! e[0m" fi } # 設置內核參數 # shmall 物理內存<8G =2097152 >8G MemTotal/4kb # shmmax 物理內存<8G = 4294967296 >8G 16GMemTotal = 10G=10*1024^3 kernelset() { cp $SYSCTL{,.ora_bak} && cat < >$SYSCTL fs.aio-max-nr = 1048576 fs.file-max = 6815744 kernel.shmall = 2097152 kernel.shmmax = 4294967296 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 if [ $? -eq 0 ];then echo -e " e[1;36m kernel parameters updated successfully --- OK! e[0m" fi sysctl -p } #設置oracle資源限制 oralimit() { cp $LIMITS{,.ora_bak} && cat < > $LIMITS oracle soft nproc 2047 oracle hard nproc 16384 oracle soft nofile 1024 oracle hard nofile 65536 oracle soft stack 10240 EOF if [ $? -eq 0 ];then echo -e " e[1;36m $LIMITS updated successfully ... OK! e[0m" fi cat $LIMITS | grep "^o" } #設置login文件 setlogin() { cp $PAM{,.ora_bak} && cat < >$PAM session required pam_limits.so EOF if [ $? -eq 0 ];then echo -e " e[1;36m $PAM updated successfully ... OK! e[0m" fi } #設置profile文件 setprofile() { cp $PROFILE{,.ora_bak} && cat < >$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 if [ $? -eq 0 ];then echo -e " e[1;36m $PROFILE updated successfully ... OK! e[0m" fi } #設置oracle的profile文件 setbash_profile() { cp $BASH_PROFILE{,.ora_bak} && cat < > $BASH_PROFILE umask 022 #oracle settings TMP=/tmp; export TMP TMPDIR=$TMP; export TMPDIR ORACLE_BASE=$1/oracle ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1 ORACLE_SID=$2 PATH=$ORACLE_HOME/bin/:$PATH LANG=en_US.UTF-8 ORACLE_TERM=xterm export ORACLE_BASE ORACLE_HOME ORACLE_SID ORACLE_TERM LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib; export LD_LIBRARY_PATH CLASSPATH=$ORACLE_HOME/jre:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib export CLASSPATH EOF if [ $? -eq 0 ];then echo -e " e[1;36m $BASH_PROFILE updated successfully ... OK! e[0m" fi su - oracle -c source $BASH_PROFILE } #系統環境檢查 oscheck() { #查看內存大小是否大于1G echo -e " check MEM Size ..." if [ `cat /proc/meminfo | grep MemTotal | awk "{print $2}"` -lt 1048576 ];then echo -e " e[1;33m Memory Small e[0m" exit 1 else echo -e " e[1;36m Memory checked PASS e[0m" fi #查看tmp空間大小 echo -e " check tmpfs Size ..." cp /etc/fstab{,.ora_bak} while true;do if [ `df | awk "/tmpfs/ {print $2}"` -lt 1048576 ];then echo -e " e[1;33m tmpfs Smaill e[0m" sed -i "/tmpfs/s/defaults/defaults,size=1G/" /etc/fstab && mount -o remount /dev/shm if [ $? != 0 ];then i=i+1 if [ $i -eq 3 ];then echo -e " e[1;31m set tmpfs faild. e[0m" exit 3 fi else echo -e " e[1;36 tmpfs updated successfully. e[0m" break fi else echo -e " e[1;36m tmpfs checked PASS e[0m" break fi done } usage #停止防火墻IPTABLES service iptables stop #chkconfig iptables off #關閉SELINUX cp /etc/selinux/config{,.ora_bak} && sed -i "/SELINUX/s/enforcing/disabled/;/SELINUX/s/permissive/disabled/" /etc/selinux/config setenforce 0 #執行以上函數 isroot #oscheck #yum_repo #mount_cdrom packagecheck #xdesk kernelset oralimit setlogin setprofile echo -e " e[1;33m please input oracle"s user passwd: e[0m" read oraclepw ouseradd $oraclepw echo -e " e[1;33m please input oracle install PATH (default /db) e[0m" read oraclepath if [ -z $oraclepath ];then oraclepath=/db fi if [ ! -x "$oraclepath" ];then mkdir -p "$oraclepath" chown oracle.oinstall $oraclepath echo -e " e[1;36 $oraclepath created. e[0m" fi echo -e " e[1;33m please input oracle_sid, just for env (default TSDB) e[0m" read orasid if [ -z orasid ];then orasid=TSDB fi setbash_profile $oraclepath $orasid mkdir -p $oraclepath/oracle/product/11.2.0/db_1 && chown -R oracle:oinstall $oraclepath && chmod -R 755 $oraclepath unset i echo -e " e[1;33m please input where to display the X Window (default 127.0.0.1:0.0) e[0m" read xdpy if [ -z $xdpy ];then xdpy=127.0.0.1:0.0 fi su - oracle -c export DISPLAY=$xdpy && host + echo -e " e[1;35m Oracle install pre-setting finish! && please run oracle installer as user oracle e[0m"
原文鏈接地址:http://seanlook.com/2014/12/02/oracle11gr2_installation_precheck_scripts/
文章版權歸作者所有,未經允許請勿轉載,若此文章存在違規行為,您可以聯系管理員刪除。
轉載請注明本文地址:http://specialneedsforspecialkids.com/yun/17375.html
閱讀 3228·2021-11-15 11:37
閱讀 2449·2021-09-29 09:48
閱讀 3814·2021-09-22 15:55
閱讀 3014·2021-09-22 10:02
閱讀 2636·2021-08-25 09:40
閱讀 3225·2021-08-03 14:03
閱讀 1691·2019-08-29 13:11
閱讀 1570·2019-08-29 12:49