
正文
shell脚本快速配置yum源
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
我们在使用Red Hat系列与CentOS系列的Linux系统时经常要配置yum源,本文档提出一个快速配置yum源的方法,就是用shell脚本来实现。
首先确保系统已挂载好镜像文件,然后执行vim rhel7.repo.sh命令,这个命令是创建一个脚本。
在打开的文件中添加以下内
[root@linuxprobe ~]# vim rhel7.repo.sh
#!/bin/bash cd /etc/yum.repos.d cat >>rhel7.repo<<OK
[rhel7]
name=rhel7
baseurl=file:///media/cdrom
enabled=
gpgcheck=
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
写完脚本后记得赋予脚本执行权限:
[root@linuxprobe ~]# chmod rhel7.repo.sh
或
[root@linuxprobe ~]# chmod +x rhel7.repo.sh
赋予脚本执行权限后再运行脚本:
[root@linuxprobe ~]# base rhel7.repo.sh
或
[root@linuxprobe ~]# ./rhel7.repo.sh
测试:
[root@linuxprobe ~]# yum instll httpd
Loaded plugins: fastestmirror, langpacks
No such command: instll. Please use /usr/bin/yum --help
[root@linuxprobe ~]# yum install httpd
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_64 :2.4.-.el7.centos. will be installed
--> Processing Dependency: httpd-tools = 2.4.-.el7.centos. for package: httpd-2.4.-.el7.centos..x86_64
--> Processing Dependency: /etc/mime.types for package: httpd-2.4.-.el7.centos..x86_64
--> Processing Dependency: libaprutil-.so.()(64bit) for package: httpd-2.4.-.el7.centos..x86_64
--> Processing Dependency: libapr-.so.()(64bit) for package: httpd-2.4.-.el7.centos..x86_64
--> Running transaction check
---> Package apr.x86_64 :1.4.-.el7 will be installed
---> Package apr-util.x86_64 :1.5.-.el7 will be installed
---> Package httpd-tools.x86_64 :2.4.-.el7.centos. will be installed
---> Package mailcap.noarch :2.1.-.el7 will be installed
--> Finished Dependency ResolutionDependencies Resolved=========================================================================
Package Arch Version Repository
Size
=========================================================================
Installing:
httpd x86_64 2.4.-.el7.centos. rhel7 2.7 M
Installing for dependencies:
apr x86_64 1.4.-.el7 rhel7 k
apr-util x86_64 1.5.-.el7 rhel7 k
httpd-tools x86_64 2.4.-.el7.centos. rhel7 k
mailcap noarch 2.1.-.el7 rhel7 kTransaction Summary
=========================================================================
Install Package (+ Dependent packages)Total download size: 3.0 M
Installed size: M
Is this ok [y/d/N]: y
Downloading packages:
-------------------------------------------------------------------------
Total MB/s | 3.0 MB :
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : apr-1.4.-.el7.x86_64 /
Installing : apr-util-1.5.-.el7.x86_64 /
Installing : httpd-tools-2.4.-.el7.centos..x86_64 /
Installing : mailcap-2.1.-.el7.noarch /
Installing : httpd-2.4.-.el7.centos..x86_64 /
Verifying : mailcap-2.1.-.el7.noarch /
Verifying : httpd-2.4.-.el7.centos..x86_64 /
Verifying : apr-util-1.5.-.el7.x86_64 /
Verifying : apr-1.4.-.el7.x86_64 /
Verifying : httpd-tools-2.4.-.el7.centos..x86_64 / Installed:
httpd.x86_64 :2.4.-.el7.centos. Dependency Installed:
apr.x86_64 :1.4.-.el7
apr-util.x86_64 :1.5.-.el7
httpd-tools.x86_64 :2.4.-.el7.centos.
mailcap.noarch :2.1.-.el7 Complete![root@linuxprobe ~]# ll /etc/yum.repos.d
total
-rw-r--r--. root root Jul CentOS-Base.repo.bak
-rw-r--r--. root root Jul CentOS-Debuginfo.repo
-rw-r--r--. root root Jul CentOS-Sources.repo
-rw-r--r--. root root Jul CentOS-Vault.repo
-rw-r--r--. root root Jan : ding.repo.bak
-rw-r--r--. root root Jan : rhel7.repo
-rw-r--r--. root root Jan : scootersoftware.repo
最后出现Complete!说明httpd安装成功,同时也说明了yum仓库配置成功!
注:我用的系统是RHEL/CentOS 7,用其他Linux系统的话只需要改yum仓库名称即可。







