YUM源配置与特定源配置

1.假设

公司计划将现有的mysql数据库从云平台迁移到物理机器上,并且已经在相应的物理机上安

装好相应的操作系统,现在需要运维⼈员协助在centos7.6上安装mysql8.33⽤于前期迁移准备⼯作,同时配置好本地yum源和外⽹源,⽅便后续软件包安装。

2.主要内容

了解yum源安装软件包的 有点

了解常⻅的⽹络yum

掌握本地和⽹络yum源的配置

能够使⽤yum⼯具安装软件包

3.YUM

yum( Yellow dog Updater, Modified)是一个在 Fedora 和 RedHat 以及 SUSE 中的 Shell 前端软件包管理器。

基于 RPM 包管理,能够从指定的服务器自动下载 RPM 包并且安装,可以自动处理依赖性关系,并且一次安装所有依赖的软件包,无须繁琐地一次次下载、安装。

yum 提供了查找、安装、删除某一个、一组甚至全部软件包的命令,而且命令简洁而又好记。

(软件包管理器,类似于360软件管家,以及⼿机的app市场)

分类

本地yum

yum仓库在本地,系统光盘/镜像⽂件

⽹络yum

aliyun

163

sohu

清华源

centos

redhat

epel

特定软件

nginx

mysql

zabbix

4.本地yum源备份


1.找到源⽂件


# 当前在etc⽬录,跳转到yum.repos.d⽬录
[root@localhost etc]# cd yum.repos.d/
#查看默认的源⽂件
[root@localhost yum.repos.d]# ls 
CentOS-Base.repo       CentOS-fasttrack.repo  CentOS-Vault.repo         
      mysql-community.repo
CentOS-CR.repo         CentOS-Media.repo      CentOS-x86_64-kernel.repo 
      mysql-community-source.repo
CentOS-Debuginfo.repo  CentOS-Sources.repo    mysql-community-
debuginfo.repo
[root@localhost yum.repos.d]# pwd
/etc/yum.repos.d
2.将所有的repo⽂件做成压缩包,命名为repo.tar.gz
[root@localhost yum.repos.d]# tar -zcvf repo.tar.gz ./*.repo
./CentOS-Base.repo
./CentOS-CR.repo
./CentOS-Debuginfo.repo
./CentOS-fasttrack.repo
./CentOS-Media.repo
./CentOS-Sources.repo
./CentOS-Vault.repo
./CentOS-x86_64-kernel.repo
./mysql-community-debuginfo.repo
./mysql-community.repo
./mysql-community-source.repo
# 查看⽂件信息
[root@localhost yum.repos.d]# ls


CentOS-Base.repo       CentOS-fasttrack.repo  CentOS-Vault.repo         
      mysql-community.repo
CentOS-CR.repo         CentOS-Media.repo      CentOS-x86_64-kernel.repo 
      mysql-community-source.repo
CentOS-Debuginfo.repo  CentOS-Sources.repo    mysql-community-
debuginfo.repo  repo.tar.gz
3.删除所有的repo⽂件
[root@localhost yum.repos.d]#  rm -rf ./*.repo
[root@localhost yum.repos.d]# ls
repo.tar.gz
[root@localhost yum.repos.d]# 

5.本地yum源配置

1.使⽤光盘作为yum源仓库

在vmware中装载centos7.6光盘镜像

把光盘挂载到指定⽬录下

删除/mnt⽬录下所有的⽂件

mount -o ro /dev/sr0 /mnt(选项 -o 表示挂载⽅式)

ro=readonly     rw=read and write

[root@localhost ~]# mount /dev/sr0 /mnt/ -o ro
[root@localhost ~]# ls /mnt/
CentOS_BuildTag  EULA  images    LiveOS    repodata              RPM-
GPG-KEY-CentOS-Testing-7
EFI              GPL   isolinux  Packages  RPM-GPG-KEY-CentOS-7 
TRANS.TBL


	
# 查看磁盘挂载情况

	
	[root@localhost ~]# lsblk	
	NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT	
	sda               8:0    0   20G  0 disk 	
	"#sda1            8:1    0    1G  0 part /boot	
	$#sda2            8:2    0   19G  0 part 	
	 "#centos-root 253:0    0   17G  0 lvm  /	
	 $#centos-swap 253:1    0    2G  0 lvm  [SWAP]	
	sr0              11:0    1  8.8G  0 rom  /mnt	
		4.解除挂载	
	[root@localhost ~]# umount /mnt 	
	[root@localhost ~]# ls /mnt/	
	[root@localhost ~]# lsblk 	
	NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT	
	sda               8:0    0   20G  0 disk 	
	"#sda1            8:1    0    1G  0 part /boot	
	$#sda2            8:2    0   19G  0 part 	
	 "#centos-root 253:0    0   17G  0 lvm  /	
	 $#centos-swap 253:1    0    2G  0 lvm  [SWAP]	
	sr0              11:0    1  8.8G  0 rom	
		4.将挂载添加到开机启动⽂件中	向⽂件中添加⼀⾏
				chmod +x /etc/rc.local	 		添加权限	
				echo 'mount -o ro /dev/sr0 /mnt' >> /etc/rc.local	 		
[root@localhost ~]# vim /etc/rc.local 
[root@localhost ~]# echo 'mount -o or /dev/sr0 /mnt' >> /etc/rc.local
[root@localhost ~]# vim /etc/rc.local 
[root@localhost ~]# vim /etc/rc.local 
[root@localhost ~]# ls -l /etc/rc.local 
lrwxrwxrwx. 1 root root 13 6⽉  16 20:18 /etc/rc.local -> rc.d/rc.local

编写本地repo⽂件

创建⼀个repo⽂件,并编辑。

[仓库名称] 可以有多个仓库

name= 仓库名称

baseurl= 仓库的路径,⽀持多种格式 file:// ftp:// http/s://

gpgcheck= gpg秘钥检测 0不检测,1检测,如果需要配置秘钥链接

enable= 0|1 是否启⽤当前仓库

[root@localhost ~]# ls /etc/yum.repos.d/
repo.tar.gz
[root@localhost ~]# vim /etc/yum.repos.d/20240714001.repo
[local]
name=local0
baseurl=file:///mnt
gpgcheck=0
enable=1
		6,清理缓存,查看源列表
# 清理缓存
[root@localhost ~]# yum clear all
已加载插件:fastestmirror
没有该命令:clear。请使⽤ /usr/bin/yum --help
#创建缓存
[root@localhost ~]# yum makecache 
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
local                                                                   
                 | 3.6 kB  00:00:00     
(1/2): local/other_db                                                   
                 | 2.5 MB  00:00:00     


	(2/2): local/filelists_db                                               
                 | 6.9 MB  00:00:00     
元数据缓存已建⽴
# 查看源仓库列表
[root@localhost ~]# yum repolist 
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
源标识                                               源名称               
                                 状态
local                                                local0             
                                   9,911
repolist: 9,911
[root@localhost ~]# yum repolist all 
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
源标识                                            源名称                 
                            状态
local                                             local0               
                              启⽤: 9,911  #软件数量
repolist: 9,911
		7.测试yum
	# 查看是否安装httpd
[root@localhost ~]# rpm -q httpd
httpd-2.4.6-99.el7.centos.1.x86_64


# 卸载httpd
[root@localhost ~]# yum remove httpd
已加载插件:fastestmirror
正在解决依赖关系
--> 正在检查事务
---> 软件包 httpd.x86_64.0.2.4.6-99.el7.centos.1 将被 删除
--> 解决依赖关系完成
依赖关系解决
=======================================================================
=========================================
 Package              架构                  版本                         
         源                       ⼤⼩
=======================================================================
=========================================
正在删除:
 httpd                x86_64                2.4.6-99.el7.centos.1       
          @updates                9.4 M
事务概要
=======================================================================
=========================================
移除  1 软件包
安装⼤⼩:9.4 M
是否继续?[y/N]:y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
 正在删除    : httpd-2.4.6-99.el7.centos.1.x86_64                       
                                   1/1 
 验证中      : httpd-2.4.6-99.el7.centos.1.x86_64                       
                                   1/1 


