How to install Oracle as a Linux service

Source: Internet
Author: User
Tags chmod

Method One: Use Oracle's own startup and shutdown scripts

1. Oracle User modified/etc/oratab file:

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

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

    1. #su-oracle
    2. $CD $ORACLE _home/bin
    3. $./dbstart (Start database and listen)
    4. $ PS-EFW | grep Ora_ (see if the database process is started)
    5. $ lsnrctl Status (view listening status)
    6. $ PS-EFW | grep LISTEN | Grep-v grep (View listening process, remove grep query itself)
    7. $./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:

    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 be created automatically after you run the./dbstart and./dbshut.

4. Create a service

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

  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 does 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 "$" 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. $ stop
  40. $ start
  41. ;;
  42. *)
  43. echo "Usage: ' basename ' Start|stop|restart|reload"
  44. Exit 1
  45. Esac
  46. 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)

  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 "$" 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 ' Start|stop"
  23. Exit 1
  24. Esac
  25. Exit 0

Save exit.

Open Terminal execution:

    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

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:

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

    1. # mkdir-p/home/oracle/bin
    2. # Cd/home/oracle/bin
    3. # VI Startora (create startup script)

The script reads 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 close script)

The script reads 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 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)

  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.