1. Trang chủ
  2. » Công Nghệ Thông Tin

Red Hat Linux Networking , System Administration (P27) doc

30 101 0
Tài liệu đã được kiểm tra trùng lặp

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 30
Dung lượng 663,1 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

Installing and Upgrading Software Packages IN THIS CHAPTER ■■ Using the Red Hat Package Manager ■■ Checking Software Versions ■■ Obtaining Newer Software ■■ Installing Software from Sour

Trang 1

The -g and -u options have the meaning shown in Table 29-6 Specifying -stells quota to use more understandable units for displaying disk usage andlimits For example, the following command shows bubba’s quota statistics:

# quota -s bubba

Disk quotas for user bubba (uid 502):

Filesystem blocks quota limit grace files quota limit grace /dev/hdb1 2168* 2000 2025 29 0 0

To see a complete list of quota statistics for all users and groups for a file tem, use the repquota program, which accepts the same options as quotabut requires a file system argument rather than a user argument You can usethe -a option to see a report for all file systems on which quotas are beingused The following command shows a repquota report for /dev/hdb1,using the -s option to display the output in units of megabytes:

Trang 2

Installing and Upgrading

Software Packages

IN THIS CHAPTER

■■ Using the Red Hat Package Manager

■■ Checking Software Versions

■■ Obtaining Newer Software

■■ Installing Software from Source

One of Linux’s best qualities is the amount of software available for it Evennovice Linux users can download and install new or updated software withlittle or no difficulty using RPM, the Red Hat Package Manager Blindlyinstalling software, even on an RPM-based system, may cause problems,though, and in general the more you understand about software installationand maintenance, the more comfortable you will be with the process Thischapter describes how to use RPM and to keep Fedora Core and RHEL-basedsystems current vis-à-vis updated packages and security patches It alsodescribes how to use the current version of RPM to add, remove, upgrade, andquery software packages Finally, it briefly describes the process of configuringand installing software from source code

Using the Red Hat Package Manager

RPM is a powerful software configuration manager and the preferred tool forinstalling, removing, verifying, and updating software packages on Fedora Coreand RHEL systems This section describes how to use most RPM features Latersections cover some topics in detail, though, so they are mentioned only briefly

in this one Most examples illustrate command line usage, but some show how

to use Package Manager, a graphical RPM front-end application

C H A P T E R

30

Trang 3

RPM consists of two components: a set of databases that store informationabout installed software and the programs that interface with the databases.RPM can work with binary and source packages Binary packages, referred tosimply as RPMs, contain compiled software ready for installation They use

the file extension rpm Source packages, more often called source RPMs or

SRPMs, are uncompiled packages containing source code, patches, and build

instructions, all of which are used to create binary RPMs SRPMs have a.src.rpmfile extension Because RPM offers a rich feature set that makes itseem complex and difficult to learn to use, the following sections each exploreone of RPM’s modes, in order to simplify the discussion:

General Options

At the command line, the primary RPM command is rpm In addition to themode-specific command line options discussed in the following sections, rpmaccepts the general command line options listed in Table 30-1

Table 30-1 General RPM Command Line Options

Trang 4

Table 30-1 (continued)

OPTION DESCRIPTION

quiet Displays only error information

test Performs a “dry run” of the requested operation without actually

modifying the file system or the RPM database version Shows the RPM version number

justdb Updates only the database, not the file system

The -vv option may prove useful when troubleshooting package tion or removal that fails, but be prepared to sort through voluminous andcryptic-looking output to find the information you need justdb is used tohelp repair the database The results of any operation, such as installing

installa-or removing an RPM, affect only RPM’s databases; no files are added to installa-orremoved from the file system test makes it possible to see if a commandwill succeed without actually changing anything For example, the followingcommand uses test to delete the whois package from RPM’s databasewithout actually deleting the files:

# rpm test -e jwhois

# rpmquery jwhois

jwhois-3.2.2-14