删除:
 httpd.x86_64 0:2.4.6-99.el7.centos.1                                 
完毕!
# 再次查看是否安装httpd
[root@localhost ~]# rpm -q httpd
未安装软件包 httpd 
[root@localhost ~]# yum -y install httpd
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
正在解决依赖关系
--> 正在检查事务
---> 软件包 httpd.x86_64.0.2.4.6-80.el7.centos 将被 安装
--> 正在处理依赖关系 httpd-tools = 2.4.6-80.el7.centos,它被软件包 httpd-
2.4.6-80.el7.centos.x86_64 需要
--> 解决依赖关系完成
错误:软件包:httpd-2.4.6-80.el7.centos.x86_64 (local)
          需要:httpd-tools = 2.4.6-80.el7.centos
          已安装: httpd-tools-2.4.6-99.el7.centos.1.x86_64 (@updates)
              httpd-tools = 2.4.6-99.el7.centos.1
          可⽤: httpd-tools-2.4.6-80.el7.centos.x86_64 (local)
              httpd-tools = 2.4.6-80.el7.centos
 您可以尝试添加 --skip-broken 选项来解决该问题
 您可以尝试执⾏:rpm -Va --nofiles --nodigest
[root@localhost ~]# rpm -q httpd
未安装软件包 httpd 
# 缺少依赖,安装失败



2.下载软件,使⽤软件包,作为yum源仓库

 6.⽹络yum源的分离

搜索阿⾥镜像源, 根据官⽅提示配置yum源。 

# 复制阿⾥云提供的url,下载⽂件
[root@localhost yum.repos.d]# wget -O /etc/yum.repos.d/CentOS-Base.repo 
https://mirrors.aliyun.com/repo/Centos-7.repo
--2024-07-14 20:00:04--  https://mirrors.aliyun.com/repo/Centos-7.repo
正在解析主机 mirrors.aliyun.com (mirrors.aliyun.com)... 117.23.49.221, 
117.23.49.224, 58.222.47.210, ...
正在连接 mirrors.aliyun.com (mirrors.aliyun.com)|117.23.49.221|:443... 已
连接。
已发出 HTTP 请求,正在等待回应... 200 OK
⻓度:2523 (2.5K) [application/octet-stream]
正在保存⾄: “/etc/yum.repos.d/CentOS-Base.repo”


100%
[======================================================================
>] 2,523       --.-K/s ⽤时 0s      
2024-07-14 20:00:04 (469 MB/s) - 已保存 “/etc/yum.repos.d/CentOS-
Base.repo” [2523/2523])
# 查看下载的⽂件
[root@localhost yum.repos.d]# ls 
20240714001.repo  CentOS-Base.repo  repo.tar.gz
[root@localhost yum.repos.d]# 

运⾏ yum makecache⽣成缓存 yum clear

查看源


4.查看源
[root@localhost yum.repos.d]# yum repolist all
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
源标识                                  源名称                           
                           状态
base/7/x86_64                           CentOS-7 - Base - 
mirrors.aliyun.com                        启⽤: 10,072


centosplus/7/x86_64                     CentOS-7 - Plus - 
mirrors.aliyun.com                        禁⽤
contrib/7/x86_64                        CentOS-7 - Contrib - 
mirrors.aliyun.com                     禁⽤
extras/7/x86_64                         CentOS-7 - Extras - 
mirrors.aliyun.com                      启⽤:    526
local                                   local0                         
                             启⽤:  9,911
updates/7/x86_64                        CentOS-7 - Updates - 
mirrors.aliyun.com                     启⽤:  6,173
repolist: 26,682
5.再次安装httpd
[root@localhost yum.repos.d]# yum -y install httpd
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
正在解决依赖关系
--> 正在检查事务
---> 软件包 httpd.x86_64.0.2.4.6-99.el7.centos.1 将被 安装
--> 解决依赖关系完成
依赖关系解决
=======================================================================
=========================================
 Package              架构                  版本                         
          源                      ⼤⼩
