第4章中讨论了tarball包——如何通过tar命令行命令进行创建和解包。在好用的rpm和dpkg
工具出现之前,管理员必须知道如何从tarball来解包和安装软件。

如果你经常在开源软件环境中工作,就很可能会遇到打包成tarball形式的软件。本节就带你
逐步了解这种软件的解包与安装过程。

在这个例子中用到了软件包sysstat。sysstat提供了各种系统监测工具,非常好用。
首先需要将sysstat的tarball下载到你的Linux系统上。通常能在各种Linux网站上找到sysstat包,
但最好是直接到程序的官方站点下载(http://sebastien.godard. pagesperso-orange.fr/)。

单击Download(下载)链接,就会转入文件下载页面。本书编写时的最新版本是11.1.1,发
行文件名是sysstat-11.1.1.tar.gz。

将文件下载到你的Linux系统上,然后解包。要解包一个软件的tarball,用标准的tar命令。

tar -zxvf sysstat-11.1.1.tar.gz

sysstat-11.1.1/
sysstat-11.1.1/cifsiostat.c
sysstat-11.1.1/FAQ
sysstat-11.1.1/ioconf.h
sysstat-11.1.1/rd_stats.h
sysstat-11.1.1/COPYING
sysstat-11.1.1/common.h
sysstat-11.1.1/sysconfig.in
sysstat-11.1.1/mpstat.h
sysstat-11.1.1/rndr_stats.h
[…] sysstat-11.1.1/activity.c
sysstat-11.1.1/sar.c
sysstat-11.1.1/iostat.c
sysstat-11.1.1/rd_sensors.c
sysstat-11.1.1/prealloc.in
sysstat-11.1.1/sa2.in

现在,tarball已经完成了解包,所有文件都已顺利放到了一个叫sysstat-11.1.1的目录中,你可
以跳到那个目录下继续了。

首先,用cd命令进入这个新目录中,然后列出这个目录的内容。

$ cd sysstat-11.1.1
$ ls
activity.c iconfig prealloc.in sa.h
build INSTALL pr_stats.c sar.c
CHANGES ioconf.c pr_stats.h sa_wrap.c
cifsiostat.c ioconf.h rd_sensors.c sysconfig.in
cifsiostat.h iostat.c rd_sensors.h sysstat-11.1.1.lsm
common.c iostat.h rd_stats.c sysstat-11.1.1.spec
common.h json_stats.c rd_stats.h sysstat.in
configure json_stats.h README sysstat.ioconf
configure.in Makefile.in rndr_stats.c sysstat.service.in
contrib man rndr_stats.h sysstat.sysconfig.in
COPYING mpstat.c sa1.in version.in
count.c mpstat.h sa2.in xml
count.h nfsiostat-sysstat.c sa_common.c xml_stats.c
CREDITS nfsiostat-sysstat.h sadc.c xml_stats.h
cron nls sadf.c
FAQ pidstat.c sadf.h
format.c pidstat.h sadf_misc.c
$

在这个目录的列表中,应该能看到README或AAAREADME文件。读这个文件非常重要。
该文件中包含了软件安装所需要的操作。

按照README文件中的建议,下一步是为系统配置sysstat。它会检查你的Linux系统,确保
它拥有合适的编译器能够编译源代码,另外还要具备正确的库依赖关系。

./configure

Check programs:
.
checking for gcc… gcc
checking whether the C compiler works… yes
checking for C compiler default output file name… a.out
[…]
checking for ANSI C header files… (cached) yes
checking for dirent.h that defines DIR… yes
checking for library containing opendir… none required
checking ctype.h usability… yes checking ctype.h presence… yes
checking for ctype.h… yes
checking errno.h usability… yes
checking errno.h presence… yes
checking for errno.h… yes
[…]
Check library functions:
.
checking for strchr… yes
checking for strcspn… yes
checking for strspn… yes
checking for strstr… yes
checking for sensors support… yes
checking for sensors_get_detected_chips in -lsensors… no
checking for sensors lib… no
.
Check system services:
.
checking for special C compiler options needed for large files… no
checking for _FILE_OFFSET_BITS value needed for large files… 64
.
Check configuration:
[…]
Now create files:
[…]
config.status: creating Makefile
Sysstat version: 11.1.1
Installation prefix: /usr/local
rc directory: /etc/rc.d
Init directory: /etc/rc.d/init.d
Systemd unit dir:
Configuration directory: /etc/sysconfig
Man pages directory: ${datarootdir}/man
Compiler: gcc
Compiler flags: -g -O2

如果哪里有错了,在configure步骤中会显示一条错误消息说明缺失了什么东西。如果你所
用的Linux发行版中没有安装GNU C编译器,那只会得到一条错误信息。对于其他问题,你会看
到好几条消息,说明安装了什么,没有安装什么。

下一步就是用make命令来构建各种二进制文件。make命令会编译源码,然后链接器会为这
个包创建最终的可执行文件。和configure命令一样,make命令会在编译和链接所有的源码文
件的过程中产生大量的输出。

make

–gcc -o sadc.o -c -g -O2 -Wall -Wstrict-prototypes -pipe -O2
-DSA_DIR=\”/var/log/sa\” -DSADC_PATH=\”/usr/local/lib/sa/sadc\”
-DUSE_NLS -DPACKAGE=\”sysstat\”
-DLOCALEDIR=\”/usr/local/share/locale\” sadc.c
gcc -o act_sadc.o -c -g -O2 -Wall -Wstrict-prototypes -pipe -O2 -DSOURCE_SADC -DSA_DIR=\”/var/log/sa\”
-DSADC_PATH=\”/usr/local/lib/sa/sadc\”
-DUSE_NLS -DPACKAGE=\”sysstat\”
-DLOCALEDIR=\”/usr/local/share/locale\” activity.c
[…]

make步骤结束时,可运行的sysstat软件程序就会出现在目录下!但是从那个目录下运行程序
有些不便。你会想将它安装到Linux系统中常用的位置上。要这样的话,就必须以root用户身份登
录(或者用sudo命令,如果你的Linux发行版偏好这个的话),然后用make命令的install选项。

make install

mkdir -p /usr/local/share/man/man1
mkdir -p /usr/local/share/man/man5
mkdir -p /usr/local/share/man/man8
rm -f /usr/local/share/man/man8/sa1.8
install -m 644 -g man man/sa1.8 /usr/local/share/man/man8
rm -f /usr/local/share/man/man8/sa2.8

install -m 644 -g man man/sa2.8 /usr/local/share/man/man8
rm -f /usr/local/share/man/man8/sadc.8
[…]
install -m 644 -g man man/sadc.8 /usr/local/share/man/man8
install -m 644 FAQ /usr/local/share/doc/sysstat-11.1.1
install -m 644
.lsm /usr/local/share/doc/sysstat-11.1.1

现在,sysstat包已经安装在系统上了!虽然不像使用PMS安装那样简单,但是通过tarball安
装软件也没那么难。