三种方式搭建yum源
1、本地搭建yum源:
[root@nginx1 x86_64]# vim /etc/yum.repos.d/mnt.repo
[root@nginx1 x86_64]# cd /etc/yum.repos.d/
[root@nginx1 yum.repos.d]# ll
total 36
-rw-r--r--. 1 root root 1664 Dec 9 2015 CentOS-Base.repo
-rw-r--r--. 1 root root 1309 Dec 9 2015 CentOS-CR.repo
-rw-r--r--. 1 root root 649 Dec 9 2015 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root 290 Dec 9 2015 CentOS-fasttrack.repo
-rw-r--r--. 1 root root 630 Dec 9 2015 CentOS-Media.repo
-rw-r--r--. 1 root root 1331 Dec 9 2015 CentOS-Sources.repo
-rw-r--r--. 1 root root 1952 Dec 9 2015 CentOS-Vault.repo
-rw-r--r-- 1 root root 57 Sep 6 15:23 mnt.repo
-rw-r--r--. 1 root root 100 Jul 14 05:54 nginx.repo
[root@nginx1 yum.repos.d]# pwd
/etc/yum.repos.d
[root@nginx1 yum.repos.d]#cat /etc/yum.repos.d/mnt.repo
[mnt] name=mnt baseurl=file:///mnt gpgcheck=0 enabled=1
[root@nginx1 yum.repos.d]# mount /dev/cdrom /mnt/
[root@nginx1 yum.repos.d]# df -TH
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/centos-root xfs 19G 8.5G 11G 46% /
devtmpfs devtmpfs 947M 0 947M 0% /dev
tmpfs tmpfs 957M 8.2k 957M 1% /dev/shm
tmpfs tmpfs 957M 102M 856M 11% /run
tmpfs tmpfs 957M 0 957M 0% /sys/fs/cgroup
/dev/sda1 xfs 521M 136M 386M 27% /boot
tmpfs tmpfs 192M 17k 192M 1% /run/user/0
/dev/sr0 iso9660 4.4G 4.4G 0 100% /mnt
2、阿里云yum源:
centos6.0:
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
centos7.0:
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
[base] name=CentOS-$releasever - Base - mirrors.aliyun.com failovermethod=priority baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/ http://mirrors.aliyuncs.com/centos/$releasever/os/$basearch/ #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os gpgcheck=1 gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7 #released updates [updates] name=CentOS-$releasever - Updates - mirrors.aliyun.com failovermethod=priority baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/ http://mirrors.aliyuncs.com/centos/$releasever/updates/$basearch/ #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates gpgcheck=1 gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7 #additional packages that may be useful [extras] name=CentOS-$releasever - Extras - mirrors.aliyun.com failovermethod=priority baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/ http://mirrors.aliyuncs.com/centos/$releasever/extras/$basearch/ #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras gpgcheck=1 gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7 #additional packages that extend functionality of existing packages [centosplus] name=CentOS-$releasever - Plus - mirrors.aliyun.com failovermethod=priority baseurl=http://mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/ http://mirrors.aliyuncs.com/centos/$releasever/centosplus/$basearch/ #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus gpgcheck=1 enabled=0 gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7 #contrib - packages by Centos Users [contrib] name=CentOS-$releasever - Contrib - mirrors.aliyun.com failovermethod=priority baseurl=http://mirrors.aliyun.com/centos/$releasever/contrib/$basearch/ http://mirrors.aliyuncs.com/centos/$releasever/contrib/$basearch/ #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib gpgcheck=1 enabled=0 gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
运行生成缓存:yum makecache
3、搭建yum服务器
createrepo是yum源维护的工具。
在yum server服务器上面:
yum -y install createrepo
[root@nginx1 yum.repos.d]# yum -y install httpd [root@nginx1 yum.repos.d]# systemctl restart httpd [root@nginx1 yum.repos.d]# mkdir -p /var/www/html/centos7.2/x86_64 [root@nginx1 yum.repos.d]# mount /dev/cdrom /mnt/ [root@nginx1 yum.repos.d]# cp -ar /mnt/* /var/www/html/centos7.2/x86_64 [root@nginx1 yum.repos.d]# cd /var/www/html/ [root@nginx1 html]#createrepo -p -d -o centos7.2/x86_64/ centos7.2/x86_64/
在client客户端上面:
[root@host3 yum.repos.d]# cat test.repo [test] name=test baseurl=http://172.25.254.130/centos7.2/x86_64 gpgcheck=0 [root@host3 yum.repos.d]# [root@host3 yum.repos.d]# yum clean all [root@host3 yum.repos.d]# yum install -y virt-manager …………………………………………………………………… mesa-libEGL.x86_64 0:10.6.5-3.20150824.el7 mesa-libGL.x86_64 0:10. mesa-libgbm.x86_64 0:10.6.5-3.20150824.el7 mesa-libglapi.x86_64 nmap-ncat.x86_64 2:6.40-7.el7 pango.x86_64 0:1.36.8 pixman.x86_64 0:0.32.6-3.el7 pulseaudio-libs.x86_6 pulseaudio-libs-glib2.x86_64 0:6.0-7.el7 pycairo.x86_64 0:1.8. pygobject3.x86_64 0:3.14.0-3.el7 python-ipaddr.noarch rest.x86_64 0:0.7.92-3.el7 spice-glib.x86_64 0:0 spice-gtk3.x86_64 0:0.26-5.el7 unbound-libs.x86_64 0 usbredir.x86_64 0:0.6-7.el7 virt-manager-common.n vte-profile.x86_64 0:0.38.3-2.el7 vte3.x86_64 0:0.36.4- Complete!