Oracle 11GR2 在CentOS 7 上的單例項靜默安裝

lhb_immortal發表於2017-04-13

Oracle Installation - single instance



     各位Oracle 資料庫的同仁們,兄弟在此行業蠕行多年,卻很少做些總結。現在逐漸將這些內容寫成部落格。由淺入深,算是對自己的一個交代。其中難免會有疏漏甚至是錯誤。歡迎指正。
     文章最末有我的聯絡方式 ,歡迎交流。 這一篇寫得有點兒早了,也懶得再去翻譯。看到的湊合湊合吧。


Table of Contents


正文:




1 Program planning

type contents comments
dbsoft version 11.2.0.4 ORACLE STABLE VERSION
system-version CentOS 7  
hostname `hostname`  
ipaddr    
memory   allocate memory according to your physical memory
hard disk   not less than 20G for "/"
swap   according to the physical memory in the machine.
path ORACLE_BASE ORACLE INSTALL BASIC PATH
  ORACLE_HOME ORACLE SOFTWARE
  ORADATA TO STORE DATA
  RECOVERY  
  ARCHIVE ARCHIVE LOG FILES
  REDO REDO LOG FILES
  OCR+VOTEDISK FOR RAC, 1.5*3 RAW DISK

2 Hardware Check

2.1 Memory

2.1.1 Physical Memory

Notes: Physical Memory should not less than 1G, the recommend is more than 2G.
#!/bin/sh
# For CentOS/RHEL/OpenSUSE
# The physical memory is calculated in kilobytes.
MemTotal=`grep MemTotal /proc/meminfo|awk '{print $2}'`
test $MemTotal -lt 1048576 && echo "ERRORS ::    The Physical Memory is less than 1G, Oracle database could not be installed!"
test $MemTotal -lt 2097152 && echo "WARNING::    The Physical Memory is less than 2G, Oracle recommend that more than 2G is better!"

2.1.2 Max Shared Memory

  • How much share memory we should configure

    I recommend it to be 80 percent of Physical memory.

shmsize=`df -h /dev/shm|grep shm|awk '{print $2}'|sed 's/G//'`
test `printf "%.f" \`echo $((shmsize*100))|bc\`` -lt $((MemTotal*100*4/5/1024/1024)) && mount -t tmpfs shmfs -o size=$((MemTotal*4/5/1024/1024)) /dev/shm && echo "shmfs /dev/shm tmpfs size=$((MemTotal*4/5/1024/1024) 0" >> /etc/fstab
  • How to Change the Size of shm
# The following commands are included into the scripts upper.
# temporary:
mount -t tmpfs shmfs -o size=2G /dev/shm
# permanently
echo "shmfs /dev/shm tmpfs size=2G 0 0 " >> /etc/fstab

2.1.3 Swap

We should check the size of swap,which should be adjusted according to physical memory.

physical(G) Swap(G)
1-2 1.5 physical
2-16 physical
>16 16G
  • check swap size
  • All the following commands show you the size of swap in kilo-bytes.
swapon -s 
#free
  • expand swap Get Real and Target swap size(in kilobytes)and Modify swap with the following scripts
MemTotal=`grep MemTotal /proc/meminfo|awk '{print $2}'`
# TSS means target swap size                                                  
if [ $MemTotal -lt 2 ]; then
tss=$((MemTotal*3/2));
elif [ $MemTotal -lt 16777216 -a $MemTotal -ge 2097152 ]; then
tss=$MemTotal
else
tss=16777216
fi
# rss means real swap size
rss=`swapon -s |egrep [[:digit:]]|awk '{print $3}'`

if [ $rss -lt $tss ]; then
tmp_num=`echo $((tss-rss))/1024|bc`
dd if=/dev/zero of=/home/swap bs=1024k count=$tmp_num
fi
mkswap /home/swap
swapon /home/swap
cat >> /etc/fstab <<eof home="" swap="" defaults="" 0="" eof="" 

2.2 Disk Space

Notes: for space mounted on "/" we need enough space to install Oracle software under "/", And sufficient space for data storage. It will be filled with Oracle_Software(4.7G) and temporary file which generated in /tmp(1G).
root_space=`echo \`df -h |grep -v Filesystem|head -1|awk '{print $4}'|sed 's/G//'\`*10|bc`
test $root_space -lt 58 ** echo "ERRORS :: The / path has no available sapce , It must more than 5.7G""

3 Software Check

3.1 System Version

        For linux(CentOS,RHEL,Oracle Linux, 7 is the max)

