1. 程式人生 > >CentOS配置本地yum源/阿里雲yum源/163yuan源,並配置yum源的優先順序

CentOS配置本地yum源/阿里雲yum源/163yuan源,並配置yum源的優先順序

一、用Centos映象搭建本地yum源

由於安裝centos後的預設yum源為centos的官方地址,所以在國內使用很慢甚至無法訪問,所以一般的做法都是把預設的yum源替換成aliyun的yum源或者163等國內的yum源(下文介紹如何配置)。
但是以上的方法都是需要網路的,當沒有網路的時候就無法使用了,所以還有一個常用的方法就是用Centos的iso映象搭建本地yum源,這樣安裝軟體的速度就會飛快,缺點是可能有些包沒有。

1.安裝Centos後預設的yum源如下

[[email protected] ~]# ll /etc/yum.repos.d/
total 32
-rw-r--r--. 1 root root 1664 Dec 9 2015 CentOS-Base.repo -rw-r--r--. 1 root root 1309 Dec 9 2015 CentOS-CR.repo -rw-r--r--. 1 root root 649 Dec 9 2015 CentOS-Debuginfo.repo -rw-r--r--. 1 root root 290 Dec 9 2015 CentOS-fasttrack.repo -rw-r--r--. 1 root root 630 Dec 9 2015 CentOS-Media.repo -rw-r--r--. 1
root root 1331 Dec 9 2015 CentOS-Sources.repo -rw-r--r--. 1 root root 1952 Dec 9 2015 CentOS-Vault.repo

2.把預設yum源備份(可選)

[root@kangvcar ~]# mkdir /opt/centos-yum.bak
[root@kangvcar ~]# mv /etc/yum.repos.d/* /opt/centos-yum.bak/

3.在虛擬機器上掛載CentOS映象檔案

這裡寫圖片描述

[root@kangvcar ~]# mount -t iso9660 /dev/sr0 /opt/centos
mount: /dev/sr0 is write-protected, mounting read-only

4.編寫repo檔案並指向映象的掛載目錄

[[email protected] ~]# vi /etc/yum.repos.d/local.repo  
[local]
name=local
baseurl=file:///opt/centos
enabled=1
gpgcheck=0

5.清除快取

[root@kangvcar ~]# yum clean all
Loaded plugins: fastestmirror
Cleaning repos: local
Cleaning up everything
Cleaning up list of fastest mirrors
[root@kangvcar ~]# yum makecache        //把yum源快取到本地,加快軟體的搜尋好安裝速度
[root@kangvcar ~]# yum list        //列出了3780個包

二、把預設的CentOS yum源修改成國內的aliyun yum源

1.安裝Centos後預設的yum源如下

[[email protected] ~]# ll /etc/yum.repos.d/
total 32
-rw-r--r--. 1 root root 1664 Dec  9  2015 CentOS-Base.repo
-rw-r--r--. 1 root root 1309 Dec  9  2015 CentOS-CR.repo
-rw-r--r--. 1 root root  649 Dec  9  2015 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root  290 Dec  9  2015 CentOS-fasttrack.repo
-rw-r--r--. 1 root root  630 Dec  9  2015 CentOS-Media.repo
-rw-r--r--. 1 root root 1331 Dec  9  2015 CentOS-Sources.repo
-rw-r--r--. 1 root root 1952 Dec  9  2015 CentOS-Vault.repo

2.把預設yum源備份(可選)

[root@kangvcar ~]# mkdir /opt/centos-yum.bak
[root@kangvcar ~]# mv /etc/yum.repos.d/* /opt/centos-yum.bak/

3.下載aliyun yum源repo檔案(對應自己的系統版本下載即可)

