Linux - 关于YUM源的三种配置方式

98 阅读4分钟

『环境准备』

两台Linux服务器,并关闭防火墙、禁用SELINUX

【01】关闭防火墙

systemctl stop firewalld && systemctl disable firewalld

【02】禁用SELINUX

setenforce 0 && sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config

【03】检查SELINUX是否已经禁用

[root@node1 home]# cat /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of these two values:
#     targeted - Targeted processes are protected,
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted

『通过File的方式配置』

单机(本地) 即可配置

【01】将操作系统的iso映像文件上传到服务器的/mnt/iso目录下(目录不存在可手动创建)

[root@node01 ~]# mkdir -p /mnt/iso

【02】挂载iso到/dev/cdrum目录(centos7.9该目录下的cdrum是个软连接)

[root@node01 ~]# mkdir -p /dev/cdrum
[root@node01 ~]# mount -o loop /mnt/iso/CentOS-7-x86_64-DVD-2009.iso /dev/cdrum/

【03】创建本地的yum仓库目录 /vat/ftp/pub/os79

[root@node01 ~]# mkdir -p /var/ftp/pub/os79

【04】将iso文件的内容(/dev/cdrom目录下的内容)拷贝到yum仓库目录

[root@node01 ~]# cp -a /dev/cdrum/* /var/ftp/pub/os79/

【05】配置yum的.repo配置文件(在/etc/yum.repos.d目录下进行配置)

[root@node01 ~]# cat > /etc/yum.repos.d/os79.repo << EOF
> [os79]
> name=Local yum package
> baseurl=file:///var/ftp/pub/os79
> gpgcheck=0
> proxy=_none_
> EOF

【06】清理(索引和下载包)缓存,将软件包信息提前在本地索引缓存

[root@node01 ~]# yum clean all && yum makecache fast
已加载插件:fastestmirror
正在清理软件源: os79
已加载插件:fastestmirror
Determining fastest mirrors
os79                                                             | 3.6 kB  00:00:00     
(1/2): os79/group_gz                                             | 153 kB  00:00:00     
(2/2): os79/primary_db                                           | 3.3 MB  00:00:00     
元数据缓存已建立

【07】显示已配置的软件仓库列表及各个软件仓库的软件包数量

[root@node01 ~]# yum repolist
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
源标识                      源名称                              状态
os79                        Local yum package                   4,070
repolist: 4,070

通过File方式配置YUM源完成~

『通过Ftp的方式配置』

node02通过Ftp使用node01的yum源(以Centos6.5为例)

【01】在node01下载并安装vsftpd服务

[root@node1 home]# yum -y install vsftpd
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package vsftpd.x86_64 0:2.2.2-11.el6_4.1 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=====================================================================================================================
 Package                    Arch                     Version                     Repository               Size
=====================================================================================================================
Installing:
 vsftpd                     x86_64                   2.2.2-11.el6_4.1            os65                     151 k

Transaction Summary
=====================================================================================================================
Install       1 Package(s)

Total download size: 151 k
Installed size: 331 k
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : vsftpd-2.2.2-11.el6_4.1.x86_64                                                         1/1
  Verifying  : vsftpd-2.2.2-11.el6_4.1.x86_64                                                         1/1

Installed:
  vsftpd.x86_64 0:2.2.2-11.el6_4.1

Complete!

【02】修改node01的vsftpd配置文件,添加 anon_root=/var/ftp

注意:实测不需要配置anon_root目录

[root@node1 home]# cd /etc/vsftpd
[root@node1 vsftpd]# ll
总用量 20
-rw------- 1 root root  125 3月   1 2013 ftpusers
-rw------- 1 root root  361 3月   1 2013 user_list
-rw------- 1 root root 4599 3月   1 2013 vsftpd.conf
-rwxr--r-- 1 root root  338 3月   1 2013 vsftpd_conf_migrate.sh
[root@node1 vsftpd]# vim vsftpd.conf
[root@node1 vsftpd]# tail vsftpd.conf
#
# This directive enables listening on IPv6 sockets. To listen on IPv4 and IPv6
# sockets, you must run two copies of vsftpd with two configuration files.
# Make sure, that one of the listen options is commented !!
#listen_ipv6=YES