3.2 Packages

  • 32-bit Linux:
rpm -q binutils compat-db compat-libstdc++-33 glibc glibc-devel glibc-headers gcc gcc-c++ libXp libstdc++ cpp make libaio ksh elfutils-libelf sysstat libaio libaio-devel setarch --qf '%{name}.%{arch}\n'|grep "not installed"| sort
yum install -y binutils compat-libcap1 compat-libstdc++ compat-libstdc++ gcc gcc-c++ glibc glibc glibc-devel glibc-devel ksh libaio libaio-devel libgcc libgcc libstdc++ libstdc++ libstdc++-devel libstdc++-devel libXi libXtst make sysstat
  • 64-bit Linux:
rpm -q binutils compat-db compat-libstdc++-33 glibc glibc-devel glibc-headers gcc gcc-c++ libXp libstdc++ cpp make libaio ksh elfutils-libelf sysstat libaio libaio-devel setarch --qf '%{name}.%{arch}\n'|grep "not installed"| sort
yum install -y binutils compat-libcap1 compat-libstdc++ compat-libstdc++ gcc gcc-c++ glibc glibc glibc-devel glibc-devel ksh libaio libaio-devel libgcc libgcc libstdc++ libstdc++ libstdc++-devel libstdc++-devel libXi libXtst make sysstat

3.3 Compiler

        Gcc will be installed as we install packages during the previous step. So we could skip this.

4 Create Users and Groups

/usr/sbin/groupadd -g 501 oinstall   id oracle — > gid 
/usr/sbin/groupadd -g 502 dba
/usr/sbin/groupadd -g 503 oper
/usr/sbin/groupadd -g 504 asmadmin
/usr/sbin/groupadd -g 505 asmdba        
/usr/sbin/groupadd -g 506 asmoper
/usr/sbin/useradd -g oinstall -G dba,asmdba,oper,asmadmin -m -d /home/oracle oracle
/usr/sbin/useradd -g oinstall -G asmoper,asmdba,asmadmin,oper,dba -m -d /home/grid grid

5 Kernel Parameters

Notes: Prameter shmmax is recommended up to 80% of physical memory, whose unit is byte.
cat >> /etc/sysctl.conf <>/etc/security/limits.conf < /dev/null

6 Create Directories

echo -n "Please enter GRID_ORACLE_BASE(default /g01/app/grid)":
read GRID_ORACLE_BASE
echo -n "Please enter GRID_ORACLE_HOME(default /g01/app/11.2.0)":
read GRID_ORACLE_HOME
echo -n "Please enter GRID_ORACLE_SID(default +ASM1 )":
read GRID_ORACLE_SID
echo -n "Please enter ORA_ORACLE_BASE(default /u01/app/oracle)":
read ORACLE_BASE
echo -n "Please enter ORA_ORACLE_HOME(default \$ORACLE_BASE/product/11.2.0/dbhome_1)":
read ORACLE_HOME
echo -n "Please enter ORA_ORACLE_SID(This values is expected)":
read ORA_ORACLE_SID

test -z $GRID_ORACLE_BASE && GRID_ORACLE_BASE=/g01/app/11.2.0;
test -z $GRID_ORACLE_HOME && GRID_ORACLE_HOME=/g01/app/11.2.0;
test -z $GRID_ORACLE_SID  && GRID_ORACLE_SID=+ASM1;
test -z $ORA_ORACLE_BASE && ORA_ORACLE_BASE=/u01/app/oracle;
test -z "$ORA_ORACLE_HOME" && ORA_ORACLE_HOME="$ORA_ORACLE_BASE"/product/11.2.0/dbhome_1;
while(test -z "$ORA_ORACLE_SID") ; do
echo -n "Please Be sure to enter a valid ORACLE SID NAME:"
read ORA_ORACLE_SID
done

if [ -d "$GRID_ORACLE_BASE" ] ; then
echo "$GRID_ORACLE_BASE already exists!"
else
mkdir -p "$GRID_ORACLE_BASE";
fi

if [ -d "$GRID_ORACLE_HOME" ] ; then
echo "$GRID_ORACLE_HOME already exists!"
else
mkdir -p "$GRID_ORACLE_HOME";
fi

if [ -d "$ORA_ORACLE_HOME" ] ; then
echo "$ORA_ORACLE_HOME already exists!"
else
mkdir -p "$ORA_ORACLE_HOME";
fi

