CHAPTER 10
Automating Jobs with cron
In almost every type of Linux/Solaris
environment—from development to production—DBAs rely heavily on
automating tasks such as database backups, monitoring, and maintenance
jobs. Automating routine tasks allows DBAs to be much more effective and
productive. Automated environments inherently run more smoothly and
efficiently than manually administered systems.
This chapter focuses on showing you how to leverage the cron job scheduler. The cron
scheduling tool, which is universally available on Linux/Solaris
systems, is accessible and easy to use. For these reasons, this utility
is frequently chosen by DBAs to automate database jobs. Because cron is heavily used by DBAs, developers, and SAs, it is mandatory to have a working knowledge of this tool.
This chapter builds on your knowledge of Linux/Solaris OS commands, editing files,
and shell scripting. You’ll need this skill set to automate your
database surroundings. You should be able to extend the following
recipes to meet the automation requirements of your environment.
10-1. Enabling Access to Schedule Jobs
Problem
As the oracle OS user, you’re attempting to add an entry to the cron table and you receive the following error message:
You (oracle) are not allowed to use this program (crontab)
You want to grant access to the oracle user to use the crontab utility.
Solution
As the root user, add oracle to the /etc/cron.allow file with the echo command:
# echo oracle >> /etc/cron.allow
Once the oracle entry is added to the /etc/cron.allow file, you can use the crontab utility to schedule a job.
Note You can also use an editing utility (such as vi) to add an entry to this file.
How It Works
The root user can always schedule jobs with the crontab utility, but other users must be listed in the /etc/cron.allow file. If the /etc/cron.allow file does not exist, the OS user must not appear in the /etc/cron.deny file. If neither the /etc/cron.allow nor the /etc/ cron.deny file exists, only the root user can access the crontab utility.
Note On Solaris systems, the cron.allow and cron.deny files are located in the /etc/cron.d directory.
The cron program is a job-scheduling utility that is ubiquitous in Linux/UNIX environments. This tool derives its name from chronos (the Greek word for time). The cron (the geek word for scheduler) tool allows you to schedule scripts or commands to run at a specified time and repeat at a designated frequency.
When your server boots up, a cron background process is automatically started that manages all cron jobs on the system. On Linux systems, the cron background process is also known as the cron daemon. This process is started on system startup by the /etc/init.d/crond script. You can check to see whether the cron daemon process is running with the ps command:
$ ps -ef | grep crond | grep -v grep root 3049 1 0 Aug02 ? 00:00:00 crond
On Linux systems, you can verify the status of the cron daemon using the service command:
$ /sbin/service crond status crond (pid 3049) is running...
On Solaris systems, you can verify that a cron service is running via the svcs (service status) command. This line of code prints out the services and filters the output via grep:
$ svcs -a | grep cron online Aug_13 svc:/system/cron:default
On Linux systems, the root user uses several files and directories when executing system cron jobs. The /etc/crontab file contains commands to run system cron jobs. Here’s a typical listing of the contents of the /etc/crontab file:
SHELL=/bin/bash PATH=/sbin:/bin:/usr/sbin:/usr/bin MAILTO=root HOME=/ # run-parts 01 * * * * root run-parts /etc/cron.hourly 02 4 * * * root run-parts /etc/cron.daily 22 4 * * 0 root run-parts /etc/cron.weekly 42 4 1 * * root run-parts /etc/cron.monthly
This /etc/crontab file uses the run-parts utility to run scripts located in the following directories: /etc/cron.hourly, /etc/cron.daily, /etc/cron.weekly, and /etc/cron.monthly.
If there is a system utility that has to run other than on an hourly,
daily, weekly, or monthly basis, it can be placed in the /etc/cron.d directory.
Each user can create a crontab (also known as a cron
table) file, which contains the list of programs that you want to run
at a specific time and interval. This file is usually located in the /var/spool/cron directory (on Solaris systems, look in /var/spool/cron/crontabs). For every user who creates a cron table, there is a file in the /var/spool/cron directory named after that user.
The cron background process is somewhat idle. It wakes up once every minute and checks /etc/crontab, /etc/cron.d, and the user cron table files; and determines whether there are any jobs that have to be executed.
10-2. Editing the cron Table
Problem
You have the following RMAN backup code stored in a file named rmanback.bsh in the /home/oracle/bin directory:
#!/bin/bash ORACLE_SID=TRG ORACLE_HOME=/orahome/app/oracle/product/12.1.0.2/db_1 PATH=$PATH:$ORACLE_HOME/bin # rman target / <<EOF backup database; EOF exit 0
You want to have a database backup script run automatically at 11:05 p.m. every night.
Solution
To schedule a job, you must add a line in your cron table that specifies the time you want the job to execute. You can edit your cron table directly with the -e (editor) option of the crontab command:
$ crontab -e
If you’re presented with a random number and a blank prompt when you first edit your cron table, your default editor is probably ed, not vi or vim. If you are in ed rather than vi, set your EDITOR OS variable to be vi:
$ export EDITOR=vi
When issuing the crontab -e command, you will be presented with a file to edit: cron table (or crontab). To schedule a script named rmanback.bsh (located in the /home/oracle/bin directory) to run daily at 11:05 p.m., enter the following line into your cron table (more on the cron syntax coming in recipe 10-3):
5 23 * * * /home/oracle/bin/rmanback.bsh
Exit the cron table file. If your default editor is vi, type :wq to exit. When you exit crontab, your cron table is saved for you. To view your cron entries, use the -l (list) option of the crontab command:
$ crontab -l
You should see this line:
5 23 * * * /home/oracle/bin/rmanback.bsh
The prior line indicates that you have successfully scheduled the file rmanback.bsh (located in /home/oracle/bin) to run daily at 23:05 (in 24-hour clock time/military time).
How It Works
Ensure that you become comfortable editing the cron table because you’ll modify it quite often as your automation requirements change. The most common way to modify the cron table is with the crontab -e command.
Loading the cron Table from a File
Another method for modifying your cron table is to load it directly with a file name using the following syntax:
$ crontab <filename>
With the previous line of code, the crontab utility will load the contents of the specified file into your cron table. We recommend that you perform the following steps when modifying your cron table with this method:
- Create a file with the contents of your existing cron table:
$ crontab -l > mycron.txt
- Make an additional copy of your cron
table before you edit it so that you can revert to the original if you
introduce errors and can’t readily figure out what’s incorrect. It also
provides an audit trail of changes to your cron table:
$ cp mycron.txt mycron.jul29.txt
- You can now edit the mycron.txt file with your favorite text editor:
$ vi mycron.txt
- To schedule a script named rmanback.bsh to run daily at 11:05 p.m., enter the following into the file:
5 23 * * * /home/oracle/bin/rmanback.bsh
- When you finish making edits, load the crontab back, as shown here:
$ crontab mycron.txt
If your file doesn’t conform to the cron syntax, you’ll receive an error such as the following:
"mycron.txt":6: bad day-of-week errors in crontab file, can’t install.
In this situation, either correct the syntax error or reload the original copy of the cron table.
Removing the cron Table
You can completely remove your cron table with the -r option, although you’ll rarely (if ever) use it. Having said that, note that the following will completely remove your cron table:
$ crontab -r
Just to emphasize this point, the -r option is for remove, not read. Don’t make the mistake of accidentally removing an entire cron table when you simply want to edit it. Before using the -r option, save your cron table in a text file:
$ crontab -l > cron.june10.txt
That way, you can refer to the saved file if you didn’t intend to delete your cron table. It’s a best practice to save the cron table before you edit it. We’ve worked in numerous environments in which a DBA or developer accidentally removed a cron table or erroneously removed entries. Without a backup, you’ll probably have a hard time remembering exactly what was in the cron table before the change was made.
Automating the cron Table Backup
As mentioned in the previous section, consider making a backup of the contents of the cron table before you edit it. Some DBAs have cron automatically create a backup of the contents of the cron table. Consider adding this line to your cron table (the cron syntax is described next in recipe 10-3):
* * 1 * * crontab -l > /home/oracle/scripts/crontab.$(date +\%m).txt
For the prior entry to work, the directory of /home/oracle/scripts must exist. The crontab -l command will save the contents of the cron table into a text file. The name of the file will contain a numeric number that corresponds to the current month (e.g., crontab.01.txt, ..., crontab.12.txt). It will create a copy of the contents of your cron table on the first of each month (see recipe 10-6 for more details on redirecting cron output to a file).
10-3. Understanding cron Table Entries
Problem
You’ve seen an example of a cron table entry such as the following:
5 23 * * * /home/oracle/bin/rmanback.bsh
Before you add your own entries, you want some background information about how to interpret the preceding line.
Solution
Your cron table is a list of numbers and commands that the cron background process will run at a specified time and schedule. The crontab utility expects entries to follow a well-defined format. Each entry in the crontab
is a single line composed of six fields (it is never split into
multiple lines). The first five fields specify the execution time and
frequency, and the sixth field consists of OS commands or scripts to be
executed. Here’s a sample of the format:
min hr dayOfMonth monthOfYear dayOfWeek commandsOrScripts
Table 10-1 describes each field in further detail.
Table 10-1. cron Table Column Descriptions and Allowed Values
Field
|
Description
|
Allowed Values
|
---|---|---|
Min
|
Minute of the hour
|
0-59, or *
|
Hr
|
Hour of the day (in 24-hour format)
|
0-23, or *
|
dayOfMonth
|
Day of the month
|
1-31, or *
|
monthOfYear
|
Month of the year
|
1-12, or *
|
dayOfWeek
|
Day of the week
|
0-6, or *; depending on version, a 0 can also be specified by a 7
|
commandsOrScripts
|
OS commands or scripts
|
Any combination of commands or scripts
|
Each entry, which is usually specified with a number, can also be an asterisk (*), which indicates that all possible values are in effect. For example, the following line of code instructs cron to send an email saying “wake up” at 12:05 p.m. every day of the month, each month, and each day of the week:
05 12 * * * echo "wake up" | mailx -s "wake up" dba@gmail.com
Each of the first five entries can be separated by commas or hyphens.
A comma indicates multiple values for an entry, whereas a hyphen
indicates a range of values. For example, the following entry sends an
email saying “wake up” every half hour, from 8 a.m. to 4:30 p.m., Monday
through Friday:
0,30 8-16 * * 1-5 echo "wake up" | mailx -s "wake up" dba@gmail.com
The fourth column (month of the year) and fifth column
(day of the week) can be represented with numeric values or by
three-letter abbreviations. For example, the following entry in the crontab uses three-letter abbreviations for months and days:
0,30 8-16 * Jan-Dec Mon-Fri echo "wake up" | mailx -s "wake up" dba@gmail.com
On some OS versions, you can skip a value within a range by following the entry with /<integer>. For example, if you want to run a job every other minute, use 0-59/2 in the minute column. You can also use a slash (/) with an asterisk to skip values. For example, to run a job every fourth minute, use */4 in the minute column. You can do similarly for every fourth hour */4 (00, 04, 08, 12, 16, 20).
The sixth field in the cron table entry can be a combination of commands or shell scripts. For example, the following cron entry runs the rmanback.bsh shell script (located in the /home/oracle/bin directory) daily at 4:00 a.m.:
0 4 * * * /home/oracle/bin/rmanback.bsh
Lines that start with a # are comments in the cron table. In other words, any text entered after # is ignored by cron. For example, the following comment is usually added as the first line of the cron table to provide a quick syntax guide of the required format for subsequent entries:
# min(0-59) hr(0-23) dayofMonth(1-31) monthofYear(1-12) dayofWeek(0/7-6) commandsOrScripts
Here’s another popular way to provide a quick syntax guide using the first two lines of the cron table:
# Minute Hour Day of Month Month of Year Day of Week Commands or Scripts # (0-59) (0-23) (1-31) (1-12 or Jan-Dec) (0-6 or Sun-Sat)
How It Works
Interpreting a cron
table entry can seem cryptic at first. The key is to understand that
the first five columns specify a time and frequency, and the sixth
column contains OS commands or scripts being executed.
Having said that, the cron
utility has a few quirks that need further explanation. For example,
the fifth column is the day of the week. Sunday is usually designated by
a 0 (with some OSs, Sunday can also be designated by a 7); Monday by a
1; Tuesday by a 2; and so on, to Saturday, which is indicated with a 6.
There also appear to be overlapping columns,
such as the third column (day of the month) and the fifth column (day
of the week). These columns allow you to create flexible schedules for
jobs that have to run on schedules such as the 1st and 15th day of the
month, or on a certain day of the week. Put an asterisk in the column
that you’re not using. For example, to run a backup job on the 1st and
15th (at 4:00 a.m.), do so as follows:
0 4 1,15 * * /home/oracle/bin/rmanback.bsh
Or if you need a job to run on every Tuesday (at 4:00 a.m.), do so as follows:
0 4 * * 2 /home/oracle/bin/rmanback.bsh
If you have to run a job on the 1st and 15th and every Tuesday, fill in both columns:
0 4 1,15 * 2 /home/oracle/bin/rmanback.bsh
Running a Job Every Minute
Suppose that you want a job to check once per minute
to see whether a database server is available. You can do so by putting
the following in your cron table (you have to modify the IP address for your server):
* * * * * ping 11.214.402.51
A * in every column instructs cron to run the command once per minute. If the ping command is successful, nothing happens. If an error is thrown by a command run from cron, cron will by default send an email to the email account of the OS owner of the cron
table (see recipe 10-6 for details on how to modify locations where
email is sent). This is a simple but effective method for monitoring the
availability of a database server.
Running a Job Every N Seconds
The cron utility can be scheduled to run with a granularity as small as minutes. Although you can’t schedule a cron at the granularity of seconds, it is possible to creatively run a script from cron every N many seconds. For example, suppose that you want to run a script every 30 seconds from cron. You can simulate it as follows:
* * * * * /home/oracle/bin/commands.sh * * * * * sleep 30; /home/oracle/bin/commands.sh
In this manner, you can enable commands or jobs that
have to run more frequently than 1 minute. It is probably a rare
requirement, but sometimes necessary.
Using Keywords to Run Jobs
Note that on some of the modern versions of cron, you can specify keywords to indicate a time and frequency for a job to start. For example, the following instructs cron to run a job daily at midnight:
@daily /home/oracle/bin/rmanback.bsh
Table 10-2 shows the mapping of frequency keywords to the standard syntax.
Table 10-2. Frequency Keyword and Equivalent Standard Syntax
Keyword
|
Standard Syntax
|
Translation
|
---|---|---|
hourly
|
0 * * * *
|
Run at the top of every hour
|
daily
|
0 0 * * *
|
Run daily at midnight
|
weekly
|
0 0 * * 0
|
Run weekly first day of week at midnight
|
monthly
|
0 0 1 * *
|
Run monthly on the first day of month at midnight
|
yearly
|
0 0 1 1 *
|
Run yearly on first month of the year at midnight
|
reboot
|
Execute when system reboots
| |
midnight
|
Same as daily
| |
annually
|
Same as yearly
|
Specifying a keyword is syntactically easier, but has
less flexibility as to what minute, hour, or day the job will execute.
Keep in mind that you probably won’t have several cron jobs to execute at the same time (overloading the system), so don’t overuse keywords such as hourly and daily.
USING THE AT SCHEDULER
You can use the at command to schedule a job to run once at a specified point in the future. Here’s an example:
$ echo "’go home’ | mailx -s ’time to go’ dba@gmail.com" | at 23:00
The prior command schedules an at job to send an email at 23:00 (11:00 p.m.), reminding the DBA that it is time to go home. You can use the atq (at queue) command to verify that the job is scheduled:
$ atq
111 2015-06-14 23:00 a oracle
111 2015-06-14 23:00 a oracle
If you want to remove the job, use the -r option:
$ at -r 111
In this manner, the at scheduler is a simple but effective way to create a scheduled job.
10-4. Setting Operating System Variables
Problem
You have this simple shell script that contains a SQL*Plus command:
#!/bin/bash sqlplus -s <<EOF system/manager select username from dba_users; EOF
You notice that a script executes well when you run it manually from the command line:
$ sqltest.bsh USERNAME -------------------- SYS SYSTEM ...
However, when the script runs from cron, it throws errors reporting that commands can’t be found:
sqlplus: command not found
You want to determine the cause of the issue and ensure that the script runs successfully from cron.
Solution
When cron executes a script, it doesn’t run the OS user’s startup or login files (such as .bashrc or .bash_profile), so the variables set in the startup scripts aren’t available when cron executes. When a shell script running from cron
can’t find a command, it usually means that a required directory path
has not been defined. Therefore, any script executed from cron has to explicitly set any required variables such as ORACLE_HOME, ORACLE_SID, and PATH. In this situation, one solution is to set any required variables directly within the shell script. Here’s an example:
#/bin/bash export ORACLE_HOME=/u01/app/oracle/product/12.1.0.2/db_1 export ORACLE_SID=O1212 export PATH=$PATH:$ORACLE_HOME/bin # sqlplus -s <<EOF system/foo select username from dba_users; EOF
In this way, the shell script has the required variables available when it executes from cron.
How It Works
When running a shell script from cron,
you should explicitly define any variables the shell script requires.
Don’t rely on startup scripts because they will not get executed.
The solution section showed how to directly place the
variables within the shell script. In many scenarios, however, DBAs
prefer to keep a separate script that contains required variable
definitions and execute them from any other shell scripts that require
the variables to be set.
An example will demonstrate this. Suppose that you have two shell scripts. The first one, .bash_profile, contains commands to set OS variables:
export ORACLE_HOME=/u01/app/oracle/product/12.1.0.2/db_1 export ORACLE_SID=O1212 export PATH=$PATH:$ORACLE_HOME/bin
And suppose you also have a shell script named sqltest.bsh that contains the following code:
#!/bin/bash sqlplus -s <<EOF system/manager select username from dba_users; EOF
You can instruct cron to first run the script to set the oracle
user’s environment variables and then run the script containing
database commands. You specify multiple scripts separated by a
semicolon. Here’s an example:
0 4 * * * . /home/oracle/.bash_profile; /home/oracle/bin/sqltest.bsh
Notice that the first script is run with the dot
notation to source the environment variables so that the variables are
visible to any subsequent scripts or commands that are executed.
10-5. Specifying the Execution Shell
Problem
Suppose that the following script is running from cron:
export ORACLE_HOME=/u01/app/oracle/product/12.1.0.2/db_1 export ORACLE_SID=O1212 export PATH=$PATH:$ORACLE_HOME/bin # sqlplus -s <<EOF system/foo select username from dba_users; EOF
When a cron job executes, the script is throwing an error, saying it can’t find the export command:
export: Command not found.
You want to determine why this standard Bash shell command (export, in this case) isn’t functioning properly.
Solution
A script is run from cron,
it will run the script using the default shell defined for a user.
Therefore, if your default shell is defined to be the C shell the OS
will execute any commands/scripts running from cron
using the C shell (unless otherwise noted), so commands unique to the
Bash shell will not be interpreted correctly. For example, suppose that
the default shell is the C shell; an error is returned when the
following Bash shell export command runs because the C shell doesn’t have an export command:
export ORACLE_SID=O1212 export: Command not found.
To work around this, ensure that all scripts specify
in the first line which shell should be used to interpret the commands.
Here’s an example:
#!/bin/bash
Another method to ensure that the correct shell is
used is to specify the shell to execute the script. For example, the
following cron entry instructs cron to execute the script using the Bash shell:
0 4 * * * /bin/bash /home/oracle/bin/sqltest.bsh
On Linux systems, you can also use the cron SHELL variable to instruct cron to run commands within the cron table using a specific shell:
SHELL=/bin/bash 0 4 * * * /home/oracle/bin/sqltest.bsh
How It Works
The solution section outlined three techniques to
ensure that the correct shell is used when commands or scripts are
executed. Any of these methods is fine, and DBAs use all three. The
technique used usually boils down to a personal preference or a standard
that a group has adopted.
10-6. Redirecting cron Output
Problem
You’re trying to troubleshoot issues with a cron job and want to ensure that you have a log file that captures the output when cron executes.
Solution
You can specify that any output generated by a cron entry be redirected to a file. This example writes standard output to a file named rmanback.log (for this example to work, the /home/oracle/bin/log directory must exist):
0 0 * * * /home/oracle/bin/rmanback.bsh >/home/oracle/bin/log/rmanback.log
Keep in mind that > is synonymous with 1>, so the following line is equivalent to the prior line:
0 0 * * * /home/oracle/bin/rmanback.bsh 1>/home/oracle/bin/log/rmanback.log
If you want standard error to be redirected to the same place as standard output, do so as follows:
0 0 * * * /home/oracle/bin/rmanback.bsh 1>/home/oracle/bin/log/rmanback.log 2>&1
In the previous line, 1> redirects standard output, and 2>&1
specifies that the standard error should go to the same location in
which the standard output is located (refer to recipe 2-9 for more
details on redirecting output).
If the log file already exists, > instructs the OS to overwrite the file and create a new file. If you want to append to an existing log file, use the >> syntax:
0 0 * * * /home/oracle/bin/backup.bsh 1>>/home/oracle/bin/log/bck.log 2>&1
This code appends any relevant messages (both regular
and error messages) to the existing log file. Sometimes you’ll want to
append if you have to capture the output from multiple runs of a job.
For example, it is hard to troubleshoot something that happened a few
days ago if you have a daily job that overwrites the existing log file.
How It Works
In most scenarios, you should save the output of your cron job in a log file, which provides a troubleshooting mechanism when there are issues. In addition to capturing the cron
job output in a file, you can have the output emailed to you (a unique
file name for the log file might be required). These topics are
discussed next.
Mailing Output
If you don’t redirect the output for a cron job, any output from the job will be emailed to the user who owns the cron job. On Linux systems, you can override it by specifying the MAILTO variable directly within the cron table. Here’s an example:
MAILTO=dba@gmail.com 0 0 * * * /home/oracle/bin/rmanback.bsh
If you don’t want the output to go anywhere, redirect
output to the proverbial bit bucket. The following entry sends the
standard output and standard error to the /dev/null device:
0 0 * * * /home/oracle/bin/rmanback.bsh 1>/dev/null 2>&1
Solaris systems do not support the MAILTO feature. To work around it, pipe the cron job to an email address as follows:
0 0 * * * /home/oracle/bin/rmanback.bsh | mail -s "backup" dba@gmail.com
Generating Unique Log File Names
If you have to generate a unique name for the log file each time it runs, use the date command. The following generates a unique daily log file name:
0 0 * * * /home/oracle/bin/rmanback.bsh 1>/home/oracle/bin/log/rmanback.$(/bin/date +\%Y\%m\%d).log
Note The two preceding lines of code were on one line in the cron table, but didn’t fit on this page. The line was broken into two lines (but should be just one line in the cron table). There is no way to split a single cron command line onto multiple lines with the backslash (\) character (as you can do when operating in the shell).
The percent (%) character is escaped with the backslash (\) character. The % character has to be escaped; otherwise, cron will interpret % as a newline character, and all code after the first % will be sent to the command as standard input.
You can creatively modify the date command per your requirements. For example, if you want to keep only the last 7 days of log files, specify the date command to return only the day of the week (not the year, month, or day):
0 0 * * * /home/oracle/bin/rmanback.bsh 1>/home/oracle/bin/log/rmanback.$(/bin/date +\%u).log
The date +%u command will return an integer 0 through 6, depending on the day of the week. After 7 days, you’ll end up with 7 log files: rmanback.0.log through rmanback.6.log. As each new week rolls around, the old log files will be overwritten.
ATTACHING FILES TO AN EMAIL
If you’re working with a log file or binary file that you want sent as an attachment (not as the message body), use the uuencode command or the mutt utility to accomplish this task. The basic syntax for uuencode is as follows:
uuencode [INFILE] REMOTEFILE
For example, to attach a file named prodAWR.html to an email, do so as follows:
$ uuencode prodAWR.html prodAWR.html | mail -s "prod AWR report" dba@gmail.com
You may be thinking that you could just send the email like this:
You can do so if the output contains only ASCII
text. If the file isn’t an ASCII file, however, the output will not be
interpreted as an attachment and will arrive as indecipherable text. In
this situation, you must attach the file to the email so that it won’t
be interpreted as the message body.
If available, you can also use the mutt utility to attach files to email. Here’s an example:
$ echo "AWR rpt" | mutt -a "/home/oracle/prodAWR.html" -s "AWR rpt" --dba@gmail.com
In this way, you can attach files (log files, binary files, backup files, and so on) to an email.
10-7. Embedding Conditional Logic
Problem
You want to automate a job that checks for a condition.
Solution
The solution is to realize that you can use standard Bash shell operators directly from within cron. For example, to test whether the output from the ps command returned a value, use the && or || operators (refer to Chapter 7 for details on conditional operators).
Here’s a sample cron entry that will check once per hour for a background process (smon in this situation); if the background process isn’t running, an email is sent:
01 * * * * ps -ef | grep smon>/dev/null || echo "problem" | mailx -s "issue" dba@gmail.com
In the preceding line of code, the || operator is interpreted this way: “If the command to the left of the || operator is not successful (ps does not return a value), run the code to the right of the || operator.”
Suppose that you want an automated job to run once per
hour to check for the existence of an error file, and to send an email
if it exists. You can do so as follows:
01 * * * * [ -f /home/oracle/err.txt ] && mailx -s "exists" dba@gmail.com </home/oracle/err.txt
In the prior line of code, the && is interpreted as follows: “If the command to the left of the && operator is successful (the file exists), run the code to the right of the && operator.”
DBAs and SAs use test instead of [ ] to accomplish the same task. The following line of code is equivalent to the prior line of code:
01 * * * * test -f /home/oracle/err.txt && mailx -s "exists" dba@gmail.com </home/oracle/err.txt
In this manner, you can automate tasks depending on a condition existing (or not).
How It Works
Once you understand that you can use standard Bash shell features directly from within cron, you can creatively schedule jobs as required in your environment. To that point, it’s worth repeating this example from Chapter 7:
33 * * * * ps -ef | grep dbwatch | grep -v grep || nohup /home/oracle/bin/dbwatch.bsh &
The prior line of code checks for the existence of a process; if it isn’t present, the job is restarted in the background.
You can separate commands within cron
by using a semicolon, and you can also execute code in a subshell by
enclosing it in parentheses. For example, at 2 minutes after the top of
the hour, execute the following:
02 * * * * cd /home/oracle/err ; (tail -100 err.txt) | grep ORA-00600 && echo "found error"
Caution Don’t embed overly complex logic into a cron
table; it makes the logic hard to understand and results in
less-maintainable code. If you find the logic is getting complicated,
put the code into a shell script and execute the script instead.
Table 10-3 summarizes special shell features that are often used to embed logic into cron jobs.
Table 10-3. Shell Operators and Meanings
Operator
|
Meaning
|
---|---|
&
|
Run the command in the background.
|
;
|
Run the command to the left of ; and run the command to the right of ; (e.g., separate the two commands).
|
&&
|
If command to the left of && is successful, run the command to the right of &&.
|
||
|
If the command to the left of || fails, run the command to the right of ||.
|
()
|
Execute the command within the parentheses in a subshell.
|
[ ]
|
Test a condition (can also use the test command).
|
10-8. Troubleshooting cron
Problem
Your cron job doesn’t appear to be running. You want to do some troubleshooting to determine the cause of the issue.
Solution
If you have a cron job that isn’t running correctly, follow these steps to troubleshoot the issue:
- Copy your cron entry, paste it to the OS command line, and manually run the command. A small typo in a directory or file name can often be the source of the problem. Manually running the command highlights errors like these.
- If the script runs Oracle utilities, ensure that you source (set) the required OS variables within the script (such as ORACLE_HOME, ORACLE_SID, and PATH). These variables are often set by startup scripts (such as HOME/.bashrc) when you log on. Because cron doesn’t run a user’s startup scripts, any required variables must be set explicitly within the script.
- Ensure that the first line of any shell scripts invoked from cron specifies the name of the program that will be used to interpret the commands within the script. For example, #!/bin/bash should be the first entry in a Bash shell script. Because cron doesn’t run a user’s startup scripts (such as HOME/.bashrc), you can’t assume that your OS user’s default shell will be used to run a command or script evoked from cron.
- If you execute a script, check the permissions on the script file and ensure that it is set to executable for the user running the script.
- Ensure that the cron background process or service is running.
- Check your email on the server. The cron utility will usually send an email to the OS account when there are issues with a misbehaving cron job.
- Inspect the contents of the /var/log/cron file for any errors. Sometimes this file has relevant information regarding a cron job that has failed to run.
We’ve found that any issues with cron
are usually related to one of the previously listed items. The prior
list is a good place to start when experiencing chronic issues.
How It Works
Troubleshooting cron
is necessary when the job doesn’t execute as expected, which often can
be due to environment variables not being set. If you want to explicitly
view the environment settings as cron is using them, put this line in your cron table:
* * * * * env > /tmp/env.txt
After the command executes and populates the env.txt file, remove the line from the cron table. The env.txt file will show the environment variables and values that cron is using. In this manner, you can quickly determine what cron is using for variables such as PATH and HOME; they may not be what you were expecting. Therefore, it is always better to explicitly set any required variables.
Additionally, cron will execute commands using the default shell of the OS user that owns the cron
table. This means if your default shell is the C shell, any commands
exclusive to the Bash shell will not be correctly interpreted when
running a cron job. As a best practice, explicitly instruct cron which shell to use when executing commands and scripts.
If you suspect that something is wrong with the cron service or background daemon, you can verify that it is working via the wall (write all users) command by adding this entry to your cron table:
* * * * * wall "cron is working"
If all is well, all users logged on to the server will see a message at the top of the minute, indicating that cron is working. Because all users logged on to the server will see the message, remember to remove this cron entry as soon as you’re done testing. If you don’t want to send the message to all users, use the write command with a specified terminal (use the who command to list logged-in users and terminal information).
ORACLE SCHEDULER VERSUS CRON
Oracle Scheduler is a tool that provides a way to automate job scheduling. Implemented via the DBMS_SCHEDULER
internal PL/SQL package, Oracle Scheduler offers a sophisticated set of
features for scheduling jobs. There are currently more than 70
procedures and functions available within the DBMS_SCHEDULER package.
You may be wondering whether to use Oracle Scheduler or the Linux/Solaris cron utility for scheduling and automating tasks. Here are some of the benefits that Oracle Scheduler has over cron:
- Makes the execution of a job dependent on the completion of another job
- Robust resource balancing and flexible scheduling features
- Runs jobs based on an event (such as the completion of another job)
- DBMS_SCHEDULER PL/SQL package syntax works the same, regardless of the OS
- Runs status reports using the data dictionary
- In a clustered environment, no need to worry about synchronizing multiple cron tables for each node in the cluster
- Is implemented, maintained, and monitored via Enterprise Manager
Regardless of Oracle Scheduler’s benefits, many DBAs prefer to use a scheduling utility such as cron. Here are some of the advantages of cron:
- Easy to use; simple, tried and true; takes only seconds to create or modify jobs
- Almost universally available on all Linux/Solaris boxes; for the most part, runs nearly identically, regardless of the Linux/Solaris platform (yes, there are minor differences)
- Database agnostic; operates independently of the database and works the same way regardless of the database vendor or version
- Works even when the database is not available
These lists aren’t comprehensive, but they give you
an idea of the uses of each scheduling tool. If you require something
more sophisticated than cron, consider using Oracle Scheduler. Note that cron and Oracle Scheduler aren’t mutually exclusive; for a given task, use whichever tool meets your requirements.
CHAPTER 11
Managing Server Software
Fortune 500 companies have embraced Oracle and
Red Hat Enterprise Linux, and Linux has become a dominant force in the
server industry. More and more Fortune 500 companies have adopted Linux
as a corporate standard. With Oracle’s presence over the server space
with its engineered systems, Linux has become a norm for DBAs. In the
world of engineered systems and virtualized infrastructures, DBAs often
perform or share system administration responsibilities. The greatest
Real Application Cluster (RAC)
DBAs know Linux intimately and know the best practices for tuning it.
For larger companies, a true delineation of roles and responsibilities
still exists. This chapter is for DBAs who perform software management roles in the Linux world—in particular, Red Hat and Oracle Enterprise Linux (Oracle Linux).
This chapter takes a bare-bones
Red Hat Enterprise Linux installation and registers the Red Hat server
to Oracle’s Unbreakable Linux Network, leverages Oracle’s RDBMS
PreInstall RPM for Oracle Database 11g Release 2 and Oracle Database 12c
to preconfigure a Linux server for Oracle installation, performs a
silent installation of Oracle Database 11g/12c software, clones a
fully patched Oracle installation, performs a silent database creation,
and completes the server build by setting up a silent network
configuration. Silent mode installations are the foundations of creating
an automated server installation procedure.
This chapter demonstrates how to install RPMs, switch
to Oracle’s Unbreakable Linux Network from the Red Hat Network, list the
contents of an RPM package, correlate OS executables to RPMs, download
RPMs, automate with Oracle’s validated install, and remove RPMs.
The database software management portion of this
chapter concentrates exclusively on silent installations. While learning
how to set up a database server from a soup-to-nuts implementation,
you’ll also learn about RPM and YUM package management.
11-1. Installing Packages
Problem
You want to install software components on the Linux server.
Solution #1
By far the easiest way to manage software on the Linux server is with the yum command, as shown in this example:
# yum install screen -y Loaded plugins: product-id, subscription-manager This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register. Setting up Install Process Resolving Dependencies --> Running transaction check ---> Package screen.x86_64 0:4.0.3-16.el6 will be installed --> Finished Dependency Resolution Dependencies Resolved ========================================================================================= Package Arch Version Repository Size ========================================================================================= Installing: screen x86_64 4.0.3-16.el6 viscosity 494 k Transaction Summary ========================================================================================= Install 1 Package(s) Total download size: 494 k Installed size: 795 k Downloading Packages: Running rpm_check_debug Running Transaction Test Transaction Test Succeeded Running Transaction Installing : screen-4.0.3-16.el6.x86_64 1/1 Verifying : screen-4.0.3-16.el6.x86_64 1/1 Installed: screen.x86_64 0:4.0.3-16.el6 Complete!
Solution #2
Another way to manage software on the Linux server is by executing the rpm command with the -i option (or --install) to install the package.
Here’s an example of installing the screen executable:
# rpm -ihv screen-4.0.3-1.el5.i386.rpm Preparing... ########################################### [100%] 1:screen ########################################### [100%]
The -h option displays hash marks during the installation. The -v option provides verbose output that reports the progress of the installation. The rpm executable can install packages from the local filesystem, CD, or remote server accessible by HTTP or FTP.
How It Works
Yellowdog Updater, Modified (YUM)
is a command-line, open-source package management utility for Linux
dependent on the RPM Package Manager. YUM is a modified version of the
original update command developed for Yellow Dog Linux that relies
heavily on package headers. On the header of each package, forward and
reverse dependency information is available for installation and
rollback of the package. With this information in databases known as
repositories, YUM can simplify package installation by determining other
packages required to satisfy dependencies.
In a nutshell, RPM is a package management system. RPM
originally stood for Red Hat Package Manager because it was designed by
Red Hat for Red Hat distributions. Because RPM was intended for Linux
distributions and used by many Linux distributions, RPM now stands for RPM Package Manager. The RPM system is composed of a local database, the rpm executable, and the RPM package files. The local RPM database, which is stored in the /var/lib/rpm
directory, houses metadata information about installed packages,
including package prerequisites and file attributes. Because the local
RPM database tracks all the packages and file attributes, removing a
package becomes a relatively simple operation.
The RPM package file is composed
of compressed archive files and dependency information. The package name
or label contains the following attributes:
<name>-<version>-<release>.<architecture>.rpm
Here’s an example of the package label:
unixODBC-2.2.11-7.1.i386.rpm
The unixODBC RPM is a
required RPM for Oracle Database 11g. For this example, the RPM version
is 2.2.11, and the release of the RPM is 7.1. This particular RPM is
designed for a 32-bit Intel IA32 (x86) CPU. The AMD64/Intel em64t RPM has the architecture name x86_64.
RPMs that contain source code show .src before the .rpm
suffix. Although you might not find binary RPMs associated with your
architecture and flavor of Linux, an equivalent source code RPM may be
available for another type of Linux. You can download the source and
compile the RPM.
Notice that certain RPMs have the .noarch extension in the file names to denote that the RPM doesn’t have a dependency on your system’s architecture.
Note Starting in Red Hat Enterprise Linux (RHEL)
5 and Oracle Linux (OL) 5, YUM has become the de facto standard for
most companies when it comes to installing software on Linux servers.
Starting with RHEL 5/OL and higher, up2date is no longer the tool of
choice.
11-2. Switching to the Oracle Unbreakable Linux Network
Problem
You installed RHEL 6 or 7, but want to leverage Oracle’s Unbreakable Linux Network (ULN). You want to start performing updates from ULN instead of Red Hat Network (RHN).
Solution
Before you can start taking advantage of ULN, you must download and upgrade to the new version of the up2date and up2date-gnome packages from https://linux.oracle.com/switch.html for your version of Red Hat and server architecture. In addition, you must have a valid CSI and license for Oracle Linux (OL).
You can download the files from the http://linux-update.oracle.com/rpms/ web site. For Red Hat Linux 7 64-bit architecture, download two files: uln_register_ol7.tgz and uln_register-gnome_ol7.tgz. For Red Hat Linux 6 (both 32-bit and 64-bit architectures), download two files: uln_register.tgz and uln_register-gnome.tgz. For updates to switching instructions, please review the steps from the Oracle web site: https://linux.oracle.com/switch.html.
Installing Oracle up2date for Older Releases
Once you download the up2date and up2date-gnome packages, you can upgrade the existing packages as the root user on your Red Hat system using the rpm -Uhv command, as shown here:
# rpm -Uhv up2date-5.10.1-40.8.el5.i386.rpm \ up2date-gnome-5.10.1-40.8.el5.i386.rpm warning: up2date-5.10.1-40.8.el5.i386.rpm: Header V3 DSA signature: NOKEY, key ID 1e5e0159 Preparing... ########################################### [100%] 1:up2date ########################################### [ 50%] 2:up2date-gnome ########################################### [100%]
If you don’t have up2date-gnome
installed, you can exclude that RPM. If you’re running on OS versions
prior to Red Hat Linux (RHEL) 6, you must import Oracle’s GPG keys by
executing the import option:
rpm --import /usr/share/rhn/RPM-GPG-KEY
Registering with ULN
Now you are ready to register the Red Hat server with ULN. Once you register the Red Hat server, you can start using the up2date command to automatically download and install/upgrade packages on the Linux server. The single greatest feature of up2date is that all the dependencies are automatically resolved without the administrator’s intervention.
The biggest frustration with RPM management is dealing with a colloquialism referred to as dependency hell.
For example, suppose that RPM X has a dependency on RPMs A, B, and C.
RPM B has another dependency on L, M, and N. Not realizing the RPM
dependencies, when you try to install RPM N, you encounter another
dependency for RPM N that requires RPMs H and I. You simply want to
install RPM X, but you stumble into a multitude of other RPM
requirements, and the dependency requirements stack on top of each
other. You’ll encounter situations in which up2date can significantly simplify the management of a Linux server.
To start the registration process if you are on RHEL 3, RHEL 4, or RHEL 5, you can execute the following command:
up2date --register
You can execute the command up2date --register --nox to launch up2date in non-GUI mode. Without the --nox option, your DISPLAY
parameter must be set to a valid X server or the VNC server. Initially,
you’ll see the Welcome to ULN Update Agent screen. Click the Forward
button to be directed to the ULN Login screen. Because this is the first
time you are logging in to up2date, you
must provide all the credentials onscreen, including a login ID, a
password (twice for verification), and a licensed CSI number.
For RHEL 6 and RHEL 7, execute the uln_register command to switch from RHN to ULN. Carefully follow the onscreen instructions and enter the requested information. The uln_register
process also collects machine information and uploads it to the Oracle
server. System should be subscribed to the latest OL 7 channel on ULN to
perform the YUM update in the case of RHEL 7.
How It Works
Switching from RHN to Oracle’s ULN is
straightforward. Once you purchase a license of OL, you can start
receiving support from Oracle Support instead of Red Hat. You can start
to receive support from a single front end for both the OS and the
database from Oracle Support.
Once you have successfully registered your Red Hat server with ULN, you can access the ULN portal via https://linux.oracle.com.
In the Login and Password fields, you can provide the login and
password credentials that you supplied while registering your Red Hat
server.
Whether you are on OL or RHEL, you can leverage
Oracle’s public YUM server for package management. Everyone knows that
if you are on OL, you can take advantage of Oracle’s public YUM server
for Oracle RDBMS PreInstall RPMs. However, few realize that even Red Hat
customers can take advantage of Oracle’s public YUM server. To
configure the Red Hat for Oracle public YUM server, first download the
repository configuration file. Repositories are set up in the /etc/yum.repos.d directories. You can set up more than one YUM repository for a Linux server.
To obtain a listing of available repositories for your server, execute the yum command with the repolist argument:
# yum repolist
Because you’re working with RHEL 6.6, download Oracle’s public YUM repository configuration files for OL 6 and place the file in the /etc/yum.repos.d directory:
# wget http://public-yum.oracle.com/public-yum-ol6.repo --2015-05-18 15:26:52-- http://public-yum.oracle.com/public-yum-ol6.repo Resolving public-yum.oracle.com... 67.200.133.11, 67.200.133.9 Connecting to public-yum.oracle.com|67.200.133.11|:80... connected. HTTP request sent, awaiting response... 200 OK Length: 5046 (4.9K) [text/plain] Saving to: "public-yum-ol6.repo" 100%[==============================================================================>] 5,046 --.-K/s in 0.002s 2015-05-18 15:26:52 (2.16 MB/s) - "public-yum-ol6.repo" saved [5046/5046]
You have to download the OL GPG key with the same wget command and place the file in the /etc/pki/rpm-gpg directory:
wget http://public-yum.oracle.com/RPM-GPG-KEY-oracle-ol6 -O /etc/pki/rpm-gpg/RPM-GPG-KEY-oracle
If you don’t download this GPG key, you’ll encounter the following error during any kind of YUM package maintenance:
GPG key retrieval failed: [Errno 14] Could not open/read file:///etc/pki/rpm-gpg/RPM-GPG-KEY-oracle
Once you download the Oracle GPG key, you can verify the GPG key with the gpg
command. A public key fingerprint is a short sequence of bytes used to
authenticate a longer public key. You create fingerprints by applying a
cryptographic hash function to a public key. With the –with-fingerprint parameter, you can verify the fingerprint associated with the GPG key:
# gpg --quiet --with-fingerprint /etc/pki/rpm-gpg/RPM-GPG-KEY-oracle pub 2048R/EC551F03 2010-07-01 Oracle OSS group (Open Source Software group) <build@oss.oracle.com> Key fingerprint = 4214 4123 FECF C55B 9086 313D 72F9 7B74 EC55 1F03
Note Another advantage of registering a server with Oracle’s ULN or leveraging the public YUM server is that you can execute up2date or yum
to download and install ASM-related RPMs. You don’t have to investigate
which ASM-specific RPMs have to be downloaded based on the kernel level
of your Linux server; yum automatically determines which packages need to be downloaded for you.
11-3. Associating Linux Files with RPM Packages
Problem
One of the servers has an executable you need, but another server doesn’t. You want to identify the RPM package to install on the server.
Solution #1
Look at the yum provides command with the fully qualified path to the pkill executable to see which RPM delivers the executable:
$ yum provides /usr/bin/pkill Loaded plugins: downloadonly procps-3.2.8-21.el6.x86_64 : System and process monitoring utilities Repo : public_ol6_latest Matched from: Filename : /usr/bin/pkill ... ...
Solution #2
Look for the gedit executable, but this time by passing the –qf parameters to the rpm command:
[root@rac5 bin]# rpm -qf /usr/bin/gedit gedit-2.16.0-5.el5
The -qf option also works for shared objects. If you happen to be curious about which package the libc.so file came from, you can issue the -qf option, as demonstrated here:
[root@rac5 lib]# rpm -qf libc.so glibc-devel-2.5-18
How It Works
The yum command has the provides option, which returns the package name if you specify the path of the executable or shared library. The provides option also accepts a wildcard parameter (*) for the path enclosed by double quotes, as shown here:
# yum provides "*bin/gedit" Loaded plugins: downloadonly public_ol6_UEKR3_latest/filelists | 8.2 MB 00:21 1:gedit-2.28.4-3.el6.x86_64 : Text editor for the GNOME desktop Repo : public_ol6_latest Matched from: Filename : /usr/bin/gedit
rpm provides features
to query the RPM database to extract the owning package. You can
correlate an executable or library from the OS to an RPM. You can
execute rpm with the -qf (-q for -query and -f for -file) option to determine which RPMs are associated with a specified file or executable.
11-4. Listing the Contents of an RPM Package
Problem
You want to look inside the .rpm file to view the contents of the package and peek at the destination in which the files will be extracted.
Solution #1
The repoquery executable provides the capability to view the destination location of files for a package. The repoquery comes with the yum-utils RPM and has to be installed with yum:
# yum install yum-utils
Once the yum-utils package is installed, leverage the repoquery executable with the –l option (or –listing option) against the screen rpm:
# repoquery -l screen /etc/pam.d/screen /etc/screenrc /usr/bin/screen /usr/share/doc/screen-4.0.3 /usr/share/doc/screen-4.0.3/COPYING /usr/share/doc/screen-4.0.3/FAQ /usr/share/doc/screen-4.0.3/NEWS /usr/share/doc/screen-4.0.3/README /usr/share/doc/screen-4.0.3/README.DOTSCREEN /usr/share/info/screen.info.gz /usr/share/man/man1/screen.1.gz /usr/share/screen /usr/share/screen/utf8encodings /usr/share/screen/utf8encodings/01 /usr/share/screen/utf8encodings/02 /usr/share/screen/utf8encodings/03 /usr/share/screen/utf8encodings/04 /usr/share/screen/utf8encodings/18 /usr/share/screen/utf8encodings/19 /usr/share/screen/utf8encodings/a1 /usr/share/screen/utf8encodings/bf /usr/share/screen/utf8encodings/c2 /usr/share/screen/utf8encodings/c3 /usr/share/screen/utf8encodings/c4 /usr/share/screen/utf8encodings/c6 /usr/share/screen/utf8encodings/c7 /usr/share/screen/utf8encodings/c8 /usr/share/screen/utf8encodings/cc /usr/share/screen/utf8encodings/cd /usr/share/screen/utf8encodings/d6 /var/run/screen
Solution #2
You can execute rpm with the -qlp option to list the destination location for files in a package. Here’s an example in which the contents of the openmotif21 RPM are examined with HTTP:
[root@rac5 up2date]# rpm -qlp http://dbaexpert.com/rpms/openmotif21-2.1.30- 11.RHEL4.6.i386.rpm warning: http://dbaexpert.com/rpms/openmotif21-2.1.30-11.RHEL4.6.i386.rpm: Header V3 DSA signature: NOKEY, key ID b38a8516 /usr/X11R6/lib/libMrm.so.2 /usr/X11R6/lib/libMrm.so.2.1 /usr/X11R6/lib/libUil.so.2 /usr/X11R6/lib/libUil.so.2.1 /usr/X11R6/lib/libXm.so.2 /usr/X11R6/lib/libXm.so.2.1 /usr/share/doc/openmotif21-2.1.30 /usr/share/doc/openmotif21-2.1.30/COPYRIGHT.MOTIF /usr/share/doc/openmotif21-2.1.30/README /usr/share/doc/openmotif21-2.1.30/RELEASE /usr/share/doc/openmotif21-2.1.30/RELNOTES
As mentioned in Recipe 11-1, you can execute the previous rpm command against a file on the local filesystem, CD, or remote server with HTTP or FTP access.
How It Works
You can use the repoquery command to list package contents. It will work with installed packages as well as packages not yet installed. The repoquery has numerous options. The –l option lists files in the package in question. The –i option (--info) lists descriptive information from the package.
Here’s an example using the –i option to obtain informative description about the screen package:
# repoquery -i screen Name : screen Version : 4.0.3 Release : 16.el6 Architecture: x86_64 Size : 814092 Packager : None Group : Applications/System URL : http://www.gnu.org/software/screen Repository : public_ol6_latest Summary : A screen manager that supports multiple logins on one terminal Source : screen-4.0.3-16.el6.src.rpm Description : The screen utility allows you to have multiple logins on just one terminal. Screen is useful for users who telnet into a machine or are connected via a dumb terminal, but want to use more than just one login. Install the screen package if you need a screen manager that can support multiple logins on one terminal.
The rpm command has a myriad of options, and the -p option allows you to view information directly from the package. The two commonly executed options with -p are -qip and -qlp. The -qlp option lists all the files that make up the package.
The -qip option provides detailed information about the package. Here, the same command is executing as previously, except with the -qip option:
# rpm -qip http://dbaexpert.com/rpms/openmotif21-2.1.30- 11.RHEL4.6.i386.rpm warning: http://dbaexpert.com/rpms/openmotif21-2.1.30-11.RHEL4.6.i386.rpm: Header V3 DSA signature: NOKEY, key ID b38a8516 Name : openmotif21 Relocations: /usr/X11R6 Version : 2.1.30 Vendor: (none) Release : 11.RHEL4.6 Build Date: Sat 07 Oct 2006 08:45:00 AM CDT Install Date: (not installed) Build Host: ca-build10.us.oracle.com Group : System Environment/Libraries Source RPM: openmotif21-2.1.30- 11.RHEL4.6.src.rpm Size : 2249149 License: Open Group Public License Signature : DSA/SHA1, Mon 09 Oct 2006 08:24:28 PM CDT, Key ID 2e2bcdbcb38a8516 URL : http://www.opengroup.org/openmotif/ Summary : Compatibility libraries for Open Motif 2.1. Description : This package contains the compatibility libraries for running Open Motif 2.1 applications.
Notice that the -qip
option provides additional details about the packages, such as when the
package was built, from which machines, the source RPM, the size, the
signature, and even a description of what the package is about. You can
also combine these options as -qlip, which shows both detailed information about the package and the list of all files in the package.
11-5. Downloading Packages
Problem
You want to download RPMs from the Linux terminal.
Solution
By installing a package called yum-plugin-downloadonly on RHEL 6, you can start downloading RPMs:
# yum install yum-plugin-downloadonly
After installing the yum-plugin-downloadonly package, you can execute the yum command as if you were actually installing the software, but provide it two additional parameters: --downloadonly and --downloaddir. Here’s the syntax to download the screen package to the /tmp directory:
[root@ika82 ~]# yum install --downloadonly --downloaddir=/tmp screen Loaded plugins: downloadonly Setting up Install Process Resolving Dependencies --> Running transaction check ---> Package screen.x86_64 0:4.0.3-16.el6 will be installed --> Finished Dependency Resolution Dependencies Resolved ========================================================================================= Package Arch Version Repository Size ========================================================================================= Installing: screen x86_64 4.0.3-16.el6 public_ol6_latest 494 k Transaction Summary ========================================================================================= Install 1 Package(s) Total download size: 494 k Installed size: 795 k Is this ok [y/N]: y Downloading Packages: screen-4.0.3-16.el6.x86_64.rpm | 494 kB 00:01 exiting because --downloadonly specified
You can confirm that the screen package successfully downloaded the screen RPMs to the /tmp directory by performing a directory listing:
[root@ika82 ~]# ls -ltr /tmp/*.rpm -rw-r--r--. 1 root root 505732 Apr 22 2011 /tmp/screen-4.0.3-16.el6.x86_64.rpm
How It Works
By default, the yum-plugin-downloadonly RPM is not installed; you have to install the RPM manually. The greatest benefit of downloading the RPMs with yum is that all dependent packages are automatically downloaded together. For example, the perl RPM has many dependent packages, and all the perl and dependent RPMS can be downloaded with a single command.
11-6. Automating Server Builds with Oracle RDBMS Server PreInstall RPM
Problem
You don’t want to spend time researching RPM
requirements to install Oracle Database 11g/12c. You want to take
advantage of Oracle’s preconfigured validated installation process.
Solution
If you are running on OL or RHEL (a rebuild from the
source RPM is required), you can fully leverage Oracle’s automated
preinstallation processes. Oracle’s validated install automates the
download of all the required RPMs; the installation of RPMs, including
dependency requirements; the setup of the Linux kernel parameters; the
creation of the oracle user in the /etc/passwd file; and the creation of entries in the /etc/group file for dba and oinstall. You simply execute the yum command with the following options:
# yum install oracle-rdbms-server-12cR1-preinstall ... ... Transaction Summary ========================================================================================= Install 13 Package(s) Total download size: 7.5 M Installed size: 23 M Is this ok [y/N]: y Downloading Packages: (1/13): compat-libcap1-1.10-1.x86_64.rpm | 17 kB 00:00 ... (13/13): xorg-x11-xauth-1.0.2-7.1.el6.x86_64.rpm | 34 kB 00:00 ----------------------------------------------------------------------------------------- Total 1.7 MB/s | 7.5 MB 00:04 .. Running Transaction Installing : libstdc++-devel-4.4.7-11.el6.x86_64 1/13 .. Installing : oracle-rdbms-server-12cR1-preinstall-1.0-13.el6.x86_64 13/13 Verifying : compat-libcap1-1.10-1.x86_64 1/13 .. Verifying : libXmu-1.1.1-2.el6.x86_64 13/13 Installed: oracle-rdbms-server-12cR1-preinstall.x86_64 0:1.0-13.el6 Dependency Installed: compat-libcap1.x86_64 0:1.10-1 compat-libstdc++-33.x86_64 0:3.2.3-69.el6 gcc-c++.x86_64 0:4.4.7-11.el6 ksh.x86_64 0:20120801-21.el6_6.3 libXmu.x86_64 0:1.1.1-2.el6 libXxf86dga.x86_64 0:1.1.4-2.1.el6 libXxf86misc.x86_64 0:1.0.3-4.el6 libaio-devel.x86_64 0:0.3.107-10.el6 libdmx.x86_64 0:1.1.3-3.el6 libstdc++-devel.x86_64 0:4.4.7-11.el6 xorg-x11-utils.x86_64 0:7.5-6.el6 xorg-x11-xauth.x86_64 1:1.0.2-7.1.el6 Complete!
The output for this RPM installation spans pages of output. For the complete output, visit the following URL: http://www.dbaexpert.com/blog/oracle-rdbms-server-12cr1-preinstall/.
For Linux servers that house Oracle Database 11g Release 2 on RHEL (a
recompile from the source RPM is required) or OL, you should leverage
the oracle-rdbms-server-11gR2-preinstall RPM:
# yum install oracle-rdbms-server-11gR2-preinstall
Starting from Oracle Database 11g Release 2, you no longer use the Oracle-validated install; leverage the new oracle-rdbms-server-11gR2-preinstall instead. The Oracle 12c RDBMS PreInstall RPM also modifies the kernel parameters in the /etc/sysctl.conf kernel configuration file. The following entries are added:
# oracle-rdbms-server-12cR1-preinstall setting for fs.file-max is 6815744 fs.file-max = 6815744 # oracle-rdbms-server-12cR1-preinstall setting for kernel.sem is ’250 32000 100 128’ kernel.sem = 250 32000 100 128 # oracle-rdbms-server-12cR1-preinstall setting for kernel.shmmni is 4096 kernel.shmmni = 4096 # oracle-rdbms-server-12cR1-preinstall setting for kernel.shmall is 1073741824 on x86_64 # oracle-rdbms-server-12cR1-preinstall setting for kernel.shmmax is 4398046511104 on x86_64 kernel.shmmax = 4398046511104 # oracle-rdbms-server-12cR1-preinstall setting for kernel.panic_on_oops is 1 per Orabug 19642132 kernel.panic_on_oops = 1 # oracle-rdbms-server-12cR1-preinstall setting for net.core.rmem_default is 262144 net.core.rmem_default = 262144 # oracle-rdbms-server-12cR1-preinstall setting for net.core.rmem_max is 4194304 net.core.rmem_max = 4194304 # oracle-rdbms-server-12cR1-preinstall setting for net.core.wmem_default is 262144 net.core.wmem_default = 262144 # oracle-rdbms-server-12cR1-preinstall setting for net.core.wmem_max is 1048576 net.core.wmem_max = 1048576 # oracle-rdbms-server-12cR1-preinstall setting for fs.aio-max-nr is 1048576 fs.aio-max-nr = 1048576 # oracle-rdbms-server-12cR1-preinstall setting for net.ipv4.ip_local_port_range is 9000 65500 net.ipv4.ip_local_port_range = 9000 65500
In addition, the preinstall RPM process adjusts the /etc/passwd file to include the oracle user and creates the /home/oracle directory:
oracle:x:54321:54321::/home/oracle:/bin/bash
Furthermore, entries for dba and oinstall are added to the /etc/group file:
oinstall:x:54321: dba:x:54322:oracle
How It Works
After Linux is installed and the system is released
to the DBAs, you have to quickly configure the Linux server for database
software provisioning. If the server is installed with OL 6, you can
leverage the oracle-rdbms-server-12cR1-preinstall
RPM directly from the public YUM repository. Many DBAs don’t realize
that the Oracle RDBMS 11g/12c PreInstall RPM installation option exists.
With the oracle-rdbms-server-12cR1-preinstall
RPM, you can install required packages required by the Oracle Universal
Installer with a single command. Executing the command can prepare a
majority of your Linux server requirements to install Oracle Database
Server, such as the following:
- The user oracle and the groups oinstall (software owner) and dba (for OSDBA), which are used during database installation, are created
- Kernel parameters are modified in /etc/sysctl.conf for shared memory such as semaphores, the maximum number of file descriptors, and so on
- Settings for hard and soft shell resource limits are made in ./etc/security/limits.conf such as the locked-in memory address space, the number of open files, the number of processes, and core file size
- Non-Uniform Memory Access (NUMA) and Transparent Huge Pages (THP) are also disabled in the /etc/grub.conf configuration file
Note For detailed information about NUMA, THP, and kernel parameters, please see Chapter 13.
Having Oracle RDBMS Server PreInstall RPM for OL is
one the biggest benefits of adopting OL from RHEL or other Linux
distributions. With a single command, you can preconfigure the OL
environment for OEM 12c Agent, EBS R12, and Oracle Database 11gR2/12c
installations. Not only does Oracle configure the Linux environment but
many of the best practices are also incorporated in the process.
For Oracle RDBMS Server PreInstall RPMs for Oracle
Database 11g Release 2 and Oracle Database 12c Release 1, you can
download them from the latest channel of the public-yum repository: http://public-yum.oracle.com/repo/OracleLinux/OL6/latest/x86_64/.
You have to scroll down quite a bit; the RPMs that start with capital
letters are listed above RPMs that have lowercase letters.
You can also download PreInstall RPMs for Oracle EBS R12 and OEM Agent 12c from the addons channel from the public-yum
repository. Oracle provides a separate RPM for each release of OEM 12c.
Please visit the following URL for the latest versions of oracle-ebs-server-R12-preinstall-1.0-7.el6.x86_64.rpm and oracle-em-agent-12cR4-preinstall-1.0-7.el6.x86_64.rpm RPMs: http://public-yum.oracle.com/repo/OracleLinux/OL6/addons/x86_64/.
Lots of DBAs aren’t aware that Oracle also provides
the source RPMs for each of the preinstall RPMs. For example, you can
download the source RPM for the oracle-rdbms-server-12cR1-preinstall.rpm file. The file will be called oracle-rdbms-server-12cR1-preinstall.src.rpm and will exist in the same URL location as other RPMS.
Note For step-by-step instructions on taking an OL source RPM and rebuilding it for RHEL, download the following white paper: http://www.dbaexpert.com/blog/collaborate-2014-extreme-oracle-db-infrastructure-as-a-service-paper/. This white paper goes through the process of performing an installation with the oracle-rdbms-server-12cR1-preinstall source RPM with the rpm –ihv
command and manipulating the manifest that is created. After you modify
the specification file, the paper reveals the process to generate a RPM
file with the rpmbuild command so that
you can leverage and provision Oracle’s preinstallation RPM on RHEL. You
can repeat the same procedures against the OEM Agent preinstall RPM and
the Oracle E-Business Suite preinstall RPM and leverage them on RHEL.
11-7. Upgrading Packages
Problem
You realize that you have older versions of software
components. You want to upgrade some of the older packages to the
newest release.
Solution #1
To upgrade an existing package and all the dependent packages, you can execute the yum command with the update option:
# yum update perl
Solution #2
To upgrade an existing package, you can execute rpm with the -Uhv option (or --upgrade). For this particular solution, you’ll upgrade the perl RPM. Execute the rpm executable with the -Uhv option to upgrade the perl package:
# rpm -Uhv perl-5.8.8-10.0.1.el5_2.3.i386.rpm Preparing... ########################################### [100%] 1:perl ########################################### [100%]
How It Works
The yum command with the update option is the best option for upgrading packages on the Linux server. The update option installs the latest version of a package or group of packages. If you don’t provide the package name(s), yum will attempt to upgrade all the packages. To remove and replace just the obsoleted packages, provide the --obsoletes option.
Optionally, you can upgrade an existing package with the -Uhv
option. Behind the scenes, the original package will be removed, and
the new package will be installed. The original configuration file will
remain but will be renamed with the .rpmsave extension. Because the -U option removes and installs the package(s), you can also use the -U option to install packages. If the package doesn’t exist, the package(s) will be installed.
Tip If
you have a requirement to upgrade a large quantity of packages (or even
apply upgrades to all the existing packages), you can use the -F option (or --freshen). The -F option will not install packages if the packages don’t already exist.
11-8. Removing Packages
Problem
You want to remove a package from the Linux server.
Solution #1
The preferred method of removing a package is by leveraging the yum command with the erase option. To remove the screen package without a prompt, you can execute the following syntax:
# yum -y erase screen Loaded plugins: product-id, subscription-manager This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register. Setting up Remove Process Resolving Dependencies --> Running transaction check ---> Package screen.x86_64 0:4.0.3-16.el6 will be erased --> Finished Dependency Resolution Dependencies Resolved ========================================================================================= Package Arch Version Repository Size ========================================================================================= Removing: screen x86_64 4.0.3-16.el6 @viscosity 795 k Transaction Summary ========================================================================================= Remove 1 Package(s) Installed size: 795 k Downloading Packages: Running rpm_check_debug Running Transaction Test Transaction Test Succeeded Running Transaction Erasing : screen-4.0.3-16.el6.x86_64 1/1 Verifying : screen-4.0.3-16.el6.x86_64 1/1 Removed: screen.x86_64 0:4.0.3-16.el6 Complete!
Solution #2
Another way to remove a package is to execute the rpm command with the -e option (or --erase). To remove the screen package, you can execute the following syntax:
rpm -e screen
How It Works
Similar to package installation, software can be removed from the server with the yum command using the erase option. The remove option is an alias to the erase option. The yum erase
command will uninstall any packages as well as dependent packages. You
can also uninstall a package group such as a Web Server or X Window
System with the yum remove command.
Software can also be removed from the server with the rpm command with the -e
option. You must provide the installed package name as the second
parameter; don’t provide the package file name. The example in the
solution removes the screen package from
the system. You’ll often not be able to remove an RPM because of
dependency requirements; you have to know the dependency order to remove
the designated RPM. Although we don’t recommend it, you can avoid the
dependency check with the --nodeps option.
11-9. Checking RPM Requirements to Install Oracle Database
Problem
Make sure that your database software installation
goes as smoothly as possible. Check to see whether the Linux server has
the required list of packages specified by Oracle to install Oracle
Database 12c.
Solution
You can execute the following short code snippets called rpm6.ksh (for RHEL/OL 6) and rpm7.ksh
(for RHEL/OL 7) to quickly see whether the Linux server complies with
the package requirements required to install and configure a database:
$ cat rpm6.ksh rpm -q --queryformat "%{NAME}-%{VERSION}.%{RELEASE} (%{ARCH})\n" \ binutils compat-libcap1 compat-libstdc++-33 gcc gcc-c++ glibc glibc-devel \ ksh libgcc libstdc++ libstdc++-devel libaio libaio-devel \ libXext libXtst libX11 libXau libxcb libXi make sysstat \ unixODBC unixODBC-devel $ cat rpm7.ksh rpm -q --queryformat "%{NAME}-%{VERSION}.%{RELEASE} (%{ARCH})\n" \ binutils compat-libcap1 gcc gcc-c++ glibc glibc-devel ksh \ libaio libaio-devel libgcc libstdc++ libstdc++-devel libXi libXtst \ make sysstat unixODBC unixODBC-devel
We recommend that the screen RPM be included in every
Oracle server, just as Oracle ASMLIB libraries should be part of every
server installation. Executing an RPM check with the rpm6.ksh script against an OL 6.6 server yields the following results:
$ ./rpm6.ksh binutils-2.20.51.0.2.5.42.el6 (x86_64) compat-libcap1-1.10.1 (x86_64) compat-libstdc++-33-3.2.3.69.el6 (x86_64) gcc-4.4.7.11.el6 (x86_64) gcc-c++-4.4.7.11.el6 (x86_64) glibc-2.12.1.149.el6 (x86_64) glibc-devel-2.12.1.149.el6 (x86_64) ksh-20120801.21.el6_6.3 (x86_64) libgcc-4.4.7.11.el6 (x86_64) libstdc++-4.4.7.11.el6 (x86_64) libstdc++-devel-4.4.7.11.el6 (x86_64) libaio-0.3.107.10.el6 (x86_64) libaio-devel-0.3.107.10.el6 (x86_64) libXext-1.3.2.2.1.el6 (x86_64) libXtst-1.2.2.2.1.el6 (x86_64) libX11-1.6.0.2.2.el6 (x86_64) libXau-1.0.6.4.el6 (x86_64) libxcb-1.9.1.2.el6 (x86_64) libXi-1.7.2.2.2.el6 (x86_64) make-3.81.20.el6 (x86_64) sysstat-9.0.4.27.el6 (x86_64) package unixODBC is not installed package unixODBC-devel is not installed
How It Works
Because you plan to run Oracle databases on a 64-bit
Linux OS, check for both 32-bit and 64-bit packages. For example, you
have to install both 32-bit and 64-bit components of the compat-db package. You can specify the -qf option (or --queryformat)
followed by format options to manipulate the output display. The query
string format consists of static strings similar to the printf syntax.
In this solution, the "%{NAME}-%{VERSION}.%{RELEASE} (%{ARCH})\n" format is specified to display the architecture. If the output displays (x86_64), you can confirm that the 64-bit package is installed. If the output displays (i386),
you have confirmation that the 32-bit version of the package is
installed. Here’s the complete RPM requirement for Oracle Database 12c
on RHEL and OL 6 and 7: http://www.dbaexpert.com/blog/rpm-requirement-on-red-hat-and-oracle-linux-6-and-7-for-oracle-database-12c-release-1/.
You still have to review the output from the provided
scripts to ensure that the output meets or exceeds the level of the
package expected. The primary purpose of this script is to provide a
single consolidated output to review the RPMs, compared with what is
required by Oracle to successfully install Oracle Database 12c.
11-10. Performing Initial Silent Oracle Software Installation with Response Files
Problem
You want to perform an initial install of the Oracle
binaries on a new server. You suspect that the network bandwidth will
cause issues when trying to run the graphical installer. You want to do a
silent install of the Oracle binaries with a response file.
On another note, you want to reduce the amount of time
needed to install Oracle Database 12c. You want to automate the
installation procedures by performing the installation with the silent
option.
Solution #1
In this solution, only Oracle software binaries are
installed to the designated target Oracle Home directory. This solution
assumes that you have successfully downloaded, copied, and unbundled the
Oracle installation software on your database server. After unbundling
the installation software, you should see a directory named response in the database directory.
First, change the directory to the response directory and list the files. You should see several response files:
dbca.rsp db_install.rsp netca.rsp
For this solution, you’re interested in the db_install.rsp
response file to perform a silent installation of the Oracle Database
12c software stack. Before you manipulate this response file, make a
backup copy of the file. Open the db_install.rsp response file with an editor such as vi
and provide valid values for your environment for various variables
within the response file. In this example, the response file is called 12c_db.rsp and is placed in the /tmp
directory. Little over a dozen parameters were modified because you’re
interested only in installing the software; you don’t want to create a
database with the installation. In a typical new implementation, you’ll
install Oracle Database 12c and apply the latest PSU. You’ll want to
create the database after the PSU is applied.
Let’s review the contents of the response file to
install the Oracle Database Software. You’ll filter out all comments and
blank lines of the response file with the egrep
command. Then you’ll perform another level of filtering and look only
at lines that have a value associated after the equal sign. Using the
following one–liner code example, you can review all the pertinent
variables to the db_install.rsp response file:
$ egrep -v "^#|^$" db_install.rsp |awk -F"=" ’{if ($2)print $1"=" $2}’ oracle.install.responseFileVersion=/oracle/install/rspfmt_dbinstall_response_schema_v12.1.0 oracle.install.option=INSTALL_DB_SWONLY ORACLE_HOSTNAME=dal66a UNIX_GROUP_NAME=oinstall INVENTORY_LOCATION=/u01/app/oraInventory SELECTED_LANGUAGES=en ORACLE_HOME=/u01/app/oracle/product/12.1.0.2/dbhome_1 ORACLE_BASE=/u01/app/oracle oracle.install.db.InstallEdition=EE oracle.install.db.DBA_GROUP=dba oracle.install.db.OPER_GROUP=dba oracle.install.db.BACKUPDBA_GROUP=dba oracle.install.db.DGDBA_GROUP=dba oracle.install.db.KMDBA_GROUP=dba SECURITY_UPDATES_VIA_MYORACLESUPPORT=false DECLINE_SECURITY_UPDATES=true
The first parameter to review is the oracle.install_ option. This parameter accepts three values: INSTALL_DB_SWONLY, INSTALL_DB_AND_CONFIG, and UPGRADE_DB. You’ll look at INSTALL_DB_SWONLY in this solution to install only the software.
UNIX_GROUP_NAME is usually either dba or oinstall.
Depending on the level of delineation you want among various support
organizations, you can opt to have different groups. For example, you
can create a special Linux group in the /etc/group file have the backup team assigned to this group, and assign this group to the BACKUPDBA_GROUP.
ORACLE_HOSTNAME should be the local hostname on which the installation will occur. The ORACLE_HOME
directory must point to the directory location in which you want the
Oracle software to be installed, and it should be a directory in which
the oracle account has write access. The ORACLE_HOME variable will match the value in the oratab file (usually located in the /etc directory) for your installation. The oratab file contains entries for databases that run locally on the server.
Each line of the oratab file consists of three parameters: database name, database software location (also known as ORACLE_HOME),
and startup flag. The last parameter plays a significant role in
automating database startups. If the value of the last parameter is set
to Y, the dbstart shell script located in the $ORACLE_HOME/bin directory will include the database to start when the server reboots. The ORACLE_HOME_NAME is a unique name for the software home of this installation.
The oracle.install.db.InstallEdition has an option only for the Enterprise Edition (EE).
In previous releases, you can specify whether the installation was for
the Standard Editor or EE, but because you downloaded the EE software,
the response file has this parameter prepopulated with the value of EE.
Set your directory to the database directory (the
directory to which the downloaded zip files will extract). In this
directory, you’ll find the runInstaller executable. The response directory is a subdirectory of this directory. Now you can install the binaries by executing the runInstaller with the following command-line syntax:
$ ./runInstaller -silent -responseFile /tmp/db_install.rsp Starting Oracle Universal Installer... Checking Temp space: must be greater than 500 MB. Actual 3674 MB Passed Checking swap space: must be greater than 150 MB. Actual 4095 MB Passed Preparing to launch Oracle Universal Installer from /tmp/OraInstall2015-05-16_12-53-14PM. Please wait ...[oracle@dal66a database]$ You can find the log of this install session at: /u01/app/oraInventory/logs/installActions2015-05-16_12-53-14PM.log The installation of Oracle Database 12c was successful. Please check ’/u01/app/oraInventory/logs/silentInstall2015-05-16_12-53-14PM.log’ for more details. As a root user, execute the following script(s): 1. /u01/app/oraInventory/orainstRoot.sh 2. /u01/app/oracle/product/12.1.0.2/dbhome_1/root.sh Successfully Setup Software.
Once the installation completes successfully, as root execute both the orainstRoot.sh and root.sh scripts. In this example, the orainstRoot.sh script resides in the /u01/app/oraInventory directory, and the root.sh script resides in the /u01/app/oracle/product/12.1.0/dbhome_1 directory:
$ sudo /u01/app/oraInventory/orainstRoot.sh Changing permissions of /u01/app/oraInventory. Adding read,write permissions for group. Removing read,write,execute permissions for world. Changing groupname of /u01/app/oraInventory to oinstall. The execution of the script is complete. $ sudo /u01/app/oracle/product/12.1.0.2/dbhome_1/root.sh Check /u01/app/oracle/product/12.1.0.2/dbhome_1/install/root_dal66a_2015-05-16_13-22-19.log for the output of root script
You can now start using this new installation of the Oracle software and create a database.
Solution #2
In this solution, you’ll install the Oracle software
binaries to the designated target Oracle Home directory and also create
a database so that you can get a kick start into Oracle development and
deployment. This solution assumes that you have successfully uploaded
and unbundled the Oracle install software on your database server.
You’ll manipulate the same db_install.rsp response file as in Solution #1, except you’ll also input values for the Database Configuration Options section and change the oracle.install.option to INSTALL_DB_AND_CONFIG from INSTALL_DB_SWONLY. All the parameters needed to create the database in the Database Configuration Options start with oracle.install.db.xxxxxx.
Let’s review a sample response file that was
manipulated to install Oracle Database 12c software and to create a
database called DBATOOLS to the /oradata1 filesystem:
$ egrep -v "^#|^$" 12c_db_with_database.rsp |awk -F"=" ’{if ($2)print $1"=" $2}’ oracle.install.responseFileVersion=/oracle/install/rspfmt_dbinstall_response_schema_v12.1.0 oracle.install.option=INSTALL_DB_AND_CONFIG ORACLE_HOSTNAME=dal66a UNIX_GROUP_NAME=oinstall INVENTORY_LOCATION=/u01/app/oraInventory SELECTED_LANGUAGES=en ORACLE_HOME=/u01/app/oracle/product/12.1.0/dbhome_2 ORACLE_BASE=/u01/app/oracle oracle.install.db.InstallEdition=EE oracle.install.db.DBA_GROUP=dba oracle.install.db.OPER_GROUP=dba oracle.install.db.BACKUPDBA_GROUP=dba oracle.install.db.DGDBA_GROUP=dba oracle.install.db.KMDBA_GROUP=dba oracle.install.db.config.starterdb.type=GENERAL_PURPOSE oracle.install.db.config.starterdb.globalDBName=DBATOOLS oracle.install.db.config.starterdb.SID=DBATOOLS oracle.install.db.ConfigureAsContainerDB=true oracle.install.db.config.PDBName=vna01 oracle.install.db.config.starterdb.characterSet=WE8MSWIN1252 oracle.install.db.config.starterdb.memoryOption=false oracle.install.db.config.starterdb.memoryLimit=1024 oracle.install.db.config.starterdb.installExampleSchemas=false oracle.install.db.config.starterdb.password.ALL=oracle123 oracle.install.db.config.starterdb.password.SYS=oracle123 oracle.install.db.config.starterdb.password.SYSTEM=oracle123 oracle.install.db.config.starterdb.password.DBSNMP=oracle123 oracle.install.db.config.starterdb.password.PDBADMIN=oracle123 oracle.install.db.config.starterdb.managementOption=DEFAULT oracle.install.db.config.starterdb.enableRecovery=true oracle.install.db.config.starterdb.storageType=FILE_SYSTEM_STORAGE oracle.install.db.config.starterdb.fileSystemStorage.dataLocation=/oradata1 oracle.install.db.config.starterdb.fileSystemStorage.recoveryLocation=/oradata1 SECURITY_UPDATES_VIA_MYORACLESUPPORT=false DECLINE_SECURITY_UPDATES=true
Invoking the runInstaller command in silent mode and providing the configuration file mentioned previously produce the following results:
$ ./runInstaller -silent -responseFile /tmp/12c_db_with_database.rsp Starting Oracle Universal Installer... Checking Temp space: must be greater than 500 MB. Actual 3665 MB Passed Checking swap space: must be greater than 150 MB. Actual 4095 MB Passed Preparing to launch Oracle Universal Installer from /tmp/OraInstall2015-05-16_01-44-57PM. Please wait ...[oracle@dal66a database]$ [WARNING] [INS-30011] The ADMIN password entered does not conform to the Oracle recommended standards. CAUSE: Oracle recommends that the password entered should be at least 8 characters in length, contain at least 1 uppercase character, 1 lower case character and 1 digit [0-9]. ACTION: Provide a password that conforms to the Oracle recommended standards. You can find the log of this install session at: /u01/app/oraInventory/logs/installActions2015-05-16_01-44-57PM.log The installation of Oracle Database 12c was successful. Please check ’/u01/app/oraInventory/logs/silentInstall2015-05-16_01-44-57PM.log’ for more details. As a root user, execute the following script(s): 1. /u01/app/oraInventory/orainstRoot.sh 2. /u01/app/oracle/product/12.1.0/dbhome_2/root.sh Successfully Setup Software. As install user, execute the following script to complete the configuration. 1. /u01/app/oracle/product/12.1.0/dbhome_2/cfgtoollogs/configToolAllCommands RESPONSE_FILE=<response_file> Note: 1. This script must be run on the same host from where installer was run. 2. This script needs a small password properties file for configuration assistants that require passwords (refer to install guide documentation).
As you can see, the output looks very similar to the
output in Solution #1. The primary difference in this output is that you
are prompted to execute the $ORACLE_HOME/cfgtoollogs/configToolsAllCommands
script with the response file name as an input parameter. The response
file that is being requested is not the same as the response file used
for the software installation; it is a small password properties file.
The db_install.rsp response file doesn’t store any passwords, but the actual installation does prompt you for passwords for SYS, SYSTEM, DBSNMP, PDBADMIN, EMADMIN, and ASMSNMP users to configure the database.
Here’s a sample password properties file needed to configure the database deployment with passwords for the SYS, SYSTEM, DBSNMP, PDBADMIN, EMADMIN, and ASMSNMP accounts:
$ cat cfgrsp.properties oracle.assistants.server|S_SYSPASSWORD=oracle123 oracle.assistants.server|S_SYSTEMPASSWORD=oracle123 oracle.assistants.server|S_DBSNMPPASSWORD=oracle123 oracle.assistants.server|S_PDBADMINPASSWORD=oracle123 oracle.assistants.server|S_EMADMINPASSWORD=oracle123 oracle.assistants.server|S_ASMSNMPPASSWORD=oracle123
Note Once
you are finished with the installation, please remember to discard the
password properties file or change the passwords. For installation
purposes, please set the file permission to 600.
The output to the configToolAllCommands with the password property file is rather verbose and lengthy. Here’s a section of the generated output:
$ /u01/app/oracle/product/12.1.0/dbhome_2/cfgtoollogs/configToolAllCommands RESPONSE_FILE=/home/oracle/cfgrsp.properties Setting the invPtrLoc to /u01/app/oracle/product/12.1.0/dbhome_2/oraInst.loc perform - mode is starting for action: configure May 16, 2015 1:51:21 PM oracle.install.config.common.NetCAInternalPlugIn invoke INFO: NetCAInternalPlugIn: ... adding </ouiinternal> May 16, 2015 1:51:21 PM oracle.install.driver.oui.config.GenericInternalPlugIn invoke INFO: Executing NETCA May 16, 2015 1:51:21 PM oracle.install.driver.oui.config.GenericInternalPlugIn invoke INFO: Command /u01/app/oracle/product/12.1.0/dbhome_2/bin/netca /orahome /u01/app/oracle/product/12.1.0/dbhome_2 /orahnam OraDB12Home1 /instype typical /inscomp client,oraclenet,javavm,server,ano /insprtcl tcp /cfg local /authadp NO_VALUE /responseFile /u01/app/oracle/product/12.1.0/dbhome_2/network/install/netca_typ.rsp /silent /silent /ouiinternal May 16, 2015 1:51:21 PM ... ... ... oracle.install.driver.oui.config.GenericInternalPlugIn handleProcess INFO: Read: 78% complete May 16, 2015 2:00:17 PM oracle.install.driver.oui.config.GenericInternalPlugIn handleProcess WARNING: Skipping line: 78% complete May 16, 2015 2:00:17 PM oracle.install.driver.oui.config.GenericInternalPlugIn handleProcess INFO: Read: 100% complete May 16, 2015 2:00:17 PM oracle.install.driver.oui.config.GenericInternalPlugIn handleProcess WARNING: Skipping line: 100% complete May 16, 2015 2:00:17 PM oracle.install.driver.oui.config.GenericInternalPlugIn handleProcess INFO: Read: Look at the log file "/u01/app/oracle/cfgtoollogs/dbca/DBATOOLS/DBATOOLS.log" for further details. May 16, 2015 2:00:17 PM oracle.install.driver.oui.config.GenericInternalPlugIn handleProcess WARNING: Skipping line: Look at the log file "/u01/app/oracle/cfgtoollogs/dbca/DBATOOLS/DBATOOLS.log" for further details. perform - mode finished for action: configure You can see the log file: /u01/app/oracle/product/12.1.0/dbhome_2/cfgtoollogs/oui/configActions2015-05-16_01-51-20-PM.log
As a final validation, you have to review the log file
and check to see whether the database is running. First, review the
configuration tools log file to confirm that you have reached 100%
progress for DBCA:
$ cat /u01/app/oracle/cfgtoollogs/dbca/DBATOOLS/DBATOOLS.log Unique database identifier check passed. /oradata1/ has enough space. Required space is 7665 MB , available space is 61030 MB. File Validations Successful. Copying database files DBCA_PROGRESS : 1% DBCA_PROGRESS : 2% DBCA_PROGRESS : 27% Creating and starting Oracle instance .. Completing Database Creation .. Creating Pluggable Databases DBCA_PROGRESS : 78% DBCA_PROGRESS : 100% Database creation complete. For details check the logfiles at: /u01/app/oracle/cfgtoollogs/dbca/DBATOOLS. Database Information: Global Database Name:DBATOOLS System Identifier(SID):DBATOOLS
You can perform a couple of basic health checks to validate that the DBATOOLS
database is running and the database listener is up by checking on the
PMON process and the database listener process. With the ps command, you can filter on the process listing for the keywords pmon and tns, separated by a pipe to denote that you’re looking for both conditions with the egrep command.
You can also introduce a grep command with a –v option to ignore output that has the word grep in the list, as shown here:
$ ps -ef |egrep “pmon|tns” |grep -v grep oracle 8357 1 0 13:59 ? 00:00:00 ora_pmon_DBATOOLS root 15 2 0 13:27 ? 00:00:00 [netns] oracle 7486 1 0 13:51 ? 00:00:00 /u01/app/oracle/product/12.1.0/dbhome_2/bin/tnslsnr LISTENER -inherit
How It Works
Using a response file allows you to fully automate
the installation and configuration of Oracle software. The Oracle
Universal Installer reads the values you specify in the response file to
perform the installation. This technique is desirable in several
scenarios. For example, if you often perform remote installs across a
WAN with limited bandwidth, using the graphical installer may not be an
option (because of extremely slow response times and network hangups).
You can easily customize the response file for
database options required for your environment. You can then reuse the
same response file for future installations. The silent installation
technique allows you to perform repeatable and standardized Oracle
installations and even upgrades. You can document the exact steps
required and have junior DBAs and/or SAs install the oracle binaries using a response file.
As a surprise to some DBAs, you can create your own custom response file with the runInstaller program and the -record option. In essence, your selections during the runInstaller session will be recorded into the specified response file name. The syntax to create a custom response file looks like this:
./runInstaller -record -destinationFile /tmp/custom_db_install.rsp
The -destinationFile
option specifies the location of the target response file. You don’t
have to actually perform an install to create a response file. As long
as you navigate to the Summary screen of the installation process, the
response file will be created.
Make sure that the value you specify for ORACLE_HOME doesn’t conflict with an already existing home in the oraInst.loc file. This file is usually located in the /etc directory. For ORACLE_HOME_NAME, review the contents of the inventory.xml file located in the OraInventory subdirectory, which is usually located in the $ORACLE_BASE/../oraInventory/ContentsXML directory (i.e., /u01/app/oraInventory/ContentsXML directory).
11-11. Creating a Database with a Response File
Problem
You can’t launch the DBCA in GUI mode because your
network connectivity is extremely slow or because you are behind
multiple firewalls in an extremely secure data center. You want to
create a database with the DBCA in silent mode.
You want to automate your database builds and to build databases with consistent configurations and initialization parameters.
Solution
The good news is that you can create a database in silent mode after you modify the dbca.rsp
response file to your desired configuration. This particular solution
demonstrates the simplicity of creating a database after modifying a
minimal number of parameters in the dbca.rsp response file. At a minimum, the parameters OPERATION_TYPE, GDBNAME, SID, TEMPLATE_NAME, SYSPASSWORD, SYSTEMPASSWORD, DATAFILEDESTINATION, STORAGETYPE, CHARACTERSET, and NATIONALCHARACTERSET should be modified.
Oracle Database 12c has the multitenancy option to create pluggable databases (PDBs). You can enable PDBs by setting the CREATEASCONTAINERDATABASES to yes and then specifying the NUMBEROFPDBS, PDBPREFIX, and PDBADMINPASSWORD parameters. In this example, all the previously mentioned parameters in the dbca.rsp file were modified after the original file was backed up to dbca.rsp.BKUP.
Here’s a sample dbca.rsp response file in the /tmp directory that has been manipulated to create a database called TOOLSDEV with two pluggable databases. To reveal just the modified responses, leverage the egrep command with the –v option to ignore all lines that start with a comment and blank lines:
$ cat /tmp/dbca.rsp |egrep -v "^#|^$" [GENERAL] RESPONSEFILE_VERSION = "12.1.0" OPERATION_TYPE = "createDatabase" [CREATEDATABASE] GDBNAME = "TOOLSDEV" SID = "TOOLSDEV" CREATEASCONTAINERDATABASE =yes NUMBEROFPDBS =2 PDBNAME =vna PDBADMINPASSWORD = "oracle123" TEMPLATENAME = "General_Purpose.dbc" SYSPASSWORD = "oracle123" SYSTEMPASSWORD = "oracle123" EMCONFIGURATION = "NONE" DATAFILEDESTINATION =/oradata1 RECOVERYAREADESTINATION=/oradata1 STORAGETYPE=FS CHARACTERSET = "AL32UTF8" NATIONALCHARACTERSET= "AL16UTF16" DATABASETYPE = "MULTIPURPOSE" AUTOMATICMEMORYMANAGEMENT = "FALSE" TOTALMEMORY = "1024"
Because the software is already installed, you have to launch dbca in silent mode from $ORACLE_HOME/bin directory. In this solution, dbca is launched with the -silent parameter and the -responseFile parameter, followed by the location of the response file:
$ dbca -silent -responseFile /tmp/dbca.rsp Cleaning up failed steps 5% complete Copying database files 7% complete 9% complete 41% complete Creating and starting Oracle instance 43% complete 48% complete 53% complete 57% complete 58% complete 59% complete 62% complete 64% complete Completing Database Creation 68% complete 71% complete 75% complete 85% complete 96% complete 100% complete Look at the log file "/u01/app/oracle/cfgtoollogs/dbca/TOOLSDEV/TOOLSDEV0.log" for further details.
In silent mode, dbca provides a progress status to notify you where it is in the database-creation process. During the initial phase, RMAN performs a restore of the data files. Once the restore is complete, dbca creates and starts the instance. Finally, post–database configuration steps are executed.
After the database is created, you can view the log file in the $ORACLE_BASE/cfgtoollogs/dbca/$ORACLE_SID directory. You’ll also notice an entry in the /etc/oratab file for the new database named TOOLSDEV:
TOOLSDEV:/apps/oracle/product/11.1.0/DB:N
How It Works
Nowadays, creating databases with the DBCA is
standard in many organizations. Many DBAs launch the DBCA and configure
databases in GUI mode, but a few exploit the options available to them
using the response file. By effectively leveraging DBCA with the silent
option, you can automate database creation and create databases
consistently across the organization. You can modify the dbca.rsp
file to build databases on ASM and even create RAC databases. You can
control almost every aspect of the response file similar to launching
the DBCA in GUI mode. Your DBA organization should seriously consider
standardizing on creating databases in silent mode using the dbca.rsp response file.
You can also leverage DBCA without a response file and fully supply all the parameters to create databases. The following dbca code example creates a general-purpose database called oraprod on the /oradata01 filesystem with the recovery area destination to the /fra01 filesystem. We’re also creating redo logs that are 500MB in size and multiplexing the redo logs across the /oradata01 and /fra01
filesystems. We have disabled Enterprise Manager Express configuration
in favor of the Oracle Enterprise Manager Cloud Control 12c
configuration to be done in the future. We have set pertinent
initialization parameters with the initparams parameters.
Here’s the dbca code example that creates a database, including setting pertinent initialization parameters:
./dbca -silent \ -createDatabase \ -templateName General_Purpose.dbc \ -gdbName oraprod \ -createAsContainerDatabase false \ -emConfiguration none \ -datafileDestination ’/oradata01’ \ -recoveryAreaDestination ’/fra01’ \ -storageType FS \ -sid oraprod \ -SysPassword oracle123 \ -SystemPassword oracle123 \ -emConfiguration none \ -redoLogFileSize 500 \ -listeners LISTENER \ -registerWithDirService false \ -characterSet WE8ISO8859P1 \ -nationalCharacterSet AL16UTF16 \ -databaseType MULTIPURPOSE \ -initparams audit_file_dest=’/app/oracle/admin/oraprod/adump’ \ -initparams compatible=’12.1.0.2’ \ -initparams db_create_file_dest=’/oradata01’ \ -initparams db_create_online_log_dest_1=’/oradata01’ \ -initparams db_create_online_log_dest_2=’/fra01’ \ -initparams db_recovery_file_dest=’/fra01’ \ -initparams pga_aggregate_target=1024 \ -initparams diagnostic_dest=’/app/oracle’ \ -initparams parallel_max_servers=20 \ -initparams processes=500 \ -initparams sga_target=10240 \ -initparams control_files=’/oradata01/oraprod/control01.ctl’ \ -initparams db_recovery_file_dest_size=25000
Note The
backslash (\) is needed because DBCA expects a single-line command with
all the parameters. In a nutshell, the backslash escape character tells
the shell to ignore the next character. In this example, the backslash
tells the shell to ignore the newline character, thus making the entire
script appear as a single line to DBCA.
11-12. Creating a Network Configuration with a Response File
Problem
You struggle to launch Oracle Network Configuration Assistant (NETCA)
in GUI mode because your network connectivity is extremely slow or
because you are behind multiple firewalls in an extremely secure data
center. You want to create a database listener with NETCA in silent
mode.
Solution
You can launch NETCA in silent mode by using a response file. Here’s a sample response file with modifications called netca.rsp:
$ cat /tmp/net.rsp [GENERAL] RESPONSEFILE_VERSION="12.1" CREATE_TYPE= "CUSTOM" LOG_FILE=“”/tmp/netca.log“” [Session] ORACLE_HOME="/u01/app/oracle/product/12.1.0/dbhome_2" [oracle.net.ca] INSTALLED_COMPONENTS={"server","net8","javavm"} INSTALL_TYPE=“”custom“” LISTENER_NUMBER=1 LISTENER_NAMES={"LISTENER"} LISTENER_PROTOCOLS={"TCP;1521"} LISTENER_START=“” NAMING_METHODS={"LDAP","TNSNAMES","HOSTNAME"} NSN_PROTOCOLS={"TCP;HOSTNAME;1521"} NSN_NUMBER=3 NSN_NAMES={"DEV","DBATOOLS","RMANPROD"} NSN_SERVICE = {"DEV","DBATOOLS","RMANPROD"} NSN_PROTOCOLS={"TCP;rac5.dbaexpert.com;1521","TCP;rac6.dbaexpert.com;1521","TCP;rac7.dbaexpert.com;1521"}
Executing NETCA in silent mode and passing the modified response file /tmp/net.rsp yields the following output:
$ netca -silent -responseFile /tmp/net.rsp Sun May 17 07:20:03 CDT 2015 Oracle Net Configuration Assistant Parsing command line arguments: Parameter "silent" = true Parameter "responsefile" = /tmp/net.rsp Parameter "log" = /tmp/netca.log Done parsing command line arguments. Oracle Net Services Configuration: Configuring Listener:LISTENER Listener configuration complete. Oracle Net Listener Startup: Running Listener Control: /u01/app/oracle/product/12.1.0/dbhome_2/bin/lsnrctl start LISTENER Listener Control complete. Listener started successfully. Default local naming configuration complete. Created net service name: DEV Default local naming configuration complete. Created net service name: DBATOOLS Default local naming configuration complete. Created net service name: RMANPROD Profile configuration complete. Oracle Net Services configuration successful. The exit code is 0
Behind the scenes, NETCA created three files in the $ORACLE_HOME/network/admin directory: sqlnet.ora, tnsnames.ora, and listener.ora. The output to NETCA is logged in the /tmp/netca.log file.
How It Works
Although DBAs often don’t realize the potential of
automation through response files, they can configure Oracle’s network
topology in a single command by launching NETCA. With the proper
standardization in directory structures and naming conventions, DBAs can
script and manipulate the network configuration response files by
leveraging executables such as awk and sed.
You can specify an alternate location for the netca log file by modifying the LOG_FILE parameter. Similar to the other silent installations, you must specify a valid ORACLE_HOME directory. The other portions of the netca response file that require explanation are the NSN_ parameters (NSN stands for number of service names). The parameter NSN_PROTOCOLS defines the protocol and associated parameters for each service name. The parameter NSN_NUMBER
defines the number of service names to create. For this particular
solution, the response file defines three service names to create in the
tnsnames.ora file. The names of the TNSNAMES connect strings are defined to be DEV, RMANPROD, and DBATOOLS. All three of the TNSNAMES connect strings leverage service names. For this solution, you want every server to have entries for DBATOOLS and RMANPROD.
Here’s the contents of the tnsnames.ora file:
$ cat tnsnames.ora # tnsnames.ora Network Configuration File: /u01/app/oracle/product/12.1.0/dbhome_2/network/admin/tnsnames.ora # Generated by Oracle configuration tools. RMANPROD = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = rac7.dbaexpert.com)(PORT = 1521)) ) (CONNECT_DATA = (SERVICE_NAME = RMANPROD) ) ) DEV = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = rac5.dbaexpert.com)(PORT = 1521)) ) (CONNECT_DATA = (SERVICE_NAME = DEV) ) ) DBATOOLS = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = rac6.dbaexpert.com)(PORT = 1521)) ) (CONNECT_DATA = (SERVICE_NAME = DBATOOLS) ) )
Likewise, NETCA generated the following entries in the listener.ora file:
$ cat listener.ora # listener.ora Network Configuration File: /u01/app/oracle/product/12.1.0/dbhome_2/network/admin/listener.ora # Generated by Oracle configuration tools. LISTENER = (DESCRIPTION_LIST = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = dal66a)(PORT = 1521)) (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521)) ) )
Finally, NETCA produces the sqlnet.ora file, which contains this single entry to define the directory path:
NAMES.DIRECTORY_PATH= (LDAP, TNSNAMES, HOSTNAME)
11-13. Applying Patch Set Updates (PSUs) and Interim Patches
Problem
You have to apply a patch set update (PSU) or interim patches to resolve a database issue or eradicate a bug you encountered in your database.
Solution
Most of the time, applying a patch is simple with the opatch command-line interface, which accepts numerous arguments. The syntax for opatch is as follows:
$ ./opatch -help Oracle Interim Patch Installer version 12.1.0.1.7 Copyright (c) 2015, Oracle Corporation. All rights reserved. Usage: opatch [ -help ] [ -report ] [ command ] command := apply compare lsinventory lspatches napply nrollback rollback query version prereq util
The most common supplied opatch arguments are these:
- apply
- lsinventory
- rollback
- version
Let’s take, for example, the April 2015 Patch
20299023—Database Patch Set Update 12.1.0.2.3 (includes CPUApr2015). You
can download the patch file p20299023_121020_Linux-x86-64.zip to your download directory and extract the compressed archived file with the unzip command. If you want to see the contents of the .zip file without extracting the file, pass the -l argument to the unzip command. The unzip command will create a directory called 20299023 and extract all the files into the directory.
If this is the first PSU going on the Oracle Home, or
if you have not patched in a while, you also have to download and apply
patch 6880880, which happens to be the patch update for OPatch. You have
to download patch 6880880 from support.oracle.com or follow the download link from https://updates.oracle.com/download/6880880.html.
This patch is extremely simple to apply. Simply
download the patch, upload the zip file to your server, unzip the
contents of the patch, and replace the contents of the $ORACLE_HOME/OPatch directory with the OPatch
unzipped directory from this patch. If you are applying this patch for
the Grid Infrastructure (GI) home, you must replace the contents of the OPatch directory as root.
For most patches, you can read the README.txt file
located in the base directory of the patch, which has explicit
directions on how to apply the patch. Although the majority of patches
require a simple apply parameter, some
patches have prerequisite and postpatch steps. Some patches may even
require multiple dependent patches to be executed.
The README.txt file for PSUs will indicate that you have to read the README.html file. As a general rule, prior to applying any patch, the database must be shut down. Oracle does provide what is known as an online patch for which the database doesn’t have to be shut down for high availability considerations. You must examine the README.txt (or in this case, the README.html
file) to see whether a particular patch qualifies as an online patch.
Because this particular PSU requires the database to be shut down,
you’ll incur an outage window to apply the patch.
The opatch executable is located in the $ORACLE_HOME/OPatch directory. The easiest way to apply a patch is to include the opatch executable to your PATH environment variable. To do so, simply export your PATH environment variable as $ORACLE_HOME/OPatch:$PATH.
Note Make sure to run the command opatch apply as the oracle account from the uncompressed patch subdirectory. Also, the OS environment variable ORACLE_HOME has to be set accordingly before running opatch.
The directory is already changed to 20299023. Based on the README.html file, you can apply this patch with the command opatch apply.
Here’s the OPatch process in action to apply this PSU:
$ opatch apply Oracle Interim Patch Installer version 12.1.0.1.7 Copyright (c) 2015, Oracle Corporation. All rights reserved. Oracle Home : /u01/app/oracle/product/12.1.0/dbhome_2 Central Inventory : /u01/app/oraInventory from : /u01/app/oracle/product/12.1.0/dbhome_2/oraInst.loc OPatch version : 12.1.0.1.7 OUI version : 12.1.0.2.0 Log file location : /u01/app/oracle/product/12.1.0/dbhome_2/cfgtoollogs/opatch/opatch2015-05-16_17-48-29PM_1.log Verifying environment and performing prerequisite checks... OPatch continues with these patches: 19769480 20299023 Do you want to proceed? [y|n] y User Responded with: Y All checks passed. Provide your email address to be informed of security issues, install and initiate Oracle Configuration Manager. Easier for you if you use your My Oracle Support Email address/User Name. Visit http://www.oracle.com/support/policies.html for details. Email address/User Name: You have not provided an email address for notification of security issues. Do you wish to remain uninformed of security issues ([Y]es, [N]o) [N]: Y Please shutdown Oracle instances running out of this ORACLE_HOME on the local system. (Oracle Home = ’/u01/app/oracle/product/12.1.0/dbhome_2’) Is the local system ready for patching? [y|n] y User Responded with: Y Backing up files... Applying sub-patch ’19769480’ to OH ’/u01/app/oracle/product/12.1.0/dbhome_2’ Patching component oracle.rdbms.deconfig, 12.1.0.2.0... Patching component oracle.xdk, 12.1.0.2.0... Patching component oracle.tfa, 12.1.0.2.0... Patching component oracle.rdbms.util, 12.1.0.2.0... Patching component oracle.rdbms, 12.1.0.2.0... Patching component oracle.rdbms.dbscripts, 12.1.0.2.0... Patching component oracle.xdk.parser.java, 12.1.0.2.0... Patching component oracle.oraolap, 12.1.0.2.0... Patching component oracle.xdk.rsf, 12.1.0.2.0... Patching component oracle.rdbms.rsf, 12.1.0.2.0... Patching component oracle.rdbms.rman, 12.1.0.2.0... Patching component oracle.ldap.rsf, 12.1.0.2.0... Patching component oracle.ldap.rsf.ic, 12.1.0.2.0... Verifying the update... Applying sub-patch ’20299023’ to OH ’/u01/app/oracle/product/12.1.0/dbhome_2’ ApplySession: Optional component(s) [ oracle.has.crs, 12.1.0.2.0 ] not present in the Oracle Home or a higher version is found. Patching component oracle.tfa, 12.1.0.2.0... Patching component oracle.rdbms.deconfig, 12.1.0.2.0... Patching component oracle.rdbms.rsf, 12.1.0.2.0... Patching component oracle.rdbms, 12.1.0.2.0... Patching component oracle.rdbms.dbscripts, 12.1.0.2.0... Patching component oracle.rdbms.rsf.ic, 12.1.0.2.0... Patching component oracle.ldap.rsf, 12.1.0.2.0... Patching component oracle.ldap.rsf.ic, 12.1.0.2.0... Verifying the update... Composite patch 20299023 successfully applied. Log file location: /u01/app/oracle/product/12.1.0/dbhome_2/cfgtoollogs/opatch/opatch2015-05-16_17-48-29PM_1.log OPatch succeeded.
Now check the inventory to see whether the patch exists. To view the patch list, pass the lsinventory argument to the opatch command, as shown here:
[oracle@dal66a 20299023]$ opatch lsinventory |grep ^Patch Patch 20299023 : applied on Sat May 16 17:49:12 CDT 2015 Patch description: "Database Patch Set Update : 12.1.0.2.3 (20299023)"
In this inventory listing, you are filtering on the output and are looking for a line that starts with the word Patch to determine applied patches.
Note The ^ (caret) sign, designated by pressing Shift+6, represents the metacharacter for the beginning of the line. By filtering on ^Patch from the output of the opatch inventory command, you are looking for the first letter of the line that starts with Patch to retrieve a high-level summary of just the patches that have been successfully applied to the Oracle Home.
You can see from the output that 12.0.1.2.3 PSU is applied to the Oracle Home. You can execute the command opatch lsinventory -detail to produce a detailed output of all the patches.
You are not quite finished. You still have to perform
the postpatch operations against each database that leverages this
Oracle Home. In Oracle Database 11g with the PSU, the database is
patched by executing the catbundle.sql SQL script:
SQL> @catbundle.sql psu apply
Starting in Oracle Database 12c, you have to execute the datapatch script from the $ORACLE_HOME/OPatch directory:
$ cd $ORACLE_HOME/OPatch $ ./datapatch –verbose
datapatch replaces the need to execute the catbundle.sql script to apply the database portion of the database.
How It Works
OPatch is a collection of Perl scripts and Java
classes providing the capability to apply and roll back PSUs and interim
(one-off) patches to an Oracle database environment. opatch is the primary driver that calls the Perl modules and Java classes. Although the minimum perl requirement is 5.005_03, Oracle recommends the perl
version to be at least 5.6 or greater. You can download OPatch from
MetaLink from the Patches & Updates tab by performing a simple
search on patchset 6880880. For additional information, please review MetaLink Note 224346.1.
OPatch requires a Java Runtime Environment (JRE) to be
available on the Linux server. In addition, it has requirements for
system commands such as jar, fuser, ar, and make on the Linux servers. Patch information and backups reside in the $ORACLE_HOME/.patch_storage/{patch_file} directory.
Just as you can install a patch with the apply parameter, you can uninstall a patch with the rollback parameter. The rollback parameter accepts an additional parameter, -id, to specify the patch number to roll back.
In this example, you roll back the same patch that was applied in the solution:
$ opatch rollback -id 20299023
Oracle offers a cumulative quarterly patch of the most
critical fixes of known bugs and issues in PSUs. Customers are
encouraged to apply PSUs to avoid many of the known problems. We
recommend that customers apply N-1 on PSUs. For the month of April,
customers should apply January’s PSUs. If your go-live date is far in
the future, you can apply the most recent PSU.
Oracle provides its quarterly security patch updates (SPUs)—formerly known as critical patch updates (CPUs)—to
address security vulnerabilities to the database and application server
products. Nonsecurity patches are often included in the CPU because
they are dependent patches. You probably receive e-mail updates telling
you when they are available for download. We recommend that you closely
scrutinize the quarterly SPUs and apply them in a timely manner.
Note If
you have the GI stack and Oracle Database Software, the GI stack must
always be at a higher version, higher patch set, and higher PSU than the
Oracle Database Software.
11-14. Cloning an Oracle Home
Problem
You want to easily clone a fully patched Oracle software installation from one database server to another database server. You want the cloning process
to be a simple zip and unzip of the software to a new server and to
fully benefit from all the patches that were applied on the original
server.
Solution
If you happen to be a DBA who still creates tar
archives of the Oracle binaries, you can continue to, as the saying
goes, have your cake and eat it too. It is much easier to copy the
Oracle binaries than it is to install the software from the CD or
unzipped media software, especially if the source Oracle software is
fully patched with the latest release of Oracle PSUs/one-off patches or
with a set of patches that has been fully vetted by the quality
assurance (QA) team.
You can accomplish in one command what can take hours
if you have slow WAN connectivity between your desktop and the Linux
server. With one command, you can provide an Oracle software stack that
is fully patched that might take you days to deliver if your Oracle Home
has lots of patches installed. If you are not comfortable with the
silent installation option, you also have to find an X server or VNC
server to which you set the DISPLAY environment variable.
In this solution, you see how to clone an Oracle Home after you transfer the binaries from another server using the rcp/scp, tar, zip/unzip, or rsh/ssh command. First, set the ORACLE_HOME environment variable to the new directory you just copied over. For example, the ORACLE_HOME environment variable for this solution is set to /app/oracle/product/12.1.0.2/db. From the $ORACLE_HOME/clone/bin directory, execute the perl command as shown here to clone the Oracle Database Software to the new database server:
$ perl clone.pl ORACLE_HOME=/app/oracle/product/12.1.0.2/db ORACLE_HOME_NAME=12102_home_base ORACLE_BASE=/app/oracle/product -ignoreSysPrereqs -invPtrLoc /etc/oraInst.loc ./runInstaller -clone -waitForCompletion "ORACLE_HOME=/app/oracle/product/12.1.0.2/db" "ORACLE_HOME_NAME=12102_home_base" "ORACLE_BASE=/app/oracle/product" -ignoreSysPrereqs -invPtrLoc /etc/oraInst.loc -silent -paramFile /app/oracle/product/12.1.0.2/db/clone/clone_oraparam.ini Starting Oracle Universal Installer... Checking Temp space: must be greater than 500 MB. Actual 29399 MB Passed Checking swap space: must be greater than 500 MB. Actual 3967 MB Passed Preparing to launch Oracle Universal Installer from /tmp/OraInstall2015-02-12_02-57-31PM. Please wait ...You can find the log of this install session at: /app/oracle/oraInventory/logs/cloneActions2015-02-12_02-57-31PM.log .................................................. 5% Done. .................................................. 10% Done. .................................................. 15% Done. .................................................. 20% Done. .................................................. 25% Done. .................................................. 30% Done. .................................................. 35% Done. .................................................. 40% Done. .................................................. 45% Done. .................................................. 50% Done. .................................................. 55% Done. .................................................. 60% Done. .................................................. 65% Done. .................................................. 70% Done. .................................................. 75% Done. .................................................. 80% Done. .................................................. 85% Done. .......... Copy files in progress. Copy files successful. Link binaries in progress. Link binaries successful. Setup files in progress. Setup files successful. Setup Inventory in progress. Setup Inventory successful. Finish Setup successful. The cloning of 12102_home_base was successful. Please check ’/app/oracle/oraInventory/logs/cloneActions2015-02-12_02-57-31PM.log’ for more details. Setup Oracle Base in progress. Setup Oracle Base successful. .................................................. 95% Done. As a root user, execute the following script(s): 1. /app/oracle/product/12.1.0.2/db/root.sh .................................................. 100% Done.
As part of the prerequisite checks, the cloning process will determine whether you have enough space in the /tmp
directory and sufficient swap space is available for Oracle. The
cloning process will reset various shell scripts and modify metadata
information with the local host information.
invPtrLoc is an optional parameter that specifies the fully qualified file name that contains the location of the oraInventory. The invPtrLoc parameter should not be used in a RAC environment. The oraInst.loc file, by default, is located in the /etc directory in the Linux OS and looks like this:
inventory_loc=/u01/app/oraInventory inst_group=oinstall
By default, inventory_loc will point one level below the $ORACLE_BASE directory of the oracle user account (/u01/app/oraInventory when ORACLE_BASE is /u01/app/oracle). As a precautionary measure, you should back up the oraInventory directory prior to attaching an Oracle Home. When you execute root.sh, it will also execute root.sh in silent mode.
How It Works
DBAs still continue to tar and un-tar
the Oracle binaries from one server to another. In some companies,
especially in non-RAC environments, DBAs copy the binaries from
development database servers to QA and production database servers with a
command such as tar piped to ssh.
Here’s a popular one-liner script that you can
leverage to copy Oracle binaries from one directory level above the
Oracle Home to the target node:
tar cvf - {DIR_NAME} |ssh {target_node} "cd /apps/oracle/product/12.1.0.2; tar xvf -"
Note There
is no requirement to shut down databases or listeners prior to copying
the Oracle Database Software from the source database server to the
target database server. For the GI software, you must unlock the GI
software stack, which will shut down the cluster.
The tar command piped to ssh
ensures that symbolic links get copied over as symbolic links. The best
thing about this approach is that you don’t have to incur double
storage to store a local and remote copy of the tar archive.
Perl version 5.6 or higher is required when cloning
Oracle Database 12c. When cloning Oracle software to a new server, make
sure that all the prerequisite requirements are met as the perl clone.pl process doesn’t validate them.
Starting from Oracle Database 10g, Oracle supports
cloning of Oracle Homes from source and target servers. The target
server has to have all the Linux prerequisites and packages installed to
ensure that the cloning process will be successful. You can clone the
production Oracle Home to the lower environments, such as QA or DEV
environments, to ensure that all the patches are identical from source
and target Oracle Homes. You can strategically position the cloning
process to upgrade a database from the current release to a higher
release. For example, you can clone a newer version of the Oracle Home
to the production database server. During the cutover window, you can
simply switch Oracle Homes to the newer version and execute the post
installation scripts to upgrade the database catalog.
11-15. Attaching an Oracle Home
Problem
You want to merge multiple Oracle inventories or rebuild/re-create the central inventory of all the Oracle Homes because the inventory is corrupt.
Solution
From the $ORACLE_HOME/oui/bin directory, you can execute the attachHome.sh shell script. Oracle provides a shell script to attach the Oracle Home to the oraInventory. The attachHome.sh script has the following content:
$ cat attachHome.sh #!/bin/sh OHOME=/u01/app/oracle/product/12.1.0/dbhome_2 OHOMENAME=OraDB12Home1 CUR_DIR=`pwd` cd $OHOME/oui/bin ./runInstaller -detachhome ORACLE_HOME=$OHOME ORACLE_HOME_NAME=$OHOMENAME $* > /dev/null 2>&1 ./runInstaller -attachhome ORACLE_HOME=$OHOME ORACLE_HOME_NAME=$OHOMENAME $* cd $CUR_DIR
Executing the attachHome.sh script yields the following results:
$ ./attachHome.sh Starting Oracle Universal Installer... Checking swap space: must be greater than 500 MB. Actual 4095 MB Passed The inventory pointer is located at /etc/oraInst.loc ’AttachHome’ was successful.
According to the attachHome.sh shell script, the script first detaches the Oracle Home from the oraInventory prior to attaching the new Oracle Home. In previous releases of Oracle, the runInstaller program was executed with the –attachHome option and provided the Oracle Home location and the Oracle Home name, as shown here:
$ ./runInstaller -silent -attachHome ORACLE_HOME="/u01/app/oracle/product/12.1.0/dbhome_2" ORACLE_HOME_NAME=" OraDB12Home1" Starting Oracle Universal Installer... Checking swap space: must be greater than 500 MB. Actual 8174 MB Passed The inventory pointer is located at /etc/oraInst.loc ’AttachHome’ was successful.
You can even attach RAC Oracle Homes by specifying an additional parameter called CLUSTER_NODES, which has to be enclosed in curly brackets, as shown here:
CLUSTER_NODES={rac3,rac4}
How It Works
Execute the attachHome.sh shell script to attach the Oracle Home to the central Oracle inventory. You have to execute the attachHome.sh
script from each of the Oracle Homes. Once you have successfully
attached the new Oracle Home, you can view the contents of the inventory.xml file to confirm that the new Oracle Home is listed.
As stated earlier, the oraInventory directory location resides one level below $ORACLE_BASE. Here’s what the inventory.xml file looks like:
$ cat $ORACLE_BASE/../oraInventory/ContentsXML/inventory.xml <?xml version="1.0" standalone="yes" ?> <!-- Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved. --> <!-- Do not modify the contents of this file by hand. --> <INVENTORY> <VERSION_INFO> <SAVED_WITH>12.1.0.2.0</SAVED_WITH> <MINIMUM_VER>2.1.0.6.0</MINIMUM_VER> </VERSION_INFO> <HOME_LIST> <HOME NAME="OraDB12Home1" LOC="/u01/app/oracle/product/12.1.0/dbhome_2" TYPE="O" IDX="1"/> </HOME_LIST> <COMPOSITEHOME_LIST> </COMPOSITEHOME_LIST> </INVENTORY>
You can see that the ORACLE_HOME_NAME of OraDB12Home1 is listed as a member in the XML inventory file.
CHAPTER 12
VirtualBox for Oracle
Oracle VM VirtualBox, formerly known as Sun VirtualBox or Sun xVM VirtualBox, is a hypervisor for x86 computers from Oracle Corporation. Oracle VM VirtualBox
is a cross–platform virtualization software that allows you to run
multiple OSs at the same time on Windows, Mac OS X, Linux, and Oracle
Solaris OSs. Many IT professionals heavily leverage VirtualBox to learn
new and emerging technologies. VirtualBox allows IT professionals to
test, develop, demo, and deploy their applications and databases on
virtual machines (VMs) on their local desktops or laptops.
There are two types of hypervisors: type 1 (native or bare-metal) and type 2 (hosted). A type 1 hypervisor
runs directly on a physical server with no software layer between the
hypervisor and the physical hardware, which is why it is often referred
to as a bare metal hypervisor. This hypervisor is designed to be
extremely fast for enterprise environments. VMware ESXi, Oracle VM,
Linux KVM, Hyper-V, and Citrix XenServer are all examples of type 1
hypervisors. Hypervisors are very different in their functionality and
features. Hypervisors VMware, Hyper-V, OVM, and KVM have a lot of
similarities, but they are also very different. Just as Oracle, SQL
Server, and MySQL are relational databases, there are significant
differences in how they do things, as well as the environments and
ecosystems in which they run.
A type 2 hypervisor
runs on top of an OS such as Windows (VMWare Workstation) or a Mac
(VMware Fusion), and VirtualBox (which runs on the following platforms:
Linux, Solaris, Windows, and Mac). With a type 2 hypervisor, the VM has
to go through the hypervisor software as well as the OS, thus inducing
additional overhead. A type 2 hypervisor is great for running multiple
VMs on laptops and PCs. VMware Workstation, Parallels, and VirtualBox
are additional examples of type 2 hypervisors.
This chapter focuses on installing and configuring Oracle VM VirtualBox to set up a VM to host Oracle databases.
You’ll proceed with creating additional virtual disks for Oracle ASM
virtual disks and presenting the virtual disks to other VMs as shared
storage. The chapter also briefly mentions the network infrastructure
available for VirtualBox.
You’ll dive in to the details of creating and
maintaining Linux templates, cloning new Linux VMs ready for instant
deployment from golden image templates, and managing snapshots.
12-1. Installing Oracle VM VirtualBox
Problem
You want to install Oracle VM VirtualBox to get started on the virtualization journey.
Solution
You can download and install Oracle VM VirtualBox from http://www.oracle.com/technetwork/server-storage/virtualbox/downloads/index.html#vbox.
Oracle VM VirtualBox software is available for Windows, Mac OS X,
Solaris 10+, and Linux platforms. Installing VirtualBox is simple and
straightforward, and can be completed in minutes.
This example shows what the installation on a Mac OS
looks like. If you downloaded the VirtualBox for the Mac, you have a
file name that resembles VirtualBox-4.3.26-98988-OSX.dmg. You see the installer shown in Figure 12-1 when you double-click the .dmg file.
Figure 12-1. VirtualBox installer software
Double-click the Virtualbox.pkg
icon to start the installation. On the Mac, you are directed to a
window that specifies that the package needs to run a program to
determine whether the software can be installed. Confirm that you agree
by clicking the Continue button to proceed to the Welcome screen. From
the Welcome screen, you can click the Continue button to proceed with
the installation.
On the Standard install screen, you can change the
default installation location of the binaries. By clicking the Install
button, you’ll be prompted to enter the Username and Password for an
administrative account that has privileges to install software on the
machine to continue. When the installation completes, you’ll see a
success window indicating that the software was installed without
issues.
As you can see from the installation procedures, VirtualBox is extremely simple to install and use.
How It Works
By learning to implement VirtualBox, you are
beginning the steps of creating a virtual infrastructure on your
Windows, Mac, or Linux machine. VirtualBox is the perfect vehicle for
DBAs and developers to learn about virtualization, Linux, and various
Oracle technologies. Lots of professionals learn new technologies by
installing VirtualBox on their laptops to create VMs of various OSs.
VirtualBox is the perfect virtualization technology because it is easily
accessible and completely free to deploy. VirtualBox is the preferred
type 2 hypervisor for Oracle professionals running Oracle databases on
OL.
Oracle announced recent addition of guest platforms, including the following:
- OL 6
- Ubuntu Linux and Fedora distributions
- Mac OS X 10.9 “Mavericks”
- Windows 8.1 and Windows Server 2012 R2
Note Oracle
provides downloadable Oracle virtual appliances (packaged VMs) for
VirtualBox so that you can get started with a particular Oracle
technology right away. Navigating your way around a new software stack
is challenging enough without having to spend multiple cycles on the
install process. Instead, you can download prebuilt Oracle VM VirtualBox
appliances from Oracle’s web site. Deployment of the packaged virtual
appliances is as easy as 1-2-3: download, assemble the files, and import
into VirtualBox. For more information about virtual appliances, please
see recipe 12-7.
12-2. Setting Up VirtualBox Virtual Machine (VM)
Problem
You want to create your first VM to instantiate a Linux server and install Oracle Database 12c.
Solution
You’ll focus on configuring VirtualBox to create a
new VM for OL 6/7 and installing OL 6/7 from the ISO image as a guest
OS. The OL 6/7 ISO image can be downloaded from edelivery.oracle.com—Oracle Software Delivery Cloud. You must have a (free) valid Oracle Account to download the Linux ISO.
To create a VM, click the New button in the top-left
corner of the Oracle VM VirtualBox Manager and provide a descriptive
name for the VM, location of the VM, and the OS type. The name that is
specified will be used to identify the VM configuration. Specify a
descriptive name and select the guest OS type and version. In this
example, you want to select Linux for the type and Oracle (64-bit) for
the version. You can choose Red Hat (64-bit) if your infrastructure is
still running Red Hat.
Here’s the list of Linux flavors supported by VirtualBox:
- Linux 2.2
- Linux 2.4 (32-bit/64-bit)
- Linux 2.6 (32-bit/64-bit)
- Arch Linux (32-bit/64-bit)
- Debian Linux (32-bit/64-bit)
- openSUSE (32-bit/64-bit)
- Fedora (32-bit/64-bit)
- Gentoo (32-bit/64-bit)
- Mandriva (32-bit/64-bit)
- Red Hat (32-bit/64-bit)
- TurboLinux (32-bit/64-bit)
- Ubuntu (32-bit/64-bit)
- Xandros (32-bit/64-bit)
- OL (32-bit/64-bit)
- Other Linux (32-bit/64-bit)
In the same screen, you have to configure the amount of memory allocated for this VM (see Figure 12-2).
Please be aware that the memory that you allocate in the memory size
screen will not be available while the guest VM is running. Do not
overallocate memory if you are leveraging your machine for other
applications such as Microsoft Word, Microsoft Excel, or Microsoft
PowerPoint. Microsoft products are notorious for draining memory on the
machine when they are being used. To effectively run any Oracle Database
12c, you should allocate a minimum of 4GB of memory and two virtual
CPUs (vCPUs). Allocate 4GB for this VM, take the default option to
Create a Virtual Hard Drive Now, and click the Create button.
Figure 12-2. Creating a new VM
In the next screen, provide some basic information
about the virtual hard drive you are creating for the VM. This virtual
hard drive will be where you’ll place the Linux OS. Unless you’re
planning for this virtual disk to be compatible with VMware or other
virtualization technology, choose the default VDI (VirtualBox Disk
Image). For VMware-compatible disks, select VMDK (Virtual Machine Disk).
Figure 12-3 shows the options for location and size of the virtual disk.
Figure 12-3. File location and size for virtual disk for new VM
Select the Dynamically Allocated option to choose a
thinly provisioned virtual disk. If you want better performance, you can
choose the Fixed Size option. For a fixed size disk, VirtualBox
preallocates all the space up front; the dynamically allocated disk
allocates disk space only as your usage consumption grows.
For VMDK virtual disks, you also have the option to
split the files into 2GB files. This example creates a 64GB disk; if you
choose the option to split the files of less than 2GB, you’ll have
approximately 32 files. For this VM instantiation, you’ll allocate 64GB
for the root and /u01 filesystems. You may opt to create multiple virtual disks: one for the root filesystem and another one for the /u01 filesystem. Click the Create button to create the VM.
Note If
you chose fixed size virtual disk(s), you’ll be waiting for a while
when you click the Create button. The fixed size disk will consume the
entire disk size, even if only a fraction of the disk space is being
consumed. A fixed size disk will occupy lots more disk space, but it
will incur less overhead.
Once the VDI disk is created with the specified size
(thin for dynamically allocated or thick for fixed size provisioned),
you’ll be directed back to the Oracle VM VirtualBox Manager screen. You
should also notice the newly created VM on the left side of the screen.
How It Works
You just created a VM with one vCPU, 4GB of memory,
and a 64GB virtual disk. You should allocate at least two vCPUs for any
VM running an Oracle database. You can change the number of vCPUs by
clicking the Settings button for the VM and then clicking the Processor
button in the middle of the screen. You can increase the number of vCPUs
from one to two or even higher.
You can create powerful VMs on enterprise class
servers. VirtualBox supports VM configurations up to 32 vCPUs and up to
1TB of RAM for a guest VM.
Like a physical disk, a virtual disk is created with a
specified capacity in MB/GB/TB when the image file is created. Unlike a
physical disk, a virtual disk can be expanded after it is created, even
if data already exists on the virtual disk.
VirtualBox supports four types of virtual disks: a
Virtual Disk Image (VDI) file, which is VirtualBox’s native container
for virtual disks; VMDK disks, which are leveraged by other
virtualization technologies such as VMware; VHD format, which is used by
Microsoft; and HDD format, which is leveraged by older versions of
Parallels. If you want to expand a virtual disk to a greater size or
have all the feature functionality available from VirtualBox, you should
select VDI as your disk choice.
You can create Linux guest VMs: Red Hat (5/6/7) and OL
(5/6/7) in particular. VirtualBox has limited support for 2.4 kernels;
2.6 and 3.x Linux kernels are fully supported. 32/64-bit Solaris guest
OSs are also supported on VirtualBox. Supported versions are Solaris 11,
Solaris 11 Express, and Solaris 10 U6 and higher.
12-3. Starting Up a VM for the First Time
Problem
Now that you have created your first VM you want to start installing the OL OS.
Solution
You can configure the VM (in particular, the CD/DVD
drive) so that the VM can be started from a bootable ISO image. Click
the Settings button in the top-left corner next to the New button to
view the general settings for the VM.
A window that looks like Figure 12-4 displays. Click the Storage button in the top middle of the row.
Figure 12-4. Storage settings for the VM
On the left side of the screen, choose the IDE
controller and click the empty CD icon. On the right side of the screen,
click the CD image icon for the CD/DVD drive in the Attributes section
(next to the IDE Secondary drop list) and click the Choose a Virtual
CD/DVD Disk File option. Find your ISO image for OL 6 from the browser
and select OL 6.6 ISO. As a final step, make sure to click the Live
CD/DVD check box option.
From the Storage screen, you can click the OK button
to go back to the main Oracle VM VirtualBox Manager screen. From the
Oracle VM VirtualBox Manager screen, select the VM that you just created
and click the green Start icon on the top of the screen. Because you
specified the OL 6.6 ISO image to be the virtual CD/DVD disk file, the
VM will boot off the OL 6.6 ISO image and start the Linux installation
on the VM. For complete step-by-step installation steps of OL 6.6,
please visit the DBAExpert.com/blog site and search on Oracle Linux installation.
How It Works
You’ll focus on configuring VirtualBox to create a
new VM for OL 6 and installing OL 6 from the ISO image as a guest OS.
Oracle 6.7 is the latest and greatest release of OL at the time of
writing this book. The OL 6 Update 7 ISO image can be downloaded from edelivery.oracle.com, Oracle’s Software Delivery Cloud. You must have a valid (free) Oracle Account to download the Linux ISO.
Once the Oracle 6 ISO image is set up with the virtual
CD/DVD player, click the Start button on the top portion of the Oracle
VM VirtualBox Manager ()
or right-click the VM and select the Start option. If you selected the
Live CD/DVD option, the installation process starts instantly.
12-4. Creating Additional Virtual Disks
Problem
You want to create additional virtual disks for ASM. You want to create additional disks for the DATA and FRA disk groups.
Solution
To create another virtual disk for the guest VM, you
have two options from the Oracle VM VirtualBox Manager. You can either
click the storage section of the VM, or click the Setting button next to
the New button on the top-left corner and click the Storage button on
the middle-top portion of the General screen. From the Storage screen,
look for the Serial ATA (SATA) controller and click the Controller: SATA
line. A CDROM icon and a disk icon with a plus sign will appear. Click
the disk icon with a plus sign, and you’ll see the buttons Choose
Existing Disk and Create New Disk (see Figure 12-5).
Figure 12-5. Adding a virtual hard disk
Because this is a new virtual hard disk, click the
Create New Disk button. You’ll now see the same Hard Drive File Type
screen that displays in Figure 12-6.
Figure 12-6. Hard drive file type screen for the VM
Choose the VDI (VirtualBox Disk Image) option and
click Continue. As you continue with the disk creation process, you’ll
be directed to the Storage on Physical Hard Drive screen, in which you
have to choose between creating a dynamically allocated disk or a fixed
size disk. Choose the Dynamically Allocated option and click the
Continue button to proceed to the File Location and Size screen, as
displayed in Figure 12-7.
Figure 12-7. File location and size screen for the VM
Finally you have to specify the name and size of the virtual disk. For this example, you’ll create a 64GB disk called ASMDISK1. VirtualBox will create a file called ASMDISK1.vdi.
Once you click the Create button, you’ll see your virtual disk on the
Storage Tree (left side) of the Storage screen, as seen in Figure 12-8.
Figure 12-8. Storage tree
You have to repeat these steps for each virtual disk for the ASM disk groups.
Note Alternatively,
you’ll see a disk icon with a plus sign on it under the Storage Tree
section of the screen. Clicking the disk icon enables you to either
create a CD/DVD device or a hard disk.
So far, you have gone through the process of creating
virtual disks from the Oracle VM VirtualBox Manager. Now let’s look at
creating virtual disks with the command-line interface (CLI). Here’s the command to create a VMDK to provision disks to run Oracle ASM on a Linux VMs:
$ VBoxManage createhd --filename asm1.vmdk --size 4096 --format VMDK --variant Fixed 0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100% Disk image created. UUID: 1e2ab785-7687-42a5-bfd9-28962820f0eb
In this example, you created VMDK format disks so that
you can port them to VMware later. To create a VDI disk, simply replace
the --format option to be VDI. You should always create a VDI disk if
you don’t plan to migrate to another virtualization platform.
How It Works
You want to provision four disks for each of the
DATA and FRA disk groups. The differences between VMDK, VDI, VHD, and
HDD disks was briefly covered. VirtualBox emulates the four most common
types of hard disk controllers:
IDE, SATA (AHCI), Small Computer System Interface (SCSI), and SAS. The
IDE (ATA) controllers are backward-compatible controllers that came out
by IBM PC/AT in 1984 for only hard drives. Later, the support expanded
to include CD-ROM drivers and other removable media. In the physical
world, IDE standard uses flat ribbon parallel cables with 40 or 80 wires
that can connect 2 devices. A VM may have one IDE controller enabled,
and an IDE controller can have up to four storage devices attached to
it. By default, one of the four devices is preconfigured to the CD/DVD
drive, but it can be changed. By default, a new VM has one IDE
controller with a CD/DVD virtual drive attached to it as one of the four
ports.
SATA is the
newer standard that was introduced in 2003. In the physical world,
devices attached to SATA controllers can be added/removed while the OS
is running. SATA controllers operate faster and are less CPU–resource
intensive than IDE controllers. With SATA controllers, VMs can also
handle up to 30 virtual disks. VirtualBox leverages the SATA controller
as the default controller for virtual disks and attaches the first
virtual disk to the SATA controller.
SCSI,
another standard that goes back to 1986, is a generic interface for data
transfer between all kinds of devices. SCSI controllers are still
common today in high-performance servers for connecting hard disks and
tape devices. Each SCSI controller can handle up to 15 virtual hard
disks. VirtualBox supports LSI and BugLogic SCSI controllers.
Serial Attached SCSI (SAS)
is another bus standard in which serial cables are used instead of
parallel cables. Serial cables simplify device connections and provide
more reliable and faster connections than SATA. You can think of SAS is
to SCSI as SCSI is to IDE. VirtualBox emulates LSI Logic SAS controller
and supports up to eight devices.
Whether you choose SATA, SCSI, or SAS in VirtualBox,
there won’t be much performance difference in your personal desktop. All
the controller support by VirtualBox is provided for compatibility with
legacy hardware and hypervisors.
12-5. Provisioning/Sharing a Disk with Another VM
Problem
You want to make the virtual disks to be shared disks. Disks created for RAC must be created as shared disks.
Solution
One of the caveats about a shareable disk is that
the virtual disk must be created as a fixed size disk in which the disk
file fully consumes the allocated space at the time of creation. Once
you create virtual disks for ASM disk groups, you can designate them to
be shareable with one of the two options: using the VBoxManage (Oracle
VM VirtualBox Command Line Management Interface Version) executable or
leveraging the Virtual Media Manager.
With VBoxManage modifyhd, you can change the characteristic of a virtual disk and make them shareable, as shown here:
$ VBoxManage modifyhd asm1.vmdk --type shareable
For other options with the modifyhd parameter, issue this command:
$ VBoxManage --help modifyhd
To leverage the Virtual Media Manager, click the File
menu from the top-left part of the screen and choose the menu option for
Virtual Media Manager. From the Virtual Media Manager, locate your
disk, right-click the disk, select the Sharable radio button option, and
click the OK button.
After you make the virtual disks shareable, you have
to assign them to the second or third or fourth RAC VM. You have to add
virtual disks (refer to recipe 12-4), but select the option to choose
existing disks (as shown in Figure 12-5) and select the shared disk from the file browser to complete the process for each disk.
How It Works
Shared disks are required for Oracle RAC. Making a virtual disk shareable can be accomplished via the command line with the VBoxManage
command or with the VirtualBox Media Manager. For shared disks, you
should place the shared disks in a different folder from the VM. We also
recommend the following folder topology and virtual disk placement for a
RAC configuration:
dallasrac01 dallasrac02 dallasrac_shared_disk ov01_disk.vdi ov02_disk.vdi ov03_disk.vdi data01_disk.vdi data02_disk.vdi data03_disk.vdi data04_disk.vdi fra01_disk.vdi fra02_disk.vdi fra03_disk.vdi fra04_disk.vdi
You should create separate folders for each node and a
dedicated folder for the shared disks. Disks for Oracle Cluster
Registry (OCR) and voting files be a minimum of 8GB in size, and we also
recommend 3 disks with normal redundancy for the OCR and Vote (OV) disk
group. Each OCR file is 400MB in size and each voting file is 300MB in
size in Oracle Database 12c. The Grid Infrastructure Management
Repository (GIMR) consumes approximately 3.3GB in
size and is by default in the same location as the OV files. Starting in
Oracle version 12.1.0.2, there are options to move the GIMR to another
disk group.
In this example, all the shared disks were intentionally created in a separate folder. You can create a dallasrac03 VM folder from a copy of the dallasrac01 VM folder. As a separate task, you can add the shared disks and easily provision another RAC node into the configuration.
12-6. Configuring the Virtual Network
Problem
You want to configure the virtual network for both private and public network access.
Solution
To create a virtual network within VirtualBox,
navigate to the Oracle VM VirtualBox Manager, click the VM for which you
want to create a virtual network, and click the Settings button ()
on the top-left corner next to the New button. You’ll see a window with
the title - [VM NAME] - General. This screen has eight buttons:
General, System, Display, Storage, Audio, Network, Ports, and Shared
Folders. Navigate your mouse to the top of the screen and click the
Network button on the top of the screen. Figure 12-9 shows four adapters in the Network screen.
Figure 12-9. Oracle VM VirtualBox Manager Network screen
You’ll leverage Adapter 1 to be the private network
and Adapter 2 to be the public network. The default settings for Adapter
1 are Enabled and NAT.
Click the Attached To: field drop-down list; you’ll
see that Oracle VM VirtualBox Manager offers seven different networking
offerings: Not Attached, NAT, NAT Network, Bridged Adapter, Internal
Network, Host-only Adapter, and Generic Driver. Figure 12-10 displays all the network offerings from the Oracle VM VirtualBox Manager.
Figure 12-10. Oracle VM VirtualBox Manager network adapter options
Choose Host-only Adapter for the private network (Adapter 1) and select vboxnet0
for the name. Next, configure the second adapter for the public network
interface. Click the Adapter 2 folder, and (for simplicity’s sake),
choose Internal Network for the “Attached To:” drop-down list. Click the
Enable Network Adapter check box. You’ll see the name of the Internal
Network (intnet) displayed.
How It Works
The networking portion of VirtualBox is problematic
for lots of DBAs. But with a little explanation, understanding the
networking component can be simplified. This section concentrates on
four common networking options: Network Address Translation (NAT),
Host-only Adapter, Internal Network, and Bridged Adapter. There is also
the Not Attached option, but this type is commonly leveraged for
troubleshooting. The Not Attached mode implies that
there is a network card but no network connectivity. You can think of
it as having an Ethernet cable that is not plugged into the network
interface card.
NAT, which is the default
networking mode for VirtualBox, provides the simplest way to access an
external network. NAT is popular because it typically doesn’t require
any changes to the host or guest OS. With NAT, you can surf the Web,
check e-mail, and download files from the guest VM, but the outside
world can’t communicate with the guest VM. NAT enables the guest VM to
reach the Internet via a private IP address that can’t be seen from the
host or the rest of the network. When the guest VM sends an IP packet to
a remote server, the NAT service does the following:
- Intercepts the packet
- Extracts the TCP/IP segments
- Manipulates the IP address to the IP address of the host machine
- Sends the packet to the remote server
To the outside world, only the IP address of the host
machine is revealed. Reply packets are received by the host and sent on
to the guest VM.
With the Host-only Adapter, you
can create a virtual network between the host and a set of VMs. Similar
to a loopback interface, you can establish connectivity between the VMs
and the host.
With the Bridged Adapter,
VirtualBox interfaces directly to the network interface and exchanges
packets directly, bypassing the host OS’s network layer. You can connect
to the same switch/router that the host OS is connected to and obtain
an IP address that is on the same subnet as the host. The guest VM can
act like an equal citizen as the host and be presented like any other
server on the network.
Internal Networking (or isolated network)
is similar to the bridged networking in the sense that the VM can
communicate with the outside world. With Internal Networking, the
outside world can see only the other VMs on the host that are connected
to the same internal network, so it is considered more secure. Internal
networks are created automatically and identified by name.
12-7. Leveraging/Creating Oracle VM VirtualBox Prebuilt Templates
Problem
You want to leverage the prebuilt Oracle VM
VirtualBox templates that Oracle has created and reduce the amount of
time to stand up an environment. You want to create an Oracle VM
VirtualBox template to share with another DBA or to another
organization. You also want to share the Oracle VM VirtualBox template
with VMware folks.
Solution #1: Leveraging Oracle’s Prebuilt Template
This solution looks into leveraging an Oracle template for the OL 6 Admin. Start by downloading the OL 6 Admin VM (OracleLinux65.ova) file from the Oracle web site: http://www.oracle.com/technetwork/community/developer-vm/index.html.
Note You
can download numerous prebuilt templates from Oracle. Be careful: some
of the templates are only for Oracle VM, not for VirtualBox.
Once the download of the .ova
file completes, navigate to the File menu and select the Import
Appliance option. You’ll see an Appliance Settings window, in which you
specify what to import. Click the file browser, find the .ova file that you downloaded, and click the Continue button.
From the Appliance Settings screen (see Figure 12-11),
you can review the specifications of the VM and modify components such
as the name of the VM or whether you want to enable the CD/DVD player or
the sound card. You also have the option to reinitialize the MAC
address of all the network cards.
Figure 12-11. Import Appliance: Appliance Settings screen
Click the Import button to start the import process.
You’ll be immediately directed to the terms and conditions and software
license agreement screen. You must agree to the terms and license
agreements before the process starts. Once you click the Import button,
it should take less than couple of minutes for the import of the OL 6
Admin VM to complete. You’ll see Oracle Virtual Sysadmin Days (Powered
Off) when the import is complete.
Solution #2: Creating Your Own OVA Template
You can create your own template in the form of an .ova
file. Choose the VM that you want to create an Open Virtualization
Archive or Application (OVA) template for, go to the File menu, and
select the Export Appliance option. Choose the location and version of
the Open Virtualization Format (OVF) file that you want to create and
click the Continue button. By default, VirtualBox defaults to OVF 1.0
format. You have the option to select the Write Manifest File check box.
In the Appliance Settings screen, review the VM that
you are about to export. After you make the changes that you want and
review the configuration specification, click the Export button to start
the OVA creation process. The amount of time that it takes depends on
how many virtual disks you have, the size of the virtual disks, and how
much data are in the virtual disks.
How It Works
Oracle provides numerous prebuilt templates for
various Oracle products, including OL and Oracle Solaris 10/11. You can
save hours and days by leveraging the prebuilt templates for instant VM
provisioning. Oracle recommends using its prebuilt templates for
development and education purposes, but they should never be used for
production environments. For the OL 6 Admin VM, you need at least 2GB of
RAM and 10GB of free disk space. You also have to know the password for
the root and oracle accounts: ‘oracle’ (without the single quotes).
OVF is a packaging standard designed to address the
portability and deployment of a VM or appliance so that it can be
imported and be leveraged with other virtualization technologies. With
the OVF standard, you can create a VM package that can be deployed
between VMware Player and VirtualBox. The OVF package can be stored in
an OVA, a single file distribution using the TAR format. You can think
of an OVA as a single compressed and "installable" version of a VM.
You can take an OVA file, rename it to a .tar file and execute a tar command with the –tvf options (t=list contents to standard out; v=verbose; f=read the archive from the specified file) to list the contents of the original .ova file:
$ mv OracleLinux65.ova OracleLinux65.tar $ tar -tvf OracleLinux65.tar -rw------- 0 someone 46184 Dec 6 2013 OracleLinux65.ovf -rw------- 0 someone someone 2189755904 Dec 6 2013 OracleLinux65-disk1.vmdk -rw------- 0 someone someone 68096 Dec 6 2013 OracleLinux65-disk2.vmdk -rw------- 0 someone someone 68096 Dec 6 2013 OracleLinux65-disk3.vmdk
The OVF format has two standards that you have to be
concerned with. The OVF 1.0 standard provided the standardized
virtualization format that solved the critical business need for
software vendors and cloud providers. OVF 1.0 was widely adopted and
became an international standard adopted by ISO/IEC in 2011.
The OVF 2.0 standard provides additional capabilities
over the 1.0 format for improved network configurations, shared disks,
more flexible scaling/deployment options, and basic placement policies
such as affinity rules and encryption capabilities.
12-8. Cloning a VM
Problem
You want to clone a VM to create another VM.
Solution
To clone an existing VM from the Oracle VM VirtualBox Manager, right-click the VM and select the Clone option, as displayed in Figure 12-12.
Figure 12-12. Cloning a VM
You’ll see the option to clone a VM only if the VM is
powered off. In the first screen of the cloning process, you must
provide a name for the new VM that you are about to create from the
clone. You also have the option to reinitialize the MAC address of all
the network cards during the cloning process. After you supply the name
of the cloned VM, click Continue to proceed. You’ll be directed to the
Clone Type screen, as shown in Figure 12-13.
Figure 12-13. Clone Type screen
The Clone Type screen shows two options: Full Clone
and Linked Clone. In this example, choose the Full Clone option and
click the Clone button. Depending on the size of the virtual disks,
you’ll see a status window indicating progress of the copy of virtual
disks and such. Once the cloning process is complete, you’ll land back
at the Oracle VM VirtualBox Manager screen.
For the Linked Clone option, you’ll see on the name of
the VM (Linked Base for AP02) on the VM library on the left of the
screen.
How It Works
As you have seen in this solution, cloning a
powered-off VM is extremely simple. The full clone represents an exact
copy of the source VM, including all the virtual disks. Alternatively,
you can create a linked clone in which the virtual disks will be tied to
the virtual hard drives files of the original VM. With linked clones, a
new snapshot will be created for the original VM as part of the cloning
process. Only changes to the cloned VM will be written to disk.
In this example, choose the option to fully clone the
source VM. With the full clone type, the amount of time it takes to
create a clone VM is directly correlated to the size of the virtual
disks of the source VM. For larger files, it will take longer to perform
a full clone. For linked clones, the cloning process is almost
instantaneous. You can create linked clones in minutes from the source
VM. For linked clone types, it operates in the copy-on-write technology.
12-9. Working with Snapshots
Problem
You want to create a snapshot of the VM to revert
back to in the event of a catastrophic situation such as a failed OS
upgrade or failed database upgrades.
Solution
To create a VM snapshot, you have to be in the
Oracle VM VirtualBox manager. From there, you can click the Snapshots
button on the top-right corner of the screen. The Snapshots button has a
little camera on the left of the button label and also has the number
of snapshots taken in parentheses.
Figure 12-14 shows that three snapshots already exist for the current VM called den00. If you look at the left side of the Oracle VM VirtualBox Manager, you’ll see that next to the VM den00 is the snapshot name of the latest snapshot taken: (My Snapshot).
Figure 12-14. Snapshot inventory
You can perform a snapshot from the Current State. You
can also start the clone process from the Current State or any of the
previous snapshots that were taken. If you navigate to previous
snapshots and right-click a snapshot name, you can also restore the VM
from that specific snapshot or even delete the snapshot to clean up
space.
Figure 12-15
reveals the options available for a snapshot. You can also look at
detailed information about the snapshot by choosing the Show Details
option.
Figure 12-15. Snapshot options
You can revert the VM back to a previous snapshot by
choosing the Restore Snapshot option. You’ll see a warning window that
asks whether you’re sure you want to restore the snapshot. If you click
the Restore button, your VM will be restored to the point-in-time
snapshot that was taken.
How It Works
The VM can be online or be powered off to take a
point-in-time snapshot. For Oracle databases, you should always create a
snapshot of the VM from the powered-off state. This way, all the Oracle
header files are consistent because the database should also be
offline, and you have a cold backup of the database. If you’re working
on an application server or web server, you may opt to take a snapshot
while the VM is online.
To perform a live snapshot, navigate to the Machine
menu option on top of the screen and choose the Take Snapshot option, as
displayed in Figure 12-16.
Figure 12-16. Taking an online snapshot
Figure 12-14
shows five buttons on the right pane window. The first camera button
creates a snapshot. The second button, with the semicircle arrow on the
camera, restores a snapshot. The third button, with an X on the camera,
removes a snapshot. The fourth button has a little circle at the
bottom-right corner of the camera. You can look at the details of the
snapshot such as when the snapshot was taken and additional
documentation for the snapshot. The fifth button, which looks like a
paste icon, is the cloning button. With this button, you can clone any
snapshot to create a new VM.
This example demonstrates how to leverage the CLI to perform snapshots. You can perform a snapshot with the snapshot option and pass additional parameters to create a snapshot (the take option of the CLI) and provide a name and description for the snapshot:
$ vboxmanage snapshot den00 take "CLI Snapshot" --description "Snapshot was taken via CLI" 0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
You can list all the snapshots that were taken with the snapshot [VM Name] list parameters:
$ vboxmanage snapshot den00 list Name: Den01_b4_upgrade (UUID: fa8c8efc-6c29-49cd-81a0-7339da706bc0) Description: Before our 12.1.0.2.2 upgrade Name: Before_VB_Guest_Additions (UUID: f0d88500-e06c-460e-93df-9fb31608fe30) Name: My Snapshot (UUID: e18a1bb0-a31d-4301-9184-a3f35fb3d53a) Name: CLI Snapshot (UUID: a692d5bd-b0bc-43de-91f6-582045ddf8ab) * Description: Snapshot was taken via CLI
If you want to review all the options for managing snapshots with the vboxmanage CLI, provide the –help option followed by the keyword snapshot, as shown here:
$ vboxmanage --help snapshot Oracle VM VirtualBox Command Line Management Interface Version 4.3.26 (C) 2005-2015 Oracle Corporation All rights reserved. Usage: VBoxManage snapshot <uuid|vmname> take <name> [--description <desc>] [--live] | delete <uuid|snapname> | restore <uuid|snapname> | restorecurrent | edit <uuid|snapname>|--current [--name <name>] [--description <desc>] | list [--details|--machinereadable] showvminfo <uuid|snapname>
As you can see, you have other options to delete a
snapshot, restore a snapshot, edit a snapshot, show details for a
snapshot, and even take a live snapshot with the --live option.
No comments:
Post a Comment