Автозапуск listener oracle linux

Обновлено: 06.07.2024

For Solaris OS, you should check this post: How to Auto Start Oracle Database on Solaris.

Assuming that you already have some knowledge about how to start Oracle database manually and Oracle provided shell script dbstart , then we can keep going to design and deploy our automatic startup scripts.

By default, Oracle software installation does not deploy automatic startup and shutdown init scripts on the platform, you have to create them by yourself. Here I introduce my scripts for you to use or modify with.

oratab in Linux

Please turn on the startup option by changing "N" to "Y" at the last character of the line.

]$ vi /etc/oratab
ORCL:/u01/app/oracle/product/11.2.0/dbhome_1: Y

As for the format of oratab , allow me to interpret this line as followings:

"Hello, my name is ORCL ($ORACLE_SID). I live at /u01/app/oracle/product/11.2.0/dbhome_1 ($ORACLE_HOME). You can find my SPFILE or PFILE in the default location. My answer is Y if you were asking me whether startup is required."

Creating an init script for Oracle service

]$ su -
Password:
[root@test

Also, the listener will be started or shutdown automatically at their running levels respectively.

Adding this init script to rc0, rc3 and rc5

We use 3 soft links to add them into different running levels and prioritize the execution orders by naming the file.

Testing the script

Restart the whole server

Then check the instance status

]$ ps -ef | grep smon | grep -v grep
oracle 3991 1 0 19:20 ? 00:00:00 ora_smon_ORCL
[oracle@test

]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.4.0 Production on Thu May 24 19:21:39 2018

Copyright (c) 1982, 2013, Oracle. All rights reserved.


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> select name, open_mode from v$database;

Check the listener status

LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 24-MAY-2018 19:22:05

Copyright (c) 1991, 2013, Oracle. All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 11.2.0.4.0 - Production
Start Date 24-MAY-2018 19:19:58
Uptime 0 days 0 hr. 2 min. 7 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora
Listener Log File /u01/app/oracle/diag/tnslsnr/test/listener/alert/log.xml
Listening Endpoints Summary.
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=test)(PORT=1521)))
Services Summary.
Service "ORCL" has 1 instance(s).
Instance "ORCL", status READY, has 1 handler(s) for this service.
Service "ORCLXDB" has 1 instance(s).
Instance "ORCL", status READY, has 1 handler(s) for this service.
The command completed successfully

Now the shell script will auto start Oracle database when the server boots.

This chapter describes how to identify Oracle Database processes, and provides basic information about how to stop and restart them. It also describes how to set up automatic startup and shutdown of the Oracle Database. It contains the following sections:

When using Oracle Restart, you can use Service Control Utility (SRVCTL), a command-line interface, to manage Oracle processes (database instance, listener, Oracle ASM instance). With SRVCTL, you can manage the Oracle Restart configuration, see the status of processes managed by Oracle Restart, and start or stop processes such as Oracle Database. SRVCTL has been enhanced to support single instance databases with Oracle Restart on standalone servers and on clusters with Oracle Clusterware.

2.1 Stopping and Starting Oracle Processes

This section describes how to stop and start Oracle processes. It contains the following topics:

2.1.1 Stopping and Starting Oracle Database and Oracle Automatic Storage Management Instances

This section describes how to stop and start Oracle Database and Oracle Automatic Storage Management instances.

2.1.1.1 Stopping an Oracle Database or Oracle Automatic Storage Management Instance

Do not stop an Oracle Automatic Storage Management instance until you have stopped all Oracle Database instances that use Oracle Automatic Storage Management instance to manage their storage.

To stop an Oracle Database or Oracle Automatic Storage Management instance:

Run the following commands to identify the SID and Oracle home directory for the instance that must be shut down:

On Oracle Solaris:

On other operating systems:

The oratab file contains lines similar to the following, which identify the SID and corresponding Oracle home directory for each database or Oracle Automatic Storage Management instance on the system:

Oracle recommends that you use the plus sign (+) as the first character in the SID of Oracle Automatic Storage Management instances.

Run the oraenv or coraenv script, depending on the default shell, to set the environment variables for the instance that must be shut down:

Bourne, Bash, or Korn shell:

When prompted, specify the SID for the instance.

