Create an Oracle service in Linux and start it on startup

Source: Internet
Author: User
The following operating environment is in CentOS6.4 + Oracle11gR2 (Oracle is installed in ORACLE_BASEoptoracle, and ORACLE_HOMEoptoracle11g ).

The following operating environment is in CentOS 6.4 + Oracle 11gR2 (Oracle is installed in ORACLE_BASE =/opt/oracle, and ORACLE_HOME =/opt/oracle/11g ).

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:

Ps aux | grep ora _ # If no ora _ ** related process exists, the oracle database instance does not start netstat-tlnup | grep 1521 # If no display is available, the listener has not started lsnrctl status # view the listener status netstat-tlnup | grep 1158 # If no display is displayed, EM has not started emctl status dbconsole # view the 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: # description: Oracle dbstart/dbshut # ORA_HOME required for chkconfig =/opt/oracle/11gORA_OWNER = oracleLOGFILE =/var/log/oracle. log >>$ {LOGFILE >>> {LOGFILE }>>> {LOGFILE} exitfistart () {-$ {ORA_OWNER}-c} stop () {-$ {ORA_OWNER}-c }) start >>$ {LOGFILE };;) stop >>$ {LOGFILE} start >>$ {LOGFILE };>> $ {LOGFILE }>>> {LOGFILE} echo ""

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

Chmod a + 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 | grep oracle # view the oracle service startup level chkconfig -- level 24 oracle off # modify the oracle service startup level
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 # shutdown execution ln-s/etc/init. d/oracle/etc/rc6.d/K01oracle # restart execution

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.