Create an Oracle service in Linux and start it on startup

Source: Internet
Author: User

Note: The following operating environments are available in centos 6.4 + Oracle 11gr2 (Oracle is installed in oracle_base =/opt/Oracle, and ORACLE_HOME =/opt/Oracle/11g)

After installing and configuring the Oracle database with oui, Oracle is enabled (including database instances, listeners, and EM ). After the operating system is restarted, Oracle is not started by default. Run the following command to check whether Oracle services have been started:

 
PSAux |GrepOra _ # if there is no ora _**_**The Oracle database instance does not start netstat.-Tlnup |Grep 1521# If no display is displayed, the listener does not start LSNRCTL status # view the listener status netstat-Tlnup |Grep 1158# If no display is displayed, EM does not start emctl status dbconsole # View EM status

Start the Oracle instance manually, use sqlplus to create an idle instance, and then start it with startup, as shown below:

After the database instance is started, you must start the listener to allow remote users to establish a connection. Run the following command to start the listener:

 
LSNRCTL start

 

Oracle also provides a web version manager. To use this manager, you must start related services by running the following command:

 
Emctl start dbconsole

 

At this point, you can enter: https: // {Host IP address or host name or local localhost}: 1158/em in the web browser to open the manager and log on to the relevant account to view and manage the database.

If the above operations are troublesome every time you restart the operating system, how can you enable Oracle to be automatically started when it is started as a system service?

Oracle provides many scripts for database operations under $ ORACLE_HOME/bin. dbstart and dbshut can be used to start and close databases respectively. Note that these two scripts contain the start or close of the listener, but do not perform related operations on em. Run the following command:

 
/Opt/Oracle/11g/bin/dbstart/opt/Oracle/11G # Start the database instance (including the listener)/Opt/Oracle/11g/bin/dbshut/opt/Oracle/11G # Shut Down database instances (including listeners)

 

To successfully start the database instance, you must enable the level VI/etc/oratab set in Oracle. Modify the following line:

 
Orcl:/opt/Oracle/11g:Y# The default value is orcl:/opt/Oracle/11G: N.

 

Run VI/etc/init. d/oracle as the root user to start the Oracle service. Add the following script:

#! /Bin/Sh  # Chkconfig:  2345   20   80  # Description: Oracle dbstart / Dbshut # ora_home required by chkconfig for the above two actions =/Opt/Oracle/ 11gora_owner = Oraclelogfile =/Var/log/ Oracle. Log  Echo   "  #################################  " >$ {Logfile}  Date + "  ### % T % A % d: run Oracle  " > $ {Logfile}  If [! -F $ {ora_home}/bin/dbstart] | [! -F $ {ora_home}/bin/dbshut]; Then      Echo   "  Error: missing the script file $ {ora_home}/bin/dbstart or $ {ora_home}/bin/dbshut!  " > $ {Logfile} Echo   "  #################################  " > $ {Logfile} exit  Fi  Start (){  Echo   "  ### Startup database...  "      Su -$ {Ora_owner}-C "  $ {Ora_home}/bin/dbstart $ {ora_home}  "     Echo   "  ### Done.  "      Echo   "  ### Run Database Control...  "      Su -$ {Ora_owner}-C "  $ {Ora_home}/bin/emctl start dbconsole  "      Echo   "  ### Done.  " } STOP (){  Echo   "  ### Stop Database Control...  "      Su -$ {Ora_owner}-C "  $ {Ora_home}/bin/emctl stop dbconsole  "      Echo   "  ### Done.  "      Echo   "  ### Shutdown database... "      Su -$ {Ora_owner}-C "  $ {Ora_home}/bin/dbshut $ {ora_home}  "      Echo   "  ### Done.  "  }  Case   "  $1  "   In      '  Start '  ) Start > $ {Logfile };;  '  Stop  '  ) Stop > $ {Logfile };;  '  Restart  '  ) Stop > $ {Logfile} start > $ {Logfile };; Esac  Date + "  ### % T % A % d: finished.  " > $ {Logfile}  Echo   "  #################################  " > $ {Logfile}  Echo   "" 

 

Run the following command to set/etc/init. d/Oracle to an executable file:

ChmodA + x/etc/init. d/Oracle

 

So far, you can use the following command to start and close Oracle

 
/Etc/init. d/Oracle start # Start Oracle (including database instances, listeners, and EM)/Etc/init. d/Oracle stop # disable Oracle/Etc/init. d/Oracle restart # restart Oracle

 

Add Oracle to chkconfig:

 
Chkconfig -- add Oracle

 

Run the following command to view and set the startup level of the Oracle service:

 
Chkconfig |GrepOracle # view the startup level chkconfig of the Oracle service-- Level24Oracle off # modify the startup level of the Oracle service
Chkconfig -- level 35 oracle on

 

Now you can use the following command to manage Oracle startup or shutdown

Service Oracle start # Start Service Oracle stop # disable service Oracle restart # restart

Establish a connection:

 
Ln-S/etc/init. d/Oracle/etc/rc0.d/K01oracle # ShutdownLn-S/etc/init. d/Oracle/etc/rc6.d/k01oracle # restart and execute

 

 

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.