一、yum源共享
服务端:
- 安装http协议
- 关闭防火墙
- 挂载yum源镜像到网络共享目录
yum install httpd -y
systemctl stop firewalld
systemctl disable firewalld
systemctl start httpd
systemctl enable httpd
mkdir /var/www/html/source7.0
可以通过在浏览器中输入:http://服务端ip/rhel7
可以看到镜像中的内容,代表挂载没有问题
更改yum源配置文件
[kiosk@foundation79 Desktop]$ vim /etc/yum.repos.d/yum.repo
[rhel7.2] name=rhel7.2 baseurl=file:///var/www/html/soource7.0 gpgcheck=0 |
将镜像挂载到网络共享目录下
mount mount /iso/rhel-server-7.0-x86_64-dvd.iso /var/www/html/rhel7.0
df ##参看设备挂载情况
客户机:
更改yum源配置:
vim /etc/yum.repos.d/rhel_dvd.repo
[rhel_dvd] gpgcheck = 0 enabled = 1 baseurl = http://172.25.254.79/source7.0 name = Remote classroom copy of dvd |
实战:
yum服务器端:
[kiosk@foundation79 Desktop]$ df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda9 125254908 21261612 103993296 17% /
devtmpfs 3951352 0 3951352 0% /dev
tmpfs 3964400 580 3963820 1% /dev/shm
tmpfs 3964400 33732 3930668 1% /run
tmpfs 3964400 0 3964400 0% /sys/fs/cgroup
/dev/sda7 505580 149292 356288 30% /boot
/dev/loop0 3654720 3654720 0 100% /var/www/html/source7.0
tmpfs 792884 40 792844 1% /run/user/1000
tmpfs 792884 0 792884 0% /run/user/0
[kiosk@foundation79 Desktop]$ vim /etc/yum.repos.d/yum.repo
[rhel7.2] name=rhel7.2 baseurl=file:///var/www/html/source7.0 gpgcheck=0 |
效果检验
客户机:
配置之前:
[root@localhost ~]# yum search ImageM
Loaded plugins: langpacks
http://content.example.com/rhel7/repodata/repomd.xml: [Errno 14] curl#7 - "Failed connect to content.example.com:80; No route to host"
Trying other mirror.
配置之后:
[kiosk@foundation79 Desktop]$ yum search ImageM
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-
: manager
rhel7.2 | 4.1 kB 00:00
(1/2): rhel7.2/group_gz | 134 kB 00:00
(2/2): rhel7.2/primary_db | 3.4 MB 00:00
============================= N/S matched: ImageM ==============================
ImageMagick-c++.i686 : ImageMagick Magick++ library (C++ bindings)
ImageMagick-c++.x86_64 : ImageMagick Magick++ library (C++ bindings)
ImageMagick-perl.x86_64 : ImageMagick perl bindings
ImageMagick.i686 : An X application for displaying and manipulating images
ImageMagick.x86_64 : An X application for displaying and manipulating images
Name and summary matches only, use "search all" for everything.
二、第三方yum源配置
1、创建一个文件夹,并把需要的RPM安装包存放到这
[root@foundation79 mnt]# mkdir /mnt/yum_local
[root@foundation79 mnt]# mv vincent.rpm yum_local/
2、使用createrepo在RPM包的路径下创建YUM索引数据库
[root@foundation79 mnt]# createrepo yum_local/
Spawning worker 0 with 1 pkgs
Spawning worker 1 with 0 pkgs
Spawning worker 2 with 0 pkgs
Spawning worker 3 with 0 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete
创建完成后,会多一个repodata文件夹:
[root@foundation79 mnt]# ls yum_local/repodata/*
yum_local/repodata/0ba95458f34b58ca25c8419ba5a3a4af91ae99ad12f18d3d937d3d421cfd362f-primary.sqlite.bz2
yum_local/repodata/11148022609abc00018b877b565a4bc4b1cb11b9a510e1d2cd3a83acd6b0e1c5-filelists.sqlite.bz2
yum_local/repodata/2f8f58f9c973195abd254944d0c0d0a40f67ebd2eb2dbd27fc943b311608bd37-primary.xml.gz
yum_local/repodata/4739bb582e93ab2cfbeb597724678ccef8186eae2eae702c2ac4cc7dd081ec62-other.xml.gz
yum_local/repodata/516ef7bc957978862f7e1eedbc7d47b949e6cdf8ab24f2dd8a265765b552a6ea-filelists.xml.gz
yum_local/repodata/ebe0b2b5db08f8272bb018d59bc69c62a89f6c320c6a7f78e90f7c39237648d7-other.sqlite.bz2
yum_local/repodata/repomd.xml
3、更改本地yum.repo文件,指向本地YUM源
[root@foundation79 mnt]# cat > /etc/yum.repos.d/yum.repo << end
> [local_yum]
> name=my_yum
> baseurl=file:///mnt/yum_local
> gpgcheck=0
> end
4、清除YUM以前的缓存信息
[root@foundation79 mnt]# yum clean all
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Cleaning repos: local_yum
Cleaning up everything
检验结果:
[root@foundation79 mnt]# yum repolist
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
local_yum | 2.9 kB 00:00:00
local_yum/primary_db | 2.5 kB 00:00:00
repo id repo name status
local_yum my_yum 1
repolist: 1
安装yum命令并将yum源改为网易的镜像库
1.卸载原来的yum及相关软件
rpm -qa|grep yum|xargs rpm -e --nodeps
2.下载新的yum源
网易的镜像网站为:http://mirrors.163.com,我安装的系统是红帽7版本,所以选择下载Centos7的镜像源,在以下网址http://mirrors.163.com/centos/7/os/x86_64/Packages/ 下载所需文件,所需的文件为:
rpm-4.11.3-25.el7.x86_64.rpm
yum-metadata-parser-1.1.4-10.el7.x86_6
python-urlgrabber-3.10-8.el7.noarch.rpm
yum-3.4.3-154.el7.centos.noarch.rpm
yum-plugin-fastestmirror-1.1.31-42.el7.noarch.rpm
3.安装
rpm -ivh *.rpm --nodeps
4.配置文件
网易镜像的配置文件可以在http://mirrors.163.com/.help/centos.html 进行下载,Centos7的镜像下载链接为:http://mirrors.163.com/.help/CentOS7-Base-163.repo
wget http://mirrors.163.com/.help/CentOS7-Base-163.repo
变量转化为相应的系统版本,在这里就是 7 。在vi编辑器下执行下述指令即可更改:
:$s/$releasever/7/g
5.完成
[root@79 yum]# yum repolist
Loaded plugins: product-id, search-disabled-repos,
base/x86_64/primary_db | 5.9 MB 00:00:03
http://mirrors.163.com/centos/7/os/x86_64/Packages/repodata/repomd.xml: [Errno 14] HTTP Error 404 - Not Found
Trying other mirror.
extras/x86_64 | 3.4 kB 00:00:00
extras/x86_64/primary_db | 150 kB 00:00:00
updates/x86_64 | 3.4 kB 00:00:00
updates/x86_64/primary_db | 3.6 MB 00:00:00
repo id repo name status
base/x86_64 CentOS-7 - Base - 163.com 9,911
custom custom 0
extras/x86_64 CentOS-7 - Extras - 163.com 314
updates/x86_64 CentOS-7 - Updates - 163.com 946
repolist: 11,171
一个自动执行脚本
#!/bin/bash ###make a local yum source to install httpd service##### #before start,copy the **.iso to a file i choose ‘/iso’ # mkdir /mount #make a file use to mount the **.iso mount /iso/rhel-server-7.0-x86_64-dvd.iso /mount #mount the **.iso to the mount file mkdir /etc/backup ##make a file to bak the *.repo file mv /etc/yum.repos.d/* /etc/backup/ #move the *.repo file to the backfile yum clean all ##to refesh ######add the yum.repo file to add the yum source## cat > /etc/yum.repos.d/yum.repo << end |
[test]
name=myyum
baseurl=file:///mount
gpgcheck=0
end
yum clean all ## to refresh
yum repolist ##to see whether the yum-repo-setting is working
### above, the local yum-source is ok! now use the local yum-source we create to down httpd server. setting the httpd server to share the local-iso-source with http###
######install http server###
yum install httpd -y ##install the httpd server
systemctl start httpd ##start the httpd server
systemctl enable httpd ##set start httpd server every time start the sys
systemctl stop firewalld
systemctl disable firewalld
###setting http server let the httpd server can find our iso source
umount /mount #unmount the **iso file inorder to let it mount under the http sserver
yum clean all
yum repolist
mkdir /var/www/html/myshare ##make a file in http server-file to let it find the iso-source
mount /iso/rhel-server-7.0-x86_64-dvd.iso /var/www/html/myshare ##mount the iso-source to the http server
systemctl restart httpd
###now because we unmount the /mount that we set local-source to mount the http server so we can not use localyum###
###to modify the local-yum-source to let it share the source with http server###
cat > /etc/yum.repos.d/yum.repo << end
[test]
name=myyum
baseurl=http://172.25.6.11/myshare
gpgcheck=0
end
yum clean all
yum repolist
#####set automount when start the system######
cat >> /etc/fstab << end
/iso/rhel-server-7.0-x86_64-dvd.iso /var/www/html/myshare iso9660 ro 0 0
end