Centos 7 silently deploys oracle 11g

 Address of this article:

http://peihexian.iteye.com/blog/2397975

 A friend asked for help to deploy oracle 11.2 under linux. After two days of tossing, I sorted out the script for later use.

1. Preparations

 When centos 7 is installed, an account other than root is established. When I test the local virtual machine, I only choose the minimal installation, there is no graphical interface, and there is no other account. When restarting after installing the dependency package, I will be asked to establish a management other than root. It doesn't matter if linux has been installed, you can agree to the license agreement when prompted and then follow the prompt to create an account.

 

2. Installation process

Centos 7 uses firewalld firewall, not iptables. First disable firewalld firewall, and pay attention to release port 1521 when you need to enable it later.

#systemctl stop firewalld.service
systemctl stop firewalld
systemctl disable firewalld

 

3. Because my script is edited in windows, running the script when it is uploaded to linux via ssh cannot be used. I need to convert the format through dos2unix, so install dos2unix first.

yum install dos2unix

 In addition, you need to use the unzip decompression tool to decompress the oracle linux installation zip later, and also install it.

yum install unzip

 

4. Upload the two compressed zip files of oracle for linux to the /tmp directory in linux, decompress them and prepare for use

cd /tmp

unzip linux.x64_11gR2_database_1of2.zip

unzip linux.x64_11gR2_database_2of2.zip

 After decompression, the database directory will be generated in /tmp.

 

5. Run the silent installation script 1, which is used to create oracle users and groups such as dba and oinstall, and to modify the environment variables and other parameters in the oracle user .bash_profile, vi /tmp/oracle_install.sh , the script content is as follows

 