=======================================================================
=========================================
正在安装:


 httpd                x86_64                2.4.6-99.el7.centos.1       
           updates                2.7 M
事务概要
=======================================================================
=========================================
安装  1 软件包
总下载量:2.7 M
安装⼤⼩:9.4 M
Downloading packages:
httpd-2.4.6-99.el7.centos.1.x86_64.rpm                                 
                  | 2.7 MB  00:00:02     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
 正在安装    : httpd-2.4.6-99.el7.centos.1.x86_64                       
                                   1/1 
 验证中      : httpd-2.4.6-99.el7.centos.1.x86_64                       
                                   1/1 
已安装:
 httpd.x86_64 0:2.4.6-99.el7.centos.1                                 
完毕!
[root@localhost yum.repos.d]# 

7.特点软件源配置

移除epel源

[root@localhost ~]# rm -rf /etc/yum.repos.d/epel.repo 
[root@localhost ~]# yum clear all
已加载插件:fastestmirror
没有该命令:clear。请使⽤ /usr/bin/yum --help
[root@localhost ~]# yum makecache 
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
extras                                                                 
                  | 2.9 kB  00:00:00     
local                                                                   
                 | 3.6 kB  00:00:00     
os                                                                     
                  | 3.6 kB  00:00:00     
updates                                                                 
                 | 2.9 kB  00:00:00     
元数据缓存已建⽴

网上搜索NGINX资源

redhat安装

[root@localhost ~]# vim /etc/yum.repos.d/nginx.repo

配置

[root@localhost ~]# yum clean all
已加载插件:fastestmirror
正在清理软件源: nginx-stable
Cleaning up list of fastest mirrors
Other repos take up 745 M of disk space (use --verbose for details)
[root@localhost ~]# yum makecache 
已加载插件:fastestmirror
Determining fastest mirrors
nginx-stable                                                           
                  | 2.9 kB  00:00:00     
(1/3): nginx-stable/7/x86_64/filelists_db                               
                 | 121 kB  00:00:01     
(2/3): nginx-stable/7/x86_64/primary_db                                 
                 |  97 kB  00:00:01     
(3/3): nginx-stable/7/x86_64/other_db                                   
                 |  59 kB  00:00:00     
元数据缓存已建⽴



[root@localhost ~]# yum list|grep nginx
nginx.x86_64                         1:1.26.1-2.el7.ngx             
nginx-stable
nginx-debug.x86_64                   1:1.8.0-1.el7.ngx 
nginx-stable
nginx-debuginfo.x86_64               1:1.26.1-2.el7.ngx             
nginx-stable
nginx-module-geoip.x86_64            1:1.26.1-2.el7.ngx             
nginx-stable
nginx-module-geoip-debuginfo.x86_64  1:1.26.1-2.el7.ngx             
nginx-stable
nginx-module-image-filter.x86_64     1:1.26.1-2.el7.ngx             
nginx-stable
nginx-module-image-filter-debuginfo.x86_64
                                     1:1.26.1-2.el7.ngx             
nginx-stable
nginx-module-njs.x86_64              1:1.26.1+0.8.5-2.el7.ngx       
nginx-stable
nginx-module-njs-debuginfo.x86_64    1:1.26.1+0.8.5-2.el7.ngx       
nginx-stable
nginx-module-perl.x86_64             1:1.26.1-2.el7.ngx             
nginx-stable
nginx-module-perl-debuginfo.x86_64   1:1.26.1-2.el7.ngx             
nginx-stable
nginx-module-xslt.x86_64             1:1.26.1-2.el7.ngx             
nginx-stable
nginx-module-xslt-debuginfo.x86_64   1:1.26.1-2.el7.ngx             
nginx-stable
nginx-nr-agent.noarch                2.0.0-12.el7.ngx               
nginx-stable
[root@localhost ~]# 



安装并且检查


