本机cmd中执行
- C:\Users\lenovo>e: //切换到e盘下
- E:\>dir //查看e盘下所有的目录和文件
- 驱动器 E 中的卷是 新加卷
- 卷的序列号是 BE8A-9808
- E:\ 的目录
- 1970/01/01 08:00 64,311,808 0338db614b95b200426c357864b53a7386a4e5cc9c71d9162176de706741cd34.tar
- 2022/11/10 14:28 <DIR> 0f04ae71e99f5ef9021b92f76bac3979e25c98d73a51d33ce76a78da6afa9f27
- 2023/03/28 18:30 <DIR> 2019
- E:\>scp //默认可以使用scp进行传输文件
- usage: scp [-346BCpqrTv] [-c cipher] [-F ssh_config] [-i identity_file]
- [-J destination] [-l limit] [-o ssh_option] [-P port]
- [-S program] source ... target
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 安装软件包的优点:
自动处理依赖关系:当您安装一个软件包时,如果它依赖于其他的软件包,Yum 会自动安装这些依赖,无需您手动逐个查找和安装。例如,安装一个图形化界面软件时,它可能依赖于特定的库文件和其他支持组件,Yum 会一并处理。
方便的软件搜索和浏览:您可以通过简单的命令搜索和查看可用的软件包。
软件包的更新管理:可以轻松更新已安装的软件包到最新版本,保持系统的安全性和稳定性。
安装过程中的关键步骤:
配置 Yum 源:有些系统默认已经配置好常用的源,您也可以根据需要添加或修改源的配置。
执行安装命令:如前面提到的 yum install <软件包名称> 。
一些常见的 Yum 相关命令:
yum list:列出所有可用的软件包。
yum info <软件包名称>:查看指定软件包的详细信息。
总之,Yum 源安装软件包极大地简化了在 Linux 系统中安装和管理软件的过程,提高了效率和便利性。
2、了解常见的网络yum源
华为云 yum 源:例如对于 centos7 系统,其.repo 文件内容如下:
- #centos-base.repo
- #
- # the mirror system uses the connecting ip address of the client and the
- # update status of each mirror to pick mirrors that are updated to and
- # geographically close to the client. you should use this for centos updates
- # unless you are manually picking other mirrors.
- #
- # if the mirrorlist= does not work for you, as a fallback you can try the
- # remarked out baseurl= line instead.
- #
- #
- (base)
- name=centos7
- baseurl=https://repo.huaweicloud.com/centos/$releasever/os/$basearch/
- gpgcheck=0
-
- # released updates
- (updates)
- name=centos-$releasever-updates-repo.huaweicloud.com
- baseurl=https://repo.huaweicloud.com/centos/$releasever/updates/$basearch/
- # mirrorlist=https://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
- gpgcheck=1
- gpgkey=https://repo.huaweicloud.com/centos/rpm-gpg-key-centos-7
-
- # additional packages that may be useful
- (extras)
- name=centos-$releasever-extras-repo.huaweicloud.com
- baseurl=https://repo.huaweicloud.com/centos/$releasever/extras/$basearch/
- # mirrorlist=https://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
- gpgcheck=1
- gpgkey=https://repo.huaweicloud.com/centos/rpm-gpg-key-centos-7
-
- # additional packages that extend functionality of existing packages
- (centosplus)
- name=centos-$releasever-plus-repo.huaweicloud.com
- baseurl=https://repo.huaweicloud.com/centos/$releasever/centosplus/$basearch/
- # mirrorlist=https://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
其中,$releasever表示系统版本,$basearch表示系统架构(如 x86_64)。
- 中国科技大学源:如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。
- 网易开源镜像:例如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。
- 阿里云镜像: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 源为例)
- 查看本地操作系统版本,执行指令:cat /etc/redhat-release。
- 打开华为云开源镜像站(https://mirrors.huaweicloud.com/home),找到对应的操作系统版本的.repo 文件链接(如:https://repo.huaweicloud.com/repository/conf/centos7.repo )。
- 进入服务器的 /etc/yum.repos.d/ 目录,可以执行以下命令下载并编辑.repo 文件:
- cd /etc/yum.repos.d/
- vi local.repo
- 按 i 键进入编辑模式,输入以下内容(注意将 $releasever 替换成实际的操作系统版本号):
- #centos-base.repo
- #
- # The mirror system uses the connecting IP address of the client and the
- # update status of each mirror to pick mirrors that are updated to and
- # geographically close to the client. You should use this for CentOS updates
- # unless you are manually picking other mirrors.
- #
- # If the mirrorlist= does not work for you, as a fallback you can try the
- # remarked out baseurl= line instead.
- #
- #
-
- (base)
- name=centos7
- baseurl=https://repo.huaweicloud.com/centos/$releasever/os/$basearch/
- gpgcheck=0
- # released updates
- (updates)
- name=centos-$releasever-updates-repo.huaweicloud.com
- baseurl=https://repo.huaweicloud.com/centos/$releasever/updates/$basearch/
- # mirrorlist=https://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
- gpgcheck=1
- gpgkey=https://repo.huaweicloud.com/centos/rpm-gpg-key-centos-7
- # additional packages that may be useful
- (extras)
- name=centos-$releasever-extras-repo.huaweicloud.com
- baseurl=https://repo.huaweicloud.com/centos/$releasever/extras/$basearch/
- # mirrorlist=https://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
- gpgcheck=1
- gpgkey=https://repo.huaweicloud.com/centos/rpm-gpg-key-centos-7
- # additional packages that extend functionality of existing packages
- (centosplus)
- name=centos-$releasever-plus-repo.huaweicloud.com
- baseurl=https://repo.huaweicloud.com/centos/$releasever/centosplus/$basearch/
- # mirrorlist=https://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
编辑完成后,按 Esc 键,输入 :wq 保存并退出。
执行以下命令更新 Yum 源:
yum clean all:清除原有缓存。
yum makecache:构建新的缓存。
配置本地 Yum 源(以 CentOS 7 系统为例)
挂载 ISO 镜像文件(假设镜像文件已上传至服务器):
创建挂载点:mkdir /opt/centos。
挂载镜像:mount /your_iso_file_path /opt/centos (将 /your_iso_file_path 替换为实际的镜像文件路径)。
进入 /etc/yum.repos.d/ 目录,备份原有的.repo 文件(以防需要恢复):mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/old/ 。
创建并编辑本地 Yum 源配置文件:
vi /etc/yum.repos.d/local.repo
输入以下内容:
- (centos)
- name=centos # Yum 源的名称,可自定义
- baseurl=file:///opt/centos # 本地 Yum 源的位置,指向挂载点目录
- gpgcheck=0 # 不进行 GPG 签名检查
- enabled=1 # 启用该 Yum 源
编辑完成后保存并退出。
执行 yum clean all 命令清空缓存。
执行 yum makecache 命令重建缓存。
配置完成后,就可以使用 Yum 命令来安装、更新软件包了。
另外,如果想要配置局域网 Yum 源,可以参考以下步骤(需要至少两台服务器,一台作为源服务器,其他机器作为客户端):
配置局域网 Yum 源(服务器端)
按照上述本地 Yum 源的配置方法,在源服务器上完成本地 Yum 源的配置。
安装并启动 HTTP 服务(如 Apache HTTP Server 或 Nginx 等),将挂载的 ISO 镜像目录通过 HTTP 服务共享出去。
配置客户端机器的 Yum 源:
编辑 /etc/yum.repos.d/ 目录下的.repo 文件,添加类似以下内容:
(centos)
name=centos
baseurl=http://源服务器 IP/共享目录 # 替换为实际的源服务器 IP 和共享目录
gpgcheck=0
enabled=1
然后在客户端机器上执行 yum clean all 和 yum makecache 命令更新缓存。
这样,局域网内的客户端机器就可以通过源服务器提供的 Yum 源来安装软件包了。需注意,客户端机器要能访问源服务器的共享目录。在实际配置过程中,可能需要根据具体的网络环境和服务器设置进行适当调整。同时,确保拥有足够的权限来执行相关操作。
常见的一些网络 Yum 源有阿里云、华为云、网易等提供的开源镜像站点。例如,阿里云的 CentOS 7 yum 源地址为:http://mirrors.aliyun.com/repo/centos-7.repo 。
操作:
- 配置本地yum源
- rpm -ivh xxx //rpm需要手动添加依赖
- 能够使用yum工具安装软件包
- yum不止执行安装,还可以自动处理依赖关系
- yum是基于rpm的,相当于rpm升级版,自动解决依赖关系
- ls -l /etc/yum.repos.d/ //查看现有的yum仓库镜像
(1)打包,做成一个tar压缩包
- yum repolist all
- tar -czvf /etc/yum.repos.d/bak.tar.gz /etc/yum.repos.d/*
- rm -rf /etc/yum.repos.d/*.repo
- ls -l /etc/yum.repos.d/
- yum repolist all
- yum clean all //清空缓存
- yum makecache //生成缓存
(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)规定软件包查找位置
- [root@1 ~]# vim /etc/yum.repos.d/hh.repo
- [a]
- name=a
- baseurl=file:///mnt
- gpgcheck=0
- [root@1 ~]# yum clean all
- 已加载插件:fastestmirror
- 正在清理软件源: a
- Cleaning up everything
- Maybe you want: rm -rf /var/cache/yum, to also free up space taken by orphaned data from disabled or removed repos
- Cleaning up list of fastest mirrors
- [root@1 ~]# yum makecache
- 已加载插件:fastestmirror
- Determining fastest mirrors
- a | 3.6 kB 00:00:00
- (1/4): a/group_gz | 166 kB 00:00:00
- (2/4): a/primary_db | 5.9 MB 00:00:00
- (3/4): a/filelists_db | 6.9 MB 00:00:00
- (4/4): a/other_db | 2.5 MB 00:00:00
2、配置网络yum源
(1)阿里云
https://developer.aliyun.com/mirror/
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
yum clean all
yum makecache
(2) 腾讯云
https://mirrors.cloud.tencent.com/
根据帮助文档一步一步做即可
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup //备份系统旧配置文件
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.cloud.tencent.com/repo/centos7_base.repo
yum clean all
yum makecache //更新缓存
显示下图即为成功
[root@1 ~]# yum repolist
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
源标识 源名称 状态
extras/7/x86_64 Qcloud centos extras - x86_64 526
os/7/x86_64 Qcloud centos os - x86_64 10,072
updates/7/x86_64 Qcloud centos updates - x86_64 6,173
repolist: 16,771
[root@1 ~]# yum list | grep python3
libselinux-python3.x86_64 2.5-15.el7 os
python3.i686 3.6.8-21.el7_9 updates
python3.x86_64 3.6.8-21.el7_9 updates
python3-debug.i686 3.6.8-21.el7_9 updates
python3-debug.x86_64 3.6.8-21.el7_9 updates
python3-devel.i686 3.6.8-21.el7_9 updates
python3-devel.x86_64 3.6.8-21.el7_9 updates
python3-idle.i686 3.6.8-21.el7_9 updates
python3-idle.x86_64 3.6.8-21.el7_9 updates
python3-libcomps.x86_64 0.1.8-14.el7 extras
python3-libs.i686 3.6.8-21.el7_9 updates
python3-libs.x86_64 3.6.8-21.el7_9 updates
python3-pip.noarch 9.0.3-8.el7 os
python3-rpm-generators.noarch 6-2.el7 os
python3-rpm-macros.noarch 3-34.el7 os
python3-setuptools.noarch 39.2.0-10.el7 os
python3-test.i686 3.6.8-21.el7_9 updates
python3-test.x86_64 3.6.8-21.el7_9 updates
python3-tkinter.i686 3.6.8-21.el7_9 updates
python3-tkinter.x86_64 3.6.8-21.el7_9 updates
python3-wheel.noarch 0.31.1-5.el7_7 os
(3)epel源配置
对官⽅和官⽹源的扩展,有些软件找不到
- [root@1 ~]# yum -y install epel-release.noarch
- [root@1 ~]# ls /etc/yum.repos.d/
- CentOS-Base.repo epel.repo hh.repo.b
- CentOS-Base.repo.backup epel-testing.repo
- [root@1 ~]# yum -y install sl //安装小火车
- [root@1 ~]# sl
(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/
- [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>
3、自建yum源仓库
- [root@1 ~]# vim /etc/yum.conf
- keepcache=1 //将0改为1 YUM 在下载软件包后保留其缓存
- [root@1 ~]# yum remove -y nginx //卸载nginx
- [root@1 ~]# yum -y install nginx //安装nginx
- [root@1 ~]# 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@1 ~]# yum install --downloadonly --downloaddir=./soft samba //只下载不安装
- --downloadonly 选项表示只进行下载操作,不进行安装。
- --downloaddir=./soft 则指定了下载的软件包保存的目录为当前目录下的 soft 文件夹。
- ......
- 总计 1.2 MB/s | 9.0 MB 00:00:07
- exiting because "Download Only" specified
- [root@1 ~]# ls soft/
- 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 samba-4.10.16-25.el7_9.x86_64.rpm
- libldb-1.5.4-2.el7.x86_64.rpm samba-client-libs-4.10.16-25.el7_9.x86_64.rpm
- libtalloc-2.1.16-1.el7.x86_64.rpm samba-common-4.10.16-25.el7_9.noarch.rpm
- libtdb-1.3.18-1.el7.x86_64.rpm samba-common-libs-4.10.16-25.el7_9.x86_64.rpm
- libtevent-0.9.39-1.el7.x86_64.rpm samba-common-tools-4.10.16-25.el7_9.x86_64.rpm
- libwbclient-4.10.16-25.el7_9.x86_64.rpm samba-libs-4.10.16-25.el7_9.x86_64.rpm
- nettle-2.7.1-9.el7_9.x86_64.rpm trousers-0.3.14-2.el7.x86_64.rpm
- pyldb-1.5.4-2.el7.x86_64.rpm
- 安装createrepo
- createrepo 是一个用于创建 YUM 软件仓库的命令行工具。
- 它的主要作用是根据指定目录中的 RPM 软件包生成元数据,包括软件包的依赖关系、版本信息等,以便 YUM 客户端能够正确地解析和安装所需的软件。
- 以下是一个使用 createrepo 的示例:
- 假设您有一个目录 /opt/packages ,其中包含了一些 RPM 软件包。您可以在该目录下运行以下命令来创建软件仓库:
- createrepo /opt/packages
- 执行完该命令后,createrepo 会在 /opt/packages 目录下生成一些元数据文件,如 repodata 目录,其中包含了 repomd.xml 等重要的配置和描述文件。
- 这样,您就可以将这个目录配置为 YUM 源,让客户端能够从这里获取和安装软件包。
- [root@1 ~]# yum -y install createrepo
- [root@1 ~]# createrepo soft/ //把soft⽂件夹做成⼀个本地的⾃建仓库
- Spawning worker 0 with 19 pkgs
- Workers Finished
- Saving Primary metadata
- Saving file lists metadata
- Saving other metadata
- Generating sqlite DBs
- Sqlite DBs complete
- [root@1 ~]# ls
- soft
- [root@1 ~]# cd soft/
- [root@1 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
- [root@1 soft]# vim /etc/yum.repos.d/soft.repo
- [soft]
- name=soft
- baseurl=file:///root/soft
- gpgcheck=0
- enable=1
- [root@1 soft]# yum clean all
- 已加载插件:fastestmirror
- 正在清理软件源: extras nginx-stable os soft updates
- Cleaning up everything
- Maybe you want: rm -rf /var/cache/yum, to also free up space taken by orphaned data from disabled or removed repos
- Cleaning up list of fastest mirrors
- [root@1 soft]# yum makecache
- [root@1 soft]# yum -y install samba //全程直接下载,使用我们自己创建的yum仓库