How to set the Automatic startup and shutdown of ORACLE11g with RHEL5

Source: Internet
Author: User

Write the script. After registering the service, it is tested that ORACLE can be started with RHEL, but it cannot be closed with the system being disabled. Find answers online and find that almost all posts in the setup process are copied from the same article as they are, which won't work at all. A large copy of the world's articles. Ask for help from others and fail to get a good solution. Instead, I tried to analyze the problem slowly, and finally found the key cause of the problem.
Now I will post my entire successful setup process for your reference, so that you can avoid detours. In addition, I would like to give other people a suggestion: Do not just copy it out of context, otherwise, it will cause serious harm !!
First, you must set in RHEL to allow the ORACLE system to start automatically, because it is disabled by default. The procedure is as follows:
Modify the/etc/oratab file under the root account:
# Vi/etc/oratab
Find the line orcl =/db/app/oracle/product/11.1.0/db_1: N.
Changed:
Orcl =/db/app/oracle/product/11.1.0/db_1: Y
That is, change the last N to Y, which means that automatic start is not allowed to be changed to allow automatic start.
Then, modify the startup and shutdown scripts of ORACLE, respectively dbstart and dbshut. Execute these two scripts to start and close the ORACLE script.
Modify the $ ORACLE_HOME/bin/dbstart file under the oracle account:
Copy codeThe Code is as follows:
# Su-ORACLE
$ Cd $ ORACLE_HOME/bin
$ Vi dbstart

Locate ORACLE_HOME_LISTNER = $1.
Changed:
ORACLE_HOME_LISTNER = $ ORACLE_HOME
The reason for this step is that when the script is automatically generated, that is, when ORACLE is installed into RHEL, this script does not know your
What is ORACLE_HOME_LISTNER? Now you need to specify this parameter so that it will not be reported when you execute this script.
ORACLE_HOME_LISTNER is not specified. Note: After 10 Gb, The dbstart and dbshut scripts have merged the start and close of the listener.
The script for starting and disabling the database instance. Instead of being separated separately.
In the same way, we also need to modify this parameter of dbshut. This is not detailed here. They are in the same directory.
Again, it is to write a script and register it as a system service so that it can run during startup and shutdown. It calls and executes dbstart and dbshut. No
Is the database enabled and disabled ?! This script is stored in the/etc/init. d directory. The Script Name Is oracle11.
The script is as follows:
Copy codeThe Code 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 "$1" 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 $ 0' start | stop"
Exit 1
Esac
Exit 0

Save and exit.
Now, I want to give a key explanation for this script:
First: # chkconfig: 2345 99 10 is a line of comment, but it is indeed an essential line, unless you do not use the chkconfig command to automatically generate a symbolic connection file, but completely create it manually. Otherwise, the chkconfig System reports that oracle11 does not have the chkconfig Service permission.
Second, su oracle-c $ ORACLE_HOME/bin/dbstart and touch/var/lock/subsys/oracle11 are used to execute the 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.
The su oracle-c $ ORACLE_HOME/bin/dbshut and rm-f/var/lock/subsys/oracle11 lines are used to first execute the dbshut emergency, then, delete the file with the same name as oracle11 from the service activity list, indicating that the service is neither active nor closed.
So why do we need to do touch/var/lock/subsys/oracle11 and rm-f/var/lock/subsys/oracle11? The reason is related to the mechanism of the LINUX system: LINUX determines whether a service is started based on whether a file with the same name as the server is in the/var/lock/subsys/directory, if yes, the service has been started. When the system is shut down, LINUX will close all the services listed here and delete files with the same name as the service. If a service is started, but there is no file with the same name of the Service in this directory, the service will not be closed. All articles on the Internet set this location wrong, so we will find that ORACLE can be started with the system, but it is not closed with the system. I also analyzed/etc/rc. d/rc. local and found this principle. After the test, it is true that. This is also the case when I analyze the mysql startup and shutdown scripts. It turns out that. Please note this.
Finally, register the script as a system service. There are two methods:
1. Assign the executable permissions to the script first. Run the following command:
Copy codeThe Code is as follows:
# Su-root
Chown oracle/etc/init. d/oracle11
Chmod 775/etc/init. d/oracle11

Create a symbolic link file.
Chkconfig -- add/etc/init. d/oracle11. to execute this command, you need to write # chkconfig: 2345 99 10 in the script. In this way, when the command is executed, go back to the oracle11 file to search for this line of comment, parse this line of comment, and add it to/etc/rc according to the parsing result. d/rc2.d;/etc/rc. d/rc3.d;/etc/rc. d/rc4.d;/etc/rc. d/rc5.d create a symbolic connection file S99oracle11, which is executed when the system starts. In fact, this file points to/etc/init. d/oracle11. When started, the system sends a start parameter to this file, and then runs the start branch in the oracle11 file. In the/etc/rc. d/rc0.d;/etc/rc. d/rc1.d;/etc/rc. d/rc6.d: Create the K10oracle11 file. This file must be executed when the system shuts down. In fact, this file also points to/etc/init. d/oracle11. When it is disabled, the system sends a stop parameter to the file, and the stop branch in the oracle11 file is executed.
I think you should understand the meaning of the numbers in # chkconfig: 2345 99 10: point out that the service is started at Level 2, 3, and 5, and 99 is in the corresponding/etc/rc. d/rcN. d (N is the level specified above, here is 2345) the serial number of the link file generated under the directory (startup priority level) S99oracle11, 10. d/rcN. d (N is a level other than 2345) the serial number of the link file generated by the Directory (priority of service stop) K10oracle11. As for the reason for creating naming rules for files and files in these directories, you need to have a familiar understanding of the LINUX system startup process.
Second, if you want to manually create a symbolic connection file, run the following command:
Copy codeThe Code is as follows:
# 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

The effect is the same as running chkconfig -- add oracle11.
At this point, the setup process is over. Let's test it as follows:
Copy codeThe Code is as follows:
# Cd/etc/init. d
Sh oracle11 start

After execution, check the oracle11log file in the/var/log directory. Is there any output information for the startup branch of the script?
Sh oracle11 stop
After the command is executed, check the oracle11log file in the/var/log directory. Is there any script to close the branch output information?
If the information is displayed, the setting is successful. If not, set it again and pay attention to file permissions. LINUX has strict user concepts. After all, it is a multi-user system.
The article is original to the author. For more information, see the source.
From: http://blog.csdn.net/kanon_lgt/

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.