[root@localhost ~]# yum install nginx -y
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
正在解决依赖关系
--> 正在检查事务
---> 软件包 nginx.x86_64.1.1.26.1-2.el7.ngx 将被 安装
--> 正在处理依赖关系 libpcre2-8.so.0()(64bit),它被软件包 1:nginx-1.26.1-
2.el7.ngx.x86_64 需要
--> 正在检查事务
---> 软件包 pcre2.x86_64.0.10.23-2.el7 将被 安装
--> 解决依赖关系完成
依赖关系解决
=======================================================================
=========================================
 Package              架构                  版本                         
     源                           ⼤⼩
=======================================================================
=========================================
正在安装:
 nginx                x86_64                1:1.26.1-2.el7.ngx         
       nginx-stable                807 k
为依赖⽽安装:
 pcre2                x86_64                10.23-2.el7                 
      os                          201 k
事务概要
=======================================================================
=========================================
安装  1 软件包 (+1 依赖软件包)
总下载量:1.0 M


安装⼤⼩:3.4 M
Downloading packages:
(1/2): pcre2-10.23-2.el7.x86_64.rpm                                     
                 | 201 kB  00:00:00     
warning: /var/cache/yum/x86_64/7/nginx-stable/packages/nginx-1.26.1-
2.el7.ngx.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID 7bd9bf62: 
NOKEY
nginx-1.26.1-2.el7.ngx.x86_64.rpm 的公钥尚未安装
(2/2): nginx-1.26.1-2.el7.ngx.x86_64.rpm                               
                  | 807 kB  00:00:02     
-----------------------------------------------------------------------
-----------------------------------------
总计                                                                     
       476 kB/s | 1.0 MB  00:00:02     
从 https://nginx.org/keys/nginx_signing.key 检索密钥
导⼊ GPG key 0xB49F6B46:
 ⽤户ID     : "nginx signing key <signing-key-2@nginx.com>"
 指纹       : 8540 a6f1 8833 a80e 9c16 53a4 2fd2 1310 b49f 6b46
 来⾃       : https://nginx.org/keys/nginx_signing.key
导⼊ GPG key 0x7BD9BF62:
 ⽤户ID     : "nginx signing key <signing-key@nginx.com>"
 指纹       : 573b fd6b 3d8f bc64 1079 a6ab abf5 bd82 7bd9 bf62
 来⾃       : https://nginx.org/keys/nginx_signing.key
导⼊ GPG key 0x8D88A2B3:
 ⽤户ID     : "nginx signing key <signing-key-3@nginx.com>"
 指纹       : 9e9b e90e acbc de69 fe9b 204c bcdc d8a3 8d88 a2b3
 来⾃       : https://nginx.org/keys/nginx_signing.key
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
 正在安装    : pcre2-10.23-2.el7.x86_64                                 
                                   1/2 
 正在安装    : 1:nginx-1.26.1-2.el7.ngx.x86_64                         
                                    2/2 
----------------------------------------------------------------------


Thanks for using nginx!
Please find the official documentation for nginx here:
* https://nginx.org/en/docs/
Please subscribe to nginx-announce mailing list to get
the most important news about nginx:
* https://nginx.org/en/support.html
Commercial subscriptions for nginx are available on:
* https://nginx.com/products/
----------------------------------------------------------------------
 验证中      : pcre2-10.23-2.el7.x86_64                                 
                                   1/2 
 验证中      : 1:nginx-1.26.1-2.el7.ngx.x86_64                         
                                    2/2 
已安装:
 nginx.x86_64 1:1.26.1-2.el7.ngx                                       
作为依赖被安装:
 pcre2.x86_64 0:10.23-2.el7                                           
完毕!
您在 /var/spool/mail/root 中有新邮件
# 启动服务
[root@localhost ~]# nginx
# 查看指令
[root@localhost ~]# whereis nginx


nginx: /usr/sbin/nginx /usr/lib64/nginx /etc/nginx /usr/share/nginx 
/usr/share/man/man8/nginx.8.gz
# 访问服务器
[root@localhost ~]# curl http://localhost
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed 
and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
# 停⽤nginx
[root@localhost ~]# nginx -s stop
#访问测试
[root@localhost ~]# curl http://localhost


[root@localhost ~]# 

  • 13
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值