Linux程序包管理(2)
CentOS: yum, dnf
URL: ftp://172.16.0.1/pub/
YUM: yellow dog, Yellowdog Update Modifier
yum repository: yum repo
存储了众多rpm包,以及包的相关的元数据文件(放置于特定目录下:repodata);
文件服务器:
ftp://
http://
nfs://
file:///
yum客户端:
配置文件:
/etc/yum.conf:为所有仓库提供公共配置
/etc/yum.repos.d/*.repo:为仓库的指向提供配置
仓库指向的定义:(等号左右不能有空格)
[repositoryID]
name=Some name for this repository
baseurl=url://path/to/repository/
enabled={1|0}
gpgcheck={1|0}
gpgkey=URL
enablegroups={1|0}
failovermethod={roundrobin|priority}
默认为:roundrobin,意为随机挑选;
cost=
默认为1000
教室里的yum源:http://172.16.0.1/cobbler/ks_mirror/CentOS-6.6-x86_64/
CentOS 6.6 X84_64 epel: http://172.16.0.1/fedora-epel/6/x86_64/
yum命令的用法:
yum [options] [command] [package ...]
command is one of:
* install package1 [package2] [...]
* update [package1] [package2] [...]
* update-to [package1] [package2] [...]
* check-update
* upgrade [package1] [package2] [...]
* upgrade-to [package1] [package2] [...]
* distribution-synchronization [package1] [package2] [...]
* remove | erase package1 [package2] [...]
* list [...]
* info [...]
* provides | whatprovides feature1 [feature2] [...]
* clean [ packages | metadata | expire-cache | rpmdb | plugins | all ]
* makecache
* groupinstall group1 [group2] [...]
* groupupdate group1 [group2] [...]
* grouplist [hidden] [groupwildcard] [...]
* groupremove group1 [group2] [...]
* groupinfo group1 [...]
* search string1 [string2] [...]
* shell [filename]
* resolvedep dep1 [dep2] [...]
* localinstall rpmfile1 [rpmfile2] [...]
(maintained for legacy reasons only - use install)
* localupdate rpmfile1 [rpmfile2] [...]
(maintained for legacy reasons only - use update)
* reinstall package1 [package2] [...]
* downgrade package1 [package2] [...]
* deplist package1 [package2] [...]
* repolist [all|enabled|disabled]
* version [ all | installed | available | group-* | nogroups* | grouplist | groupinfo ]
* history [info|list|packages-list|packages-info|summary|addon-info|redo|undo|rollback|new|sync|stats]
* check
* help [command]
显示仓库列表:
repolist [all|enabled|disabled]
显示程序包:
list
# yum list [all | glob_exp1] [glob_exp2] [...]
# yum list {available|installed|updates} [glob_exp1] [...]
安装程序包:
install package1 [package2] [...]
reinstall package1 [package2] [...] (重新安装)
升级程序包:
update [package1] [package2] [...]
downgrade package1 [package2] [...] (降级)
检查可用升级:
check-update
卸载程序包:
remove | erase package1 [package2] [...]
查看程序包information:
info [...]
查看指定的特性(可以是某文件)是由哪个程序包所提供:
provides | whatprovides feature1 [feature2] [...]
清理本地缓存:
clean [ packages | metadata | expire-cache | rpmdb | plugins | all ]
构建缓存:
makecache
搜索:
search string1 [string2] [...]
以指定的关键字搜索程序包名及summary信息;
查看指定包所依赖的capabilities:
deplist package1 [package2] [...]
查看yum事务历史:
history [info|list|packages-list|packages-info|summary|addon-info|redo|undo|rollback|new|sync|stats]
安装及升级本地程序包:
* localinstall rpmfile1 [rpmfile2] [...]
(maintained for legacy reasons only - use install)
* localupdate rpmfile1 [rpmfile2] [...]
(maintained for legacy reasons only - use update)
包组管理的相关命令:
* groupinstall group1 [group2] [...]
* groupupdate group1 [group2] [...]
* grouplist [hidden] [groupwildcard] [...]
* groupremove group1 [group2] [...]
* groupinfo group1 [...]
如何使用光盘当作本地yum仓库:
(1) 挂载光盘至某目录,例如/media/cdrom
# mount -r -t iso9660 /dev/cdrom /media/cdrom
(2) 创建配置文件
[CentOS7]
name=
baseurl=
gpgcheck=
enabled=
yum的命令行选项:
--nogpgcheck:禁止进行gpg check;
-y: 自动回答为“yes”;
-q:静默模式;
--disablerepo=repoidglob:临时禁用此处指定的repo;
--enablerepo=repoidglob:临时启用此处指定的repo;
--noplugins:禁用所有插件;
yum的repo配置文件中可用的变量:
$releasever: 当前OS的发行版的主版本号;
$arch: 平台;
$basearch:基础平台;
$YUM0-$YUM9
http://mirrors.magedu.com/centos/$releasever/$basearch/os
创建yum仓库:
createrepo [options] <directory>
程序包编译安装:
testapp-VERSION-release.src.rpm --> 安装后,使用rpmbuild命令制作成二进制格式的rpm包,而后再安装;
源代码 --> 预处理 --> 编译(gcc) --> 汇编 --> 链接 --> 执行
源代码组织格式:
多文件:文件中的代码之间,很可能存在跨文件依赖关系;
C、C++: make (configure --> Makefile.in --> makefile)
java: maven
C代码编译安装三步骤:
./configure:
(1) 通过选项传递参数,指定启用特性、安装路径等;执行时会参考用户的指定以及Makefile.in文件生成makefile;
(2) 检查依赖到的外部环境;
make:
根据makefile文件,构建应用程序;
make install
开发工具:
autoconf: 生成configure脚本
automake:生成Makefile.in
建议:安装前查看INSTALL,README
开源程序源代码的获取:
官方自建站点:
apache.org (ASF)
mariadb.org
...
代码托管:
SourceForge
Github.com
code.google.com
c/c++: gcc (GNU C Complier)
编译C源代码:
前提:提供开发工具及开发环境
开发工具:make, gcc等
开发环境:开发库,头文件
glibc:标准库
通过“包组”提供开发组件
CentOS 6: "Development Tools", "Server Platform Development",
第一步:configure脚本
选项:指定安装位置、指定启用的特性
--help: 获取其支持使用的选项
选项分类:
安装路径设定:
--prefix=/PATH/TO/SOMEWHERE: 指定默认安装位置;默认为/usr/local/
--sysconfdir=/PATH/TO/SOMEWHERE:配置文件安装位置;
System types:
Optional Features: 可选特性
--disable-FEATURE
--enable-FEATURE[=ARG]
Optional Packages: 可选包
--with-PACKAGE[=ARG]
--without-PACKAGE
第二步:make
第三步:make install
安装后的配置:
(1) 导出二进制程序目录至PATH环境变量中;
编辑文件/etc/profile.d/NAME.sh
export PATH=/PATH/TO/BIN:$PATH
(2) 导出库文件路径
编辑/etc/ld.so.conf.d/NAME.conf
添加新的库文件所在目录至此文件中;
让系统重新生成缓存:
ldconfig [-v]
(3) 导出头文件
基于链接的方式实现:
ln -sv
(4) 导出帮助手册
编辑/etc/man.config文件
添加一个MANPATH
练习:
1、yum的配置和使用;包括yum repository的创建;
2、编译安装apache 2.2; 启动此服务;
博客作业:程序包管理:rpm/yum/编译