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 there is no ora _ ** related process, the oracle database instance is not started.
Netstat-tlnup | grep 1521 # If no display is displayed, the listener is not started.
Lsnrctl status # view listener status
Netstat-tlnup | grep 1158 # If no display is displayed, EM is not started
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:
Copy codeThe Code is as follows:
Lsnrctl start
Oracle also provides a web version manager. To use this manager, you must start related services by running the following command:
Copy codeThe Code is as follows:
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:
Copy codeThe Code is as follows:
/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:
Copy codeThe Code is as follows:
Orcl:/opt/oracle/11g: Y # The default value is orcl:/opt/oracle/11g: N.
Create a script for starting oracle services as root: Vi/etc/init. d/oracle, add the following script:
Copy codeThe Code is as follows:
#! /Bin/sh
# Chkconfig: 2345 20 80
# Description: Oracle dbstart/dbshut
# Required for chkconfig
ORA_HOME =/opt/oracle/11g
ORA_OWNER = oracle
LOGFILE =/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:
Copy codeThe Code is as follows:
Chmod a + x/etc/init. d/oracle
So far, you can use the following command to start and close oracle
Copy codeThe Code is as follows:
/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:
Copy codeThe Code is as follows:
Chkconfig -- add oracle
Run the following command to view and set the startup level of the oracle service::
Copy codeThe Code is as follows:
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
Copy codeThe Code is as follows:
Service oracle start # start
Service oracle stop # disable
Service oracle restart # restart
Establish a connection:
Copy codeThe Code is as follows:
Ln-s/etc/init. d/oracle/etc/rc0.d/K01oracle # shutdown and execute
Ln-s/etc/init. d/oracle/etc/rc6.d/K01oracle # restart and execute