shell腳本快速配置yum源


我們在使用Red Hat系列與CentOS系列的Linux系統時經常要配置yum源,本文檔提出一個快速配置yum源的方法,就是用shell腳本來實現。

首先確保系統已掛載好鏡像文件,然后執行vim rhel7.repo.sh命令,這個命令是創建一個腳本

在打開的文件中添加以下內
用一個神奇的方法配置yum源用一個神奇的方法配置yum源

[root@linuxprobe ~]# vim rhel7.repo.sh 
1 #!/bin/bash 2 3 cd /etc/yum.repos.d 4 5 cat >>rhel7.repo<<OK 6 [rhel7] 7 name=rhel7 8 baseurl=file:///media/cdrom 9 enabled=1 10 gpgcheck=0 11 OK 12 13 mkdir -p /media/cdrom 14 mount /dev/cdrom /media/cdrom 15 echo "/dev/cdrom /media/cdrom iso9660 defaults 0 0" >> /etc/fstab 16 17 yum clean all 18 yum makecache

寫完腳本后記得賦予腳本執行權限:

[root@linuxprobe ~]# chmod 755 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 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!

[root@linuxprobe ~]# 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倉庫名稱即可。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM