YUM 仓库的搭建
一、yum仓库的工作原理
yum客户端:以安装为例 第一步:获取仓库元数据 缓存于本地:/var/cache/yum 第二步:安装程序包 yum客户端程序在本地分析元数据文件,并结合本地系统环境(已安装的包)做出要安装的程序包的决策 X --> Y,Z,M,N 第三步:获取程序包 根据决策联系Yum仓库,下载各程序包缓存于本地后,一并进行安装;
二、使yum仓库配置文件的修改
用yum机制:
1、确保有yum repo可用;
rpm包的文件服务器,repodata目录所在父目录就是一个可用仓库;
ftp ftp://server/path/to/repository ftp仓库baseurl的目录配置 http http://server/path/to/repository http仓库baseurl的目录配置 nfs nfs://server/nfs_path nts仓库baseurl的目录配置 file file:///path/to/repository 本地仓库baseurl的目录配置 file:///media/cdrom
2、yum客户端
指供repo配置文件,指明仓库访问路径及各种属性信息
主配置文件(中心配置文件):/etc/yum.conf
一个或几个相关仓库的配置信息可保存为一个文件,文件名都以.repo结尾:/etc/yum.repos.d/
在.repo文件定义一个yum repo指向的格式:
[REPOID] name=Some name for this repository baseurl=file:///media/cdrom ftp:///pub/ftp/centos Must be a URL to the directory where the yum repository's 'repodata' directory lives enabled={0|1} gpgcheck={0|1} gpgcheck检测 0 不检测 1 检测 gpgkey=URL gpgkey检测 0 不检测 1 检测 mirrorlist=URL to a file mirrorlist url 链接 mirrorlist Specifies a URL to a file containing a list of baseurls cost={1..n} 带宽开销
默认为1000,指定访问此仓库的开销
三、实验
三种方法配置yum仓库
一、本地yum仓库的配置
1、到镜像源网站下载适合自己平台centos的镜像源dvd2
2、虚拟机挂载光驱
3、虚拟机挂载光盘镜像
[[email protected] ~]# mount 查看挂载情况 /dev/mapper/vg0-root on / type ext4 (rw) proc on /proc type proc (rw) sysfs on /sys type sysfs (rw) devpts on /dev/pts type devpts (rw,gid=5,mode=620) tmpfs on /dev/shm type tmpfs (rw) /dev/sda1 on /boot type ext4 (rw) /dev/mapper/vg0-usr on /usr type ext4 (rw) /dev/mapper/vg0-var on /var type ext4 (rw) none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw) [[email protected] /]# mount /dev/dvd/ tmp/zz 挂载光盘镜像 mount: block device /dev/sr0 is write-protected, mounting read-only 只读 [[email protected] /]# mount 查看挂载情况 /dev/mapper/vg0-root on / type ext4 (rw) proc on /proc type proc (rw) sysfs on /sys type sysfs (rw) devpts on /dev/pts type devpts (rw,gid=5,mode=620) tmpfs on /dev/shm type tmpfs (rw) /dev/sda1 on /boot type ext4 (rw) /dev/mapper/vg0-usr on /usr type ext4 (rw) /dev/mapper/vg0-var on /var type ext4 (rw) none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw) /dev/sr0 on /tmp/zz type iso9660 (ro) [[email protected] /]# cd /tmp/zz [[email protected] zz]# ls -a 进入目录查看 . .discinfo GPL Packages 软件包 RPM-GPG-KEY-CentOS-6 RPM-GPG-KEY-CentOS-Testing-6 .. EFI p_w_picpaths RELEASE-NOTES-en-US.html RPM-GPG-KEY-CentOS-Debug-6 TRANS.TBL CentOS_BuildTag EULA isolinux repodata yum仓库索引目录 RPM-GPG-KEY-CentOS-Security-6 .treeinfo
vim /etc/yum.repos.d/local.repo [base] name=local yum cangku 仓库名 baseurl=file:///tmp/zz/ 仓库链接 gpgcheck=0 gpgcheck不检测 5、实验结果 [[email protected] zz]# yum clean all 清除yum缓存 Loaded plugins: fastestmirror, refresh-packagekit, security Cleaning repos: base Cleaning up Everything Cleaning up list of fastest mirrors [[email protected] zz]# yum repolist all 查看可用yum仓库 Loaded plugins: fastestmirror, refresh-packagekit, securty Determining fastest mirrors base | 4.0 kB 00:00 ... base/primary_db | 4.4 MB 00:00 ... repo id repo name status base local yum cangku 仓库名 enabled: 6,367 可用软件包 repolist: 6,367 目录索引
注意前提、虚拟机配置能上网
1、去镜像官网 http://mirrors.163.com
2、找到centos帮助
3、点击属性
4、复制链接
5、下载yum镜像源网站yum目录索引
[[email protected] yum.repos.d]# wget http://mirrors.163.com/.help/CentOS6-Base-163.repo 下载yum镜像源网站yum目录索引 --2014-07-12 10:24:39-- http://mirrors.163.com/.help/CentOS6-Base-163.repo Resolving mirrors.163.com... 123.58.173.106 Connecting to mirrors.163.com|123.58.173.106|:80... connected. HTTP request sent, awaiting response... 200 OK Length: 2006 (2.0K) [application/octet-stream] Saving to: `CentOS6-Base-163.repo' 100%[==========================================================================================================>] 2,006 --.-K/s in 0.08s 2014-07-12 10:24:41 (25.2 KB/s) - `CentOS6-Base-163.repo' saved [2006/2006] [[email protected] yum.repos.d]# ls -a . .. CentOS6-Base-163.repo CentOS6-Base-163.repo.bak centos local.repo yum目录索引
1、注意安装服务前的工作 安装httpd 、ceraterepo 两款软件 下载yum软件
[[email protected] yum.repos.d]# rpm -q httpd 查询是否安装httpd软件 httpd-2.2.15-30.el6.centos.x86_64 [[email protected] yum.repos.d]# rpm -q createrepo 查询是否安装createrepo软件 createrepo-0.9.9-18.el6.noarch 2、启动httpd服务 80端口监听 [[email protected] yum.repos.d]# service httpd start 启动httpd服务 [ OK ] [[email protected] yum.repos.d]# ss -tanlp State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 128 80端口监听
3、复制软件包、生成目录索引
[[email protected] html]# pwd 查询当前目录 /var/www/html [[email protected] html]# ls -a 查询当前目录下的文件 . .. book [[email protected] book]# createrepo /var/www/html/book/ 创建yum目录索引 Spawning worker 0 with 548 pkgs Workers Finished Gathering worker results Saving Primary metadata Saving file lists metadata Saving other metadata Generating sqlite DBs Sqlite DBs complete 创建信息 [[email protected] html]# cd book [[email protected] book]# ls -a 进入软件包查看 cdparanoia-libs-10.2-5.1.el6.i686.rpm 软件包 repodata yum目录索引 cdparanoia-libs-10.2-5.1.el6.x86_64.rpm
4、文件配置
[[email protected] html]# vim /etc/yum.repos.d/local.repo [base] name=local yum cangku 仓库名 baseurl=http://172.16.111.43/book 目录链接 gpgcheck=0 gpgcheck 不检测
四、总结
此文主要的重点是配置文本的新建编辑、baseurl的指向要搞清楚、yum仓库的工作原理和yum目录索引记录的建立
转载于:https://blog.51cto.com/1983939925/1440540