配置本地yum源、网络yum源、安装mysql

一、yum源概述

1.yum
软件包管理器,类似于360软件管家,以及⼿机的app市场
2.yum优点
Rpm安装(下载软件,单独安装,需要解决依赖关系)
源码安装 confgure make make install
yum基于rpm,相当于rpm升级版,⾃动解决依赖关系
3.分类:
本地yum源
yum仓库在本地,系统光盘/镜像⽂件⽹络yum源
aliyun  163源  sohu源  清华源  centos源  redhat源  epel源
特定软件:
nginx  mysql  zabbix

二、本地yum源配置

1.找到源文件
2. 将所有的repo⽂件做成压缩包,命名为repo.tar.gz
3.删除所有的repo⽂件

三、网络yum源的分离

1.搜索阿里镜像源
2.根据官方提示配置yum源
https://developer.aliyun.com/mirror/centos
3.下载
4.运⾏ yum makecache⽣成缓存 yum clear
5.查看源

4.特定软件源配置:

1.移除epel源,如果不⾏就全清空

[root@keke ~]# rm -rf /etc/yum.repos.d/epel.repo
您在 /var/spool/mail/root 中有新邮件
[root@keke ~]# yum clear all
已加载插件:fastestmirror
没有该命令:clear。请使⽤ /usr/bin/yum --help
[root@keke ~]# 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
元数据缓存已建⽴
2.搜nginx的镜像:

nginx news

3. 安装稳定版本

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

4. 创建缓存

[root@keke ~]# 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@keke ~]# 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
元数据缓存已建⽴
您在 /var/spool/mail/root 中有新邮件
[root@keke ~]# 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
5.安装并且检查 

[root@keke ~]# yum install nginx -y


6. 启动(停用)服务

# 启动服务
[root@keke ~]# nginx
# 查看指令
[root@keke ~]# whereis nginx
nginx: /usr/sbin/nginx /usr/lib64/nginx /etc/nginx /usr/share/nginx
/usr/share/man/man8/nginx.8.gz
# 访问服务器
[root@keke ~]# 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@keke ~]# nginx -s stop
您在 /var/spool/mail/root 中有新邮件
# 访问测试
[root@keke ~]# curl http://localhost
curl: (7) Failed connect to localhost:80; 拒绝连接
[root@keke ~]
四.缓存某些软件到本地: 
1.缓存安装软件包

下⼀次还⽤
国外源
2.如何缓存
vim /etc/yum.conf
[main]
cachedir=/var/cache/yum/$basearch/$releaserver         # 定义软件包缓存路径
keepcache=1         #开启缓存
debuglevel=2
logfile=/var/log/yum.log
        1.vim /etc/yum.cong
        2.keepcache=1
        3.测试 yum -y. install tree
        4./var/cache/yum/x66_32/7/base/packages/treeexxxxxx.rpm
 [root@keke ~]# vim /etc/yum.conf

3.卸载,然后安装nginx 查看缓存⽂件
 [root@keke ~]# yum -y remove nginx.x86_64

# 安装
[root@keke ~]# yum install nginx -y
# 查找安装包
[root@keke ~]# find /var/cache/ -name "*tree*" -type f
/var/cache/yum/x86_64/7/os/packages/tree-1.6.0-10.el7.x86_64.rpm
您在 /var/spool/mail/root 中有新邮件
[root@keke ~]# find /var/cache/ -name "*nginx*" -type f
/var/cache/yum/x86_64/7/nginx-stable/packages/nginx-1.26.1-
2.el7.ngx.x86_64.rpm
[root@keke ~]#
4.只下载不安装

[root@keke ~]# yum install --downloadonly --downloaddir=./soft/ samba

 [root@keke ~]# ls soft/

6.自建yum仓库:
1.安装createrepo制作仓库的软件

[root@keke ~]# yum -y install createrepo

 2.把soft⽂件夹做成⼀个本地的⾃建仓库

[root@keke ~]# createrepo soft/
[root@keke ~]# cd soft/

[root@keke soft]# ls
avahi-libs-0.6.31-20.el7.x86_64.rpm pytalloc-2.1.16- 1.el7.x86_64.rpm
cups-libs-1.6.3-52.el7_9.x86_64.rpm python-tdb-1.3.18- 1.el7.x86_64.rpm
gnutls-3.3.29-9.el7_6.x86_64.rpm repodata  libldb-1.5.4-2.el7.x86_64.rpm samba-4.10.16-
25.el7_9.x86_64.rpm
libtalloc-2.1.16-1.el7.x86_64.rpm samba-client-libs-4.10.16- 25.el7_9.x86_64.rpm
libtdb-1.3.18-1.el7.x86_64.rpm samba-common-4.10.16- 25.el7_9.noarch.rpm
libtevent-0.9.39-1.el7.x86_64.rpm samba-common-libs-4.10.16- 25.el7_9.x86_64.rpm
libwbclient-4.10.16-25.el7_9.x86_64.rpm samba-common-tools-4.10.16- 25.el7_9.x86_64.rpm
nettle-2.7.1-9.el7_9.x86_64.rpm samba-libs-4.10.16- 25.el7_9.x86_64.rpm
pyldb-1.5.4-2.el7.x86_64.rpm trousers-0.3.14- 2.el7.x86_64.rpm
3.在/etc/yum.repos.d/下创建 soft.repo
vim /etc/yum.repos.d/soft.repo
[soft]
name=soft
baseurl=file:///root/soft/
gpgcheck=0
enable=1
yum clean all
yum makecache
 4.再次安装samba

