一、什么是Yum
Yum的全称为 Yellowdog Update Modifier,其主要目的是为了解决RPM包安装时的依赖关系的问题。yum只是一个用于软件安装的前端工具,其主要的服务对象还是RPM软件包。
二、yum配置客户端
1、主配置文件(中心配置文件):/etc/yum.conf。
通常不需要进行修改,保持其默认配置即可。
2、提供repo配置文件,指明仓库访问路径及各种属性信息。
在目录/etc/yum.repos.d/目录中创建.repo文件,其格式如下:
[REPOID] 任意字符即可;
name=自定义 任意字符即可;
baseurl=ftp:// 指明yum仓库的位置,支持服务器的类型包括ftp,nfs,http,file;
file:/// 当用多个yum仓库时,可在每一行指定一个baseurl;
enabled={0|1} 是否启用此repo的配置,默认为enabled=1;
gpgcheck={0|1} 是否启用校验;
gpgkey=URL 如启用校验,应指明密钥的位置;
cost={1..n} 默认为1000,指定访问此仓库的开销;
如下这是我系统中自定的yum源:
[[email protected] Packages]# cat /etc/yum.repos.d/epel.repo
[epel]
name=Extra Packages for Enterprise Linux 6 - $basearch
#baseurl=http://download.fedoraproject.org/pub/epel/6/$basearch
mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=$basearch
failovermethod=priority
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
3、yum的repo配置文件中可用的变量所表达的意义:
$releasever: 程序的版本,对Yum而言指的是redhat-release版本;只替换为主版本号,如RedHat 6.5,则替换为6;
$arch: 系统架构
$basearch: 系统基本架构,如i686,i586等的基本架构为i386;
$uuid:
$YUM0-9: 在系统中定义的环境变量,可以在yum中使用;
三、yum客户端常用命令的使用
1、 显示仓库列表
[[email protected] yum.repos.d]# yum repolist all #显示所有仓库信息
显示所有程序包:yum list
yum list [all | glob_exp1] [glob_exp2] [...]
可以使用通配符
如:
[[email protected] ~]# yum list zsh* #显示所有出现zsh的软件包
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
Available Packages
zsh.x86_64 4.3.10-7.el6 dvd
zsh-html.x86_64 4.3.10-7.el6 dvd
yum list [available|installed|updates] [glob_exp1] [...]
可用的 :已安装的: 可升级的
2、安装程序包:yum install
install package1 [package2] [...]
如:
[[email protected] Packages]# yum install gcc #安装gcc包
Loaded plugins: fastestmirror, refresh-packagekit, security
Setting up Install Process
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package gcc.x86_64 0:4.4.7-11.el6 will be installed
--> Processing Dependency: cpp = 4.4.7-11.el6 for package: gcc-4.4.7-11.el6.x86_64
--> Processing Dependency: cloog-ppl >= 0.15 for package: gcc-4.4.7-11.el6.x86_64
--> Running transaction check
---> Package cloog-ppl.x86_64 0:0.15.7-1.2.el6 will be installed
--> Processing Dependency: libppl_c.so.2()(64bit) for package: cloog-ppl-0.15.7-1.2.el6.x86_64
--> Processing Dependency: libppl.so.7()(64bit) for package: cloog-ppl-0.15.7-1.2.el6.x86_64
---> Package cpp.x86_64 0:4.4.7-11.el6 will be installed
--> Processing Dependency: libmpfr.so.1()(64bit) for package: cpp-4.4.7-11.el6.x86_64
--> Running transaction check
---> Package mpfr.x86_64 0:2.4.1-6.el6 will be installed
---> Package ppl.x86_64 0:0.10.2-11.el6 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
=================================================================================
Package Arch Version Repository Size
=================================================================================
Installing:
gcc x86_64 4.4.7-11.el6 dvd 10 M
Installing for dependencies:
cloog-ppl x86_64 0.15.7-1.2.el6 dvd 93 k
cpp x86_64 4.4.7-11.el6 dvd 3.7 M
mpfr x86_64 2.4.1-6.el6 dvd 157 k
ppl x86_64 0.10.2-11.el6 dvd 1.3 M
Transaction Summary #上面说明安装gcc所依赖的包
=================================================================================
Install 5 Package(s)
Total download size: 15 M
Installed size: 33 M
Is this ok [y/N]: y #选择yes,和面会把和gcc依赖的那4个包也一并安装了
Downloading Packages:
---------------------------------------------------------------------------------
Total 44 MB/s | 15 MB 00:00
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : mpfr-2.4.1-6.el6.x86_64 1/5
Installing : cpp-4.4.7-11.el6.x86_64 2/5
Installing : ppl-0.10.2-11.el6.x86_64 3/5
Installing : cloog-ppl-0.15.7-1.2.el6.x86_64 4/5
Installing : gcc-4.4.7-11.el6.x86_64 5/5
Verifying : ppl-0.10.2-11.el6.x86_64 1/5
Verifying : cpp-4.4.7-11.el6.x86_64 2/5
Verifying : gcc-4.4.7-11.el6.x86_64 3/5
Verifying : cloog-ppl-0.15.7-1.2.el6.x86_64 4/5
Verifying : mpfr-2.4.1-6.el6.x86_64 5/5
Installed:
gcc.x86_64 0:4.4.7-11.el6
Dependency Installed:
cloog-ppl.x86_64 0:0.15.7-1.2.el6 cpp.x86_64 0:4.4.7-11.el6
mpfr.x86_64 0:2.4.1-6.el6 ppl.x86_64 0:0.10.2-11.el6
Complete!
重新安装
yum reinstall package1 [package2] [...]
如果需要安装老版本需要指定版本号
3、升级程序包:
yum update package1 [package2] [...]
4 、检查可有升级包:
yum check-update
5、卸载程序包:
yum remove | erase package1 [package2] [...]
[[email protected] repo]# yum remove gcc -y #卸载gcc
Loaded plugins: fastestmirror, refresh-packagekit, security
Setting up Remove Process
Resolving Dependencies
--> Running transaction check
---> Package gcc.x86_64 0:4.4.7-11.el6 will be erased
--> Finished Dependency Resolution
Dependencies Resolved
=================================================================================
Package Arch Version Repository Size
=================================================================================
Removing:
gcc x86_64 4.4.7-11.el6 @dvd 19 M
Transaction Summary
=================================================================================
Remove 1 Package(s)
Installed size: 19 M
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Erasing : gcc-4.4.7-11.el6.x86_64 1/1
Verifying : gcc-4.4.7-11.el6.x86_64 1/1
Removed:
gcc.x86_64 0:4.4.7-11.el6
Complete!
[[email protected] repo]#
注:依赖包都会被卸载
6、查看程序包的信息
yum info [...]
如:
[[email protected] Packages]# yum info gcc #查看gcc程序包的信息
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
Installed Packages
Name : gcc
Arch : x86_64
Version : 4.4.7
Release : 11.el6
Size : 19 M
Repo : installed
From repo : dvd
Summary : Various compilers (C, C++, Objective-C, Java, ...)
URL : http://gcc.gnu.org
License : GPLv3+ and GPLv3+ with exceptions and GPLv2+ with exceptions
Description : The gcc package contains the GNU Compiler Collection version 4.4.
: You‘ll need this package in order to compile C code.
7、查看指定的特性是由哪个哪个程序包提供的
yum provides | whatprovides feature1 [feature2] [...]
[[email protected] repo]# yum provides /usr/bin/yum #查询/usr/bin/yum这个文件是由哪个包
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
* epel: ftp.cuhk.edu.hk
yum-3.2.29-60.el6.centos.noarch : RPM package installer/updater/manager #这里提示的生成这个文件的包
Repo : installed
Matched from:
Other : Provides-match: /usr/bin/yum
8、清理被动缓存:
yum clean [ packages | metadata | expire-cache | rpmdb | plugins | all ]
[[email protected] yum.repos.d]# yum clean all
Loaded plugins: fastestmirror, refresh-packagekit, security
Cleaning repos: DVD epel mageeduepel room xen4centos
Cleaning up Everything
Cleaning up list of fastest mirrors
9、构建缓存
yum makecache
[[email protected] repo]# yum makecache
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
epel/metalink | 4.5 kB 00:00
* epel: ftp.cuhk.edu.hk
epel/group_gz | 149 kB 00:05
epel/filelists_db | 8.2 MB 01:54
epel/updateinfo | 698 kB 00:05
http://ftp.cuhk.edu.hk/pub/linux/fedora-epel/6/x86_64/repodata/9333930f38142066e752ead41b011f970ed231367457be506c74f25a37dc5249-other.sqlite.bz2: [Errno 12] Timeout on http://ftp.cuhk.edu.hk/pub/linux/fedora-epel/6/x86_64/repodata/9333930f38142066e752ead41b011f970ed231367457be506c74f25a37dc5249-other.sqlite.bz2: (28, ‘Operation too slow. Less than 1 bytes/sec transfered the last 30 seconds‘)
Trying other mirror.
epel/other_db | 2.8 MB 00:22
Metadata Cache Created
四、创建本地yum源
[[email protected] Packages]# mkdir -p /yum/repo/ #创建目录/yum/repo
[[email protected] Packages]# cp /mnt/Packages/*.rpm /yum/repo/ #拷贝/mnt/Packages下所有已.rpm结尾的文件到/yum/repo目录下
[[email protected] ~]# man createrepo #man下createrepo这个命令,提示系统上没有这个命令,那么我们需要安装下,以下是安装步骤
No manual entry for createrepo
[[email protected] Packages]# yum install createrepo-0.9.9-22.el6.noarch.rpm #安装creterepo这个程序
Loaded plugins: fastestmirror, refresh-packagekit, security
Setting up Install Process
Examining createrepo-0.9.9-22.el6.noarch.rpm: createrepo-0.9.9-22.el6.noarch
Marking createrepo-0.9.9-22.el6.noarch.rpm to be installed
Loading mirror speeds from cached hostfile
* epel: ftp.cuhk.edu.hk
Resolving Dependencies
--> Running transaction check
---> Package createrepo.noarch 0:0.9.9-22.el6 will be installed
--> Processing Dependency: python-deltarpm for package: createrepo-0.9.9-22.el6.noarch
--> Running transaction check
---> Package python-deltarpm.x86_64 0:3.5-0.5.20090913git.el6 will be installed
--> Processing Dependency: deltarpm = 3.5-0.5.20090913git.el6 for package: python-deltarpm-3.5-0.5.20090913git.el6.x86_64
--> Running transaction check
---> Package deltarpm.x86_64 0:3.5-0.5.20090913git.el6 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
=================================================================================
Package Arch Version Repository Size
=================================================================================
Installing:
createrepo noarch 0.9.9-22.el6 /createrepo-0.9.9-22.el6.noarch 291 k
Installing for dependencies:
deltarpm x86_64 3.5-0.5.20090913git.el6 DVD 71 k
python-deltarpm
x86_64 3.5-0.5.20090913git.el6 DVD 27 k
Transaction Summary
=================================================================================
Install 3 Package(s)
Total size: 388 k
Total download size: 98 k
Installed size: 520 k
Is this ok [y/N]: y
Downloading Packages:
---------------------------------------------------------------------------------
Total 2.3 MB/s | 98 kB 00:00
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : deltarpm-3.5-0.5.20090913git.el6.x86_64 1/3
Installing : python-deltarpm-3.5-0.5.20090913git.el6.x86_64 2/3
Installing : createrepo-0.9.9-22.el6.noarch 3/3
Verifying : python-deltarpm-3.5-0.5.20090913git.el6.x86_64 1/3
Verifying : createrepo-0.9.9-22.el6.noarch 2/3
Verifying : deltarpm-3.5-0.5.20090913git.el6.x86_64 3/3
Installed:
createrepo.noarch 0:0.9.9-22.el6
Dependency Installed:
deltarpm.x86_64 0:3.5-0.5.20090913git.el6
python-deltarpm.x86_64 0:3.5-0.5.20090913git.el6
Complete!
[[email protected] repo]# createrepo ./ #cd到/yum/repo目录下将repo目录下的rmp包使用createrepo命令创建出repodata这个文件
Spawning worker 0 with 4184 pkgs
Workers Finished
Gathering worker results
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete #这里提示我们创建完成
[[email protected] repo]# cd repodata/ #cd到repodata目录下查看里面的文件,这样我们的一个本地yum仓库就创建好了
[[email protected] repodata]# ls
0782d476e717e94767e3a4baec916c498149d8ff5571008bd47e542cca5e756b-filelists.sqlite.bz2
38d0b586da870d4e099594c37199b180c00e60fbb3c96cf4a2f520e7235485d6-other.xml.gz
5d46c2e877448d2b252e808ec42d6c1b717bdc0744bcad78f3885cdd3542cd29-primary.xml.gz
acce1185959aef63665ade812996b0471d8c7bf69d01ad60a5a6caf834fb26ac-filelists.xml.gz
c212bdef68a2fa09f321bc217b53231d4e7b5df74448446d4e3be083f86f9502-other.sqlite.bz2
d8256b97e837a57f513159f3a609416d73567963e99512cc391bf91a74fd2600-primary.sqlite.bz2
repomd.xml
[[email protected] yum.repos.d]# yum repolist #重载yum仓库
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
* epel: ftp.cuhk.edu.hk
http://172.16.0.1/fedora-epel/6/x86_64/repodata/repomd.xml: [Errno 12] Timeout on http://172.16.0.1/fedora-epel/6/x86_64/repodata/repomd.xml: (28, ‘connect() timed out!‘)
Trying other mirror.
http://172.16.0.1/cobbler/ks_mirror/CentOS-6.6-x86_64/repodata/repomd.xml: [Errno 12] Timeout on http://172.16.0.1/cobbler/ks_mirror/CentOS-6.6-x86_64/repodata/repomd.xml: (28, ‘connect() timed out!‘)
Trying other mirror.
xen4centos | 2.9 kB 00:00 ...
xen4centos/primary_db | 3.4 MB 00:00 ...
repo id repo name status
DVD dvdiso 6,518
epel Extra Packages for Enterprise Linux 6 - x86_64 11,764
mageeduepel mageedu.com 12,922
room dream room 4,184
xen4centos Xen4 CentOS 4,184 #这边可以查看到我们新建的yum仓库已经可以使用了
repolist: 39,572
[[email protected] yum.repos.d]# cat rom.repo #我们查看下我们对仓库的定义
[room]
name=dream room
baseurl=http://172.16.0.1/cobbler/ks_mirror/CentOS-6.6-x86_64/
gpgcheck=0
[mageeduepel]
name=mageedu.com
baseurl=http://172.16.0.1/fedora-epel/6/x86_64/
gpgcheck=0
[xen4centos] #这边是我们对新仓库的定义内容
name=Xen4 CentOS
baseurl=file:///yum/repo
gpgcheck=0
如上我们一个本地的yum仓库就创建好了,其中createrepo命令还有很多选项,我们这边不常用,所有已就不介绍了
五、程序包编译安装
1、为何进行程序包编译
(1)、找不到何事的程序包
(2)、每一个程序包在编译的时候也许有20个程序包,但是只编译了前面10个,我们要用到后面10个的时候,所有只有编译安装了。
rpm包有2种格式:
编译好的rpm包
源码rpm包
未编译的rpm包格式:testapp-VERSION-release.src.rpm 其中有src.rpm中src是不知道你的程序包需要安装在什么平台之上的。
2、C代码编译安装三步骤:
./configure:
(1) 通过选项传递参数,指定启用特性、安装路径等;执行时会参考用户的指定以及Makefile.in文件生成makefile;
(2) 检查依赖到的外部环境;
make:
根据makefile文件,构建应用程序;
make install
3、事例如何编译Apache程序包:
(1)、准备编译环境
开发工具:make, gcc等
开发环境:开发库,头文件
glibc:标准库
那么我们如何获得这个工具可以通过安装“包组”提供开发组件,安装的“包组”如下
CentOS 6: "Development Tools", "Server Platform Development",
这样我们的环境就准备好了
(2)、操作
[[email protected] ~]# cd /mnt/ #首先们要先下载一个程序包,我这边的httpd-2.2.31.tar.bz2是从网上下载的
[[email protected] mnt]# ls
httpd-2.2.31.tar.bz2
[[email protected] mnt]# tra xf httpd-2.2.31.tar.bz2 #解压程序包
[[email protected] mnt]# ls
httpd-2.2.31 httpd-2.2.31.tar.bz2
[[email protected] mnt]# cd httpd-2.2.31
[[email protected] httpd-2.2.31]# ls #查看httpd-2.2.31里面的文件
ABOUT_APACHE BuildBin.dsp config.log docs httpd.mak LAYOUT Makefile modules.lo README srclib
acinclude.m4 buildconf config.nice emacs-style httpd.spec libhttpd.dep Makefile.in modules.o README.platforms support
Apache.dsw buildmark.o config.status httpd include libhttpd.dsp Makefile.win NOTICE README-win32.txt test
build CHANGES configure httpd.dep INSTALL libhttpd.mak modules NWGNUmakefile ROADMAP VERSIONING
BuildAll.dsp config.layout configure.in httpd.dsp InstallBin.dsp LICENSE modules.c os server
[[email protected] httpd-2.2.31]# less INSTALL #查看INSTALL里面的文件
APACHE INSTALLATION OVERVIEW
Quick Start - Unix
------------------
For complete installation documentation, see [ht]docs/manual/install.html or
http://httpd.apache.org/docs/2.2/install.html
$ ./configure --prefix=PREFIX #这里提示了我们需要安装的步骤
$ make
$ make install
$ PREFIX/bin/apachectl start
对于./configure 这个脚本有很多的选项,我们可以使用./configure --help去查看
[[email protected] httpd-2.2.31]# ./configure --help
这边选项太多,就不一一列出了,只写几个常用的选项
安装路径设定:
--prefix=/PATH/TO/SOMEWHERE: 指定默认安装位置;默认为/usr/local/
--sysconfdir=/PATH/TO/SOMEWHERE:配置文件安装位置;
Optional Features: 可选特性
--disable-FEATURE
--enable-FEATURE[=ARG]
Optional Packages: 可选包
--with-PACKAGE[=ARG]
--without-PACKAGE
[[email protected] httpd-2.2.31]# ./configure --prefix=/usr/local/apache2 #指定安装路径 第一步
[[email protected] httpd-2.2.31]# make #执行第二步make
[[email protected] httpd-2.2.31]# make install #执行第三步make install 这样程序就安装完成了
[[email protected] httpd-2.2.31]# cd /usr/local/apache2/ #切换到apache2目录下
[[email protected] apache2]# ls bin #查看bin下的文件
ab apu-1-config dbmmanage htcacheclean htpasswd logresolve
apachectl apxs envvars htdbm httpd rotatelogs
apr-1-config checkgid envvars-std htdigest httxt2dbm
[[email protected] apache2]# bin/apachectl start #执行bin下的apachectl这个脚本
[[email protected] apache2]# netstat -tan #查看服务
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address Stat
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTN
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTN
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTN
tcp 0 0 127.0.0.1:6010 0.0.0.0:* LISTN
tcp 0 0 127.0.0.1:6011 0.0.0.0:* LISTN
tcp 0 0 0.0.0.0:58427 0.0.0.0:* LISTN
tcp 0 0 127.0.0.1:6013 0.0.0.0:* LISTN
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTN
tcp 0 0 192.168.0.18:22 192.168.0.23:51983 ESTALISHED
tcp 0 0 192.168.0.18:22 192.168.0.23:52830 ESTALISHED
tcp 0 0 192.168.0.18:22 192.168.0.23:52990 ESTALISHED
tcp 0 0 :::22 :::* LISTN
tcp 0 0 ::1:631 :::* LISTN
tcp 0 0 ::1:25 :::* LISTN
tcp 0 0 ::1:6010 :::* LISTN
tcp 0 0 ::1:6011 :::* LISTN
tcp 0 0 ::1:6013 :::* LISTN
tcp 0 0 :::57027 :::* LISTN
tcp 0 0 :::111 :::* LISTN
tcp 0 0 :::80 :::* LISTN
#80端口处于监听状态,我们的服务以及启动了
#在网页上输入我们的IP地址这样就可以看到
4、完成上面一些操作后我们还需要对一些文件进行修改
安装后的配置:
(1) 导出二进制程序目录至PATH环境变量中;
编辑文件/etc/profile.d/NAME.sh
export PATH=/PATH/TO/BIN:$PATH
[[email protected] ld.so.conf.d]# cd /etc/profile.d/
[[email protected] profile.d]# ls
colorls.csh glib2.sh less.csh vim.csh
colorls.sh gnome-ssh-askpass.csh less.sh vim.sh
cvs.csh gnome-ssh-askpass.sh qt.csh which2.sh
cvs.sh lang.csh qt.sh
glib2.csh lang.sh udisks-bash-completion.sh
[[email protected] profile.d]# vim apache2.sh
[[email protected] profile.d]# cat apache2.sh
export PATH=/usr/local/apache2/bin:$PATH
(2) 导出库文件路径
编辑/etc/ld.so.conf.d/NAME.conf
添加新的库文件所在目录至此文件中;
[[email protected] ~]# cd /etc/ld.so.conf.d/
[[email protected] ld.so.conf.d]# ls
kernel-2.6.32-504.el6.x86_64.conf qt-x86_64.conf
mysql-x86_64.conf xulrunner-64.conf
[[email protected] ld.so.conf.d]# vim apache2.conf #新建一个文件存放apache2库文件路径
[[email protected] ld.so.conf.d]# cat apache2.conf
/usr/local/apache2/lib
让系统重新生成缓存:
ldconfig [-v]
(3) 导出头文件
基于链接的方式实现:
ln -sv
(4) 导出帮助手册
编辑/etc/man.config文件
添加一个MANPATH
这样我们一个程序的编译安装就好了。
六、总结。
在以上的学习中,发现最难得还是rpm包的编译安装,有些地方还是不太懂,不过rpm包的编译安装需要用到好多的知识点,这样又可以把之前所有学的再复习一遍,感觉这种方法不错的。