Note: you must first modify the environment variables of Oracle and root users.
Vi ~ /. Bash_profle
Add the following content:
Umask 022
Export ORACLE_BASE =/home/oracle/app
Export ORACLE_HOME = $ ORACLE_BASE/oracle/product/11.2.0/dbhome_1
Export ORACLE_SID = orcl
Export PATH = $ PATH: $ HOME/bin: $ ORACLE_HOME/bin
Export LD_LIBRARY_PATH = $ ORACLE_HOME/lib:/usr/lib
1. Use the root user to modify the/etc/oratab file:
$ Vi/etc/oratab
Orcl:/home/oracle/app/oracle/product/11.2.0/dbhome_1: N
Changed:
Orcl:/home/oracle/app/oracle/product/11.2.0/dbhome_1: Y
That is, change the last N to Y.
2. Use the oracle user to modify the $ ORACLE_HOME/bin/dbstart file:
# Su-oracle
$ Cd $ ORACLE_HOME/bin
$ Vi dbstart
Locate ORACLE_HOME_LISTNER =... and change it
ORACLE_HOME_LISTNER = $ ORACLE_HOME
Modify dbshut as well
Vi dbshut
ORACLE_HOME_LISTNER = $ ORACLE_HOME
Note: It is a modification, not an addition, but the search function of vi is used for searching:
ORACLE_HOME_LISTNER, modify and save the modification.
Iii. Test and run dbshut. Check whether dbstart can start the oracle service and listener service:
Or an error may be reported during startup, indicating that dbstart or dbshut has insufficient permissions.
1. modify the permissions of dbstart and dbshut log files:
$ Su-root
# Cd $ ORACLE_HOME
# Chown oracle: oinstall $ ORACLE_HOME/startup. log
# Chown oracle: oinstall $ ORACLE_HOME/shutdown. log
# Chown oracle: oinstall $ ORACLE_HOME/listener. log
2. Execute the corresponding script for testing (optional)
# Su-oracle
$ Cd $ ORACLE_HOME/bin
$./Dbstart (./dbshut)
$ Ps-efw | grep ora _
$ Lsnrctl status
$ Ps-efw | grep LISTEN | grep-v grep
4. Create a service
$ Su-root
# Cd/etc/rc. d/init. d/
# Vi oracle
----- Script -----
#! /Bin/bash
# Chkconfig: 345 99 10
# Description: Startup Script for Oracle Databases
#/Etc/rc. d/init. d/oracle
Export ORACLE_BASE =/home/oracle/app
Export ORACLE_HOME = $ ORACLE_BASE/oracle/product/11.2.0/dbhome_1
Export ORACLE_SID = orcl
Export PATH = $ PATH: $ HOME/bin: $ 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
Echo-n "Starting Oracle :"
Su-$ ORA_OWNR-c "$ ORACLE_HOME/bin/dbstart"
Su-$ ORA_OWNR-c "$ ORACLE_HOME/bin/lsnrctl start"
Touch/var/lock/Oracle
Su-$ ORA_OWNR-c "$ ORACLE_HOME/bin/emctl start dbconsole"
# Su-$ ORA_OWNR-c "$ ORACLE_HOME/bin/isqlplusctrl start"
Echo "OK"
;;
Stop)
# Oracle listener and instance shutdown
Echo-n "Shutdown Oracle :"
Su-$ ORA_OWNR-c "$ ORACLE_HOME/bin/emctl stop dbconsole"
# Su-$ ORA_OWNR-c "$ ORACLE_HOME/bin/isqlplusctrl stop"
Su-$ ORA_OWNR-c "$ ORACLE_HOME/bin/dbshut"
Su-$ ORA_OWNR-c "$ ORACLE_HOME/bin/lsnrctl stop"
Rm-f/var/lock/Oracle
Echo "OK"
;;
Reload | restart)
$0 stop
$0 start
;;
*)
Echo "Usage: 'basename $ 0' start | stop | restart | reload"
Exit 1
Esac
Exit 0
---- Skip the following steps if the startup is successful ----
5. check:
Based on the above running results, when the corresponding running level is on (for example, 5: on), in the corresponding/etc/rc. d/rcN. d (for example, the value corresponding to 5: on is/etc/rc. d/rc5.d) the following will generate a file: S99oradbstart, use vi S99oradbstart to open the file, you can see the content of the file and/etc/rc. d/init. d/oradbstart has the same content, indicating that the configuration is successful. In fact, S99oradbstart is one to/etc/rc. d/init. d/oradbstart link, we can use the file command to view:
$ File/etc/rc. d/rc5.d/S99oradbstart
S99oradbstart: symbolic link to '../init. d/oradbstart
6. One Note:
In the script file: # chkconfig: 345 99 10
It is pointed out that Level 3 and Level 5 start this service, and 99 is in the corresponding/etc/rc. d/rcN. d (N is the level specified above, here is 345) the serial number of the link file generated under the directory (startup priority level) S99oradbstart, 10. d/rcN. d (N is a level other than 345) the serial number of the link file generated by the Directory (priority of service stop) K10oradbstart.