How to set up and shut down automatically with Oracle 11g with Redhat 5 system

Source: Internet
Author: User

Recently, Oracle system basic debugging passed, it is time to set up Oracle with Rhel automatically start and shut down the service, the reason to put this task in the last to do, because I think this should not be difficult, but really implemented, still encountered a small obstacle: write good script, register good service , the test, Oracle can start with Rhel boot, but not with the system shutdown and shutdown. Find the answer on the Internet, found that almost all of the setup process posts are copied from the same article, it simply won't work. The world article a big copy. Ask someone for help, and don't get a good solution. Helpless, his quiet heart to slowly research and analysis, finally found the key reason for the problem.

Now put my entire success of the process of setting up, for everyone to reference, in order to everyone can less detours, but also to give other people a suggestion: Cut Mo Blunt Copy, out of context, otherwise its harm Big Yan!!

First, you set the Allow Oracle system to start automatically in Rhel because it is set to disallowed by default. The operation is as follows:

To modify the/etc/oratab file under the root account:
# Vi/etc/oratab
Find Orcl=/db/app/oracle/product/11.1.0/db_1:n this line
Switch
Orcl=/db/app/oracle/product/11.1.0/db_1:y
That is, change the last n to Y, meaning that automatic start will not be allowed to start automatically.

Then, you modify the Oracle's own startup and shutdown scripts, respectively, Dbstart and Dbshut. Executing both scripts enables the startup and shutdown of Oracle scripts.

To modify the $oracle_home/bin/dbstart file under ORACLE account:
# su-oracle
$ cd $ORACLE _home/bin
$ VI Dbstart
Find Oracle_home_listner=$1 this line
Switch
oracle_home_listner= $ORACLE _home

This is done because when the script is automatically generated, when Oracle is installed into Rhel, the script does not know your

What is Oracle_home_listner, now to display this parameter, so that it does not report when executing this script

Oracle_home_listner no errors have been specified. Note: The Dbstart and Dbshut scripts have merged the boot and shutdown of the listener into numbers after 10g

According to the startup and shutdown scripts of the library instance. And it's not separate anymore.

In the same way, we also want to modify this parameter of Dbshut. It is not written in detail here, they are in the same directory.

Again, write a script, register it as a system service, and let it run when it is turned on and off. Its role is to invoke and execute Dbstart and Dbshut. This does not

Did you implement database startup and shutdown?! This script is placed in the/ETC/INIT.D directory, and the script name is ORACLE11

The script is as follows:

#!/bin/bash
# chkconfig:2345 99 10
# Description:startup Script for Oracle Databases
#/etc/rc.d/init.d/oradbstart
Export oracle_base=/db/app/oracle/
Export Oracle_home=/db/app/oracle/product/11.1.0/db_1
Export ORACLE_SID=ORCL
Export path= $PATH: $ORACLE _home/bin
Case "$" in
Start

echo "-----Startup Oracle-----" >>/var/log/oracle11log
Su oracle-c $ORACLE _home/bin/dbstart
Touch/var/lock/subsys/oracle11

echo "-----Startup Oracle Successful-----" >>/var/log/oracle11log
echo "OK"
;;

Stop
echo "-----shutdwn Oracle-----" >>/var/log/oracle11log

Su oracle-c $ORACLE _home/bin/dbshut
Rm-f/var/lock/subsys/oracle11

echo "-----Shutdown Oracle Successful-----" >>/var/log/oracle11log

echo "OK"
;;

*)
echo "Usage: ' basename ' Start|stop"
Exit 1

Esac

Exit 0
Save and exit.

Now, I want to make a key explanation for this script:

First: # chkconfig:2345 99 10 is a one-line comment, but it is a crucial one, unless you automatically generate the symbolic connection file without Chkconfig command, instead of creating it entirely by hand. Otherwise, the execution of the Chkconfig system will report an error that ORACLE11 does not have chkconfig service permissions.

Second: Su oracle-c $ORACLE _home/bin/dbstart and touch/var/lock/subsys/oracle11 The role of the two lines is to first execute Dbstart script to start Oracle, Then create a file in the Service Activity list directory with the same name as the ORACLE11 service, indicating that the service is active, that is, started.

and Su oracle-c $ORACLE _home/bin/dbshut and rm-f/var/lock/subsys/oracle11 These two lines of action is the first to execute Dbshut anxious Oh script off Oracle, Then delete the file that has the same name as ORACLE11 from the Service Activity list directory, indicating that the service is not active, that is, it has been closed.