if [ -d "$ORA_ORACLE_BASE" ] ; then
echo "$ORA_ORACLE_BASE already exists!"
else
mkdir -p "$ORA_ORACLE_BASE";
fi

chown -R grid:oinstall `echo "$GRID_ORACLE_BASE" |awk -F '/' '{print "/"$2}'`
chown -R oracle:oinstall `echo "$ORA_ORACLE_BASE" |awk -F '/' '{print "/"$2}'`

7 Modify User's Profile

bprofile='.test'
if [ "$Platform" = 'HP-UX' ] ; then
bprofile='.profile'
elif [ "$Platform" = 'AIX'  ] ; then
bprofile='.profile'
elif [ "$Platform" = 'Linux'  ] ; then
bprofile='.bash_profile'
fi

cat >> /home/grid/"$bprofile" <> /home/oracle/"$bprofile" <<eof oracle_base="$ORA_ORACLE_BASE" oracle_home="\$ORACLE_BASE/product/11.2.0/dbhome_1" oracle_sid="$ORA_ORACLE_SID" path="\$PATH:\$ORACLE_HOME/bin" export="" umask="" 022="" stty="" erase="" ^h="" eof="" 

8 System Check

8.1 network

  • hostnamee
    • should be made up with: number,character,sign(except [- " @]
    • should not more than 8 characters
    • It will be better with lower case.
    • you should get the name with `hostname`
  • Ipaddress
# check your ipaddress with either the following command
ip a 
ifconfig -a
# edit the ipaddress configure file with vi/vim/emacs and so on.
vi /etc/sysconfig/network-scripts/ifcfg-eth0

TYPE=Ethernet     # network type
#BOOTPROTO=dhcp    # ip allocate automatically
BOOTPROTO=static   # static ip address
IPADDR=192.168.1.101
NETMASK=255.255.255.0
DEFROUTE=yes     
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
NAME=eth0         # net-card name
DEVICE=eth0       # device name
ONBOOT=yes        # up when system bootup or not.

8.2 firewalls

# CentOS/RHEL 7 
systemctl stop firewalld.service
systemctl disable firewalld.service
iptables -F

8.3 SELinux

# for CentOS / RHEL /OenSUSE
sed -i "s/SELINUX=enforcing/SELINUX=disabled/" /etc/selinux/config

9 Install Oracle Software

9.1 Modify ResponseFile

ResponseFile locate at /database/response/db_install.rsp. When you Modifying the file,Please confirm the content listed following:

oracle.install.responseFileVersion=/oracle/install/rspfmt_dbinstall_response_schema_v11_2_0
oracle.install.option=INSTALL_DB_SWONLY
ORACLE_HOSTNAME=build001
UNIX_GROUP_NAME=oinstall
INVENTORY_LOCATION=/u01/app/oracle/oraInventory
SELECTED_LANGUAGES=en,zh_CN,zh_TW
ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1
ORACLE_BASE=/u01/app/oracle
oracle.install.db.InstallEdition=EE
oracle.install.db.isCustomInstall=false
oracle.install.db.DBA_GROUP=dba
oracle.install.db.OPER_GROUP=dba
DECLINE_SECURITY_UPDATES=true

9.2 Install Software

Attention: The path of responseFile must be absolutely path.
./runInstaller -silent -force -ignoreSysprereqs -ignorePrereq -showProgress -responseFile /home/oracle/database/response/db_install.rsp

9.3 Pay Attention

The last step we should not skip is to read what showing up in the screen, and JUST DO WHAT IT TOLD US!

...
/u01/app/oracle/oraInventory/orainstRoot.sh
/u01/app/oracle/product/11.2.0/dbhome_1/root.sh
To execute the configuration scripts:
         1. Open a terminal window
         2. Log in as "root"
         3. Run the scripts
         4. Return to this window and hit "Enter" key to continue 

Successfully Setup Software.

10 Create database with DBCA

10.1 Modify PresponseFile

[GENERAL]
RESPONSEFILE_VERSION = "11.2.0"
OPERATION_TYPE = "createDatabase"
[CREATEDATABASE]
GDBNAME = "uprr"
SID = “uprr"
TEMPLATENAME = "General_Purpose.dbc"
SYSPASSWORD="Asdqwe123"
SYSTEMPASSWORD="Asdqwe123"
DATAFILEDESTINATION = "/u01/app/oracle/oradata"
RECOVERYAREADESTINATION= "/u01/app/oracle/flash_recovery_area"
CHARACTERSET = "AL32UTF8"
NATIONALCHARACTERSET= "UTF8"
Notes: You should change the values of GDBNAME,SID.

10.2 Create Database

            Attention:         The path of responseFile must be absolutely path.
        su - oracle
        $ORACLE_HOME/bin/dbca -silent -responseFile /database/response/dbca.rsp

11 Create Listener with NETCA

        Attention:         The path of responseFile must be absolutely path.And,we could use the original file "netca.rsp"
            $ORACLE_HOME/bin/netca -silent -responseFile /database/response/netca.rsp

12 Do some Adjustment

12.1 undo tablespace

  • check file location and file size.
        col file_name for a60
        set lines 200
        select file_name,bytes/(1024*1024) from dba_data_files where tablespace_name='UNDOTBS1';
            FILE_NAME                                 BYTES/(1024*1024)
         -------------------------------------------  -----------------

        /u01/app/oracle/oradata/halberd/undotbs01.dbf                30
  • Adjust file size
        alter database datafile '/u01/app/oracle/oradata/halberd/undotbs01.dbf' resize 1G;
  • Re-confirm
        SQL> select file_name,bytes/(1024*1024) from dba_data_files where tablespace_name='UNDOTBS1';

        FILE_NAME						     BYTES/(1024*1024)
        ------------------------------------------------------------ -----------------
        /u01/app/oracle/oradata/halberd/undotbs01.dbf				  1024

12.2 temple tablespace

  • Check tablespace(file) size and file_name
        col name for a60
        select file#,bytes/(1024*1024),name from v$tempfile;
             FILE# BYTES/(1024*1024) NAME
        ---------- ----------------- ------------------------------------------------------------
	         1		  20 /u01/app/oracle/oradata/halberd/temp01.dbf
  • Adjust file size
        alter database tempfile '/u01/app/oracle/oradata/halberd/temp01.dbf' resize 1G;

12.3 redo file

一般來說,redo檔案推薦大小為2G. 根據儲存型別及儲存的冗餘級別,每個redo 組使用一個redo 或者 2個redo, 當每個組有2個redo時,建議將兩個redo日誌成員儲存在不同的磁碟上,以防其中一個磁碟損壞。raid 5,自帶冗餘,因此建立一個組裡建立一個日誌檔案即可。

  • Check logfile group,members and size of the logfile
        select group#,members,status,bytes/(1024*1024) from v$log;
            GROUP#    MEMBERS STATUS	       BYTES/(1024*1024)
        ---------- ---------- ---------------- -----------------
	         1	    1      INACTIVE		      50
        	 2	    1      CURRENT		      50
	         3	    1      UNUSED		      50
  • check redo log file name
        select group#,member from v$logfile;
            GROUP# MEMBER
        ---------- ------------------------------------------------------------
	         3 /u01/app/oracle/oradata/halberd/redo03.log
	         2 /u01/app/oracle/oradata/halberd/redo02.log
	         1 /u01/app/oracle/oradata/halberd/redo01.log
  • drop the existing file goups
        alter database drop logfile group 1;
        alter database drop logfile group 2;
        alter database drop logfile group 3;
Notes: The groups will be droped but not the file. When the logfile group status is current or active, it will show us an error if we try to drop the group such as the logfile group 2 is current. Thus we should execute this command : alter system switch logfile; then wait until the status changed to inactive. If the file group's status is active , we should know that the database waiting it be archived event in no archive mode. we could execute this command : alter database clear unarhived logfile group 2; (no term) Create redo logfiles
alter database add logfile group 1 (‘/u01/app/oracle/oradata/halberd/redo01.log’)size 2G reuse;
alter database add logfile group 2 (‘/u01/app/oracle/oradata/halberd/redo02.log’)size 2G reuse;
alter database add logfile group 3 (/u01/app/oracle/oradata/halberd/redo03.log’)size 2G reuse;

12.4 parameters

After installaion of database,we should adjust some parameters to sute the productive environment.

The Most Important sessions,processes

The default value for the two parameter is too small to support our productive enrionment. We could execute the forllowing command to change it :

sqlplus / as sysdba
alter system set processes=3000 scope=spfile;
alter system set sessions=3000 scope=spfile;  
startup force;
show parameter processes
show parameter sessions
Notes: we must restart the database after change the parameters to bring them into effect.

Author: Halberd  QQ:472539294 Tel: 18258160531 E-mail: lhb_yinglang@126.com

Editor: Emacs 26.0.50.1 (Org mode 8.2.10)

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/25313300/viewspace-2137241/,如需轉載,請註明出處,否則將追究法律責任。

相關文章