# ls -l /usr/bin/jwhois

-rwxr-xr-x 1 root root 57040 Nov 9 21:28 /usr/bin/jwhois

The first command deletes the jwhois package but, because the test wasspecified, the package wasn’t actually deleted The second command uses therpmquerycommand to see if the jwhois RPM is installed As you can see, thepackage is still installed

N OT E The rpm command supports more options than those listed in Table 30-1 To simplify the discussion, this chapter examines only the most common and helpful options.

One common use of justdb is to remove an RPM’s entry from the base after the package has been upgraded using a non-RPM source, such as atarball In such cases, the RPM entry is invalid and needs to be removed with-out deleting the installed files The most common use of justdb is to repairthe RPM database if it becomes corrupted

Trang 5

data-Query Mode

RPM’s query mode is one of its most powerful and useful features The generalform of an RPM query is:

rpmquery [query_opts]

rpmquery(or, if you prefer the old style, rpm -q or rpm query) specifies

a query operation and query_opts specifies what to query, the type of query,how the query should run, or the format of its output You can use the com-mand rpmquery in place of rpm -q or rpm query Most commonly,queries use the following general syntax:

rpmquery [query_opts] package [ ]

package names the RPM to query Query multiple RPMs using a separated list of package names Query mode’s power comes at the cost of along list of options for the query_opts argument The options fall into two

space-broad categories One group, referred to as package selection options, controls which package or packages to query, and the other, known as output selection

options, defines what information to display Table 30-2 lists many but not all of

the options available in query mode The Type column uses S to mark a packageselection option and I to mark an information selection option Unless men-tioned otherwise, all options require at least one package name as an argument

Table 30-2 RPM Query Mode Options

OPTION TYPE DESCRIPTION

dump I For each file stored in the queried RPM(s), displays

its path, size, modification time, MD5 checksum, permissions, owner, group, and whether it is a configuration file, documentation file, a device, or a symlink (must be used with -l, -c, or -d).

Trang 6

Table 30-2 (continued)

OPTION TYPE DESCRIPTION

-f file S Queries the RPM that owns file Does not require

a package specification.

-g group S Lists the packages in the RPM group named

group Does not require a package specification.

RPM(s).

last I Displays the installation date and time of each

RPM queried, starting with the most recently installed RPM.

-p package [ ] S Queries the uninstalled RPM named package.

provides I Lists all of the capabilities the queried RPM(s)

provides.

qf ‘ I Creates a customized output format for displayed format_str’ information, using format_str as the model.

querytags I Prints all known tags for use with the qf option.

Does not require a package specification.

requires I Lists all RPMs on which the package depends.

-s I For each file in the original RPM, displays its state,

which is one of normal, not installed, or replaced.

whatprovides S Queries all RPMs that provide capability.

capability

whatrequires S Queries all RPMs that need capability in order

As you can see in Table 30-2, RPM’s query mode is extensive and flexible,allowing you to obtain any type of information stored in the RPM databases.Using the qf option, in fact, you can create customized query output for use

in reports and scripts The next few sections demonstrate how to use many ofthese options First, here are a couple of usage tips:

■■ When using the -f, option, the file argument must be to a full path

That is, the command rpm -qf /usr/bin/xmms will show the name ofthe RPM that contains xmms; rpm -qf xmms will not

■■ When specifying a package name with the -p option, you must use thecomplete RPM filename

Trang 7

Querying Package Dependencies

The provides, requires, whatrequires, and whatprovidesoptions allow you to identify dependencies between packages The capabilityargument represents the dependency itself, which is often the name of anotherRPM or the name of a particular file RPM uses dependencies to maintain system integrity, so, for example, if one RPM requires something a secondRPM provides, you cannot, in normal usage, delete the second RPM To illus-trate, to determine on what capabilities the RPM package depends, use the requiresoption as shown in the following command:

$ rpmquery requires rpm