Run the following commands to shut down the instance:

After the instance shuts down, you can quit SQL*Plus.

2.1.1.2 Restarting an Oracle Database or Oracle Automatic Storage Management Instance

If the database instance uses Oracle Automatic Storage Management for storage management, then you must start the Oracle Automatic Storage Management instance before you start the database instance.

To restart an Oracle Database or Oracle Automatic Storage Management instance:

Repeat steps 1 and 2, if required, to set the ORACLE_SID and ORACLE_HOME environment variables to identify the SID and Oracle home directory for the instance you want to start.

Run the following commands to start the instance:

After the instance starts, you can exit from SQL*Plus.

2.1.2 Stopping and Starting Oracle Restart

To stop or start Oracle Restart, run the following command:

Start: This option is used to start Oracle Restart

Syntax and Options:

Stop: This option is used to stop Oracle Restart

Syntax and Options:

Oracle Database Administrator's Guide for more information about the srvctl commands

2.2 Automating Shutdown and Startup

Oracle recommends that you configure the system to automatically start Oracle Database when the system starts, and to automatically shut it down when the system shuts down. Automating database startup and shutdown guards against incorrect database shutdown.

To automate database startup and shutdown, use the dbstart and dbshut scripts, which are located in the $ORACLE_HOME/bin directory. The scripts refer to the same entries in the oratab file, which are applied on the same set of databases. You cannot, for example, have the dbstart script automatically start sid1 , sid2 , and sid3 , and have the dbshut script shut down only sid1 . However, you can specify that the dbshut script shuts down a set of databases while the dbstart script is not used at all. To do this, include a dbshut entry in the system shutdown file, but do not include the dbstart entry from the system startup files.

The init command in the operating system documentation for more information about system startup and shutdown procedures

2.2.1 Automating Database Startup and Shutdown on Other Operating Systems

To automate database startup and shutdown by using the dbstart and dbshut scripts:

Log in as the root user.

Edit the oratab file for the platform.

To open the file, use one of the following commands:

On Oracle Solaris:

On IBM AIX on POWER Systems (64-Bit) and Linux:

Database entries in the oratab file are displayed in the following format:

In this example, the values Y and N specify whether you want the scripts to start or shut down the database, respectively. For each database for which you want to automate shutdown and startup, first determine the instance identifier (SID) for that database, which is identified by the SID in the first field. Then, change the last field for each to Y .

You can set dbstart to autostart a single-instance database which uses an Automatic Storage Management installation auto-started by Oracle Clusterware. This is the default behavior for an Automatic Storage Management cluster. To do this, you must change the oratab entry of the database and the Automatic Storage Management installation to use a third field with the value W and N , respectively. These values specify that dbstart auto-starts the database only after the Automatic Storage Management instance is started.

If you add new database instances to the system and automate the startup for them, then you must edit the entries for those instances in the oratab file.

Change directory to one of the following, depending on the operating system:

Platform Initialization File Directory
Linux and Oracle Solaris /etc/init.d
IBM AIX on POWER Systems (64-Bit) /etc

Create a file called dbora , and copy the following lines into this file:

Change the value of the ORACLE_HOME environment variable to specify the Oracle home directory for the installation. Change the value of the ORACLE environment variable to the user name of the owner of the database installed in the Oracle home directory (typically, oracle ).

This script can only stop Oracle Net listener for which a password has not been set. In addition, if the listener name is not the default name, LISTENER , then you must specify the listener name in the stop and start commands:

Change the group of the dbora file to the OSDBA group (typically dba ), and set the permissions to 750:

Create symbolic links to the dbora script in the appropriate run-level script directories, as follows:

This chapter describes the commands and associated syntax of the Listener Control utility .

This chapter contains the following topics:

Listener Control Utility Overview

The Listener Control utility enables you to administer listener s .You can use its commands to perform basic management functions on one or more listeners. Additionally, you can view and change parameter settings.

The basic syntax of Listener Control utility commands is as follows:

In the preceding command, listener_name is the name of the listener to be administered. If no name is specified, then the default name, LISTENER , is assumed.

You can also issue Listener Control utility commands at the LSNRCTL> program prompt. To obtain the prompt, enter lsnrctl with no arguments at the operating system command line. When you run lsnrctl , the program is started. You can then enter the necessary commands from the program prompt. The basic syntax of issuing commands from LSNRCTL> program prompt is as follows:

