第七天笔记

本机 cmd 中执行
1 、任务要求
1 )配置本地 yum
2 )网络 yum
3 )安装 mysql
2 、任务拆解
1 yum 源配置
2 mysql 数据库软件
1 、配置 yum
介绍:
1 、了解 yum 源安装软件包
Yum 源安装软件包是在 Linux 系统中一种非常便捷和常用的软件安装方式
Yum Yellowdog Updater, Modified )是一个在众多 Linux 发行版中广泛使用的软件包管理器。它
通过预先配置好的软件源( Yum 源)来获取软件包的信息和进行安装。
Yum 源的作用
Yum 源就像是一个软件仓库,包含了各种各样的软件包及其相关的依赖信息。常见的 Yum 源有系
统默认提供的官方源,也有第三方维护的源。
Yum 安装软件包的优点
1. 自动处理依赖关系:当您安装一个软件包时,如果它依赖于其他的软件包, Yum 会自动安装这
些依赖,无需您手动逐个查找和安装。
例如,安装一个图形化界面软件时,它可能依赖于特定的库文件和其他支持组件,
Yum 会一并处理。
2. 方便的软件搜索和浏览:您可以通过简单的命令搜索和查看可用的软件包。
3. 软件包的更新管理:可以轻松更新已安装的软件包到最新版本,保持系统的安全性和稳定性。
安装过程中的关键步骤
1. 配置 Yum 源:有些系统默认已经配置好常用的源,您也可以根据需要添加或修改源的配置。
2. 执行安装命令:如前面提到的 yum install < 软件包名称 >
一些常见的 Yum 相关命令
1. yum list :列出所有可用的软件包。
2. yum info < 软件包名称 > :查看指定软件包的详细信息。
总之, Yum 源安装软件包极大地简化了在 Linux 系统中安装和管理软件的过程,提高了效率和便利
性。
2 、了解常见的网络 yum
1. 华为云 yum :例如对于 centos7 系统,其 .repo 文件内容如下:
其中, $releasever 表示系统版本, $basearch 表示系统架构(如 x86_64 )。
2. 中国科技大学源 :如 http://centos.ustc.edu.cn/centos/ 。使用中科大源的方法之一是,
先进入 /etc/yum.repos.d/ 目录,重命名 centos 自带的 yum 源文件(如 mv centos
base.repo centos-base.repo.save ),然后执行 wget
http://mirrors.ustc.edu.cn/centos/centos-base.5.mirrors.repo -o
/etc/yum.repos.d/centos-base.repo ,最后运行 yum makecache
3. 网易开源镜像 :例如 http://mirrors.163.com/centos/ 。使用网易源可参考如下步骤:进
/etc/yum.repos.d/ 目录,重命名 centos 自带的 yum 源文件(如 mv centos-base.repo
centos-base.repo.save ),执行 wget http://mirrors.sohu.com/help/centos-base
sohu.repo ,再运行 yum makecache
4. 阿里云镜像 http://mirrors.aliyun.com/repo/centos-7.repo (适用于 centos7
统)。
配置网络 yum 源的具体步骤可能因 Linux 发行版和版本而有所不同。一般来说,需要将相应
.repo 文件下载或创建到 /etc/yum.repos.d/ 目录下,然后运行相关命令更新 yum 缓存。
在实际使用中,你可以根据网络连接情况、 yum 源的稳定性和速度等因素选择合适的网络 yum 源。
同时,注意 .repo 文件中的版本信息要与你的系统版本相匹配。另外,还有一些其他的 yum 源可供选
择,例如一些特定软件或项目的官方 yum 源等,可以根据具体需求进行查找和配置。
3 、掌握本地和网络 yum 源的配置
Yum (全称为 Yellowdog Updater, Modified )是一个在 Fedora CentOS BCLinux RedHat
Linux 发行版中的软件包管理器。它基于 RPM 包管理,能够自动处理依赖性关系,一次安装所有依赖的
软件包。配置 Yum 源可以让系统通过指定的服务器或本地镜像来获取软件包。以下是本地和网络 Yum
源的常见配置方法:
配置网络 Yum 源(以 CentOS 7 系统,使用华为云 yum 源为例)
1. 查看本地操作系统版本,执行指令: cat /etc/redhat-release
2. 打开华为云开源镜像站( https://mirrors.huaweicloud.com/home ),找到对应的操作系统版
本的 .repo 文件链接(如: https://repo.huaweicloud.com/repository/conf/centos7.repo
)。
3. 进入服务器的 /etc/yum.repos.d/ 目录,可以执行以下命令下载并编辑 .repo 文件:
cd /etc/yum.repos.d/
vi local.repo
i 键进入编辑模式,输入以下内容(注意将 $releasever 替换成实际的操作系统版本号):
编辑完成后,按 Esc 键,输入 :wq 保存并退出。
1. 执行以下命令更新 Yum 源:
yum clean all :清除原有缓存。
yum makecache :构建新的缓存。
配置本地 Yum 源(以 CentOS 7 系统为例)
1. 挂载 ISO 镜像文件(假设镜像文件已上传至服务器):
创建挂载点: mkdir /opt/centos
挂载镜像: mount /your_iso_file_path /opt/centos (将
/your_iso_file_path 替换为实际的镜像文件路径)。
2. 进入 /etc/yum.repos.d/ 目录,备份原有的 .repo 文件(以防需要恢复): mv
/etc/yum.repos.d/*.repo /etc/yum.repos.d/old/ 
3. 创建并编辑本地 Yum 源配置文件:
vi /etc/yum.repos.d/local.repo
输入以下内容:
编辑完成后保存并退出。
1. 执行 yum clean all 命令清空缓存。
2. 执行 yum makecache 命令重建缓存。
配置完成后,就可以使用 Yum 命令来安装、更新软件包了。
另外,如果想要配置局域网 Yum 源,可以参考以下步骤(需要至少两台服务器,一台作为源服务
器,其他机器作为客户端):
配置局域网 Yum 源(服务器端)
1. 按照上述本地 Yum 源的配置方法,在源服务器上完成本地 Yum 源的配置。
2. 安装并启动 HTTP 服务(如 Apache HTTP Server Nginx 等),将挂载的 ISO 镜像目录通过
HTTP 服务共享出去。
3. 配置客户端机器的 Yum 源:
编辑 /etc/yum.repos.d/ 目录下的 .repo 文件,添加类似以下内容:
然后在客户端机器上执行 yum clean all yum makecache 命令更新缓存。
这样,局域网内的客户端机器就可以通过源服务器提供的 Yum 源来安装软件包了。需注意,客户端
机器要能访问源服务器的共享目录。在实际配置过程中,可能需要根据具体的网络环境和服务器设置进
行适当调整。同时,确保拥有足够的权限来执行相关操作。
常见的一些网络 Yum 源有阿里云、华为云、网易等提供的开源镜像站点。例如,阿里云的 CentOS
7 yum 源地址为: http://mirrors.aliyun.com/repo/centos-7.repo
操作:
1 、配置本地 yum
rpm -ivh xxx //rpm 需要手动添加依赖
能够使用 yum 工具安装软件包
yum 不止执行安装,还可以自动处理依赖关系
yum是基于 rpm 的,相当于 rpm 升级版,自动解决依赖关系
ls -l /etc/yum.repos.d/ // 查看现有的 yum 仓库镜像
1 )打包,做成一个 tar 压缩包
2 )删除 mnt 目录下的所有文件
rm -rf /mnt/*
ls /mnt/
3 )将光盘数据挂载到 /mnt 目录中,就可以在该目录中读取光盘内容
lsblk // 找到 sr0
mount -o ro /dev/sr0 /mnt // 以只读方式挂载光盘
4 )设置开机自挂载
echo "mount -o ro /dev/sr0 /mnt" >> /etc/rc.local // 开机自动挂载
5 )规定软件包查找位置
2 、配置网络 yum
1 )阿里云
https://developer.aliyun.com/mirror/
2) 腾讯云
https://mirrors.cloud.tencent.com/
下午
3 epel 源配置
对官⽅和官⽹源的扩展,有些软件找不到
4 nginx 源配置
1 )移除 epel
[root@1 ~]# rm -rf /etc/yum.repos.d/epel*
[root@1 ~]# ls /etc/yum.repos.d/
CentOS-Base.repo CentOS-Base.repo.backup hh.repo.b
[root@1 ~]# yum clean all
[root@1 ~]# yum makecache
2 )百度搜索 nginx 镜像
https://nginx.org/
找到 repo 文件内容
[root@1 ~]# vim /etc/yum.repos.d/nginx.repo
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true // 启用模块热修复功能
[root@1 ~]# yum clean all
[root@1 ~]# yum makecache
[root@1 ~]# vim /etc/yum.repos.d/nginx.repo
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true // 启用模块热修复功能
[root@1 ~]# yum clean all
[root@1 ~]# yum makecache
[root@1 ~]# 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
pcp-pmda-nginx.x86_64
[root@1 ~]# yum -y install nginx
[root@1 ~]# nginx // 启动服务
[root@1 ~]# whereis nginx // 查看指令
nginx: /usr/sbin/nginx /usr/lib64/nginx /etc/nginx /usr/share/nginx
/usr/share/man/man8/nginx.8.gz
[root@1 ~]# 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>
[root@1 ~]# nginx -s stop // nginx
[root@1 ~]# curl http://localhost
curl: (7) Failed connect to localhost:80; 拒绝连接
3 、自建 yum 源仓库
2 、作业
任务 1 、插⼊优盘,读取优盘数据
任务 2 、在 vmware 配置光盘 iso ⽂件,在 linux 系统中读取光盘⽂件
任务 3 、配置阿⾥云 yum 仓库
[root@2 ~]# ls /etc/yum.repos.d/
CentOS-Base.repo hh.repo.backup
[root@2 ~]# yum clean all
[root@2 ~]# yum makecache
[root@2 ~]# yum repolist
任务 5 、配置腾讯镜像仓库
https://mirrors.tuna.tsinghua.edu.cn/help/pypi/ // 查找帮助文档
[root@2 ~]# mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS
Base.repo.backup
[root@2 ~]# ls /etc/yum.repos.d/
CentOS-Base.repo.backup hh.repo.backup
[root@2 ~]# yum clean all
[root@2 ~]# yum makecache
[root@2 ~]# yum repolist
任务 6 、⾃建仓库 包含 tree net-tools bash-completion nginx 等包
vim /etc/yum.conf // keepcache 后改为 1
1029 yum install --downloadonly --downloaddir=./soft net-tools
1030 yum install --downloadonly --downloaddir=./soft bash-completion
1031 yum install --downloadonly --downloaddir=./soft nginx
1032 yum install --downloadonly --downloaddir=./soft tree
  • 12
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值