Set Oracle 11gR2 in CentOS to automatically start the system service

Source: Internet
Author: User
Tags centos

After installation in Linux, you must manually start and close the database (dbstart | dbshut), listener (lsnrctl), and console (emtcl) each time ). How can I add Oracle to a Linux system service and start it on its own? The following uses CentOS 6.3 as an example to explain how to use CentOS!

** 1. Redhat init introduction **

When Linux is started, an init program is run, and then init is used to start subsequent tasks, including multi-user environments (set in inittab) and networks. The running level is the function level of the current program running, which ranges from 1 to 6 and has different functions. These levels are specified in/etc/inittab (the file location of other releases is different). This file is the main file that the init Program is looking. The first running service is stored in the/etc/rc. d Directory.

** The file starts with "S", which indicates "start", followed by "start sequence", and "K" indicates "kill". Similarly, "number" indicates the end sequence. For example,/etc/rc3.d/S55sshd indicates that it is related to runtime level 3, and 55 indicates its startup sequence./etc/rc3.d/K15nginx indicates that it is related to runtime level 3, 15 is the order in which it is closed. **
Init. d
This directory stores some service startup scripts, multiple rpm packages during system installation, which can be used to start, stop, and restart these services during execution.
Rcx. d (x is 0 ~ 6)
This directory is the startup-level execution program link directory, and the files in it all point to some soft connections of files in the init. d Directory.

** 2. Modify the dbstart and dbshut startup closing scripts so that the listener can be automatically started when the database is started (that is, the listener is started when the database is started and the listener is stopped when the database is stopped ):**

Modify ORACLE_HOME_LISTNER = $1 in dbstart to ORACLE_HOME_LISTNER = $ ORACLE_HOME.
{{{
| # Vim/u01/app/oracle/product/11.2.0/db_1/bin/dbstart
Find the following code, before the actual script code
| # First argument is used to bring up Oracle Net Listener
ORACLE_HOME_LISTNER = $1
| # ** Change ORACLE_HOME_LISTNER = $1 to ORACLE_HOME_LISTNER = $ ORACLE_HOME **
If [! $ ORACLE_HOME_LISTNER]; then
Echo "ORACLE_HOME_LISTNER is not SET, unable to auto-start Oracle Net Listener"
Echo "Usage: $0 ORACLE_HOME"
Else
LOG = $ ORACLE_HOME_LISTNER/listener. log
}}}


Modify ORACLE_HOME_LISTNER = $1 in dbshut to ORACLE_HOME_LISTNER = $ ORACLE_HOME.


{{{
Also modify the dbshut script:
| # Vim/u01/app/oracle/product/11.2.0/db_1/bin/dbshut
| # The this to bring down Oracle Net Listener
ORACLE_HOME_LISTNER = $1
| # ** Change ORACLE_HOME_LISTNER = $1 to ORACLE_HOME_LISTNER = $ ORACLE_HOME **
If [! $ ORACLE_HOME_LISTNER]; then
Echo "ORACLE_HOME_LISTNER is not SET, unable to auto-stop Oracle Net Listener"
Echo "Usage: $0 ORACLE_HOME"
Else
LOG = $ ORACLE_HOME_LISTNER/listener. log
}}}

** 3. To successfully start a database instance, you must enable a level set in Oracle: vi/etc/oratab. Modify the line as follows :**


{{{
Orcl:/opt/oracle/11g: Y # The default value is orcl:/opt/oracle/11g: N.
}}}

** 4. Create a script for starting oracle services as the root user (create an Oracle service startup script): vi/etc/init. d/oracle, and add the following script :**


Create a file named oracle (or oracle11g) and copy the following script code to the file (the path of the oracle directory in the file is changed according to the actual installation path ):


{{{
| #! /Bin/sh
| # Chkconfig: 345 61 61
| # Description: Oracle 11g R2 AutoRun Servimces
| #/Etc/init. d/oracle
| #
| # Run-level Startup script for the Oracle Instance, Listener, and
| # Web Interface

Export ORACLE_BASE =/u01/app/oracle
Export ORACLE_HOME = $ ORACLE_BASE/product/11.2.0/db_1
Export ORACLE_SID = ORCL
Export PATH = $ PATH: $ ORACLE_HOME/bin

ORA_OWNR = "oracle"

| # If the executables do not exist -- display error

If [! -F $ ORACLE_HOME/bin/dbstart-o! -D $ ORACLE_HOME]
Then
Echo "Oracle startup: cannot start"
Exit 1
Fi

| # Depending on parameter -- startup, shutdown, restart
| # Of the instance and listener or usage display

Case "$1" in
Start)
| # Oracle listener and instance startup
Su $ ORA_OWNR-lc $ ORACLE_HOME/bin/dbstart
Echo "Oracle Start Succesful! OK ."
;;
Stop)
| # Oracle listener and instance shutdown
Su $ ORA_OWNR-lc $ ORACLE_HOME/bin/dbshut
Echo "Oracle Stop Succesful! OK ."
;;
Reload | restart)
$0 stop
$0 start
;;
*)
Echo $ "Usage: 'basename $ 0' {start | stop | reload }"
Exit 1
Esac
Exit 0
}}}


Save and exit

** 5. Grant the execution permission of the startup script and link it to it **


{{{
[Root @ localhost ~] # Chmod 777/etc/init. d/oracle
[Root @ localhost ~] # Ln-s/etc/init. d/oracle/etc/rc1.d/K61oracle
[Root @ localhost ~] # Ln-s/etc/init. d/oracle/etc/rc3.d/S61oracle
}}}

** 6. Run the following command to start and close oracle **


{{{
[Root @ localhost ~] #/Etc/init. d/oracle start # start oracle (including database instances, listeners, and EM)
[Root @ localhost ~] #/Etc/init. d/oracle stop # disable oracle
[Root @ localhost ~] #/Etc/init. d/oracle restart # restart oracle
}}}

** 7. Add the oracle startup script to the system service and set auto-start **


{{{
[Root @ localhost ~] # Chkconfig -- add oracle
[Root @ localhost ~] # Chkconfig -- level 345 oracle on
}}}

** 8. Restart the system with reboot and view the Oracle process **


{{{
[Root @ localhost ~] # Ps-ef | grep oracle
[Root @ localhost ~] # Chkconfig | grep oracle # View The oracle service startup level
}}}

** 9. Use the following command to manage oracle startup or shutdown **


{{{
[Root @ localhost ~] # Service oracle start # start
[Root @ localhost ~] # Service oracle stop # Disable
[Root @ localhost ~] # Service oracle restart # restart
}}}

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.