You can combine commands in a standard text file, and then run them as a sequence of commands. To execute in batch mode, use the format:

For most commands, the Listener Control utility establishes an Oracle Net connection with the listener that is used to transmit the command. To initiate an Oracle Net connection to the listener, the Listener Control utility must obtain the protocol addresses for the named listener or a listener named LISTENER . This is done by resolving the listener name with one of the following mechanisms:

listener.ora file in the directory specified by the TNS_ADMIN environment variable

listener.ora file in the ORACLE_HOME/network/admin directory.

Naming method, for example, a tnsnames.ora file

If none of the preceding mechanisms resolve the listener name, then the Listener Control utility uses the default listener name LISTENER , resolves the host name IP address and uses port 1521.

The Listener Control utility supports several types of commands:

Operational commands, such as START, and STOP.

Modifier commands, such as SET TRC_LEVEL.

Informational commands, such as STATUS and SHOW LOG_FILE.

SET and SHOW Commands of the Listener Control utility

You can use the SET command to alter parameter values for a specified listener. You set the name of the listener you want to administer with the SET CURRENT_LISTENER command. Parameter values remain in effect until the listener is shut down. If you want these settings to persist, then use the SAVE_CONFIG command to save changes to the listener.ora .

You can use the SHOW command to display the current value of a configuration setting.

Distributed Operation s

The Listener Control utility can perform operations on a local or a remote listener.

To set up a computer to remotely administer a listener, do the following:

Ensure that the Listener Control utility ( lsnrctl ) executable is installed in the ORACLE_HOME/bin directory.

Ensure that the name of the listener you want to administer can be resolved through a listener.ora file or a naming method, as described in "Listener Control Utility Overview".

All commands except START can be issued when a listener is administered remotely. The Listener Control utility can only start the listener on the same computer from where the utility is running.

When issuing commands, specify the listener name as an argument. For example:

If the name is omitted, then listener name set with the SET CURRENT_LISTENER command is used, or the default name, LISTENER is assumed.

Oracle Net Listener Security

Local listener administration is secure through local operating system authentication, which restricts listener administration to the user who started the listener or to the super user. By default, remote listener administration is disabled.

Oracle recommends that you perform listener administration in the default mode, and access the system remotely using a remote login. When you administer the listener remotely, use Oracle Enterprise Manager or Secure Shell (SSH) to access the remote host.

If you are using Oracle Clusterware 10gR2 or above for RAC or just for a single instance using ASM, the Clusterware automatically starts and stops the Oracle database instances and listeners, so the following procedures are not necessary. Where the Clusterware is not being used, these methods allow you to automate the startup and shutdown of databases on Linux.

These methods work on all RHEL and Oracle Linux versions up to and including RHEL7/OL7.

What I Use

This article contains a number of variations, but this is what I currently use, which is a variation on the "su" command.

The scripts are created using the cat command, with all the "$" characters escaped. If you want to manually create these files, rather than using the cat command, remember to remove the "\" characters before the "$" characters.

Create a "scripts" directory.

Create an environment file called "setEnv.sh". This is an example from a 12.2 installation. Adjust the contents according to your installation.

Add a reference to the "setEnv.sh" file at the end of the "/home/oracle/.bash_profile" file if you want the settings to be applied for a normal login. The profile will not be set during the start/stop of a service, so this is not necessary for the automatic start/stop functionality.

Create a "start_all.sh" and "stop_all.sh" script that can be called from a startup/shutdown service. Make sure the ownership and permissions are correct.

You should be able to start/stop the database with the following scripts run from the "oracle" user.

Now we need to create the Linux service to call the scripts we created previously. The reset of this section represents what I so for OL6, but it will also work for OL7. If you are using OL7 and prefer to use systemd directly, you can follow the instructions provided here.

Create a file called "/etc/init.d/dbora" as the root user, containing the following.

Use the chmod command to set the privileges to 750.

Associate the "dbora" service with the appropriate run levels and set it to auto-start using the following command.

You can start and stop the database using the service, which is what will happen on a reboot.

systemd Services

