How to install Oracle as a Linux Service

Source: Internet
Author: User

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:

 
 
  1. $ vi /etc/oratab  
  2. 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:

 
 
  1. # su - oracle  
  2. $ cd $ORACLE_HOME/bin  
  3. $ 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

 
 
  1. # Su-oracle
  2. $ Cd $ ORACLE_HOME/bin
  3. $./Dbstart start database and listener)
  4. $ Ps-efw | grep ora _ check whether the database process is started)
  5. $ Lsnrctl status to view the listener status)
  6. $ Ps-efw | grep LISTEN | grep-v grep view the listening process and remove the grep query itself)
  7. $./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:

 
 
  1. $su - root  
  2. #cd $ORACLE_HOME  
  3. #chown oracle:oinstall startup.log  
  4. #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

 
 
  1. $ Su-root
  2. # Cd/etc/rc. d/init. d/
  3. # 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)

 
 
  1. #!/bin/bash  
  2. # chkconfig: 345 80 10  
  3. # description: Startup Script for oracle Databases  
  4. # /etc/rc.d/init.d/oracle  
  5. export ORACLE_BASE=/u01/oracle  
  6. export ORACLE_HOME=/u01/oracle/product  
  7. export ORACLE_SID=pa 
  8. export PATH=$PATH:$ORACLE_HOME/bin  
  9. ORA_OWNR="oracle" 
  10. # if the executables do not exist -- display error  
  11. if [ ! -f $ORACLE_HOME/bin/dbstart -o ! -d $ORACLE_HOME ]  
  12. then  
  13. echo "oracle startup: cannot start"  
  14. exit 1  
  15. fi  
  16. # depending on parameter -- startup, shutdown, restart  
  17. # of the instance and listener or usage display  
  18. case "$1" in  
  19. start)  
  20. # oracle listener and instance startup  
  21. echo -n "Starting oracle: "  
  22. su - $ORA_OWNR -c "$ORACLE_HOME/bin/dbstart"  
  23. touch /var/lock/oracle  
  24. su - $ORA_OWNR -c "$ORACLE_HOME/bin/emctl start dbconsole"  
  25. su - $ORA_OWNR -c "$ORACLE_HOME/bin/isqlplusctl start"  
  26. echo "OK"  
  27. ;;  
  28. stop)  
  29. # oracle listener and instance shutdown  
  30. echo -n "Shutdown oracle: "  
  31. su - $ORA_OWNR -c "$ORACLE_HOME/bin/emctl stop dbconsole"  
  32. su - $ORA_OWNR -c "$ORACLE_HOME/bin/isqlplusctl stop"  
  33. su - $ORA_OWNR -c "$ORACLE_HOME/bin/dbshut"  
  34. su - $ORA_OWNR -c "$ORACLE_HOME/bin/lsnrctl stop"  
  35. rm -f /var/lock/oracle  
  36. echo "OK"  
  37. ;;  
  38. reload|restart)  
  39. $0 stop  
  40. $0 start  
  41. ;;  
  42. *)  
  43. echo "Usage: `basename $0` start|stop|restart|reload"  
  44. exit 1  
  45. esac  
  46. 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)

 
 
  1. #!/bin/bash  
  2. # chkconfig: 345 80 10  
  3. # description: Startup Script for oracle Databases  
  4. # /etc/rc.d/init.d/oracle  
  5. export ORACLE_BASE=/u01/oracle  
  6. export ORACLE_HOME=/u01/oracle/product  
  7. export ORACLE_SID=pa 
  8. export PATH=$PATH:$ORACLE_HOME/bin  
  9. case "$1" in  
  10. start)  
  11. su oracle -c $ORACLE_HOME/bin/dbstart  
  12. touch /var/lock/oracle  
  13. echo "OK"  
  14. ;;  
  15. stop)  
  16. echo -n "Shutdown oracle: "  
  17. su oracle -c $ORACLE_HOME/bin/dbshut  
  18. rm -f /var/lock/oracle  
  19. echo "OK"  
  20. ;;  
  21. *)  
  22. echo "Usage: 'basename $0' start|stop"  
  23. exit 1  
  24. esac  
  25. exit 0 

Save and exit.

Open the terminal and execute:

 
 
  1. $su - root  
  2. #chown oracle.oinstall /etc/rc.d/init.d/oracle  
  3. #chmod 775 /etc/rc.d/init.d/oracle 

Then execute:

 
 
  1. #chkconfig --add oracle 

Or run the following command:

 
 
  1. #chkconfig --level 345 oracle on  
  2. #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:

 
 
  1. $file /etc/rc.d/rc5.d/S99oradbstart  
  2. 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

 
 
  1. # Mkdir-p/home/oracle/bin
  2. # Cd/home/oracle/bin
  3. # Vi startora (create STARTUP script)

The script content is as follows:

 
 
  1. Sqlplus/nolog <EOF
  2. Connect/as sysdba
  3. Startup
  4. Exit
  5. Exit
  6. Echo "oracle start OK! "
  7. # Vi stopora (create a close script)

The script content is as follows:

 
 
  1. sqlplus /nolog << EOF 
  2. connect / as sysdba  
  3. shutdown immediate  
  4. exit  
  5. exit  
  6. echo "oracle  shutdown ok!"  
  7. # chown oracle:oinstall startora  stopora  
  8. # chmod 775 startora  stopora 

2. Create a service

 
 
  1. # cd /etc/rc.d/init.d  
  2. # 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)

 
 
  1. #!/bin/bash  
  2. # chkconfig: 345 80 10  
  3. # description: Startup Script for oracle Databases  
  4. export ORACLE_BASE=/u01/oracle  
  5. export ORACLE_HOME=/u01/oracle/product  
  6. export ORACLE_SID=pa 
  7. export PATH=$PATH:$ORACLE_HOME/bin:/home/oracle/bin  
  8. export ORA_OWNER=oracle 
  9. case "" in  
  10. "start")  
  11. su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl start"  
  12. su - $ORA_OWNER -c "/home/oracle/bin/startora"  
  13. ;;  
  14. "stop")  
  15. su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl stop"  
  16. su - $ORA_OWNER -c "/home/oracle/bin/stopora"  
  17. ;;  
  18. esac  
  19. $su - root  
  20. #chown oracle.oinstall /etc/rc.d/init.d/oracle  
  21. #chmod 775 /etc/rc.d/init.d/oracle 

Then execute:

# Chkconfig -- add oracle

Or run the following command:

 
 
  1. #chkconfig --level 345 oracle on  
  2. #chkconfig --list oracle 

Normal output:

Oracle 0: off 1: off 2: off 3: on 4: on 5: on 6: off

Related Article

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.