Method 1: Use the script that comes with oracle to start and close... 1
1. oracle user modify the/etc/oratab file:... 1
2. oracle users modify the $ ORACLE_HOME/bin/dbstart file:... 1
3. Test and run dbshut and dbstart 1.
3.1. Execute the corresponding script for testing... 2
3.2. modify the permissions of dbstart and dbshut log files:... 2
4. Create a service... 2
5. Check... 5
6. One Note:... 6
6.1 chkconfig: 345 99 10. 6 in the script file
6.2 command Description:... 6
6.3 chkconfig: function description... 6
Method 2: Use the self-built startup and shutdown scripts... 7
1. Create a startup and shutdown script... 7
2. Create a service... 8
Method 1: Use the launch and close scripts provided by oracle
1. oracle users modify the/etc/oratab file:
- $ vi /etc/oratab
- orcl:/oracle/app/product/10.2.0/db_1:N
Changed:
Orcl:/oracle/app/product/10.2.0/db_1: Y
That is, change the last N to Y to allow dbstart to start the database at system startup.
2. oracle users 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 =/u01/app/oracle/product/10.1.0/db_1
Or directly modify it:
ORACLE_HOME_LISTNER = $ ORACLE_HOME
3. Test and run dbshut and dbstart.
Check whether the oracle service and listener service can be started:
3.1. Execute the corresponding script for testing
- # Su-oracle
- $ Cd $ ORACLE_HOME/bin
- $./Dbstart start database and listener)
- $ Ps-efw | grep ora _ check whether the database process is started)
- $ Lsnrctl status to view the listener status)
- $ Ps-efw | grep LISTEN | grep-v grep view the listening process and remove the grep query itself)
- $./Dbshut: Shut down the database. The listener will not be closed. You need to manually stop the database)
3.2. modify the permissions of 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 exist. They are automatically created only after you run./dbstart and./dbshut.
4. Create a service
- $ Su-root
- # Cd/etc/rc. d/init. d/
- # Vi oracle (oracle indicates the name of the service to be installed in the system, which can be any one)
There are two types of scripts available, and the startup content is different.
Modify the blue font position of the environment variable according to your environment)
Script 1 starts the database, listener, dbconsole, and sqlplus)
The following three lines in red are required
345: Define the running level
80: Priority of Service Startup when the instance is started (the smaller the number, the earlier the instance is started)
10: Service stop priority when Shutdown (the smaller the number, the earlier the shutdown)
- #!/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 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"
- 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)
- $0 stop
- $0 start
- ;;
- *)
- echo "Usage: `basename $0` start|stop|restart|reload"
- exit 1
- esac
- exit 0
Script 2 only starts databases and listeners)
The following three lines in red are required
345: Define the running level
80: Priority of Service Startup when the instance is started (the smaller the number, the earlier the instance is started)
10: Service stop priority when Shutdown (the smaller the number, the earlier the shutdown)
- #!/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 "$1" 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 $0' start|stop"
- exit 1
- esac
- exit 0
Save and exit.
Open the terminal and execute:
- $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
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: and
5: on corresponds to:/etc/rc. d/rc5.d) the following file will be generated: S99oradbstart, open with vi S99oradbstart
The content of this file is the same as that of/etc/rc. d/init. d/oradbstart, indicating that the configuration is successful.
S99oradbstart is a link to/etc/rc. d/init. d/oradbstart. We can use the file command to view it:
- $file /etc/rc.d/rc5.d/S99oradbstart
- S99oradbstart:symbolic link to '../init.d/oradbstart
In this way, the oracle service will start automatically after the instance is started.
You can also manually control the service running:
# Service oracle start
# Disable service oracle stop
$ Ps-ef | grep ora check whether oracle-related processes have been started
6. One Note:
6.1 chkconfig: 345 99 10 in the script file
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 corresponds to the level specified above
The serial number of the link file generated by the/etc/rc. d/rcN. d (N is a level other than 345) Directory (priority of service stop)
K10oradbstart.
6.2 command instructions:
Ps: monitor background processes
-E: displays all processes.
-F full format.
-H does not display the title.
-L long format.
-W width output.
Grep: A Command Used in linux to search for the content contained in the output content.
For example, if you want to search for a string of characters "bbb" in aaa.txt, you can use
Cat aaa.txt | grep bbb
2. I want to search for files containing bb in the current directory. You can use
Ls | grep bb
Example: ps-efw | grep LISTEN | grep-v grep: View listeners with LISTEN, except for those with grep.
6.3 chkconfig: Function Description
Check and set various services of the system.
Syntax: chkconfig [-- add] [-- del] [-- list] [System Service] Or chkconfig [-- level <level code>] [System Service] [on/off/reset]
Note: This is a program developed by Red Hat following the GPL rules. It can query the system services that the operating system will execute at each execution level, including various resident services.
Parameters:
-- Add adds the specified system service, enables the chkconfig command to manage it, and adds relevant data in the system startup description file.
-- Del: deletes the specified system service. It is no longer managed by the chkconfig command, and relevant data is also deleted in the description file started by the system.
-- List lists the specified system services.
-- Level <level code> specifies the execution level of the read system service.
Note: runlevel can be regarded as the system status and image. You can think of runlevel as Normal, safemode, and Command prompt only in Microsoft windows. To access each runlevel, you need to start or close a series of services. These services are stored in the/etc/rc. d/rc? directory as initialization scripts ?. D/or/etc/rc ?. D
Below (? Indicates the serial number of runlevel ).
In most linux releases, there are usually eight runlevels
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
In most Desktop linux systems, the default runlevel is 5, and the GUI is used when users log on;
In most server versions, the default runlevel of linux is 3, and the character interface is used for user login;
Runlevel 1 and 2 are rarely used except debugging;
Runlevel s and S are not directly used by users, but used to prepare for Single user mode.
Method 2: Use the self-built startup and shutdown scripts
1. Create a script to start and stop
- # Mkdir-p/home/oracle/bin
- # Cd/home/oracle/bin
- # Vi startora (create STARTUP script)
The script content is as follows:
- Sqlplus/nolog <EOF
- Connect/as sysdba
- Startup
- Exit
- Exit
- Echo "oracle start OK! "
- # Vi stopora (create a close script)
The script content is 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 three lines of red fonts are required, and the blue font is configured according to the actual environment.
345: Define the running level
80: Priority of Service Startup when the instance is started (the smaller the number, the earlier the instance is started)
10: Service stop priority when Shutdown (the smaller the number, the earlier the shutdown)
- #!/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