/bin/bash beecrypt >= 4.1.2 config(rpm) = 4.4.1-18.1 fileutils

libbeecrypt.so.6 libbz2.so.1 libc.so.6 [ ]

N OT E Throughout this chapter, RPM commands that display package version numbers might result in different version numbers on your system.

The example output is truncated to preserve space As the output shows, theRPM package requires, in part, the /bin/bash capability and a config(rpm)capability greater than or equal to version 4.4.1-18.1 In this case, the/bin/bashcapability refers to the existence of bash shell, /bin/bash, and theconfig(rpm)capability identifies the minimum acceptable version of rpm

To identify what capabilities a package provides, use the providesoption:

$ rpmquery provides rpm

config(rpm) = 4.4.1-18.1 rpm = 4.4.1-18.1

The two output lines indicate that RPM provides the capabilities (most ofwhich are filenames, in this case) config(rpm) and rpm itself, both at version4.4.1-18.1

To determine which RPMs depend on a given capability, use whatrequirescapability to list all packages requiring capability For exam-ple, the following command shows all the packages that require the RPM capa-bility the RPM package provides Although potentially confusing, keep in mindthat the name of the package can be used as a capability

Trang 8

$ rpmquery whatrequires rpm

rpm-python-4.4.1-18.1 up2date-4.4.17-1 yum-2.3.2-2 rpm-build-4.4.1-18.1 rpm-devel-4.4.1-18.1 createrepo-0.4.2-2

The command output shows six packages requiring the rpm capability One

of the things this tells you is that these six packages depend on RPM, so beforeyou can remove the RPM package, therefore, you have to remove the six pack-ages that depend on it Not that you should ever remove RPM from a FedoraCore or RHEL system, of course

The options for querying RPM dependency information offer systemadministrators valuable information about the relationships between themany RPMs that constitute an installed Red Hat system

What’s in That RPM?

You will often find it useful or necessary to determine the contents of an RPM,whether it is installed or not A number of the options listed in Table 30-2 makethis possible The possibilities range from simply displaying the package nameand version numbers all the way to listing detailed information about each file

an RPM installs In fact, you can list all installed RPMs using the -a option.Most queries, though, fall somewhere between these extremes and query a lim-ited subset of packages or a limited selection of package characteristics or files.The simplest query option, rpm -q or rpmquery, shows only an RPM’sname and version number, as the following command illustrates:

Group : Applications/Internet Source RPM: jwhois-3.2.2-6.FC3.1.sr c.rpm

Size : 200210 License: GPL Packager : Red Hat, Inc <http://bugzilla.redhat.com/bugzilla>

URL : http://www.gnu.org/software/jwhois/

Summary : Internet whois/nicname client.

Description :

Trang 9

The output wraps because several lines are longer than 80 characters The -ioption results in a more comprehensive listing describing the RPM Two ofthe entries may require additional explanation The Group label organizesRPM packages by function Descriptors, which are Applications andInternetin the example, are separated by / and become increasingly spe-cific as you move from left to right Unfortunately, the values in the Groupfield are not standardized, and vary from vendor to vendor and even amongRPM packagers The current list of groups (see /usr/share/doc/rpm-4.3.2/GROUPS)in Fedora Core and RHEL is:

Trang 10

The -f file option approaches package listing from another direction Forany given file, you can find out which RPM installed it using -f file, wherefilecontains the full path specification The following command illustratesone way to use this option:

$ rpmquery -f /usr/bin/find

findutils-4.1.20-7

Not much to it, right? Well, suppose that you do not know the path to anapplication binary, just its name In such a case, take advantage of shell com-mands and standard Linux utility programs For example, the next commanduses the which command and the bash shell’s command substitution toresolve a binary’s name to a full path before invoking rpm:

$ rpmquery -f $(which emacs)

So far, every RPM query option discussed applies to installed packages

