Method One: Use Oracle's own startup and shutdown scripts
1. Oracle User modified/etc/oratab file:
- $ vi/etc/oratab
- Orcl:/oracle/app/product/10.2.0/db_1:n
Switch
Orcl:/oracle/app/product/10.2.0/db_1:y
That is, change the last n to Y, allowing the Dbstart startup database to run at system startup.
2. ORACLE User modified $oracle_home/bin/dbstart file:
- # su-oracle
- $ cd $ORACLE _home/bin
- $ VI Dbstart
Find oracle_home_listner= ..... This line, modified into
Oracle_home_listner=/u01/app/oracle/product/10.1.0/db_1
or directly modified to:
oracle_home_listner= $ORACLE _home
3. Test run Dbshut, Dbstart
See if you can start Oracle Services and Listener services:
3.1. Execute the appropriate script to test
- #su-oracle
- $CD $ORACLE _home/bin
- $./dbstart (Start database and listen)
- $ PS-EFW | grep Ora_ (see if the database process is started)
- $ lsnrctl Status (view listening status)
- $ PS-EFW | grep LISTEN | Grep-v grep (View listening process, remove grep query itself)
- $./dbshut (shut down the database, monitoring will not shut down, need to stop manually)
3.2. Modify the permissions of the Dbstart and Dbshut log files:
- $su-root
- #cd $ORACLE _home
- #chown Oracle:oinstall Startup.log
- #chown Oracle:oinstall Shutdown.log
Note: Startup.log and Shutdown.log may not be created automatically after you run the./dbstart and./dbshut.
4. Create a service
- $su-root
- # cd/etc/rc.d/init.d/
- # VI Oracle (Oracle is the service name that will be installed to the system, can be taken)
There are two scripts to choose from, starting with different content.
Modify the Environment Variable configuration section (blue font position) according to your environment
Script 1 (Start database, listen, Dbconsole, Sqlplus)
The following 3 lines of the red font are required
345: Define Run Level
80: Service Start priority at boot (the smaller the number starts sooner)
10: Service Stop priority at shutdown (the smaller the number, the sooner it is closed)
- #!/bin/bash
- # chkconfig:345 80 10
- # Description:startup Script for Oracle Databases
- #/etc/rc.d/init.d/oracle
- Export oracle_base=/u01/oracle
- Export oracle_home=/u01/oracle/product
- Export oracle_sid=pa
- Export path= $PATH: $ORACLE _home/bin
- ora_ownr="Oracle"
- # If the executables does 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 "$" in
- Start
- # Oracle Listener and Instance startup
- Echo-n "Starting Oracle:"
- su-$ORA _ownr-c "$ORACLE _home/bin/dbstart"
- Touch/var/lock/oracle
- su-$ORA _ownr-c "$ORACLE _home/bin/emctl start Dbconsole"
- su-$ORA _ownr-c "$ORACLE _home/bin/isqlplusctl 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/isqlplusctl 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)
- $ stop
- $ start
- ;;
- *)
- echo "Usage: ' basename ' Start|stop|restart|reload"
- Exit 1
- Esac
- Exit 0
Script 2 (Start database and listen only)
The following 3 lines of the red font are required
345: Define Run Level
80: Service Start priority at boot (the smaller the number starts sooner)
10: Service Stop priority at shutdown (the smaller the number, the sooner it is closed)
- #!/bin/bash
- # chkconfig:345 80 10
- # Description:startup Script for Oracle Databases
- #/etc/rc.d/init.d/oracle
- Export oracle_base=/u01/oracle
- Export oracle_home=/u01/oracle/product
- Export oracle_sid=pa
- Export path= $PATH: $ORACLE _home/bin
- Case "$" in
- Start
- Su oracle-c $ORACLE _home/bin/dbstart
- Touch/var/lock/oracle
- echo "OK"
- ;;
- Stop
- Echo-n "Shutdown Oracle:"
- Su oracle-c $ORACLE _home/bin/dbshut
- Rm-f/var/lock/oracle
- echo "OK"
- ;;
- *)
- echo "Usage: ' basename ' Start|stop"
- Exit 1
- Esac
- Exit 0
Save exit.
Open Terminal execution:
- $su-root
- #chown oracle.oinstall/etc/rc.d/init.d/oracle
- #chmod 775/etc/rc.d/init.d/oracle
Then execute:
- #chkconfig--add Oracle
or run the following command
- #chkconfig--level 345 Oracle on
- #chkconfig--list Oracle
Normal output:
Oracle 0:off 1:off 2:off 3:on 4:on 5:on 6:off
5. Check
Depending on the result of the operation above, when the corresponding RunLevel is on (for example: 5:on), the corresponding/ETC/RC.D/RCN.D (for example: and
5:on corresponds to:/etc/rc.d/rc5.d) A file is generated below: S99oradbstart, open with VI S99oradbstart
The file, you can see the contents of the file and/etc/rc.d/init.d/oradbstart content the same, indicating that the configuration is successful, in fact
S99oradbstart is a link to/etc/rc.d/init.d/oradbstart, and we can use the file command to view:
- $file/etc/rc.d/rc5.d/s99oradbstart
- S99oradbstart:symbolic link to '. /init.d/oradbstart
After this is turned on, the Oracle service will start automatically.
You can also manually control the service run:
#service Oracle Start Start
#service Oracle Stop shutdown
$ps-ef | grep ora See if the Oracle-related process has started
6. A little note:
6.1 In the script file: # chkconfig:345 99 10
Indicates that the 3,4,5 level starts the service, 99 is in the corresponding/ETC/RC.D/RCN.D (n is the level specified earlier, here is 345) The serial number of the linked file generated under the directory (Start priority level) s99oradbstart,10 for the level indicated above
/ETC/RC.D/RCN.D (n is a level other than 345) the serial number of the linked file generated by the directory (priority level of service stop)
K10oradbstart.
6.2 Command Description:
PS: Monitor Background process
-e Displays all processes.
-F full format.
-H does not display the caption.
-L long format.
-W wide output.
grep: is a command used under Linux to search for content contained in the output.
1. For example, I want to search for a string of characters called "BBB" named Aaa.txt, which can be used
Cat Aaa.txt|grep BBB
2. I want to search the current directory contains BB files, you can use
LS |grep bb
Example: PS-EFW | grep LISTEN | Grep-v grep: View the monitor containing the listen, removing the listener containing grep.
6.3 Chkconfig: Function description
Check and set up the various services of the system.
Syntax: chkconfig [--add][--del][--list][system service] or Chkconfig [--level < rank code >][system service][on/off/reset]
Note: This is a program developed by Red Hat in accordance with the GPL rules, which can query which system services the operating system performs at each level of execution, including a variety of resident services.
Parameters:
--add adds the specified system service, allows the CHKCONFIG directive to manage it, and adds relevant data to the system-initiated narrative file.
--del deletes the specified system service, is no longer managed by the Chkconfig directive, and deletes the relevant data within the system-initiated narrative file.
--list lists the system services that are specified.
--level< Class code > Specify which execution level the system service should be opened or closed.
Note: RunLevel can be thought of as a system state, image a little, you can think RunLevel a bit like Microsoft's Windows operating system Normal,safemode, and command prompt only. Entering each runlevel requires starting or shutting down the corresponding series of services (services), which are placed in directory/ETC/RC.D/RC in the form of initialization scripts. d/or/ETC/RC? D
The following (?) represents the corresponding serial number of the RunLevel.
In most Linux distributions, there are typically 8 runlevel
Runlevel System State
0 Halt The System
1 Single user mode
2 Basic Multi User mode
3 Multi User mode
5 Multi user mode with GUI
6 Reboot The System
s, s single user mode
Most of the desktop Linux system default RunLevel is 5, the user login is a graphical interface;
And most of the server version of the Linux system default RunLevel is 3, the user login is the character interface;
RunLevel 1 and 2 are rarely used except for commissioning;
RunLevel s and s are not intended for direct user use, but are used to prepare for single user mode.
Method Two: Use a self-built startup and shutdown script
1. Create a startup and shutdown script
- # mkdir-p/home/oracle/bin
- # Cd/home/oracle/bin
- # VI Startora (create startup script)
The script reads as follows:
- Sqlplus/nolog << EOF
- Connect/as SYSDBA
- Startup
- Exit
- Exit
- echo "Oracle Start ok!"
- # VI Stopora (create close script)
The script reads as follows:
- Sqlplus/nolog << EOF
- Connect/as SYSDBA
- Shutdown immediate
- Exit
- Exit
- echo "Oracle Shutdown ok!"
- # chown Oracle:oinstall Startora Stopora
- # chmod 775 Startora Stopora
2. Create a service
- # CD/ETC/RC.D/INIT.D
- # VI Oracle
The following 3 lines of the red font are required, and the blue font is configured according to the actual environment.
345: Define Run Level
80: Service Start priority at boot (the smaller the number starts sooner)
10: Service Stop priority at shutdown (the smaller the number, the sooner it is closed)
- #!/bin/bash
- # chkconfig:345 80 10
- # Description:startup Script for Oracle Databases
- Export oracle_base=/u01/oracle
- Export oracle_home=/u01/oracle/product
- Export oracle_sid=pa
- Export path= $PATH: $ORACLE _home/bin:/home/oracle/bin
- Export ora_owner=Oracle
- Case ' "in
- "Start")
- su-$ORA _owner-c "$ORA _home/bin/lsnrctl start"
- su-$ORA _owner-c "/home/oracle/bin/startora"
- ;;
- "Stop")
- su-$ORA _owner-c "$ORA _home/bin/lsnrctl Stop"
- su-$ORA _owner-c "/home/oracle/bin/stopora"
- ;;
- Esac
- $su-root
- #chown oracle.oinstall/etc/rc.d/init.d/oracle
- #chmod 775/etc/rc.d/init.d/oracle
Then execute:
#chkconfig--add Oracle
or run the following command
- #chkconfig--level 345 Oracle on
- #chkconfig--list Oracle
Normal output:
Oracle 0:off 1:off 2:off 3:on 4:on 5:on 6:off