Linux运维实战教程
Linux运维实战教程
yum源分为本地yum源和网络yum源。
步骤一:在centos虚拟机中挂载光盘
1)创建挂载点目录
[root@localhost ~]# mkdir /mnt/cdrom [root@localhost ~]# df /mnt/cdrom 文件系统 1K-块 已用 可用 已用% 挂载点 /dev/sda3 39517336 7718416 31798920 20% /
2)挂载光盘
[root@localhost ~]# mount /dev/cdrom /mnt/cdrom mount: /dev/sr0 写保护,将以只读方式挂载
3)查看挂载记录
[root@localhost ~]# df -hT /mnt/cdrom 文件系统 类型 容量 已用 可用 已用% 挂载点 /dev/sr0 iso9660 4.3G 4.3G 0 100% /mnt/cdrom
步骤二:更改配置文件
1)进入/etc/yum.repos.d/中查看文件
[root@localhost ~]# cd /etc/yum.repos.d/ [root@localhost yum.repos.d]# ll 总用量 28 -rw-r--r--. 1 root root 1664 8月 30 2017 CentOS-Base.repo -rw-r--r--. 1 root root 1309 8月 30 2017 CentOS-CR.repo -rw-r--r--. 1 root root 649 8月 30 2017 CentOS-Debuginfo.repo -rw-r--r--. 1 root root 314 8月 30 2017 CentOS-fasttrack.repo -rw-r--r--. 1 root root 630 8月 30 2017 CentOS-Media.repo -rw-r--r--. 1 root root 1331 8月 30 2017 CentOS-Sources.repo -rw-r--r--. 1 root root 3830 8月 30 2017 CentOS-Vault.repo
2)将CentOS-Base.repo和CentOS-Debuginfo.repo改名或者移动,绕过网络安装,以便使用本地安装
#本次使用改名 方便作为备份文件 [root@localhost yum.repos.d]# mv CentOS-Debuginfo.repo CentOS-Debuginfo.repo.bak [root@localhost yum.repos.d]# mv CentOS-Base.repo CentOS-Base.repo.bak
3)编辑文件CentOS-Media.repo(使用vim编辑器)
[root@localhost yum.repos.d]# vim CentOS-Media.repo # CentOS-Media.repo # # This repo can be used with mounted DVD media, verify the mount point for # CentOS-7. You can use this repo and yum to install items directly off the # DVD ISO that we release. # # To use this repo, put in your DVD and use it with the other repos too: # yum --enablerepo=c7-media [command] # # or for ONLY the media repo, do this: # # yum --disablerepo=\* --enablerepo=c7-media [command] [c7-media] name=CentOS-$releasever - Media baseurl=file:///mnt/cdrom gpgcheck=0 #用来检查GPG-KEY,0为不检查,1为检查 enabled=1 #是否用该yum源,0为禁用,1为使用 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 ~ ~ ~ "CentOS-Media.repo" 20L, 563C 17,1 全部
4)清除yum缓存,测试yum源配置
清除yum缓存:
[root@localhost yum.repos.d]# yum clean all 已加载插件:fastestmirror, langpacks 正在清理软件源:c7-media 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@localhost yum.repos.d]# yum list 已加载插件:fastestmirror, langpacks c7-media | 3.6 kB 00:00 (1/2): c7-media/group_gz | 156 kB 00:00 (2/2): c7-media/primary_db | 3.1 MB 00:00 Determining fastest mirrors 已安装的软件包 GConf2.x86_64 3.2.6-8.el7 @anaconda GeoIP.x86_64 1.5.0-11.el7 @anaconda ModemManager.x86_64 1.6.0-2.el7 @anaconda ModemManager-glib.x86_64 1.6.0-2.el7 @anaconda NetworkManager.x86_64 1:1.8.0-9.el7 @anaconda NetworkManager-adsl.x86_64 1:1.8.0-9.el7 @anaconda NetworkManager-glib.x86_64 1:1.8.0-9.el7 @anaconda NetworkManager-libnm.x86_64 1:1.8.0-9.el7 @anaconda NetworkManager-libreswan.x86_64 1.2.4-2.el7 @anaconda NetworkManager-libreswan-gnome.x86_64 1.2.4-2.el7 @anaconda NetworkManager-ppp.x86_64 1:1.8.0-9.el7 @anaconda
出现已安装的软件包时,便成功配置了。
步骤一:备份
1)进入/etc/yum.repos.d 查看目录下文件
[root@localhost yum.repos.d]# ll 总用量 28 -rw-r--r--. 1 root root 1664 8月 30 2017 CentOS-Base.repo.bak -rw-r--r--. 1 root root 1309 8月 30 2017 CentOS-CR.repo -rw-r--r--. 1 root root 649 8月 30 2017 CentOS-Debuginfo.repo.bak -rw-r--r--. 1 root root 314 8月 30 2017 CentOS-fasttrack.repo -rw-r--r--. 1 root root 563 3月 18 19:37 CentOS-Media.repo -rw-r--r--. 1 root root 1331 8月 30 2017 CentOS-Sources.repo
2)将所有文件备份到新建目录repo_bak下
[root@localhost yum.repos.d]# mkdir repo_bak [root@localhost yum.repos.d]# mv *.repo repo_bak/ [root@localhost yum.repos.d]# mv *.repo.bak repo_bak/ [root@localhost yum.repos.d]# ll 总用量 0 drwxr-xr-x. 2 root root 195 3月 18 23:13 repo_bak
步骤二:下载
下载阿里的CentOS-Base.repo 到/etc/yum.repos.d/。
1)下载文件
[root@localhost yum.repos.d]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 2523 100 2523 0 0 15876 0 --:--:-- --:--:-- --:--:-- 15968 #查看文件是否下载完成 [root@localhost yum.repos.d]# ll 总用量 4 -rw-r--r--. 1 root root 2523 3月 18 23:16 CentOS-Base.repo drwxr-xr-x. 2 root root 195 3月 18 23:13 repo_baktos-7.repo
2)运行yum clean all 清除缓存,运行 yum makecache 生成新的缓存
[root@localhost yum.repos.d]# yum clean all #清空缓存 已加载插件:fastestmirror, langpacks 正在清理软件源:base extras 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@localhost yum.repos.d]# yum makecache #生成新的缓存 已加载插件:fastestmirror, langpacks ^Chttp://mirrors.aliyuncs.com/centos/7/os/x86_64/repodata/repomd.xml: [Errno 14] curl#56 - "Callback aborted" 正在尝试其它镜像。 http://mirrors.cloud.aliyuncs.com/centos/7/os/x86_64/repodata/repomd.xml: [Errno 14] curl#6 - "Could not resolve host: mirrors.cloud.aliyuncs.com; 未知的名称或服务" 正在尝试其它镜像。 base | 3.6 kB 00:00:00 extras | 2.9 kB 00:00:00 updates | 2.9 kB 00:00:00 (1/10): base/7/x86_64/group_gz | 153 kB 00:00:00 (2/10): base/7/x86_64/primary_db | 6.1 MB 00:00:03 (3/10): extras/7/x86_64/filelists_db | 226 kB 00:00:00 (4/10): extras/7/x86_64/other_db | 134 kB 00:00:00 (5/10): extras/7/x86_64/primary_db | 225 kB 00:00:00 (6/10): base/7/x86_64/filelists_db | 7.2 MB 00:00:05 (7/10): base/7/x86_64/other_db | 2.6 MB 00:00:01 (8/10): updates/7/x86_64/filelists_db | 3.9 MB 00:00:02 (9/10): updates/7/x86_64/other_db | 516 kB 00:00:00 (10/10): updates/7/x86_64/primary_db | 6.5 MB 00:00:03 Determining fastest mirrors * base: mirrors.aliyun.com * extras: mirrors.aliyun.com * updates: mirrors.aliyun.com 元数据缓存已建立
元数据缓已建立说明生成成功。
步骤三:安装EPEL源
1)
[root@localhost yum.repos.d]# yum list | grep epel-release epel-release.noarch 7-11 extras [root@localhost yum.repos.d]# yum install -y epel-release 已加载插件:fastestmirror, langpacks Loading mirror speeds from cached hostfile * base: mirrors.aliyun.com * extras: mirrors.aliyun.com * updates: mirrors.aliyun.com 正在解决依赖关系 --> 正在检查事务 ---> 软件包 epel-release.noarch.0.7-11 将被 安装 --> 解决依赖关系完成 依赖关系解决 ======================================================================================= Package 架构 版本 源 大小 ======================================================================================= 正在安装: epel-release noarch 7-11 extras 15 k 事务概要 ======================================================================================= 安装 1 软件包 总下载量:15 k 安装大小:24 k Downloading packages: epel-release-7-11.noarch.rpm | 15 kB 00:00:00 Running transaction check Running transaction test Transaction test succeeded Running transaction 正在安装 : epel-release-7-11.noarch 1/1 验证中 : epel-release-7-11.noarch 1/1 已安装: epel-release.noarch 0:7-11 完毕!
2)再次检查文件,是否生成epel.repo和epel-testing.repo
[root@localhost yum.repos.d]# ll 总用量 12 -rw-r--r--. 1 root root 2523 3月 18 23:16 CentOS-Base.repo -rw-r--r--. 1 root root 951 10月 2 2017 epel.repo -rw-r--r--. 1 root root 1050 10月 2 2017 epel-testing.repo drwxr-xr-x. 2 root root 195 3月 18 23:13 repo_bak
3)再次运行yum clean all 清除缓存,运行 yum makecache 生成新的缓存
[root@localhost yum.repos.d]# yum clean all 已加载插件:fastestmirror, langpacks 正在清理软件源:base epel extras 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@localhost yum.repos.d]# yum makecache 已加载插件:fastestmirror, langpacks base | 3.6 kB 00:00:00 epel/x86_64/metalink | 6.6 kB 00:00:00 epel | 4.7 kB 00:00:00 extras | 2.9 kB 00:00:00 updates | 2.9 kB 00:00:00 (1/16): base/7/x86_64/group_gz | 153 kB 00:00:00 (2/16): base/7/x86_64/filelists_db | 7.2 MB 00:00:01 (3/16): base/7/x86_64/other_db | 2.6 MB 00:00:00 (4/16): epel/x86_64/updateinfo | 1.0 MB 00:00:00 (5/16): epel/x86_64/group_gz | 96 kB 00:00:01 (6/16): epel/x86_64/other_db | 3.3 MB 00:00:01 (7/16): epel/x86_64/primary_db | 6.9 MB 00:00:01 (8/16): extras/7/x86_64/filelists_db | 226 kB 00:00:00 (9/16): extras/7/x86_64/other_db | 134 kB 00:00:00 (10/16): extras/7/x86_64/primary_db | 225 kB 00:00:00 (11/16): epel/x86_64/prestodelta | 1.2 kB 00:00:02 (12/16): base/7/x86_64/primary_db | 6.1 MB 00:00:05 (13/16): epel/x86_64/filelists_db | 12 MB 00:00:04 (14/16): updates/7/x86_64/filelists_db | 3.9 MB 00:00:02 (15/16): updates/7/x86_64/other_db | 516 kB 00:00:00 (16/16): updates/7/x86_64/primary_db | 6.5 MB 00:00:03 Determining fastest mirrors * base: mirrors.aliyun.com * epel: mirrors.bfsu.edu.cn * extras: mirrors.aliyun.com * updates: mirrors.aliyun.com 元数据缓存已建立
4)检查仓库是否启用
[root@localhost yum.repos.d]# yum repolist enabled 已加载插件:fastestmirror, langpacks Loading mirror speeds from cached hostfile * base: mirrors.aliyun.com * epel: mirrors.bfsu.edu.cn * extras: mirrors.aliyun.com * updates: mirrors.aliyun.com 源标识 源名称 状态 base/7/x86_64 CentOS-7 - Base - mirrors.aliyun.com 10,072 epel/x86_64 Extra Packages for Enterprise Linux 7 - x86_64 13,558 extras/7/x86_64 CentOS-7 - Extras - mirrors.aliyun.com 453 updates/7/x86_64 CentOS-7 - Updates - mirrors.aliyun.com 1,898 repolist: 25,981
5)查看所有的仓库
[root@localhost yum.repos.d]# yum repolist all 已加载插件:fastestmirror, langpacks Loading mirror speeds from cached hostfile * base: mirrors.aliyun.com * epel: mirrors.bfsu.edu.cn * 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 禁用 epel/x86_64 Extra Packages for Enterprise Linux 7 - x86_ 启用: 13,558 epel-debuginfo/x86_64 Extra Packages for Enterprise Linux 7 - x86_ 禁用 epel-source/x86_64 Extra Packages for Enterprise Linux 7 - x86_ 禁用 epel-testing/x86_64 Extra Packages for Enterprise Linux 7 - Test 禁用 epel-testing-debuginfo/x86_64 Extra Packages for Enterprise Linux 7 - Test 禁用 epel-testing-source/x86_64 Extra Packages for Enterprise Linux 7 - Test 禁用 extras/7/x86_64 CentOS-7 - Extras - mirrors.aliyun.com 启用: 453 updates/7/x86_64 CentOS-7 - Updates - mirrors.aliyun.com 启用: 1,898 repolist: 25,981
步骤四:测试安装
1)
[root@localhost yum.repos.d]# yum install -y httpd已加载插件:fastestmirror, langpacks Loading mirror speeds from cached hostfile * base: mirrors.aliyun.com * epel: mirrors.bfsu.edu.cn * extras: mirrors.aliyun.com * updates: mirrors.aliyun.com 正在解决依赖关系 --> 正在检查事务 ---> 软件包 httpd.x86_64.0.2.4.6-97.el7.centos 将被 安装 --> 正在处理依赖关系 httpd-tools = 2.4.6-97.el7.centos,它被软件包 httpd-2.4.6-97.el7.centos.x86_64 需要 --> 正在处理依赖关系 /etc/mime.types,它被软件包 httpd-2.4.6-97.el7.centos.x86_64 需要 --> 正在处理依赖关系 libaprutil-1.so.0()(64bit),它被软件包 httpd-2.4.6-97.el7.centos.x86_64 需要 --> 正在处理依赖关系 libapr-1.so.0()(64bit),它被软件包 httpd-2.4.6-97.el7.centos.x86_64 需要 --> 正在检查事务 ---> 软件包 apr.x86_64.0.1.4.8-7.el7 将被 安装 ---> 软件包 apr-util.x86_64.0.1.5.2-6.el7 将被 安装 ---> 软件包 httpd-tools.x86_64.0.2.4.6-97.el7.centos 将被 安装 ---> 软件包 mailcap.noarch.0.2.1.41-2.el7 将被 安装 --> 解决依赖关系完成依赖关系解决======================================================================================= Package 架构 版本 源 大小=======================================================================================正在安装: httpd x86_64 2.4.6-97.el7.centos updates 2.7 M 为依赖而安装: apr x86_64 1.4.8-7.el7 base 104 k apr-util x86_64 1.5.2-6.el7 base 92 k httpd-tools x86_64 2.4.6-97.el7.centos updates 93 k mailcap noarch 2.1.41-2.el7 base 31 k事务概要=======================================================================================安装 1 软件包 (+4 依赖软件包)总下载量:3.0 M 安装大小:10 M Downloading packages:(1/5): apr-1.4.8-7.el7.x86_64.rpm | 104 kB 00:00:06 (2/5): apr-util-1.5.2-6.el7.x86_64.rpm | 92 kB 00:00:06 (3/5): mailcap-2.1.41-2.el7.noarch.rpm | 31 kB 00:00:00 (4/5): httpd-tools-2.4.6-97.el7.centos.x86_64.rpm | 93 kB 00:00:07 (5/5): httpd-2.4.6-97.el7.centos.x86_64.rpm | 2.7 MB 00:00:07 --------------------------------------------------------------------------------------- 总计 390 kB/s | 3.0 MB 00:07 Running transaction check Running transaction testTransaction test succeeded Running transaction 正在安装 : apr-1.4.8-7.el7.x86_64 1/5 正在安装 : apr-util-1.5.2-6.el7.x86_64 2/5 正在安装 : httpd-tools-2.4.6-97.el7.centos.x86_64 3/5 正在安装 : mailcap-2.1.41-2.el7.noarch 4/5 正在安装 : httpd-2.4.6-97.el7.centos.x86_64 5/5 验证中 : httpd-2.4.6-97.el7.centos.x86_64 1/5 验证中 : apr-1.4.8-7.el7.x86_64 2/5 验证中 : mailcap-2.1.41-2.el7.noarch 3/5 验证中 : httpd-tools-2.4.6-97.el7.centos.x86_64 4/5 验证中 : apr-util-1.5.2-6.el7.x86_64 5/5 已安装: httpd.x86_64 0:2.4.6-97.el7.centos 作为依赖被安装: apr.x86_64 0:1.4.8-7.el7 apr-util.x86_64 0:1.5.2-6.el7 httpd-tools.x86_64 0:2.4.6-97.el7.centos mailcap.noarch 0:2.1.41-2.el7 完毕!
2)卸载
事务概要 ======================================================================================= 移除 1 软件包 安装大小:9.4 M 是否继续?[y/N]:y Downloading packages: Running transaction check Running transaction test Transaction test succeeded Running transaction 正在删除 : httpd-2.4.6-97.el7.centos.x86_64 1/1 验证中 : httpd-2.4.6-97.el7.centos.x86_64 1/1 删除: httpd.x86_64 0:2.4.6-97.el7.centos 完毕!
推荐阅读
>>>新手必备-Linux系统安装配置+Xshell远程连接
运维界升职加薪必备的云计算技术,你学了吗?
学完高级运维云计算课程之后,你可以:
跨越90%企业的招聘硬门槛
增加70%就业机会
拿下BAT全国TOP100大厂敲门砖
体系化得到运维技术硬实力
技术大佬年薪可达30w+