#各系統版本repo檔案對應的下載操作
CentOS 5
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-5.repo
CentOS 6
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
CentOS 7
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
[[email protected] ~]# cat /etc/redhat-release        //檢視系統的版本
CentOS Linux release 7.2.1511 (Core)
[[email protected] ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
--2017-06-20 06:43:08--  http://mirrors.aliyun.com/repo/Centos-7.repo
Resolving mirrors.aliyun.com (mirrors.aliyun.com)... 112.124.140.210, 115.28.122.210
Connecting to mirrors.aliyun.com (mirrors.aliyun.com)|112.124.140.210|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2573 (2.5K) [application/octet-stream]
Saving to: ‘/etc/yum.repos.d/CentOS-Base.repo100%[=======================================================================================================>] 2,573       --.-K/s   in 0s      
2017-06-20 06:43:08 (118 MB/s) - ‘/etc/yum.repos.d/CentOS-Base.repo’ saved [2573/2573]

4.清除快取

[root@kangvcar ~]# yum clean all
Loaded plugins: fastestmirror
Cleaning repos: base extras updates
Cleaning up everything
Cleaning up list of fastest mirrors
[root@kangvcar ~]# yum makecache        //把yum源快取到本地,加快軟體的搜尋好安裝速度
[root@kangvcar ~]# yum list        //總共列出了9954個包

三、把預設的CentOS yum源修改成國內的163源

1.安裝Centos後預設的yum源如下

[[email protected] ~]# ll /etc/yum.repos.d/
total 32
-rw-r--r--. 1 root root 1664 Dec  9  2015 CentOS-Base.repo
-rw-r--r--. 1 root root 1309 Dec  9  2015 CentOS-CR.repo
-rw-r--r--. 1 root root  649 Dec  9  2015 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root  290 Dec  9  2015 CentOS-fasttrack.repo
-rw-r--r--. 1 root root  630 Dec  9  2015 CentOS-Media.repo
-rw-r--r--. 1 root root 1331 Dec  9  2015 CentOS-Sources.repo
-rw-r--r--. 1 root root 1952 Dec  9  2015 CentOS-Vault.repo

2.把預設yum源備份(可選)

[root@kangvcar ~]# mkdir /opt/centos-yum.bak
[root@kangvcar ~]# mv /etc/yum.repos.d/* /opt/centos-yum.bak/

3.下載163 yum源repo檔案

#各系統版本repo檔案對應的下載操作
CentOS 5
wget -O /etc/yum.repos.d/CentOS5-Base-163.repo http://mirrors.163.com/.help/CentOS5-Base-163.repo
CentOS 6
wget -O /etc/yum.repos.d/CentOS6-Base-163.repo http://mirrors.163.com/.help/CentOS6-Base-163.repo
CentOS 7
wget -O /etc/yum.repos.d/CentOS7-Base-163.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo
[[email protected] ~]# cat /etc/redhat-release        //檢視系統的版本
CentOS Linux release 7.2.1511 (Core)
[[email protected]car ~]# wget -O /etc/yum.repos.d/CentOS7-Base-163.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo
--2017-06-20 06:29:47--  http://mirrors.163.com/.help/CentOS7-Base-163.repo
Resolving mirrors.163.com (mirrors.163.com)... 123.58.173.185, 123.58.173.186
Connecting to mirrors.163.com (mirrors.163.com)|123.58.173.185|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1572 (1.5K) [application/octet-stream]
Saving to: ‘/etc/yum.repos.d/CentOS7-Base-163.repo’
100%[=======================================================================================================>] 1,572       --.-K/s   in 0s      
2017-06-20 06:29:47 (293 MB/s) - ‘/etc/yum.repos.d/CentOS7-Base-163.repo’ saved [1572/1572]

4.清除快取

[root@kangvcar ~]# yum clean all
Loaded plugins: fastestmirror
Cleaning repos: base extras updates
Cleaning up everything
Cleaning up list of fastest mirrors
[root@kangvcar ~]# yum makecache        //把yum源快取到本地,加快軟體的搜尋好安裝速度
[root@kangvcar ~]# yum list        //總共列出了9951個包

四、修改yum源的優先順序

ps:當既有本地yum源又有163源的時候,我們在裝軟體包的時候當然希望先用本地的yum源去安裝,本地找不到可用的包時再使用163源去安裝軟體,這裡就涉及到了優先順序的問題,yum提供的外掛yum-plugin-priorities.noarch可以解決這個問題

1.檢視系統是否安裝了優先順序的外掛

[[email protected] ~]# rpm -qa | grep yum-plugin-
yum-plugin-fastestmirror-1.1.31-34.el7.noarch        
//這裡看到沒有安裝yum-plugin-priorities.noarch這個外掛
[[email protected] ~]# yum search yum-plugin-priorities        
//用search檢視是否有此外掛可用
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
====================================================== N/S matched: yum-plugin-priorities =======================================================
yum-plugin-priorities.noarch : plugin to give priorities to packages from different repos

2.安裝yum-plugin-priorities.noarch外掛

[root@kangvcar ~]# yum -y install yum-plugin-priorities.noarch

3.檢視外掛是否啟用

[[email protected] ~]# cat /etc/yum/pluginconf.d/priorities.conf
[main]
enabled = 1
//1為啟用;0為禁用

4.修改本地yum源優先使用

[[email protected] ~]# ll /etc/yum.repos.d/
total 8
-rw-r--r--. 1 root root 2573 May 15  2015 CentOS-Base.repo
-rw-r--r--. 1 root root   67 Jun 20 06:04 local.repo
//有兩個repo檔案
[[email protected] ~]# vi /etc/yum.repos.d/local.repo
[local]
name=local
baseurl=file:///opt/centos
enabled=1
gpgcheck=0
priority=1
//在原基礎上加入priority=1 ;數字越小優先順序越高
//可以繼續修改其他源的priority值,經測試僅配置本地源的優先順序為priority=1就會優先使用本地源了

5.測試

配置優先順序前:(使用阿里雲yum源)
[[email protected] ~]# yum -y install vim
Dependencies Resolved
=================================================================================================================================================
Package                            Arch                         Version                                     Repository                     Size
=================================================================================================================================================
Installing:
vim-enhanced                       x86_64                       2:7.4.160-1.el7_3.1                         updates                       1.0 M
Updating for dependencies:
vim-common                         x86_64                       2:7.4.160-1.el7_3.1                         updates                       5.9 M
省略···
配置優先順序後:(使用本地yum源)
[[email protected] ~]# yum -y install vim
Dependencies Resolved
=================================================================================================================================================
Package                                     Arch                        Version                                Repository                  Size
=================================================================================================================================================
Installing:
vim-enhanced                                x86_64                      2:7.4.160-1.el7                        local                      1.0 M
Installing for dependencies:
gpm-libs                                    x86_64                      1.20.7-5.el7                           local                       32 k
perl                                        x86_64                      4:5.16.3-286.el7                       local                      8.0 M
perl-Carp                                   noarch                      1.26-244.el7                           local                       19 k
perl-Encode                                 x86_64                      2.51-7.el7                             local                      1.5 M
perl-Exporter                               noarch                      5.68-3.el7                             local                       28 k
perl-File-Path                              noarch                      2.09-2.el7                             local                       26 k
perl-File-Temp                              noarch                      0.23.01-3.el7                          local                       56 k
省略···

相關推薦

阿里申請免費SSL證書配置到Tomcat實現https訪問

在阿里雲的證書列表中,點下載證書,就可以根據你的伺服器下載相關的證書。 選擇Tomcat,下載,阿里雲上面還附有教程,很方便。唯一要注意的是,阿里雲上面的ECS只支援開放443埠,所以Tomcat要把8443埠改成443埠,並在阿里雲上面新增開放443埠,才可以用https訪

阿里伺服器上部署tomcat進行訪問測試

    要求將一個專案部署到新買的阿里雲伺服器上。使用xshell遠端連線(連線使用的ip是例項的公網ip)。     在部署配置tomcat之前首先進行JDK的部署,先說明一下,我使用的CentOS7.4.     選擇JDK1.

使用阿里搭建自己的伺服器部署IIS為自己的app提供服務

之前幫實驗室搭過一個阿里雲,最近看到阿里雲有學生優惠,就自己買了個伺服器,搭了個同樣的伺服器供自己折騰,主要做測試服。下面記錄下搭建過程中遇到的問題。 買伺服器什麼就不說了,去阿里雲註冊個帳號,然後像淘寶一樣購物就好了。 買完之後可以拿到自己伺服器的公網IP

CentOS配置本地yum/阿里yum/163yuan配置yum優先順序

一、用Centos映象搭建本地yum源 由於安裝centos後的預設yum源為centos的官方地址,所以在國內使用很慢甚至無法訪問,所以一般的做法都是把預設的yum源替換成aliyun的yum源或者163等國內的yum源(下文介紹如何配置)。 但

RHEL7.4配置CentOS Yum阿里

由於沒有購買RedHat的服務,所以RHEL7.3在yum更新的時候由於沒有更新源造成更新失敗,於是把RedHat的更新源設定成阿里的更新源。wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com

centos 7 yum 設定 阿里 kubernetes 庫

cat <<EOF > /etc/yum.repos.d/kubernetes.repo [kubernetes] name=Kubernetes baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x

liunux掛載ntfs格式的U盤配置本地yum

# 系統為CentOS-6.6 # U盤是ntfs格式 yum install gcc (安裝gcc,不然下面安裝會報錯) wget https://tuxera.com/opensource/ntfs-3g_ntfsprogs-2016.2.22.tgz tar xf

Linux下掛載映象配置本地yum

一:掛載光碟機 1.連線光碟機,(映象)如下圖所示 注意哦:千萬不要把6的映象掛成7的,6的映象掛6.*的都可以。 2.建立掛載點(將分割槽對映到Linux中的一個目錄

阿里Linux的mysql安裝使用yum安裝

1、下載 我下載的mysql5.7 rpm格式的,在Linux的根目錄下下載(防止出現安裝的問題) wget https://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm     2、安裝

eclipse中配置Maven與本地倉庫和阿里映象設定

eclipse中配置Maven 1 在window-preference中搜索maven 在1 Maven Installation 找到Maven安裝路徑的bin的路徑 2  User setting 找到Maven的setting 及本地倉庫 引入Maven

【Linux篇】配置apt-get為阿里

1.到 /etc/apt/sources.list 裡全部成替換成如下內容 (內網) deb http://mirrors.cloud.aliyuncs.com/ubuntu/ trusty main restricted universe multiverse d

Maven settings.xml配置(指定本地倉庫、阿里映象設定)

一、settings.xml檔案會在兩個目錄下存在:1、Maven安裝目錄(全域性):%MAVEN_HOME%\conf\settings.xml2、使用者安裝目錄(使用者):${user.home}\.m2\settings.xml第一個是全域性配置,第二個是使用者配置。當

三、eclipse中Maven本地倉庫和阿里中央倉庫配置

由於中央倉庫伺服器在國外,下載依賴包比較慢,而阿里雲的倉庫是國內的,而阿里雲基本上可以提供我們全部的需要找到本地maven安裝路徑修改conf下的settings.xml<mirror> <id>aliyun</id>

CentOS修改映象為國內阿里或163

系統預設設定的是國外的。這樣就會導致下載速度緩慢。用國內幾家比較熱門的映象源,穩定性和速度很高。下面的映象全部支援Linux的任何一個發行版的系統。拿Centos來進行做教程阿里雲Linux安裝軟體映象源得益與阿里雲的高速發展,阿里雲是最近新出的一個映象源。阿里雲Linux安

阿里CentOS7.3RPM方式安裝MySQL以及配置遠端連線

1. 下載Mysql安裝包 2. 解除安裝阿里映象自帶的MariaDB資料庫 3. 解壓安裝下載的Mysql資料庫 *4. 環境配置 1.下載MySQL安裝包 https://dev.mysql.com/downloads/ 官方網址,根據自己需求

DOCKER 建立 配置 執行 NGINX 環境(阿里伺服器)

1. 拉取nginx #拉取nginx的最新穩定版 sudo docker pull nginx 2.Docker建立Nginx容器並執行 #1.對映埠 80:80 ===>443:443 埠 #2.配置資料儲存路徑 /opt/nginx/conf.d :/etc/nginx/c

阿里linux伺服器------第三章:配置phpmysql環境實現動態網站

在第二章中我們講述瞭如何配置靜態網站,接下來我們配置動態網站需要的環境 第一步:配置php環境,開啟putty連線到自己的伺服器執行以下命令   安裝php yum install php php-devel 重啟apache使php生效 y 安裝php的擴充套

PHPMailer 在本地傳送成功 阿里上傳送失敗原因

阿里雲預設不允許訪問SMTP 25埠,可申請解封25埠或換ssl加密方式連線和埠 $mail = new PHPMailer(); $mail->IsSMTP(); # $mail->Host = 'smtp.exmail.qq.com'; # 本地可直接使用 $mail

實戰:基於 Spring 的應用配置如何遷移至阿里應用配置管理 ACM

最近遇到一些開發者朋友,準備將原有的Java Spring的應用配置遷移到 阿里雲應用配置管理 ACM 中。遷移過程中,遇到不少有趣的問題。本文將通過一個簡單的樣例來還原遷移過程中遇到的問題和相關解決思路,以期達到和讀者交流的目的。 什麼樣的配置適合進入配置中心 這是所有準備遷移配置到配置中心的使用者遇到

阿里伺服器ECS安裝執行環境及配置

Elastic Compute Service(ECS)是阿里雲提供的一種基礎雲端計算服務。隨時建立所需數量的雲伺服器ECS例項。在使用過程中,隨著業務的擴充套件,您可以隨時擴容磁碟、增加頻寬。如果不再需要雲伺服器,也能隨時釋放資源,節省費用。 包括例項規格、塊儲存、映象、快照、頻寬和安全組