shell脚本快速配置yum源
我们在使用Red Hat系列与CentOS系列的Linux系统时经常要配置yum源,本文档提出一个快速配置yum源的方法,就是用shell脚本来实现。
首先确保系统已挂载好镜像文件,然后执行vim rhel7.repo.sh命令,这个命令是创建一个脚本。
在打开的文件中添加以下内
[ ~]# vim rhel7.repo.sh 1 #!/bin/bash cd /etc/yum.repos.d cat >>rhel7.repo<<OK [rhel7] name=rhel7 baseurl=file:///media/cdrom enabled=1 gpgcheck=0 OK mkdir -p /media/cdrom mount /dev/cdrom /media/cdrom echo "/dev/cdrom /media/cdrom iso9660 defaults 0 0" >> /etc/fstab yum clean all yum makecache
写完脚本后记得赋予脚本执行权限:
[ ~]# chmod 755 rhel7.repo.sh 或 [ ~]# chmod +x rhel7.repo.sh
赋予脚本执行权限后再运行脚本:
[ ~]# base rhel7.repo.sh 或 [ ~]# ./rhel7.repo.sh
测试:
[ ~]# yum instll httpd
Loaded plugins: fastestmirror, langpacks
No such command: instll. Please use /usr/bin/yum --help
[ ~]# yum install httpd
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_64 0:2.4.6-17.el7.centos.1 will be installed
--> Processing Dependency: httpd-tools = 2.4.6-17.el7.centos.1 for package: httpd-2.4.6-17.el7.centos.1.x86_64
--> Processing Dependency: /etc/mime.types for package: httpd-2.4.6-17.el7.centos.1.x86_64
--> Processing Dependency: libaprutil-1.so.0()(64bit) for package: httpd-2.4.6-17.el7.centos.1.x86_64
--> Processing Dependency: libapr-1.so.0()(64bit) for package: httpd-2.4.6-17.el7.centos.1.x86_64
--> Running transaction check
---> Package apr.x86_64 0:1.4.8-3.el7 will be installed
---> Package apr-util.x86_64 0:1.5.2-6.el7 will be installed
---> Package httpd-tools.x86_64 0:2.4.6-17.el7.centos.1 will be installed
---> Package mailcap.noarch 0:2.1.41-2.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
=========================================================================
Package Arch Version Repository
Size
=========================================================================
Installing:
httpd x86_64 2.4.6-17.el7.centos.1 rhel7 2.7 M
Installing for dependencies:
apr x86_64 1.4.8-3.el7 rhel7 103 k
apr-util x86_64 1.5.2-6.el7 rhel7 92 k
httpd-tools x86_64 2.4.6-17.el7.centos.1 rhel7 77 k
mailcap noarch 2.1.41-2.el7 rhel7 31 k
Transaction Summary
=========================================================================
Install 1 Package (+4 Dependent packages)
Total download size: 3.0 M
Installed size: 10 M
Is this ok [y/d/N]: y
Downloading packages:
-------------------------------------------------------------------------
Total 23 MB/s | 3.0 MB 00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : apr-1.4.8-3.el7.x86_64 1/5
Installing : apr-util-1.5.2-6.el7.x86_64 2/5
Installing : httpd-tools-2.4.6-17.el7.centos.1.x86_64 3/5
Installing : mailcap-2.1.41-2.el7.noarch 4/5
Installing : httpd-2.4.6-17.el7.centos.1.x86_64 5/5
Verifying : mailcap-2.1.41-2.el7.noarch 1/5
Verifying : httpd-2.4.6-17.el7.centos.1.x86_64 2/5
Verifying : apr-util-1.5.2-6.el7.x86_64 3/5
Verifying : apr-1.4.8-3.el7.x86_64 4/5
Verifying : httpd-tools-2.4.6-17.el7.centos.1.x86_64 5/5
Installed:
httpd.x86_64 0:2.4.6-17.el7.centos.1
Dependency Installed:
apr.x86_64 0:1.4.8-3.el7
apr-util.x86_64 0:1.5.2-6.el7
httpd-tools.x86_64 0:2.4.6-17.el7.centos.1
mailcap.noarch 0:2.1.41-2.el7
Complete!
[ ~]# ll /etc/yum.repos.d
total 28
-rw-r--r--. 1 root root 1612 Jul 4 2014 CentOS-Base.repo.bak
-rw-r--r--. 1 root root 640 Jul 4 2014 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root 1331 Jul 4 2014 CentOS-Sources.repo
-rw-r--r--. 1 root root 156 Jul 4 2014 CentOS-Vault.repo
-rw-r--r--. 1 root root 66 Jan 12 12:37 ding.repo.bak
-rw-r--r--. 1 root root 68 Jan 30 19:54 rhel7.repo
-rw-r--r--. 1 root root 176 Jan 30 15:28 scootersoftware.repo最后出现Complete!说明httpd安装成功,同时也说明了yum仓库配置成功!
注:我用的系统是RHEL/CentOS 7,用其他Linux系统的话只需要改yum仓库名称即可。
相关推荐
flycappuccino 2020-09-27
shipinsky 2020-09-23
touchfuture 2020-09-16
hongsheyoumo 2020-09-04
laisean 2020-11-11
zhangjie 2020-11-11
大牛牛 2020-10-30
firefaith 2020-10-30
liguojia 2020-10-20
wangzhaotongalex 2020-10-20
CARBON 2020-10-20