As it happens, many of them can be used on uninstalled packages, but only ifthe query specifies -p, which tells RPM to query an uninstalled package Sup-pose, for example, that you just downloaded the fortune-mod-1.2.1-1.i386.rpmpackage To list its files, use -l, as explained earlier, and -p:

$ rpm -qpl fortune-mod-1.2.1-1.i386.rpm

/etc/profile.d/fortune.sh /usr/bin/randstr

/usr/bin/rot /usr/bin/strfile /usr/bin/unstr

The output, truncated to conserve space, is identical to that of an installedpackage

Trang 11

Formatting Query Output

Inveterate tweakers and hard-core tinkerers appreciate the qf optionbecause it allows custom formatting of RPM query output On the downside, qfmight not work with all query options, and RPMs rarely contain all theinformation that can potentially be displayed The general form of a queryusing query format strings is:

rpmquery qf ‘format_str’ [query_opts]

format_stris the workhorse of custom query formatting A format_strmust contain at least one tag; all other components are optional Optional ele-ments include literal text, directives to control the output’s width and justifi-cation, control character sequences, output modifiers, and array iterators Atag is a predefined token or symbol representing a piece of information Exam-ples include SUMMARY, DESCRIPTION, NAME, and VERSION, but there aremany more; as of version 4.3.2, RPM understood 149 tags! Each tag must beembedded in a %{} construct, for example: %{SUMMARY} or %{NAME}

T I P Type rpm querytags to view the entire list of tags RPM understands.

There are a couple of details to bear in mind First, format_str should be

delimited by single quotes (‘), also called apostrophes or strong quotes, or by regular double quotation marks (“), often called weak quotes Format strings

used in shell scripts should be embedded between strong quotes to protectthem from effects of shell expansion, described in Appendix A Second, makesure to type qf (notice the double hyphen); -qf means something elseentirely, as described in the previous section To avoid confusion or the possi-bility of a typing error, consider using the long option queryformat, a syn-onym of qf

To keep this chapter from turning into a book about RPM, I discuss only a fewformat string elements The most important are directives to control the mini-mum width and justification of the displayed fields and escape sequences Tospecify the width of a field, place a number between a tag’s percent sign and itsopening brace, for example %20{NAME} By default, output is right-justified, so

to force left justification, prefix the field width with -, for example %-20{NAME}.The escape sequences are the same as those discussed in Chapter 28, such as \nfor a newline and \t for a tab

To illustrate, try the following examples and compare their output The firstexample is the output of an unmodified query:

Trang 12

$ rpmquery setup bc hdparm popt

setup-2.5.36-1 bc-1.06-17.1 hdparm-5.7-2 popt-1.9.1-21

You have seen this sort of query output already It is simple and tive but not terribly attractive The next command uses two tags, NAME andVERSION, to specify the output fields:

informa-$ rpmquery qf ‘%{NAME}%{VERSION}’ setup bc hdparm popt

setup2.5.36bc1.06hdparm5.7popt1.9.1$

Blech! This looks worse than the first example because all of the output runstogether, including the command prompt Yet, it serves as a starting point.First, separate the fields using field-width specifications:

$ rpmquery-q qf ‘%-20{NAME}%10{VERSION}’ setup bc hdparm popt

setup 2.5.36bc 1.06hdparm 5.7popt 1.9.1$

Each NAME field is 20 characters wide and left-justified The VERSION umn is 10 characters wide and is right-justified (the default) Judicious use ofthe \t and \n escape sequences solves the jumbled output problem:

col-$ rpmquery qf ‘%-20{NAME}\t%10{VERSION}\n’ setup bc hdparm popt

setup 2.5.36

bc 1.06 hdparm 5.7 popt 1.9.1

\t, the tab character, separates the name and version number fields; \n, thenewline, puts the command prompt back on its own line, where it belongs