With the introduction of RHEL7/OL7, services are now managed using systemd. You can continue to use the existing methods shown below for creating a service to auto-start Oracle, as systemd is backwards compatible. If you prefer to use systemd directly, you can follow the instructions provided here.

The systemd example assumes you have the scrips defined above in the "/home/oracle/scripts/" directory present.

The "su" Command

The following method for automating database startup and shutdown of Oracle instances on Linux works equally well for Oracle 9i, 10g, 11G and 12c. It can be used on any RHEL-style distribution, including Oracle Linux, up to an including RHEL7. I still use this method for Oracle 12c on OL6. It will work for RHEL7/OL7, but I prefer to use the systemd services.

Once the instance is created, edit the "/etc/oratab" file setting the restart flag for each instance to 'Y'.

Create a file called "/etc/init.d/dbora" as the root user, containing the following code. Adjust the paths to match your system.

Use the chmod command to set the privileges to 750.

Associate the "dbora" service with the appropriate run levels and set it to auto-start using the following command.

The relevant instances should now startup/shutdown automatically at system startup/shutdown.

For Oracle 9i the dbstart and dbshut commands didn't control the listener, so listener management had to be done separately, as shown below.

The "rsh" Command

Some of the Oracle 10g documentation recommends using the "rsh" command in the "dbora" service. Later database versions switched back to using the "su" command. I have never liked or used this approach on a real system.

With Oracle 10g, Oracle switched from recommending the "su" command to the "rsh" command. In Oracle 10g release 2, the dbstart command includes an automatic start of the listener, so there are some differences between the two versions, but the following represents Oracle's preferred method for Oracle 10g.

Once the instance is created, edit the "/etc/oratab" file setting the restart flag for each instance to 'Y'.

Create a file called "/etc/init.d/dbora" as the root user, containing the following.

Use the chmod command to set the privileges to 750.

Associate the "dbora" service with the appropriate run levels and set it to auto-start using the following command.

The relevant instances should now startup/shutdown automatically at system startup/shutdown.

This method relies on the presence of an RSH server, which requires additional packages and configuration.

This can be quite problematic when attempting to use this method under later Linux distributions, where rsh is deprecated. As a result, I prefer to use the "su" command method.

This method can also be used for 11g databases that are not using ASM or RAC.

The "runuser" Command

For a time the Oracle 12c documentation recommended using the "runuser" command in the "dbora" service. The latest version of the documents have reverted the using the "su" command. An example of using the "runuser" command is shown below, but I don't use this.

Once the instance is created, edit the "/etc/oratab" file setting the restart flag for each instance to 'Y'.

Create a file called "/etc/init.d/dbora" as the root user, containing the following code, which is a modified version of the example from the documentation, which doesn't work.

If you want the service to wait while the startup completes, remove the "&". This is especially important for shutdowns that take a long time, like when shutting down WebLogic and Cloud Control services.

Use the chmod command to set the privileges to 750. Associate the "dbora" service with the appropriate run levels and set it to auto-start using the following command.

Known Issues

When using Oracle 10g Release 2, calling dbstart without the "$ORACLE_HOME" might result in the following error message.

Failed to auto-start Oracle Net Listener using /ade/vikrkuma_new/oracle/bin/tnslsnr

This is due to a hard coded path in the dbstart script. You should not see this error if you pass the "$ORACLE_HOME" as a parameter to dbstart and dbshut. To correct this, edit the "$ORACLE_HOME/bin/dbstart" script and replace the following line (approximately line 78).

The dbstart script should now start the listener as expected.

dbstart and dbshut Deprecation?

The Oracle 11gR2 documentation states the use of the dbstart and dbshut scripts are deprecated. The preferred replacement is Oracle Restart.

Both dbstart and dbshut are still present in Oracle 11gR2, so you can continue to use them (I still use them). In order to use Oracle Restart you must install Grid Infrastructure (GI), which you will already have if you are using RAC or ASM for a standalone instance. In these cases, Oracle Restart will already be present and running. For single instance databases that don't use ASM, I think it is unreasonable to expect people to install GI.

The Oracle 12c documentation has no mention of the deprecation of dbstart and dbshut and has reinstated the documentation about them. As a result, you are free to use dbstart and dbshut in a supported manner for all versions of the database.

Читайте также: