yum源搭建
搭建本地yum源
红帽系统镜像中有我们可能会用到的一些软件,搭载好的yum源相当于手机上的应用市场,可以在其中下载需要的软件。以下操作是在真机和server虚拟机中搭载yum源
1.之前我介绍过,/mnt目录是Linux系统中的临时挂载点,我们需要先将红帽7.3的镜像挂载在真机的/mnt目录下,挂载完成后对/mnt目录进行的操作就是对镜像进行的操作。
[kiosk@foundation67 Desktop]$ mount rhel-server-7.3-x86_64-dvd.iso /mnt
mount: only root can do that #注意:必须是超级用户才能进行挂载
[kiosk@foundation67 Desktop]$ su
Password:
[root@foundation67 Desktop]# mount rhel-server-7.3-x86_64-dvd.iso /mnt
mount: /dev/loop0 is write-protected, mounting read-only
2.输入df指令,df指令可以查看系统挂载情况
[root@foundation67 Desktop]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda8 328423752 16996088 311427664 6% /
devtmpfs 3949744 0 3949744 0% /dev
tmpfs 3964732 500 3964232 1% /dev/shm
tmpfs 3964732 9436 3955296 1% /run
tmpfs 3964732 0 3964732 0% /sys/fs/cgroup
/dev/sda6 505580 151500 354080 30% /boot
/dev/sda1 303104 34528 268576 12% /boot/efi
tmpfs 792948 16 792932 1% /run/user/1000
/dev/sdb1 15101488 6276288 8825200 42% /run/media/kiosk/KINGSTON
/dev/loop0 3704296 3704296 0 100% /mnt
3.从上图中可以看出/mnt目录下挂载完成,相当于建好了一个仓库,但是仓库建好后必须要知道前往仓库的路径,只有这样才能去仓库之中买东西,挂载完成后就需要修改配置文件,修改配置文件就相当于告知系统仓库的路径。配置文件在/etc/yum.repos.d/
目录下
[root@foundation67 Desktop]# cd /etc/yum.repos.d/
[root@foundation67 yum.repos.d]# ls
redhat.repo yum.repo
4.将该目录下的所有文件清空
[root@foundation67 yum.repos.d]# rm -rf *
5.清空之后必须新建一个以.repo结尾的文件,名称可以随便起
[root@foundation67 yum.repos.d]# vim yum.repo
[root@foundation67 yum.repos.d]# cat yum.repo
[rhel7.3] #仓库描述
name=rhel7.3 server #对软件源的描述
baseurl=file:///mnt #镜像挂载的地址
gpgcheck=0 #不检测gpgkey
enabled=1 #此yum源语句块立即生效
6.之后对yum源进行检测:
先清空之前的yum源信息
[root@foundation67 yum.repos.d]# 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: rhel7.3
Cleaning up everything
之后列出yum的信息
[root@foundation67 yum.repos.d]# 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.
rhel7.3 | 4.1 kB 00:00:00
(1/2): rhel7.3/group_gz | 136 kB 00:00:00
(2/2): rhel7.3/primary_db | 3.9 MB 00:00:00
repo id repo name status
rhel7.3 rhel7.3 server 4,751
repolist: 4,751
列出yum信息后可以先在真机上下载gcc服务进行测试
yum安装格式为
yum install 软件名 -y
[root@foundation67 yum.repos.d]# yum install gcc -y
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.
Resolving Dependencies
--> Running transaction check
---> Package gcc.x86_64 0:4.8.5-11.el7 will be installed
--> Processing Dependency: cpp = 4.8.5-11.el7 for package: gcc-4.8.5-11.el7.x86_64
--> Processing Dependency: libgomp = 4.8.5-11.el7 for package: gcc-4.8.5-11.el7.x86_64
--> Processing Dependency: glibc-devel >= 2.2.90-12 for package: gcc-4.8.5-11.el7.x86_64
--> Processing Dependency: libgcc >= 4.8.5-11.el7 for package: gcc-4.8.5-11.el7.x86_64
--> Processing Dependency: libmpc.so.3()(64bit) for package: gcc-4.8.5-11.el7.x86_64
--> Processing Dependency: libmpfr.so.4()(64bit) for package: gcc-4.8.5-11.el7.x86_64
--> Running transaction check
---> Package cpp.x86_64 0:4.8.5-11.el7 will be installed
---> Package glibc-devel.x86_64 0:2.17-157.el7 will be installed
--> Processing Dependency: glibc = 2.17-157.el7 for package: glibc-devel-2.17-157.el7.x86_64
--> Processing Dependency: glibc-headers = 2.17-157.el7 for package: glibc-devel-2.17-157.el7.x86_64
--> Processing Dependency: glibc-headers for package: glibc-devel-2.17-157.el7.x86_64
---> Package libgcc.x86_64 0:4.8.5-4.el7 will be updated
---> Package libgcc.x86_64 0:4.8.5-11.el7 will be an update
---> Package libgomp.x86_64 0:4.8.5-4.el7 will be updated
---> Package libgomp.x86_64 0:4.8.5-11.el7 will be an update
---> Package libmpc.x86_64 0:1.0.1-3.el7 will be installed
---> Package mpfr.x86_64 0:3.1.1-4.el7 will be installed
--> Running transaction check
---> Package glibc.x86_64 0:2.17-105.el7 will be updated
--> Processing Dependency: glibc = 2.17-105.el7 for package: glibc-common-2.17-105.el7.x86_64
---> Package glibc.x86_64 0:2.17-157.el7 will be an update
---> Package glibc-headers.x86_64 0:2.17-157.el7 will be installed
--> Processing Dependency: kernel-headers >= 2.2.1 for package: glibc-headers-2.17-157.el7.x86_64
--> Processing Dependency: kernel-headers for package: glibc-headers-2.17-157.el7.x86_64
--> Running transaction check
---> Package glibc-common.x86_64 0:2.17-105.el7 will be updated
---> Package glibc-common.x86_64 0:2.17-157.el7 will be an update
---> Package kernel-headers.x86_64 0:3.10.0-514.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
=========================================================================================================
Package Arch Version Repository Size
=========================================================================================================
Installing:
gcc x86_64 4.8.5-11.el7 rhel7.3 16 M
Installing for dependencies:
cpp x86_64 4.8.5-11.el7 rhel7.3 5.9 M
glibc-devel x86_64 2.17-157.el7 rhel7.3 1.1 M
glibc-headers x86_64 2.17-157.el7 rhel7.3 668 k
kernel-headers x86_64 3.10.0-514.el7 rhel7.3 4.8 M
libmpc x86_64 1.0.1-3.el7 rhel7.3 51 k
mpfr x86_64 3.1.1-4.el7 rhel7.3 203 k
Updating for dependencies:
glibc x86_64 2.17-157.el7 rhel7.3 3.6 M
glibc-common x86_64 2.17-157.el7 rhel7.3 11 M
libgcc x86_64 4.8.5-11.el7 rhel7.3 97 k
libgomp x86_64 4.8.5-11.el7 rhel7.3 152 k
Transaction Summary
=========================================================================================================
Install 1 Package (+6 Dependent packages)
Upgrade ( 4 Dependent packages)
Total download size: 44 M
Downloading packages:
---------------------------------------------------------------------------------------------------------
Total 54 MB/s | 44 MB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Updating : libgcc-4.8.5-11.el7.x86_64 1/15
Updating : glibc-2.17-157.el7.x86_64 2/15
Updating : glibc-common-2.17-157.el7.x86_64 3/15
Installing : mpfr-3.1.1-4.el7.x86_64 4/15
Installing : libmpc-1.0.1-3.el7.x86_64 5/15
Installing : cpp-4.8.5-11.el7.x86_64 6/15
Updating : libgomp-4.8.5-11.el7.x86_64 7/15
Installing : kernel-headers-3.10.0-514.el7.x86_64 8/15
Installing : glibc-headers-2.17-157.el7.x86_64 9/15
Installing : glibc-devel-2.17-157.el7.x86_64 10/15
Installing : gcc-4.8.5-11.el7.x86_64 11/15
Cleanup : libgomp-4.8.5-4.el7.x86_64 12/15
Cleanup : glibc-2.17-105.el7.x86_64 13/15
Cleanup : glibc-common-2.17-105.el7.x86_64 14/15
Cleanup : libgcc-4.8.5-4.el7.x86_64 15/15
rhel7.3/productid | 1.6 kB 00:00:00
Verifying : glibc-common-2.17-157.el7.x86_64 1/15
Verifying : glibc-devel-2.17-157.el7.x86_64 2/15
Verifying : kernel-headers-3.10.0-514.el7.x86_64 3/15
Verifying : mpfr-3.1.1-4.el7.x86_64 4/15
Verifying : libgcc-4.8.5-11.el7.x86_64 5/15
Verifying : glibc-2.17-157.el7.x86_64 6/15
Verifying : cpp-4.8.5-11.el7.x86_64 7/15
Verifying : libgomp-4.8.5-11.el7.x86_64 8/15
Verifying : gcc-4.8.5-11.el7.x86_64 9/15
Verifying : glibc-headers-2.17-157.el7.x86_64 10/15
Verifying : libmpc-1.0.1-3.el7.x86_64 11/15
Verifying : libgomp-4.8.5-4.el7.x86_64 12/15
Verifying : libgcc-4.8.5-4.el7.x86_64 13/15
Verifying : glibc-common-2.17-105.el7.x86_64 14/15
Verifying : glibc-2.17-105.el7.x86_64 15/15
Installed:
gcc.x86_64 0:4.8.5-11.el7
Dependency Installed:
cpp.x86_64 0:4.8.5-11.el7 glibc-devel.x86_64 0:2.17-157.el7
glibc-headers.x86_64 0:2.17-157.el7 kernel-headers.x86_64 0:3.10.0-514.el7
libmpc.x86_64 0:1.0.1-3.el7 mpfr.x86_64 0:3.1.1-4.el7
Dependency Updated:
glibc.x86_64 0:2.17-157.el7 glibc-common.x86_64 0:2.17-157.el7 libgcc.x86_64 0:4.8.5-11.el7
libgomp.x86_64 0:4.8.5-11.el7
Complete!
7.安装完成,说明yum源搭载完成
在真机上搭载yum源来让虚拟机使用
1.以上操作是在真机上配置yum源,配置yum源后可以在真机上下载http服务,下载完http服务后就可以让虚拟机使用搭载在真机上的yum源来下载虚拟机所必须的一些软件(起到共享的作用),但是想要让虚拟机使用真机上的yum源就必须将版本7.0的镜像挂载在真机的/var/www/html/rhel7.0目录上(rhel7.0是后面新建的)并且开启http服务。
注意:虚拟机的版本号必须要和镜像的版本号匹配,只有这样在yum源中下载软件才能在虚拟机中使用。而且真机的镜像也必须要和真机使用的镜像相匹配(我使用的真机版本是7.3),否则安装的http服务可能不能正常使用
[root@foundation67 yum.repos.d]# yum install httpd -y
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.
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_64 0:2.4.6-45.el7 will be installed
--> Processing Dependency: httpd-tools = 2.4.6-45.el7 for package: httpd-2.4.6-45.el7.x86_64
--> Processing Dependency: libapr-1.so.0()(64bit) for package: httpd-2.4.6-45.el7.x86_64
--> Processing Dependency: libaprutil-1.so.0()(64bit) for package: httpd-2.4.6-45.el7.x86_64
--> Running transaction check
---> Package apr.x86_64 0:1.4.8-3.el7 will be installed
---> Package apr-util.x86_64 0:1.5.2-6.el7 will be installed
---> Package httpd-tools.x86_64 0:2.4.6-45.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
=========================================================================================================
Package Arch Version Repository Size
=========================================================================================================
Installing:
httpd x86_64 2.4.6-45.el7 rhel7.3 1.2 M
Installing for dependencies:
apr x86_64 1.4.8-3.el7 rhel7.3 103 k
apr-util x86_64 1.5.2-6.el7 rhel7.3 92 k
httpd-tools x86_64 2.4.6-45.el7 rhel7.3 84 k
Transaction Summary
=========================================================================================================
Install 1 Package (+3 Dependent packages)
Total download size: 1.4 M
Installed size: 4.3 M
Downloading packages:
---------------------------------------------------------------------------------------------------------
Total 20 MB/s | 1.4 MB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : apr-1.4.8-3.el7.x86_64 1/4
Installing : apr-util-1.5.2-6.el7.x86_64 2/4
Installing : httpd-tools-2.4.6-45.el7.x86_64 3/4
Installing : httpd-2.4.6-45.el7.x86_64 4/4
Verifying : httpd-tools-2.4.6-45.el7.x86_64 1/4
Verifying : apr-util-1.5.2-6.el7.x86_64 2/4
Verifying : httpd-2.4.6-45.el7.x86_64 3/4
Verifying : apr-1.4.8-3.el7.x86_64 4/4
Installed:
httpd.x86_64 0:2.4.6-45.el7
Dependency Installed:
apr.x86_64 0:1.4.8-3.el7 apr-util.x86_64 0:1.5.2-6.el7 httpd-tools.x86_64 0:2.4.6-45.el7
Complete!
2.通过上述操作,在真机中下载了httpd服务,这样就可以让两个虚拟机使用挂载在真机中的镜像来下载软件,比较方便
通过以下操作来关闭防火墙和开启httpd服务,并且将红帽7.0版本的镜像挂载在/var/www/html/rhel7.0目录上来让两个虚拟机从这个镜像中下载软件,这就相当于手机中的应用市场
[root@foundation67 yum.repos.d]# systemctl stop firewalld
[root@foundation67 yum.repos.d]# systemctl disable firewalld
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
Removed symlink /etc/systemd/system/basic.target.wants/firewalld.service.
[root@foundation67 yum.repos.d]# systemctl start httpd
[root@foundation67 yum.repos.d]# systemctl status httpd
● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
Active: active (running) since Sat 2019-01-19 22:14:56 CST; 8s ago
Docs: man:httpd(8)
man:apachectl(8)
Main PID: 6460 (httpd)
Status: "Processing requests..."
CGroup: /system.slice/httpd.service
├─6460 /usr/sbin/httpd -DFOREGROUND
├─6544 /usr/sbin/httpd -DFOREGROUND
├─6545 /usr/sbin/httpd -DFOREGROUND
├─6546 /usr/sbin/httpd -DFOREGROUND
├─6547 /usr/sbin/httpd -DFOREGROUND
└─6548 /usr/sbin/httpd -DFOREGROUND
Jan 19 22:14:16 foundation67.ilt.example.com systemd[1]: Starting The Apache HTTP Server...
Jan 19 22:14:36 foundation67.ilt.example.com httpd[6460]: AH00557: httpd: apr_sockaddr_info_get() fa...om
Jan 19 22:14:36 foundation67.ilt.example.com httpd[6460]: AH00558: httpd: Could not reliably determi...ge
Jan 19 22:14:56 foundation67.ilt.example.com systemd[1]: Started The Apache HTTP Server.
Hint: Some lines were ellipsized, use -l to show in full.
在/var/www/html/目录下新建rhel7.0目录,之后要将7.0的镜像挂载在rhel7.0这个目录上
[root@foundation67 yum.repos.d]# mkdir /var/www/html/rhel7.0
[root@foundation67 yum.repos.d]# mount /home/kiosk/Desktop/rhel-server-7.0-x86_64-dvd.iso /var/www/html/rhel7.0
mount: /dev/loop1 is write-protected, mounting read-only
3.挂载完成后便可以修改两个虚拟机中的配置文件来在7.0镜像中下载软件,以下操作在虚拟机中进行,要确保虚拟机和真机可以ping得通。我的网络在之前已经配置好了,不在详述,要查看网络配置的相关操作,可以查阅一下我的“Linux远程免密登录那篇博客”,里面有比较详细的描述
[root@server Desktop]# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.25.254.117 netmask 255.255.255.0 broadcast 172.25.254.255
inet6 fe80::5054:ff:fe00:430b prefixlen 64 scopeid 0x20<link>
ether 52:54:00:00:43:0b txqueuelen 1000 (Ethernet)
RX packets 93 bytes 7065 (6.8 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 92 bytes 6705 (6.5 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 0 (Local Loopback)
RX packets 430 bytes 36540 (35.6 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 430 bytes 36540 (35.6 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@server Desktop]# ping 172.25.254.67
PING 172.25.254.67 (172.25.254.67) 56(84) bytes of data.
64 bytes from 172.25.254.67: icmp_seq=1 ttl=64 time=0.199 ms
64 bytes from 172.25.254.67: icmp_seq=2 ttl=64 time=0.156 ms
64 bytes from 172.25.254.67: icmp_seq=3 ttl=64 time=0.171 ms
^C
--- 172.25.254.67 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 1999ms
rtt min/avg/max/mdev = 0.156/0.175/0.199/0.020 ms
在虚拟机中进行yum源的配置文件的修改,相当于告知虚拟机yum源在真机中的路径,可以让虚拟机沿着路径从真机中下载必须的软件
[root@server Desktop]# cd /etc/yum.repos.d/
[root@server yum.repos.d]# ls
rhel_dvd.repo
[root@server yum.repos.d]# rm -rf *
[root@server yum.repos.d]# vim yum.repo
[root@server yum.repos.d]# cat yum.repo
[rhel7.0]
name=rhel7.0 server
baseurl=http://172.25.254.67/rhel7.0
gpgcheck=0
enabled=1
4.配置文件修改完成后进行测试
[root@server yum.repos.d]# yum clean all
Loaded plugins: langpacks
Cleaning repos: rhel7.0
Cleaning up everything
[root@server yum.repos.d]# yum repolist
Loaded plugins: langpacks
rhel7.0 | 4.1 kB 00:00
(1/2): rhel7.0/group_gz | 134 kB 00:00
(2/2): rhel7.0/primary_db | 3.4 MB 00:00
repo id repo name status
rhel7.0 rhel7.0 server 4,305
repolist: 4,305
关闭虚拟机防火墙,否则虚拟机不能成功地从真机中下载软件
[root@server yum.repos.d]# systemctl stop firewalld
[root@server yum.repos.d]# systemctl disable firewalld
rm '/etc/systemd/system/basic.target.wants/firewalld.service'
rm '/etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service'
可以先安装dhcp软件来测试yum源有没有搭载成功,下载好的dhcp软件在后续刚好也会使用到
[root@server yum.repos.d]# yum install dhcp -y
Loaded plugins: langpacks
Resolving Dependencies
--> Running transaction check
---> Package dhcp.x86_64 12:4.2.5-27.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================================================
Package Arch Version Repository Size
================================================================================================================
Installing:
dhcp x86_64 12:4.2.5-27.el7 rhel7.0 506 k
Transaction Summary
================================================================================================================
Install 1 Package
Total download size: 506 k
Installed size: 1.4 M
Downloading packages:
dhcp-4.2.5-27.el7.x86_64.rpm | 506 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : 12:dhcp-4.2.5-27.el7.x86_64 1/1
Verifying : 12:dhcp-4.2.5-27.el7.x86_64 1/1
Installed:
dhcp.x86_64 12:4.2.5-27.el7
Complete!