This short discussion is only a taste of the capabilities of query formatting.Nevertheless, it provides a solid foundation for creating richer, more visuallyappealing query output It is worth pointing out that the query format capa-bility lets you create custom queries that are simply impossible using anyother query option available So, if you need RPM information you cannotobtain using the standard query options, use qf to create a custom querythat displays the information you need, and only that information

Package Installation and Removal

Although RPM’s query feature is one of its most powerful features, it earns itskeep because of its package-management features This section summarizeshow to install, remove, and upgrade software packages using RPM

Trang 13

Although they appear similar, force and nodeps serve different poses nodeps only disables dependency checks Use it only if you are cer-tain that a dependency conflict will not cause problems later on forceforces a package’s installation regardless of all potential problems As a result,some situations may require using force and nodeps together Com-mon uses of force include installing a package when one or more of itsfiles conflict with files installed by another package or when any other severeinstallation failure would occur Do not use force to install older packagesover new packages; use the oldpackage option for that To overwritedependencies, similarly, you should use nodeps whenever possible The force is a blunt instrument that might not have the results you want,expect, or intend.

pur-The following command demonstrates installing an RPM:

# rpm -ivh fortune-mod-1.2.1-1.i386.rpm

Preparing ########################################### [100%] 1:fortune-mod ########################################### [100%]

Table 30-3 Common RPM Installation Options

OPTION DESCRIPTION

force Install the package even if it is already installed, install an older

package version, and replace files already installed force also ignores dependencies.

-h Print up to 50 hash marks (#) to illustrate the progress of the

installation.

nodeps Do not perform a dependency check before installing or

upgrading a package.

test Do not install the package or update the database, just identify

and display possible conflicts or dependency errors.

-v Be slightly verbose and show some useful information during

the installation.

Trang 14

The next example shows the error generated by trying to install a packagealready installed and how to use force to ignore the error:

# rpm -ivh fortune-mod-1.2.1-1.i386.rpm

Preparing ########################################### [100%]

package fortune-mod-1.2.1-1 is already installed

# rpm -ivh force fortune-mod-1.2.1-1.i386.rpm

Preparing ########################################### [100%]

1:fortune-mod ########################################### [100%]

forcecaused RPM to ignore the conflict and perform the installation Toavoid encountering such conflicts, use the test option, as shown in thenext command, to perform a “dry run” installation to catch any problems:

# rpm -ivh test fortune-mod-1.2.1-1.i386.rpm

Preparing ########################################### [100%]

package fortune-mod-1.2.1-1 is already installed

As you can see in the preceding example, adding test to the commandline generated an error message What you cannot see is that neither RPM’sdatabases nor any files changed Testing a package installation using test

is great protection against the heartburn caused by installing incompatiblesoftware

ver-T I P The upgrade (-U) option is almost always the method to use because

it simply does the right thing The only exception is when installing multiple versions of the kernel, in which case you do want to have several versions of the same package(s) installed.

The following sequence of commands illustrates how to upgrade an RPMand the difference between the -U and -F options:

# rpm -Fvh fortune-mod-1.0-13.i386.rpm

# rpm -q fortune-mod

package fortune-mod is not installed

Trang 15

Hmm Nothing happened The rpm command line used -F, so it did notinstall the fortune-mod package because an earlier version did not exist.

# rpm -Uvh fortune-mod-1.0-13.i386.rpm

Preparing ########################################### [100%] 1:fortune-mod ########################################### [100%]

With -U, RPM “upgraded” the fortune-mod package, even though an lier version was not installed

ear-# rpm -Fvh fortune-mod-1.2.1-1.i386.rpm

Preparing ########################################### [100%] 1:fortune-mod ########################################### [100%]

This time, the freshen operation succeeded

rpm -V package [ ]

The -V option requests RPM to verify the status of files in package, thename of the RPM to verify As with many other RPM operations, multiplepackages can be verified simultaneously Table 30-4 explains the file character-istics that RPM evaluates when verifying an RPM

Ngày đăng: 07/07/2014, 09:20