#!/bin/bash
# oracle 11g R2 for linux installation auxiliary script
# Redkey
# version 1.2
# date 2017.10.28
#define constants
SYSCTL=/etc/sysctl.conf
LIMITS=/etc/security/limits.conf
PAM=/etc/pam.d/login
PROFILE=/etc/profile
BASH_PROFILE=/home/oracle/.bash_profile
#loop variable
i=1
#define display color
#color definition information (33 yellow) warning (31 red) process (36 light blue)
# Determine if the executing user is root
root()
{
    if [ $USER != "root" ];then
        echo -e "\n\e[1;31m the user must be root,and now you user is $USER,please su to root. \e[0m"
        exit4
    else
        echo -e "\n\e[1;36m check root ... OK! \e[0m"
    be
}
#Hang on the CD to the /mnt/cdrom directory
mount_cdrom()
{
echo -e "\n\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
be
if [ $? -eq 0 ];then
    echo -e "\n\e[1;36m CDROM mount on /mnt/cdrom ... OK! \e[0m"
be
}
#Set yum local CD source
yum_repo()
{
    rm -rf /etc/yum.repos.d/* && cat <<EOF >> /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 "\n\e[1;36m  /etc/yum.repos.d/Server.repo  ... OK! \e[0m"
be
}
#Add the oracle user, add the group oinstall to which the oracle user belongs and the additional group dba
ouseradd()
{
    if [[ `grep "oracle" /etc/passwd` != "" ]];then
    userdel -r oracle
    be
    if [[ `grep "oinstall" /etc/group` = "" ]];then
        groupadd oinstall
    be
    if [[ `grep "dba" /etc/group` = "" ]];then
        groupadd dba
    be
    useradd oracle -g oinstall -G dba && echo $1 |passwd oracle --stdin
    if [ $? -eq 0 ];then
        echo -e "\n\e[1;36m oracle's password updated successfully  --- OK! \e[0m"
    else
        echo -e "\n\e[1;31m oracle's password set faild.   --- NO!\e[0m"
    be
}
#Check the packages required by oracle and install them
packagecheck()
{
for package in binutils compat-libcap1 compat-libstdc++ gcc gcc-c++ glibc glibc-devel ksh libgcc libstdc++ libstdc++-devel libaio libaio-devel make sysstat unzip elfutils-libelf elfutils-libelf-devel elfutils-libelf-devel-static kernel-headers unixODBC unixODBC-devel
    rpm -q $package 2> /dev/null
    if [ $? != 0 ];then
        yum -y install $package
        echo  -e "\n\e[1;36m $package is already installed ... OK! \e[0m"
    be
done
}
#Install Desktop Suite X Window System/Desktop
xdesk()
{
    LANG=C yum -y groupinstall "X Window System" "Desktop"
    if [ $? -eq 0 ];then
        echo  -e "\n\e[1;36m $package is already installed ... OK! \e[0m"
    be
}
# set kernel parameters
kernelset()
{
    cp $SYSCTL{,.bak} && cat <<EOF >>$SYSCTL
fs.aio-max-nr = 1048576
fs.file-max = 6815744
kernel.shmall = 2097152
kernel.shmmax = 4294967295
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 = 1048575
EOF
    if [ $? -eq 0 ];then
        echo -e "\n\e[1;36m kernel parameters updated successfully --- OK! \e[0m"
    be
sysctl -p
}
#Set oracle resource limit
oralimit ()
{
    cp $LIMITS{,.bak} && cat <<EOF >> $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 "\n\e[1;36m $LIMITS updated successfully ... OK! \e[0m"
    be
}
#Set up the login file
setlogin()
{
    cp $PAM{,.bak} && cat <<EOF >>$PAM
session     required    pam_limits.so
EOF
    if [ $? -eq 0 ];then
        echo -e "\n\e[1;36m  $PAM updated successfully ... OK! \e[0m"
    be
}
#Set the profile file
setprofile()
{
    cp $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
    be
be
EOF
    if [ $? -eq 0 ];then
        echo -e "\n\e[1;36m  $PROFILE updated successfully ... OK! \e[0m"
    be
}
#Set oracle's profile file
setbash_profile()
{
    cp $BASH_PROFILE{,.bak} && cat <<EOF >> $BASH_PROFILE
umask 022
ORACLE_BASE=$1
ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1
ORACLE_SID=$2
PATH=$ORACLE_HOME/bin/:$PATH
LANG = en_US.UTF-8
export ORACLE_BASE ORACLE_HOME ORACLE_SID PATH
EOF
    if [ $? -eq 0 ];then
        echo -e "\n\e[1;36m $BASH_PROFILE updated successfully ... OK! \e[0m"
    be
. $BASH_PROFILE
}
#System environment check
oscheck()
{
#Check if the memory size is greater than 1G
echo -e "\n check MEM Size ..."
if [ `cat /proc/meminfo | grep MemTotal | awk '{print $2}'` -lt 1048576 ];then
    echo  -e "\n\e[1;33m Memory Small \e[0m"
    exit 1
else
    echo -e "\n\e[1;36m Memory checked PASS \e[0m"
be
#View tmp space size
echo -e "\n check tmpfs Size ..."
cp /etc/fstab{,.bak}
while true;do
if [ `df | awk '/tmpfs/ {print $2}'` -lt 1048576 ];then
    echo -e "\n\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 "\n\e[1;31m set tmpfs faild. \e[0m"
            exit 3
        be
    else
        echo -e "\n\e[1;36 tmpfs updated successfully. \e[0m"
        break
    be
else
    echo -e "\n\e[1;36m tmpfs checked PASS \e[0m"
    break
be
done
}
#stop firewall IPTABLES
service iptables stop
chkconfig iptables off
#close SELINUX
cp /etc/selinux/config{,.bak} && sed -i '/SELINUX/s/enforcing/disabled/;/SELINUX/s/permissive/disabled/'   /etc/selinux/config
setenforce 0
#Execute the above function
is root
oscheck
#yum_repo
#mount_cdrom
packagecheck
xdesk
kernelset
oralimit
setlogin
setprofile
echo -e "\n\e[1;33m please input oracle's user passwd: \e[0m"
read oraclepw
ouseradd $oraclepw
setbash_profile
echo -e "\n\e[1;33m please input oracle install PATH(default /oracle/db) \e[0m"
read oraclepath
if [ -z $oraclepath ];then
    oraclepath=/oracle/db
be
echo -e "\n\e[1;33m  please input oracle_sid (default police) \e[0m"
read orasid
if [ -z orasid ];then
    orasid = police
be
setbash_profile $ oraclepath $ orasid
mkdir -p $oraclepath && chown -R oracle:oinstall $oraclepath && chmod -R 755 $oraclepath
unset i
echo -e "\n\e[1;35m Oracle install pre-setting finish! && please run oracle installer as user oracle \e[0m"

 

  If the oracle_install.sh script file edited on the Windows platform or the downloaded attachment is transferred to the /tmp directory for use, you need to run dos2unix oracle_install.sh to modify the character encoding format, otherwise, an error will be reported when executing the script.

 

In the above script, the oracle software is installed to the /oracle/db directory by default. The default oracle sid is police. These two parameters are modified according to the needs of your own project. Note that the values ​​of these two parameters will be used repeatedly later, and you must remember yourself. Which path to install the oracle file to, also remember the SID.

 

6. Give the script permission, run

chmod 777 /tmp/oracle_install.sh

/tmp/oracle_install.sh

 7. After the script runs, modify some environment variable parameters again

su - oracle

you .bash_profile

   The content of the oracle .bash_profile file automatically created by the above oracle_install.sh script has problems. One is duplicated, and the parameter values ​​also need to be modified. Modify ORACLE_BASE to the oracle installation path, such as the default /oracle/db of the script, and modify the ORACLE_HOME value, such as / oracle/db/product/11.2.0/db_1 , modify the SID value, such as police, delete the duplicate configuration parameter value and save it.

source .bash_profile

   Execute the above command to make the modified configuration take effect immediately.

 

8. Switch back to the root user and give the oracle user permission to read the installation source

su - root
chmod -R 777 /tmp/database
chown -R oracle:oinstall /tmp/database

 

9. Switch to the oracle user and modify the content of the silent installation parameter file

su - oracle
vi /tmp/database/response/db_install.rsp

 

  The key parameters that need to be modified are:

oracle.install.option=INSTALL_DB_SWONLY #This is used to indicate that only the software is installed, and the database is not created first
ORACLE_HOSTNAME=oracle  # 当前oracle主机hostname
UNIX_GROUP_NAME=oinstall
INVENTORY_LOCATION=/oracle/db/oraInventory #This note that if the ORACLE_BASE value has been modified in the front, it should also be changed here. The sub-path under ORACLE_BASE will have a warning during installation. If you really want to put it in a path other than ORACLE_BASE, pay attention You need to manually create and write permissions to oracle users and dba and oinstall groups. If there are no special requirements, just put them in the ORACLE_BASE path.

SELECTED_LANGUAGES=en,zh_CN,zh_TW
ORACLE_HOME=/oracle/db/product/11.2.0/db_1 #This setting is consistent with the configuration parameters in the .bash_profile of the oracle user.
ORACLE_BASE=/oracle/db #This is also the same as the configuration value in the .bash_profile of the oracle user
oracle.install.db.InstallEdition=EE #Install Enterprise Edition
oracle.install.db.DBA_GROUP=dba
oracle.install.db.OPER_GROUP=oinstall
oracle.install.db.config.starterdb.type=GENERAL_PURPOSE #Don't think about any customization, this is to copy and copy files directly, without executing the process of building the database script, which is very fast.
oracle.install.db.config.starterdb.globalDBName=police #Database name, we use it for the police, you can change it to your own.

oracle.install.db.config.starterdb.SID=police #Also, change it to the same value as the oracle user .bash_profile.
oracle.install.db.config.starterdb.characterSet=ZHS16GBK
oracle.install.db.config.starterdb.memoryOption=true
oracle.install.db.config.starterdb.password.ALL=123456 #This password is the password of the sys and system users, change it to the value you want.
Change to this should be almost the same, if you can't install it, use the attachment file I provided.

 

10. Ok, everything is ready, let's start installing the oracle software into the linux system

su - oracle
cd /tmp/database
./runInstaller -silent -ignorePrereq -responseFile /tmp/database/response/db_install.rsp

 

   There will be a warning, don't ignore it, just wait patiently, when the screen prompts you to use the root user to execute the script, open another ssh window or terminal window, and execute the two sh scripts according to the contents of the screen prompts. That's it (you need to use the root user to execute)

#Can't remember the name of the script, just look at what the screen prompts over there and execute it, it seems that the second one is root.sh or something
/oracle/db/xxxx/xxx.sh
/oracle/db/xxxx/root.sh

 

    After the two scripts here are executed, go back there and press Enter to finish the job, and the Oracle software installation is over.

 

11. Create a listener

 

su - oracle
/oracle/db/product/11.2.0/db_1/bin/netca /silent /responseFile /tmp/database/response/netca.rsp

    

    I estimate which steps have configuration problems, lack of instance name, and the created listener configuration parameter listener.ora needs to be further modified, which will be discussed later. 

 

12.dbca build library

   Modify the dbca silent library building parameter file

su - oracle
vi /tmp/database/response/dbca.rsp

 

The parameter names and contents to be modified are as follows:

GDBNAME = "police"
SID = "police"
SYSPASSWORD = "123456" #SYS user password, note the same as before
SYSTEMPASSWORD = "123456" #SYSTEM user password
CHARACTERSET = "ZHS16GBK"

 

Start building the database, pay attention to execute the following commands with the oracle user

su - oracle
/oracle/db/product/11.2.0/db_1/bin/dbca -silent -responseFile /tmp/database/response/dbca.rsp

 

13. After completion, modify the content of the following listener.ora file and add the instance to it

SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (SID_NAME = PLSExtProc)
      (Oracle_HOME = /oracle/db/product/11.2.0/db_1)
      (PROGRAM = extproc)
     )
  (SID_DESC =
      (GLOBAL_DBNAME = police)
      (ORACLE_HOME = /oracle/db/product/11.2.0/db_1)
      (SID_NAME = police)
    )
)

 

14 Start the listener, start the database

 

su - oracle #Note that the following commands are executed with the oracle user
/oracle/db/product/11.2.0/db_1/bin/lsnrctl stop LISTENER
/oracle/db/product/11.2.0/db_1/bin/lsnrctl start LISTENER

sqlplus / as sysdba
startup;

 

   To this client can access the oracle server.

 

15. Configure oracle as a linux service that starts at boot

 

su - root
vi /etc/init.d/oracle

 

  The content of the script is:

#!/bin/bash
#chkconfig: 2345 80 90
#description:auto_run
### END INIT INFO
export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK
export ORACLE_USER=oracle
export ORACLE_BASE=/oracle/db
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1
export PATH=$PATH:$ORACLE_HOME/bin
export ORACLE_SID=police


# see how we are called:
case $1 in
    start)
    su - "$ORACLE_USER"<<EOO
    lsnrctl start
    sqlplus /nolog<<EOS
    connect / as sysdba
    startup
EOS
    emctl start dbconsole
EOO
touch /var/lock/subsys/$scriptname
    ;;
    stop)
su - "$ORACLE_USER"<<EOO
    lsnrctl stop
    sqlplus /nolog<<EOS
    connect / as sysdba
    shutdown immediate
EOS
    emctl stop dbconsole
EOO
rm -f /var/lock/subsys/scriptname
    ;;
    *)
    echo "Usage: $0 {start|stop}"
    ;;
esac

 

    After saving the above script, set permissions, etc.

    

chown root.root /etc/init.d/oracle
chmod 755 /etc/init.d/oracle
service oracle start #Start service
chkconfig oracle on #Set to start automatically at boot

 

16. There are some oracle parameters that can be further optimized, such as turning off auditing, archiving, modifying the maximum number of connected users, etc. In order to facilitate editing, you can consider installing a program that supports the sqlplus command to scroll up and down, see here for details

http://blog.itpub.net/16381228/viewspace-758767/

 

//Close the problem of empty table not allocating table space

alter system set deferred_segment_creation=false;

// close audit

alter system set audit_trail=FALSE scope=spfile;

shutdown immediate;

startup mount;

//close archive

alter database noarchivelog;

alter database open;

 

 

 

 

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326096248&siteId=291194637