[root@keke soft]# yum -y install samba

03-11
<think>嗯,用户想了解如何配置和使用yum。首先,我需要回忆一下关于yum的基本知识。记得yum是软件仓库,用来管理RPM包的安装和依赖关系。配置yum通常涉及编辑.repo文件,这些文件位于/etc/yum.repos.d/目录下。还有可能涉及到本地网络配置。 根据用户提供的引用内容,引用[2]提到yum配置文件分为main和repository部分,main在/etc/yum.conf,而repository在/etc/yum.repos.d/里的各个文件。所以配置的时候需要关注这两个部分。用户可能遇到的问题包括如何创建新的文件,如何指向本地网络路径,以及如何处理GPG检查。 用户的问题可能包括步骤不清晰,比如如何挂载ISO镜像来配置本地。引用[3]中提到了创建local.repo文件,并指定baseurl为file:///路径。这时候需要确保挂载点正确,并且权限设置没问题。另外,可能需要禁用默认的网络,避免冲突。 用户还可能关心如何测试配置后的yum是否生效,比如运行yum clean all和yum makecache。此外,常见问题如无法找到包,可能和baseurl的配置错误有关,或者网络不可达。需要检查URL是否正确,网络连接是否正常。 可能还需要解释不同的类型,比如本地网络(如阿里云、清华),以及如何备份原有的配置文件,避免出错后恢复。引用[1]提到可以将默认文件移到/opt下或重命名,这样可以禁用默认,避免干扰。 总结下来,回答的结构应该分步骤,包括备份、创建repo文件、配置内容、清理缓存,然后验证。同时,常见问题部分需要列出可能的问题和解决方法,如GPG检查、路径错误等。还要注意使用正确的格式,行内变量用$符号,独立公式用$$,不过这里可能数学公式不多,但需要确保LaTeX正确。</think>### 如何配置和使用yum? #### 一、yum的核心配置方法 1. **备份默认** 操作前建议备份系统原有配置: ```bash mv /etc/yum.repos.d/*.repo /opt/backup/ # 将默认文件移动到备份目录 ``` 这是为了防止原有配置与新配置产生冲突[^1]。 2. **本地yum配置** - **挂载镜像文件** 将CentOS镜像文件挂载到指定目录: ```bash mount -o loop /path/to/CentOS-ISO /mnt/cdrom ``` - **创建配置文件** 新建`/etc/yum.repos.d/local.repo`并写入: ```ini [local-base] name=Local-CentOS-Base baseurl=file:///mnt/cdrom gpgcheck=0 enabled=1 ``` 关键参数说明: - `baseurl`:本地路径使用`file://`协议头[^3] - `gpgcheck=0`表示跳过数字签名验证 3. **网络yum配置** 以阿里云为例,创建`/etc/yum.repos.d/aliyun.repo`: ```ini [aliyun-base] name=Aliyun-CentOS-Base baseurl=https://mirrors.aliyun.com/centos/$releasever/os/$basearch/ gpgcheck=1 gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7 enabled=1 ``` 注意:`$releasever`和`$basearch`会自动解析为系统版本和架构[^2] #### 二、关键操作命令 1. **清理缓存并更新** ```bash yum clean all # 清除旧缓存 yum makecache # 生成新缓存 yum repolist all # 验证状态 ``` 2. **典型使用场景** ```bash yum install httpd -y # 安装软件包 yum update # 更新所有软件 yum search python3 # 搜索软件包 ``` #### 三、常见问题排查 | 问题现象 | 解决方案 | |---------|----------| | `Could not resolve host` | 检查网络连接和`baseurl`地址 | | `Package not found` | 确认仓库是否包含该软件包版本 | | GPG签名校验失败 | 设置`gpgcheck=0`或导入正确密钥 | #### 四、进阶配置技巧 1. **多优先级控制** 安装`yum-plugin-priorities`插件,在`.repo`文件中添加: ```ini priority=1 # 数字越小优先级越高 ``` 2. **仓库分组管理** 通过`[epel]`、`[docker]`等独立仓库配置实现分类管理
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值