pam_service_name=vsftpd
userlist_enable=YES
tcp_wrappers=YES
anon_root=/var/ftp
[root@node1 vsftpd]#

【03】修改配置文件之后重启vsftpd服务

# centos6.x
[root@node1 vsftpd]# service vsftpd restart && chkconfig vsftpd on
[root@node1 vsftpd]# chkconfig --list vsftpd
vsftpd          0:关闭  1:关闭  2:启用  3:启用  4:启用  5:启用  6:关闭
[root@node1 vsftpd]#


# centos7.x
[root@node1 vsftpd]# systemctl restart vsftpd && systemctl enable vsftpd

【04】配置node2的yum配置文件(在/etc/yum.repos.d目录下)

[root@node2 yum.repos.d]# cat os65.repo
[os65]
name=Local yum package
baseurl=ftp://192.168.56.111/pub/os65
gpgcheck=0
proxy=_none_
enabled=1

【05】清理(索引和下载包)缓存,将软件包信息提前在本地索引缓存

[root@node02 ~]# yum clean all && yum makecache fast
已加载插件:fastestmirror
正在清理软件源: os65
已加载插件:fastestmirror
Determining fastest mirrors
os65                                                             | 3.6 kB  00:00:00     
(1/2): os65/group_gz                                             | 153 kB  00:00:00     
(2/2): os65/primary_db                                           | 3.3 MB  00:00:00     
元数据缓存已建立

【06】显示已配置的软件仓库列表及各个软件仓库的软件包数量

[root@node02 ~]# yum repolist
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
源标识                      源名称                              状态
os79                        Local yum package                   4,070
repolist: 4,070

通过Ftp方式配置YUM源完成~

『通过Http的方式配置』

【01】通过wget获取到大厂的镜像源repo文件,先安装wget

[root@node01 ~]# yum -y install wget
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.163.com
 * extras: mirrors.163.com
 * updates: mirrors.njupt.edu.cn
Resolving Dependencies
--> Running transaction check
---> Package wget.x86_64 0:1.14-18.el7_6.1 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===================================================================================
 Package       Arch        Version                  Repository         Size
===================================================================================
Installing:
 wget          x86_64      1.14-18.el7_6.1          base               547 k

Transaction Summary
===================================================================================
Install  1 Package

Total download size: 547 k
Installed size: 2.0 M
Downloading packages:
wget-1.14-18.el7_6.1.x86_64.rpm                            | 547 kB  00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : wget-1.14-18.el7_6.1.x86_64                  1/1
  Verifying  : wget-1.14-18.el7_6.1.x86_64                  1/1

Installed:
  wget.x86_64 0:1.14-18.el7_6.1

Complete!
[root@node01 ~]#

【02】获取阿里的repo文件:mirrors.aliyun.com/repo/

[root@node01 yum.repos.d]# wget -O CentOS-Base.repo https://mirrors.aliyum.com/repo/Centos-7.repo
--2023-06-07 16:35:00--  https://mirrors.aliyum.com/repo/Centos-7.repo
Resolving mirrors.aliyum.com (mirrors.aliyum.com)... 47.75.39.85
Connecting to mirrors.aliyum.com (mirrors.aliyum.com)|47.75.39.85|:443... failed: Connection refused.
[root@localhost yum.repos.d]#

[root@localhost yum.repos.d]# wget -O CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo?spm=a2c6h.25603864.0.0.1d2f5969P1c04G
--2023-06-07 16:36:10--  https://mirrors.aliyun.com/repo/Centos-7.repo?spm=a2c6h.25603864.0.0.1d2f5969P1c04G
Resolving mirrors.aliyun.com (mirrors.aliyun.com)... 119.167.164.119, 112.122.156.209, 112.122.156.207, ...
Connecting to mirrors.aliyun.com (mirrors.aliyun.com)|119.167.164.119|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2523 (2.5K) [application/octet-stream]
Saving to: ‘CentOS-Base.repo’

100%[============================>] 2,523       --.-K/s   in 0.008s

2023-06-07 16:36:10 (311 KB/s) - ‘CentOS-Base.repo’ saved [2523/2523]

[root@node01 yum.repos.d]#

通过Http方式配置YUM源完成~