So why do Touch/var/lock/subsys/oracle11 and rm-f/var/lock/subsys/oracle11 these two steps? The reason is related to the mechanism of Linux system: Linux to determine whether a service is started based on whether the/var/lock/subsys/directory with the same name of the file, if there is a service has been started, when the system shuts down, Linux will close all the services listed here and delete the file with the same name as the service. If a service is started, but it does not have the same name as the service in this directory, then the service will not be closed. Articles on the Internet have set this place wrong, so it will be discovered that Oracle can boot with the system, but it does not shut down with the system. I also analyzed the/etc/rc.d/rc.local after the discovery of this principle. After the experiment, it sure did. The same is true of MySQL's startup and shutdown scripts, and it finally dawned on me. I see. Please pay attention to this place.

Finally, it is possible to register this script as a system service, with two methods:

First, the script is assigned permissions that can be executed. Execute the following command:

#su-root
Chown Oracle/etc/init.d/oracle11
chmod 775/etc/init.d/oracle11

Then create the symbolic link file.

Chkconfig--add/etc/init.d/oracle11, executing this command requires you to write the # chkconfig:2345 99 10 in the script. So when this command is executed, go back to the Oracle11 file to look for this line of comments, and parse this line of comments, according to the results of the resolution in/etc/rc.d/rc2.d;/etc/rc.d/rc3.d;/etc/rc.d/rc4.d;/etc/rc.d/ RC5.D Create the symbol connection file S99oracle11 file, this file is to be executed when the system starts, actually this file is pointing to/etc/init.d/oracle11, when the system starts to send a start parameter to this file, The start branch in the Oracle11 file is also executed. The K10oracle11 file is also created in/ETC/RC.D/RC0.D;/ETC/RC.D/RC1.D;/ETC/RC.D/RC6.D, which is to be executed when the system shuts down, in fact this file also points to/etc/init.d/ ORACLE11, shut down when the system sends a stop parameter to this file, it executes the Stop branch in the Oracle11 file.
I think you should understand the meaning of these numbers in the chkconfig:2345 99 10: Indicates that the 2,3,4,5 level starts the service, 99 is the ordinal number of the linked file generated under the corresponding/ETC/RC.D/RCN.D (n is the level specified earlier, here is the 2345) directory ( Start priority) s99oracle11,10 the ordinal (priority level of service stop) K10oracle11 for the link file generated by/ETC/RC.D/RCN.D (n is a level other than 2345) that corresponds to the level indicated above. As for why the naming rules for files and files are created in these directories, it is necessary that you have a familiar understanding of the Linux system startup process, which is not discussed here.

Second: If you want to try the fun of manually creating a symbolic connection file, execute the following command:

#su-root

Ln-s/etc/init.d/oracle11/etc/rc.d/rc2.d/s99oracle11

Ln-s/etc/init.d/oracle11/etc/rc.d/rc3.d/s99oracle11

Ln-s/etc/init.d/oracle11/etc/rc.d/rc4.d/s99oracle11

Ln-s/etc/init.d/oracle11/etc/rc.d/rc5.d/s99oracle11

Ln-s/etc/init.d/oracle11/etc/rc.d/rc0.d/k10oracle11

Ln-s/etc/init.d/oracle11/etc/rc.d/rc1.d/k10oracle11

Ln-s/etc/init.d/oracle11/etc/rc.d/rc6.d/k10oracle11

Effect and execution Chkconfig--add Oracle11 is the same.

Here, so the setup process is over, let's test it out:

#cd/ETC/INIT.D

SH oracle11 start

After executing, look at the Oracle11log file in the/var/log directory, is there a script to start the branch output information?

SH oracle11 stop

After the execution, look at the Oracle11log file in the/var/log directory, is there a script to close the branch output information?

If you see the message, you are set up successfully. If not, please set again carefully, and note the permissions of the file. The user concept of Linux is very strict. After all, it's a multi-user system.

Article belongs to the author original, reproduced please indicate the source. From: http://blog.csdn.net/kanon_lgt/
For more information, refer to: http://www.jb51.net/article/19823.htm
For more information, refer to: http://www.jb51.net/article/19823.htm
For more information, refer to: http://www.jb51.net/article/19823.htm

How to set up and shut down automatically with Oracle 11g with Redhat 5 system

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.