Rhce Administrative Tasks: Certification Objectives
Rhce Administrative Tasks: Certification Objectives
12
RHCE
Administrative
Tasks
CERTIFICATION OBJECTIVES
T he automation of system maintenance is an objective for both the RHCSA and RHCE
exams. For the RHCE, you need to know how to create a shell script for that purpose.
You’ll study some example scripts used on RHEL 6. Standard scripts may be used on
an hourly, daily, or even weekly basis. The Linux kernel is flexible and highly customizable. With
different run-time parameters configured in the /proc directory, kernels can be modified to meet
the needs of your users.
One of the special challenges of the RHCE exam is the configuration of a custom
RPM package. It’s easier than you think. RHEL 6 already includes excellent tools to
help you create that custom RPM.
The RHCE objectives also include a number of special network options. You need
to know how to set up a system as a Kerberos client. In a complex network, you may
need to configure a special route between networks. Finally, with the variety of
systems that can be configured, you should know how to connect to remote storage
over a network; the RHCE specifies the Internet Small Computer Systems Interface
(iSCSI) for that purpose.
be helpful to know how to create your own ■ Configure system as an iSCSI Initiator
RPM. The following RHCE objective is step persistently mounting existing Target
one in that process, to The following objective relates to the con-
■ Build a simple rpm that packages a figuration of a system as a Kerberos client:
single file ■ Configure system to authenticate
This chapter also addresses several net- using Kerberos
work tasks from the RHCE objectives. Finally, the following objective is related
The configuration of an iSCSI initiator, as to the nitty-gritty of enterprise networking:
described in the following objective, is the ■ Route IP traffic and create static routes
configuration of a client:
Normally, lines that start with the pound symbol (#) are comments. This line is
an exception. The second line is a straightforward execution of the mcelog
command, which would exit silently if a device is not found (--ignorenodev) and
filters out (--filter) known problems, before appending the messages (>>) to the end
of the /var/log/mcelog file.
/usr/sbin/mcelog --ignorenodev --filter >> /var/log/mcelog
There’s actually a bug related to the 0anacron script; for more information,
search for bug 675077 at https://bugzilla.redhat.com.
#!/bin/sh
But that command is soft-linked to the /bin/bash command, the bash shell. The
next line in the file is executed automatically. The logrotate command rotates logs
as defined in the /etc/logrotate.conf file, as described in Chapter 9. Standard logging
messages are sent to /dev/null, which is essentially the Linux trash bin. Error messages,
as signified by the 2>, are sent to the standard exit value, as indicated by the &1.
Some Linux distributions (not Red Hat) link the /bin/sh command to a shell
other than bash. Unless #!/bin/bash is specified in the script, it may not be
transferable to other distributions.
The following line assigns the standard exit value to a variable named EXITVALUE:
EXITVALUE=$?
Success has an exit value of 0. If there’s a problem, the exit value is some other
number. The if command starts a conditional statement. The bang character (!),
which looks like an exclamation point, in effect means “not” or “anything but.” So
the following if conditional is true when the value of EXITVALUE is something
other than 0:
if [ $EXITVALUE != 0 ];
The fi command that follows ends the conditional statement that started with
the if. The last directive returns 0, an indication of success:
exit 0
Since that may have been confusing for users who are newer to scripts, it’s a good
time to look at some of the basic commands available for scripts.
Script Commands
Scripts are filled with various command constructs. Some groups of commands are
organized in a loop, which continues to run as long as the conditions are met.
These command constructs are also known as operators. Common operators include
for, if, and test. The end of a loop may be labeled with an operator such as done or
fi. Some operators only exist in the context of others, which will be described in the
subsections that follow.
As suggested earlier, the bang (!) is “anything but.” The -f checks to see if the
filename that follows is a currently existing regular file. The key is the test operators
common in bash shell scripts. Some of these operators are listed in Table 12-1.
The if operator normally is associated with a then, and possibly an else operator.
For example, take the following hypothetical loop:
if [ -e /etc/inittab ];
then
/bin/ls /home > /root/homedirs
else
/bin/echo "Don't reboot, /etc/inittab is missing!"
fi
For this loop, if the /etc/inittab file exists (courtesy of the -e), the command
associated with the then operator is run. If that file is missing, then the noted
message is run.
TABLE 12-1
Operator Description
Test Operators -b Checks for a block file.
for bash Scripts -d Looks to see if the file is a directory.
-e Asks if the file exists.
-eq Checks for equality of the noted variables or values.
-f Works if the file is a regular file.
-ge Looks to see if the first value is greater than or equal to the second.
-le Looks to see if the first value is less than or equal to the second.
-lt Looks to see if the first value is less than the second.
-ne Looks to see if the first value is not equal to the second.
-r Checks the file for read permissions.
-s Checks to see if the size of the file is greater than zero.
-w Inspects the file for write permissions.
-x Looks to the file for execute permissions.
|| Asks if the previous expression is false.
&& Asks if the previous expression is true.
The do Loop
The do loop normally exists within other loops. It’s fairly simple; the following
example continues until some condition related to variable n is met:
do
echo "I love Linux #$n"
done
A more complex example exists within the tmpwatch script, in the /etc/cron.daily
directory, as it is combined with an if operator:
do
if [ -d "$d" ]; then
/usr/sbin/tmpwatch "$flags" -f 30d "$d"
fi
done
This loop executes the noted tmpwatch command for all noted files from variable
d that are confirmed as directories [ -d "$d" ].
That combination may seem complex. I’ve written a simpler script for Exercise 12-1.
This particular script finds all regular files (-type f) with the given name and
passes it off to the rm command. Commands of any such complexity are perfect
candidates for scripts. I could set up that script to be run on a regular basis with a
cron job associated with the user named camera, assuming the files in that directory
are owned by that user. Similar cron jobs were discussed in Chapter 9.
EXERCISE 12-3
Create a Script
In this lab, you’ll create a simple script that lists the .doc files in the local home
directory. Of course, there are easier ways to identify local .doc files. If there are no
.doc files in an appropriate directory, you can use the touch command to create
them, or substitute a different kind of file, such as those with a .pdf or a .conf
extension. The purpose of this exercise is to help users who are newer to scripts
understand how they work.
6. As the objective is simply to identify .doc files in the local directory, it’s best
to send the output to another file. One method is with the following line,
where the >> appends the output to the end of a file.
/bin/ls -l "$d" >> docfiles
7. You may retain the remaining lines; where the fi ends the if loop, the done
ends the do loop, and the exit 0 returns a success message:
fi
done
exit 0
8. Save the changes. Execute the script from the local directory. Since the script
name is testscript, the following command executes its contents from the lo-
cal directory:
$ ./testscript
9. Check the contents of the docfiles file. If the script worked, you’ll find exist-
ing .doc files in that directory.
Then make the system re-read the configuration file with the following command:
# sysctl -p
Let’s examine this process in a bit more detail. First, kernel run-time parameters
are documented in various files in the /proc/sys directory. Add the net.ipv4.ip_forward
variable to that directory. That’s interpreted as the ip_forward file, in the net/ipv4/
subdirectory. In other words, IPv4 forwarding is documented in the ip_forward file,
in the /proc/sys/net/ipv4 directory.
As that file contains either a 0 or a 1, it is a boolean variable. So the value 1 for
the net.ipv4.ip_forward variable activates IPv4 forwarding.
What if you want to add IPv6 forwarding? While that’s not configured in the
/etc/sysctl.conf file, it’s a feature that you can add. IPv6 forwarding can be set in a
file named forwarding, in the /proc/sys/net/ipv6/conf/all directory. In other words, to
set IPv6 forwarding on reboot, you’d include the following directive in /etc/sysctl.conf:
net.ipv6.conf.all.forwarding=1
Similar directives would work for other settings associated with files in the /proc/sys
directory. Look at the icmp_* directives in the /proc/sys/net/ipv4 directory. Some of
you may recognize that the Internet Control Message Protocol (ICMP) is most
frequently associated with the ping command. In fact, a ping command is a request
for an echo. So the icmp_echo_ignore_all and icmp_echo_ignore_broadcasts relate
to a direct ping command, as well as a ping command associated with the broadcast
address.
In other words, if you add the following directives to the /etc/sysctl.conf file:
net.ipv4.icmp_echo_ignore_all = 1
net.ipv4.icmp_echo_ignore_broadcasts = 1
the local system won’t respond to a direct ping command, nor will it respond to a
request made by a ping to the broadcast address for the network.
Also known as the kernel magic sysrq key, developers may enable this directive
for development purposes. Generally, you should retain the following setting:
kernel.sysrq = 0
If there’s a crash of the Linux kernel, this option includes the PID number with
the kernel core dump file to help identify the culprit:
kernel.core_uses_pid = 1
A bridge is an older term for a switch that can regulate traffic within a single
network. The following directives disable the use of the noted iptables, ip6tables,
and arptables commands on such bridges.
net.bridge.bridge-nf-call-ip6tables = 0
net.bridge.bridge-nf-call-iptables = 0
net.bridge.bridge-nf-call-arptables = 0
Such bridges relate to virtualization on physical host systems; they don’t apply
within KVM-based virtual machines.
EXERCISE 12-2
Disable Responses to the ping Command
In this exercise, you’ll use kernel parameters to disable responses to the ping
command. While this exercise can be run on any two connected systems, this
exercise assumes that you’ll be configuring the server1.example.com system and
testing the result from the tester1.example.com system.
2. Assuming the output is a 0, try the ping localhost command. What happens?
Don’t forget to press CTRL-C to exit from the output stream. If the output is 1,
skip to Step 5.
3. Confirm the result from a remote system such as tester1.example.com. In
some situations, you may not have physical access to that system, so connect
with the appropriate ssh command. From the remote system, try the ping
server1.example.com or ping 192.168.122.50 commands.
4. Return to the server1.example.com system. Change the kernel setting de-
scribed in Step 1 with the following command:
# echo "1" > /proc/sys/net/ipv4/icmp_echo_ignore_all
Confirm by repeating the command from Step 1. Try the ping localhost com-
mand again. What happens?
5. Restore the original 0 setting to the icmp_echo_ignore_all option.
In production, it’s risky to install and compile a source RPM as the root
administrative user. Mistakes in the source RPM could easily compromise
a production system.
The source code unpacked from a source RPM (SRPM) can serve as a model for
the one that you will create. RHEL 6 tools are now available to help set up a spec
file. That spec file can then be used to build an actual binary RPM that others can
use to install the single file on their own systems.
Source RPMs
On Red Hat systems, when the GNU General Public License (GPL) refers to source
code, it refers primarily to source RPMs. In fact, Red Hat complies with such
open-source licenses in part by releasing source RPMs on their public servers at ftp.
redhat.com. The source code includes the programs and files, as created by the
developers. Source code can then be built into the binary packages used for
installing RHEL 6 and additional software after installation is complete.
In this section, you’ll download and install the source-code RPM associated with
the vsFTP server. One way to do so is with the lftp command described in Chapter 2.
To use that command to connect to the Red Hat FTP server, run the following
command:
$ lftp ftp.redhat.com
That command connects to the Red Hat public FTP server anonymously and
initiates the lftp ftp.redhat.com> prompt. To connect to the directory with source-
code packages for the RHEL 6 server, run the following command from the noted
prompt:
lftp ftp.redhat.com> cd /redhat/linux/enterprise/6Server/en/os/SRPMS
Command completion features work at the lftp prompt; in other words, if you’re not
sure what directories are available after typing in the cd command, just press TAB
once or twice.
At the noted directory, you can then download the source code for the vsFTP
server with the following command (the version number will vary with updates):
get vsftpd-2.2.2-6.el6.src.rpm
You can then run the quit command to exit from the lftp prompt and return to
the regular command line interface. The source-code SRPM should now be available
in the local directory. Even as a regular user, you’ll be able to unpack that SRPM
with the rpm command. For example, the following command run from my regular
account unpacks that source code into /home/michael/rpmbuild subdirectories:
$ rpm -ivh vsftpd-*.src.rpm
The command doesn’t install the vsFTP server, as it would with a regular RPM
package. It unpacks the SRPM into specific subdirectories.
FIGURE 12-1
Source code in
an rpmbuild/
SOURCES
subdirectory
To create an RPM, you’re going to have to set up a similar archive in the same
rpmbuild/SOURCES subdirectory. Once configured, you’ll also have to create a spec
file, to be stored in the rpmbuild/SPECS subdirectory. You’ll then be able to compile
that package with the rpmbuild command.
In general, if you want more information on how it works, run the rpmbuild
command with the -v or -vv switch. Most documentation assumes the rpmbuild
command uses a spec file in the rpmbuild/SPECS directory. In that case, you’d use
the -b switch. Options with the -t switch are associated with a spec file included in
the actual source-code archive in .tar or compressed .tar.gz format. Given current
documentation, it’s assumed that you’ll configure a separate .spec file and would
therefore use one of the -b switches described in Table 12-2.
Switches for -ba Builds both binary and source RPM packages.
the rpmbuild -bb Builds the binary RPM package.
Command
-bc Executes the %prep and %build commands from the .spec file.
-bi Executes the %prep, %build, and %install commands from the .spec file.
-bl Checks for the existence of cited files.
-bp Executes just the %prep stage of the .spec file.
-bs Builds just the source RPM package.
In general, you’d apply either the rpmbulid -ba or rpmbuild -bb command to the
spec file from the rpmbuild/SPECS subdirectory.
In many cases, the process of building an RPM from source code requires the
installation of development packages. For example, when I ran the noted rpmbuild
command on the standard server1.example.com system, it cited a need for four other
packages:
pam-devel is needed by vsftpd-2.2.2-6.el6.x86_64
libcap-devel is needed by vsftpd-2.2.2-6.el6.x86_64
openssl-devel is needed by vsftpd-2.2.2-6.el6.x86_64
tcp_wrappers-devel is needed by vsftpd-2.2.2-6.el6.x86_64
The GNU C Compiler package, gcc, is also required. With dependencies, several
other packages will probably be required on your system. So before the noted rpmbuild
command works, you should install the noted packages with a command like
# yum install gcc pam-devel libcap-devel openssl-devel tcp_wrappers-devel
Once these developmental and related compiler packages are installed, a regular
user will be able to run the aforementioned rpmbuild command to compile the
source code for the vsFTP server to create a binary and a source RPM.
Once the build process is complete, the compiled binary RPM can be found in
the rpmbuild/RPMS/x86_64 subdirectory; of course, the last bit would vary with the
architecture. The collected source RPM can be found in the rpmbuild/SRPMS
subdirectory.
should be copied to a directory created for that purpose. In addition, the rpmbuild
command, with standard .spec files, requires access to an executable file named
configure. It can be an empty file.
For my own user account, I took the following steps:
If you’re following along in a regular account, download a PDF file, such as RHEL 6
documentation available from http://docs.redhat.com/docs/en-US/Red_Hat_
Enterprise_Linux/index.html. Copy the downloaded PDF, and change that filename
with a command such as mv to corporate_policies.pdf.
That rpmbuild/SOURCES subdirectory can also contain the source code for the
previously discussed vsFTP server. Don’t be concerned about all of the patch and
other files, as the RHCE objective is to create an RPM with one file. With a
properly configured spec file, the source code for multiple packages can co-exist in
this directory.
Once installed, two commands from the rpmdevtools package are of special
interest. The rpmdev-setuptree command creates the rpmbuild/ subdirectory, with
appropriate subdirectories. The rpmdev-newspec command creates a newpackage.
spec file in the local directory, with a template that can be used to create an RPM.
Thus, if the RHCE exam expects you to build an RPM, you’d run the
rpmdev-setuptree command to build the directory structure, and then copy the gzip
compressed archive to the rpmbuild/SOURCES subdirectory. Now you can create a
spec file to process that archive.
The release number is added afterward; this default adds a 1.el6 for RHEL 6:
Release: 1%(?dist)
While the summary should describe the contents of the package, it doesn’t affect
how the RPM is created.
Summary: A package with one file
The Group is related to the package groups listed in the XML file described in
Chapter 7. To set up a package as part of a package group, you’d need to assign a real
package group; for example, the vsFTP server is part of the System Environment
/Daemons package group. But for our purposes, the assigned package group does not
matter.
Group: Miscellaneous
FIGURE 12-2
A newpackage
spec file
You can either comment out the URL, or add an appropriate address, as shown here:
URL: http://www.mheducation.com/
The Source0 is perhaps most important. It specifies the name of the gzip compressed
tar archive file, either from a remote URL or from the local rpmbuild/SOURCES/
subdirectory. While the vsftpd.spec file includes Source1, Source2, and later
directives, it’s not required. All that’s needed is the full name of the compressed
archive file.
Source0: CorPor-1.0.tar.gz
Most packages don’t include a BuildArch directive, as most packages are built to
the architecture of the local system. However, for those packages that are supposed
to be architecture-independent, it’s appropriate to include the following BuildArch
line:
BuildArch: noarch
If you forget, don’t worry. The BuildArch line is not required unless you’re told to set
up a single RPM package that can be installed on systems with all architectures.
The lines that follow are dependencies. The BuildRequires line specifies packages
that must be installed before the RPM and SRPM packages can be built with this
spec file. Review the vsftpd.spec file for this line. There are actually four BuildRequires
lines in that file, which specify the developmental packages listed as dependencies
when you applied the rpmbuild -ba command to that vsftpd.spec file. In contrast,
the Requires line would specify actual dependencies. For an RPM package from a
single file, especially one related to documentation, there’s generally no reason to
have BuildRequires or Requires dependencies. In that case, you’d comment out
these lines:
#BuildRequires
#Requires
The %description directive that follows allows you to include a brief paragraph
description of the package. One word would be sufficient.
%description
This is a package with one file, associated with corporate policies.
The %prep section is associated with any commands required to prepare the
source code. The line that follows is a bit strange. Even though it starts with a %, it
is a command. The %setup -q is a command macro that unpacks the compressed tar
archive in the rpmbuild/SOURCES directory.
%prep
%setup -q
The %build section that follows includes commands that configure and compile
the source code. It normally points to scripts within the source code, commonly set
up with script filenames like configure and make. With a one-file RPM, there’s
nothing to configure or compile, so it is appropriate to comment out or erase these
options.
%build
#%configure
#make %{?_smp_mflags}
The %install section includes commands that actually adds the files from the
package to noted directories. It normally starts with the following command to
delete the directory tree associated with any previous builds of this package:
%install
rm -rf $RPM_BUILD_ROOT
As noted before, the make command is normally used to compile actual source
code. Unless you’ve included some script, command, or executable in the source code,
it’s also not necessary. For RPM packages with one file, you should in fact erase or
comment out that line:
#make install DESTDIR=$RPM_BUILD_ROOT
However, that means you need to configure a directory where the specified
package is actually getting installed. I actually found an excellent model for this
purpose in a package for fonts for a language from Ethiopia, in the abyssinica-fonts.
spec file. The key excerpt is shown in Figure 12-3.
The directives from Figure 12-3 also provide a slightly different perspective. For
example, %{buildroot} is equivalent to $RPM_BUILD_ROOT. As there’s nothing to
compile in a group of fonts, there’s no “make” command in that file.
I’ve modified those options a bit. The install -d directive creates a directory, with
(-m) mode (chmod-style octal permissions) of 0755. The system is built on some
hypothetical root to be defined, in the /opt/CorPor-1.0 subdirectory.
FIGURE 12-3
An RPM model
for file placement
After the source code is compiled, it is cleaned with the following directive:
%clean
rm -rf $RPM_BUILD_ROOT
If desired, you can set up different ownership. For example, if user and group
michael were substituted for root in the %defattr(-,root,root,-) directive, the
corporate_policies.pdf file that follows would be owned by the user and group
michael.
Once the changes are made, you can proceed with the building of an RPM.
If there’s a problem, the last message might provide a clue. For example, the following
message is straightforward, associated with a typographical error in a file. It also shows
the location of the $RPM_BUILD_ROOT variable in the .spec file.
RPM build errors:
File not found: /home/michael/rpmbuild/BUILDROOT/CorPor-1.0-1.el6.x86_64/
opt/CorPor-1.0/corporate_policies.pdf
Some error messages are even more straightforward. When I avoided an entry in
the License field, the rpmbuild command returned the following message:
error: License field must be present in package: (main package)
Other error messages may seem more cryptic, but they point to a file which is used
to generate the RPM:
make: *** No targets specified and no makefile found. Stop.
|error: Bad exit status from /var/tmp/rpm-tmp.tF080m (%build)
The extension of the rpm-tmp file varies. For more information, examine the
contents of the latest rpm-tmp.* file the /var/tmp directory. Sometimes, the error
message includes a line number. In some cases, the rpmbuild -ba -vv command
provides very verbose (thus the -vv switch) information.
While the fakeroot package made it possible to run the rpmbuild command as a
regular user, installation of the new package still requires administrative privileges.
When installed, it loaded the noted corporate_policies.pdf file in the /opt/CorPor-1.0
directory. And an rpm -qi command applied to that package led to the output shown
in Figure 12-4.
Compare that output to the information added to the corpor.spec file described
earlier. That should help you better understand the purpose of each entry in the
spec file.
FIGURE 12-4
Information on
the single-file
RPM package
related task, when a system has two or more network devices, of setting up a special
route, using a nondefault device, to a specific network.
To review, the default IPv4 address is 0.0.0.0, so the default route goes through the
gateway address of 192.168.122.1. In a similar fashion, the default route for a statically
configured network system is configured with the GATEWAY directive in its
configuration file. Such configuration files are stored in the /etc/sysconfig/network-scripts
directory, with names like ifcfg-eth0.
But there are situations, such as a temporary disconnect on a network cable,
where the default route is not given by a DHCP server. Perhaps the DHCP server
has to be replaced, and you’ll have to set up static IP address information. In such
cases, the output to the route -n command might look more like the following:
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
In other words, since the default IP address of 0.0.0.0 is missing in the destination
field, there is no default route. That route can be added temporarily with the route
add command. For example, the following command would restore the default route
shown earlier:
# route add default gw 192.168.122.1
If multiple network devices exist on the local system, you can specify it; just for
variety, the following command specifies the second Ethernet adapter, eth1:
# route add default gw 192.168.122.1 dev eth1
To make sure that default route survives a reboot, you’ll need to make sure either
the system configures that default gateway IP address as part of a static configuration,
or the DHCP server used for the network can assign that gateway IP address. To
review, Figure 12-5 reflects the way the default gateway IPv4 address is configured
FIGURE 12-5
A static network
configuration
with a default
gateway
with the Network Configuration tool. In addition, you’ll need to make sure the
added default route survives a reboot, either by a direct change to the ifcfg-ethx
configuration file or indirectly with the Network Configuration tool.
Some systems may have multiple network devices connected to the same
network. In that case, you may need to configure a special route. As you might see,
special routes are not possible with the console-based Network Configuration tool.
The Network Connections tool does not work unless the NetworkManager
service in the /etc/init.d directory is active.
FIGURE 12-6
A special route
for a specific
network device
When the network service is restarted, it’s applied to the routing table. Based on
the previously configured routing table, the following is the result:
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.0.0 192.168.122.1 255.255.255.0 UG 0 0 0 eth0
192.168.122.0 0.0.0.0 255.255.255.0 U 1 0 0 eth0
0.0.0.0 192.168.122.1 0.0.0.0 UG 0 0 0 eth0
If you configure a Kerberos server, make sure port 88 is open in the relevant
firewalls.
What Is Kerberos
Kerberos is a network authentication protocol originally developed at the Massachusetts
Institute of Technology (MIT) that supports secure identification of networked
systems. On RHEL 6, a separate protocol such as LDAP is normally configured for
user-based authentication.
Two systems configured with and confirmed by Kerberos can communicate in
encrypted format, with a symmetric key. That key is granted by a Key Distribution
Center (KDC), which consists of an Authentication Server (AS) and a Ticket
Granting Server (TGS). When authentication is confirmed, the Kerberos client gets
a ticket good for a limited time, typically eight hours.
Given the importance of time to Kerberos, it may not work unless configured
clients and servers also use NTP services, as discussed in Chapters 5 and 17.
FIGURE 12-7
Configure a
Kerberos-based
client with
the graphical
Authentication
Configuration
Tool.
The focus of this section is on the second half of the tab. For a Kerberos-based
client, you’d retain Kerberos Password as the Authentication Method. The other
options are
■ Realm By convention, the Kerberos realm is the same as the domain name
for the network, in uppercase letters. It’s necessary if you configure DNS
support for Kerberos.
■ KDCs The KDC is the Kerberos Key Distribution Center. The entry here
should correspond either to the Fully Qualified Domain Name (FQDN) or
the IP address of the actual Kerberos server.
For the purpose of this section, accept the default options as shown in Figure 12-7.
Click Apply. After a few moments, the Authentication Configuration window will
close and changes will be made to the aforementioned configuration files. In addition,
the sssd service will be started.
FIGURE 12-8
Configure a
Kerberos-based
client with
the console
Authentication
Configuration
tool.
FIGURE 12-9
Specify Kerberos
client settings.
First, look at the changes to the /etc/nsswitch.conf file, where the sss setting is
added to the authentication files shown here:
passwd: files sss
shadow: files sss
group: files sss
In other words, when the local system looks for usernames and passwords, the files of
the local shadow password suite are checked. If the username is not found there,
control is turned over to the sssd daemon described earlier. Those files are configured
in the /etc/sssd directory.
Changes to the sssd daemon configuration are added to the end of /etc/sssd/sssd.
conf file. The added directives are shown in Figure 12-10 and are explained in Table
12-3. The directives are listed in the order that they’re shown in the figure.
FIGURE 12-10
Kerberos
Configuration in
/etc/sssd/sssd.conf
You should then be able to start the iSCSI service with a command like
# /etc/init.d/iscsi start
If successful, you’ll be able to review the available iSCSI shared storage, with the
/etc/init.d/iscsi status command. The output should be similar to that shown in
Figure 12-11.
FIGURE 12-11
Discovered iSCSI
storage
You should then be able to manage the shared storage as if it were a new hard
drive on the local system. The hard drive device file will show up in the /var/log/
messages file with information like the following, which points to device file /dev/sg3.
server1 kernel: scsi 7:0:0:0: Attached scsi generic sg3 type 12
You should then be able to create partitions and more on the new /dev/sg3 drive
just as if it were a local drive, based on the techniques discussed in Chapter 6. Of
course, a “persistent mount” as described in the relevant RHCE objective requires
that you make sure the iSCSI service starts the next time the system is rebooted with
a command like
# chkconfig iscsi on
To make sure there’s an actual mount, you may also need to set up a partition
that’s actually mounted in the /etc/fstab file. In practice, the actual device file for the
iSCSI drive may vary on each reboot. Therefore, such mounts should be configured
with the Universally Unique Identifier (UUID) numbers described in Chapter 6.
You do not need to create an iSCSI target storage server for the RHCE exam.
But as the configuration of an iSCSI server is relatively simple, you might consider
creating one for that purpose. Red Hat developer Daniel Berrangé has created
an excellent introduction to the creation of an iSCSI storage server at
http://berrange.com/tags/tgtadm/.
CERTIFICATION SUMMARY
Linux administrators need to configure scripts on a regular basis. Sample scripts are
already available in different /etc/cron.* directories. Normally, scripts start with the
#!/bin/bash line, which sets up the language for the rest of the script. Administrative
scripts can use bash commands, along with operators such as for, if, do, and test.
Kernel run-time parameters can be found in the /proc/sys directory. But changes to
such files are temporary. For more permanent changes, you’d set up options in the
/etc/sysctl.conf file. Changes to that file can be implemented with the sysctl -p
command. Many standard options relate to networking.
One new RHCE requirement is to create an RPM from a single file. To do so, you
need to know how to set up a source-code archive. The rpmdevtools and rpm-build
packages can help. The rpmdev-setup tree command can help set up the needed
directories. The rpmdev-newspec command can help create a template for a .spec
file. The rpmbuild command can then be used to process the instructions in the spec
file along with the packaged source code into an SRPM and an RPM package that
can be installed on different systems.
The RHCE objectives include requirements for several special network options.
With the help of the Network Connections tool, special IP routes can be configured
in a file in the /etc/sysconfig/network-scripts directory. Kerberos clients can be
configured in the /etc/sssd/sssd.conf file, referenced through the /etc/nsswitch.conf
file. Perhaps the easiest way to configure a Kerberos client is with the GUI
Authentication Configuration tool.
✓ TWO-MINUTE DRILL
Here are some of the key points from the certification objectives in Chapter 12.
❑ Available source RPMs can be used as a model to help create your own RPMs.
❑ RPM source-code components can be found in user home directories, in the
rpmbuild/ subdirectory, as configured with the rpmdev-setuptree command.
❑ The actual source code can be found in the rpmbuild/SOURCES subdirectory.
❑ RPMs are built with the rpmbuild command, based on a .spec file in the
rpmbuild/SPECS subdirectory. You can create a standard .spec template with
the rpmdev-newspec command.
❑ Built RPMs can be found in the rpmbuild/SRPMS and rpmbuild/RPMS
subdirectories.
SELF TEST
The following questions will help measure your understanding of the material presented in this
chapter. As no multiple-choice questions appear on the Red Hat exams, no multiple-choice questions
appear in this book. These questions exclusively test your understanding of the chapter. It is okay if
you have another way of performing a task. Getting results, not memorizing trivia, is what counts on
the Red Hat exams.
7. What command can be used to create just a regular RPM from source code, based on the test.
spec file in the rpmbuild/SPECS subdirectory? Assume all required source code is in the correct
location.
____________________________________________________________
8. When user tim builds a regular RPM associated with 64-bit systems, what’s the full path to the
directory with that RPM?
____________________________________________________________
LAB QUESTIONS
Several of these labs involve configuration exercises. You should do these exercises on test machines
only. It’s assumed that you’re running these exercises on virtual machines such as KVM.
Red Hat presents its exams electronically. For that reason, the labs in this and future chapters
are available from the CD that accompanies the book, in the Chapter12/ subdirectory. In case you
haven’t yet set up RHEL 6 on a system, refer to Chapter 1 for installation instructions.
The answers for the labs follow the Self Test answers for the fill-in-the-blank questions.
LAB ANSWERS
Lab 1
Success in this lab should be straightforward. If you’ve run the date command as suggested in the body
of the lab, the files from the /etc directory should be copied to the /backup directory a minute later.
The simplest way to set up that script to be run on an hourly basis is to configure it in the
/etc/cron.hourly directory. The script needs only two lines. The following is one example of the lines
you might include in that script:
#!/bin/bash
/bin/cp -ar /etc /backup
Of course, for that script to work, it requires executable permissions. For the purpose of this lab,
I created a script named whatever.cron in that directory with the two lines just shown. The name
of the script does not matter, as long as it’s saved to the /etc/cron.hourly directory.
As defined in the 0hourly script in the /etc/cron.d directory, hourly scripts are executed one min-
ute past every hour. Since I’m by nature impatient (and tested this file on April 14), I ran the follow-
ing command to advance the clock to the next hour (11 A.M.):
# date 04141100
One minute later, I found the contents of the /etc directory in the /backup directory.
Given the importance of the system clock for Kerberos-based authentication, you should restore
the original time.
Lab 2
If you’ve followed the instructions in this lab, the /etc/sysctl.conf file should now have the following
entry:
net.ipv4.icmp_echo_ignore_all = 1
That just makes sure the new setting survives a reboot. You may have also set the associated file,
/proc/sys/net/ipv4/icmp_echo_ignore_all, to 1, or run the sysctl -p command to implement the
change before the system is rebooted.
Of course, success can be confirmed with a ping command both from local and remote systems. If
you want to restore the original configuration, return to the server1.example.com system, and then
remove the net.ipv4.icmp_echo_ignore_all option from the /etc/sysctl.conf file.
Lab 3
If successful, you’ll have a dedicated spec file in the rpmbuild/SPECS directory, and at least a binary
RPM in a directory like rpmbuild/RPMS/noarch. Yes, you’ll have to take administrative privileges to
run the rpm command; when installed, the vsftpd.conf file should be installed in the /opt/sampleftp
directory.
If that doesn’t work, you may need to refer back to the body of the chapter for more information.
To summarize, remember to perform the following steps:
1. Set up a compressed archive for the directory with the vsftpd.conf file.
2. Install the rpm-build, rpmdevtools, and gcc packages, along with the dependencies shown when
running the rpmbuild -ba command on the newly created spec file.
3. Use the rpmdev-setuptree command to configure a directory tree to build the new RPM.
4. Use the rpmdev-newspec command to set up a newpackage.spec file to process the RPM source
code.
5. In the spec file, make sure to fill in the name, version, release number, summary, group, license,
and a description. You should comment out the BuildRequires and Requires options, as there
are no dependencies for this one file RPM.
6. Make sure to set up %install directives at the end of the file; for example, the following
directives would make sure the binary RPM, when installed, sets up the file in the specified
directory.
install -d -m 0755 $RPM_BUILD_ROOT/opt/sampleftp
install -m 0644 vsftpd.conf $RPM_BUILD_ROOT/opt/sampleftp/vsftpd.conf
7. Make sure the following directives confirm the noted directories, ownership, and filename from
the source code. Of course, you can change the ownership of the loaded file with the help of the
defattr directive.
%files
%dir /opt/sampleftp
%defattr(-,root,root,-)
/opt/sampleftp/vsftpd.conf
8. Save the file and apply the rpmbuild -ba command to the spec file.
9. Address any build errors that may appear in the rpmbuild -ba command output, or the latest
/var/tmp/rpm-tmp.* file.
10. Use the rpm command to install the newly configured RPM from an rpmbuild/RPMS/norarch
(or rpmbuild/RPMS/x86_64) subdirectory.
Lab 4
As with Lab 3, you’ll have a different dedicated .spec file in the rpmbuild/SPECS directory, and at
least a binary RPM in a directory like rpmbuild/RPMS/x86_64. Yes, you’ll have to take administrative
privileges to run the rpm command; when installed, the OVERVIEW file should be installed in the
/opt/postfixinfo directory.
If you’re ready, this can be a bit of a preview of the next chapter. The OVERVIEW file provides
background information on the philosophy behind the Postfix service.
Lab 5
If you use the Network Connections tool to set up a special route, it should set up a special file in
the /etc/sysconfig/network-scripts directory. If the specified network adapter is eth0, that special file
would be route-eth0. Given the parameters used for the outsider1.example.org network as discussed
in Chapter 1, that file would contain the following three lines:
ADDRESS0=192.168.100.0
NETMASK0=255.255.255.0
GATEWAY0=192.168.122.1
Of course, if the outsider1.example.org system is on a different network, the contents of the route-
eth0 file would change accordingly.
Lab 6
Success in this lab means the following:
1. The sssd service is running and is set to run the next time the system is booted, with commands
like /etc/init.d/sssd start and chkconfig sssd on.
2. The /etc/nsswitch.conf file includes the following entries for the shadow password suite:
passwd: files sss
shadow: files sss
group: files sss