1. 程式人生 > >Linux-yum更新倉庫

Linux-yum更新倉庫

話說

各位小夥伴,晚上好。這裡終結一下yum倉庫更新的方式。之所以總結這個,是因為上一篇在ECS安裝MySQL雖然受挫但終究或多或少有點點收穫,那就是yum的基本運作原理。這裡會按照官網方式介紹yum如何安裝MySQL來說明寡人對yum安裝的進一步認識。

目錄

1、如何更新yum固有的倉庫?
2、如何選擇yum預設安裝的版本?
3、原理總結

1、如何更新yum固有的倉庫?

地球人都知道,Yum是線上安裝。線上安裝的好處就是不用下載包包。壞處呢?壞處就是你得知道你要安裝的版本這個yum倉庫中有,否則你的yum -y install mysql就預設安裝的是倉庫中固有的版本。但是我想安裝最新版本呢?我怎麼檢視倉庫已有什麼版本?

檢視yum可以按照的版本

yum list | grep ^mysql

如果版本中沒有最新的MySQL8.0呢?怎麼辦?
1)去MySQL官網下載rpm包;
2)上傳並執行命令

 sudo yum localinstall platform-and-version-specific-package-name.rpm

效果如圖:

這裡寫圖片描述

如何檢視呢?

[root@izuf6i3jkmikgmou78pwvfz ~]# yum repolist enabled | grep "mysql.*-community.*"
mysql-connectors-community/x86_64 MySQL
Connectors Community 51 mysql-tools-community/x86_64 MySQL Tools Community 63 mysql80-community/x86_64 MySQL 8.0 Community Server 17 [root@izuf6i3jkmikgmou78pwvfz ~]#

當然也可以這麼檢視

[[email protected] ~]# yum list | grep ^mysql
mysql-community-client.x86_64 8.0.11-1.el7 @mysql80-community mysql-community-common.x86_64 8.0.11-1.el7 @mysql80-community mysql-community-libs.x86_64 8.0.11-1.el7 @mysql80-community mysql-community-libs-compat.x86_64 8.0.11-1.el7 @mysql80-community mysql-community-server.x86_64 8.0.11-1.el7 @mysql80-community mysql80-community-release.noarch el7-1 installed mysql++.x86_64 3.1.0-12.el7 epel mysql++-devel.x86_64 3.1.0-12.el7 epel mysql++-manuals.x86_64 3.1.0-12.el7 epel mysql-community-client.i686 8.0.11-1.el7 mysql80-community mysql-community-common.i686 8.0.11-1.el7 mysql80-community mysql-community-devel.i686 8.0.11-1.el7 mysql80-community mysql-community-devel.x86_64 8.0.11-1.el7 mysql80-community mysql-community-embedded-compat.i686 8.0.11-1.el7 mysql80-community mysql-community-embedded-compat.x86_64 8.0.11-1.el7 mysql80-community mysql-community-libs.i686 8.0.11-1.el7 mysql80-community mysql-community-libs-compat.i686 8.0.11-1.el7 mysql80-community mysql-community-release.noarch el7-5 mysql-connectors-community mysql-community-test.x86_64 8.0.11-1.el7 mysql80-community mysql-connector-java.noarch 1:5.1.25-3.el7 base mysql-connector-odbc.x86_64 8.0.11-1.el7 mysql-connectors-community mysql-connector-odbc-debuginfo.x86_64 8.0.11-1.el7 mysql-connectors-community mysql-connector-odbc-setup.x86_64 8.0.11-1.el7 mysql-connectors-community mysql-connector-python.noarch 2.0.4-1.el7 mysql-connectors-community mysql-connector-python.x86_64 8.0.11-1.el7 mysql-connectors-community mysql-connector-python-cext.x86_64 8.0.11-1.el7 mysql-connectors-community mysql-connector-python-debuginfo.x86_64 2.1.7-1.el7 mysql-connectors-community mysql-mmm.noarch 2.2.1-15.el7 epel mysql-mmm-agent.noarch 2.2.1-15.el7 epel mysql-mmm-monitor.noarch 2.2.1-15.el7 epel mysql-mmm-tools.noarch 2.2.1-15.el7 epel mysql-proxy.x86_64 0.8.5-2.el7 epel mysql-proxy-devel.x86_64 0.8.5-2.el7 epel mysql-ref-manual-8.0-en-html-chapter.noarch mysql-ref-manual-8.0-en-pdf.noarch 1-20180420 mysql80-community mysql-router.x86_64 8.0.11-1.el7 mysql-tools-community mysql-router-debuginfo.x86_64 8.0.11-1.el7 mysql-tools-community mysql-shell.x86_64 8.0.11-1.el7 mysql-tools-community mysql-shell-debuginfo.x86_64 8.0.11-1.el7 mysql-tools-community mysql-utilities.noarch 1.6.5-1.el7 mysql-tools-community mysql-utilities-extra.noarch 1.5.6-1.el7 mysql-tools-community mysql-workbench-community.x86_64 6.3.10-1.el7 mysql-tools-community mysql-workbench-community-debuginfo.x86_64 mysqlreport.noarch 3.5-11.el7 epel mysqltuner.noarch 1.6.0-1.el7 epel [[email protected] ~]#

2、如何選擇yum預設安裝的版本?

0k!上面表明,yum源裡面已經有這個包包了,那麼如果執行yum -y install mysql,到底安裝的是哪個版本呢?

[root@izuf6i3jkmikgmou78pwvfz ~]# yum repolist all | grep mysql
mysql-cluster-7.5-community/x86_64 MySQL Cluster 7.5 Community      禁用
mysql-cluster-7.5-community-source MySQL Cluster 7.5 Community - So 禁用
mysql-cluster-7.6-community/x86_64 MySQL Cluster 7.6 Community      禁用
mysql-cluster-7.6-community-source MySQL Cluster 7.6 Community - So 禁用
mysql-connectors-community/x86_64  MySQL Connectors Community       啟用:     51
mysql-connectors-community-source  MySQL Connectors Community - Sou 禁用
mysql-tools-community/x86_64       MySQL Tools Community            啟用:     63
mysql-tools-community-source       MySQL Tools Community - Source   禁用
mysql-tools-preview/x86_64         MySQL Tools Preview              禁用
mysql-tools-preview-source         MySQL Tools Preview - Source     禁用
mysql55-community/x86_64           MySQL 5.5 Community Server       禁用
mysql55-community-source           MySQL 5.5 Community Server - Sou 禁用
mysql56-community/x86_64           MySQL 5.6 Community Server       禁用
mysql56-community-source           MySQL 5.6 Community Server - Sou 禁用
mysql57-community/x86_64           MySQL 5.7 Community Server       禁用
mysql57-community-source           MySQL 5.7 Community Server - Sou 禁用
mysql80-community/x86_64           MySQL 8.0 Community Server       啟用:     17
mysql80-community-source           MySQL 8.0 Community Server - Sou 禁用
[root@izuf6i3jkmikgmou78pwvfz ~]# 

yum list all | grep mysql
這個命令可以讓我們非常清楚的看清楚預設啟用的版本。這個預設啟動,就是yum -y install預設安裝的版本,當然你可以隨心所欲的修改。

這裡寫圖片描述

問題關鍵來了,如何修改預設啟動版本?
兩種方式:
方式一:命令
方式二:配置

核心命令就2個

yum-config-manager --disable mysql80-community
yum-config-manager --enable mysql80-community

要想使用yum-config-manager,需要先安裝下:yum -y install yum-utils (CentOS 7.5)

[[email protected] ~]# yum -y install yum-utils
已載入外掛:fastestmirror
Loading mirror speeds from cached hostfile
軟體包 yum-utils-1.1.31-45.el7.noarch 已安裝並且是最新版本
無須任何處理

然後就是enabled disabled的事情了。
方式一:命令

[[email protected] yum.repos.d]# yum-config-manager --disable mysql80-community
已載入外掛:fastestmirror
==================================================== repo: mysql80-community =====================================================
[mysql80-community]
async = True
bandwidth = 0
base_persistdir = /var/lib/yum/repos/x86_64/7
baseurl = http://repo.mysql.com/yum/mysql-8.0-community/el/7/x86_64/
cache = 0
cachedir = /var/cache/yum/x86_64/7/mysql80-community
check_config_file_age = True
compare_providers_priority = 80
cost = 1000
deltarpm_metadata_percentage = 100
deltarpm_percentage = 
enabled = 0
enablegroups = True
exclude = 
failovermethod = priority
ftp_disable_epsv = False
gpgcadir = /var/lib/yum/repos/x86_64/7/mysql80-community/gpgcadir
gpgcakey = 
gpgcheck = True
gpgdir = /var/lib/yum/repos/x86_64/7/mysql80-community/gpgdir
gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
hdrdir = /var/cache/yum/x86_64/7/mysql80-community/headers
http_caching = all
includepkgs = 
ip_resolve = 
keepalive = True
keepcache = False
mddownloadpolicy = sqlite
mdpolicy = group:small
mediaid = 
metadata_expire = 21600
metadata_expire_filter = read-only:present
metalink = 
minrate = 0
mirrorlist = 
mirrorlist_expire = 86400
name = MySQL 8.0 Community Server
old_base_cache_dir = 
password = 
persistdir = /var/lib/yum/repos/x86_64/7/mysql80-community
pkgdir = /var/cache/yum/x86_64/7/mysql80-community/packages
proxy = False
proxy_dict = 
proxy_password = 
proxy_username = 
repo_gpgcheck = False
retries = 10
skip_if_unavailable = False
ssl_check_cert_permissions = True
sslcacert = 
sslclientcert = 
sslclientkey = 
sslverify = True
throttle = 0
timeout = 30.0
ui_id = mysql80-community/x86_64
ui_repoid_vars = releasever,
   basearch
username = 

如何恢復呢?

#恢復過來也一樣:
[[email protected] yum.repos.d]# yum-config-manager --enable mysql80-community
已載入外掛:fastestmirror
==================================================== repo: mysql80-community =====================================================
[mysql80-community]
async = True
bandwidth = 0
base_persistdir = /var/lib/yum/repos/x86_64/7
baseurl = http://repo.mysql.com/yum/mysql-8.0-community/el/7/x86_64/
cache = 0
cachedir = /var/cache/yum/x86_64/7/mysql80-community
check_config_file_age = True
compare_providers_priority = 80
cost = 1000
deltarpm_metadata_percentage = 100
deltarpm_percentage = 
enabled = 1
enablegroups = True
exclude = 
failovermethod = priority
ftp_disable_epsv = False
gpgcadir = /var/lib/yum/repos/x86_64/7/mysql80-community/gpgcadir
gpgcakey = 
gpgcheck = True
gpgdir = /var/lib/yum/repos/x86_64/7/mysql80-community/gpgdir
gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
hdrdir = /var/cache/yum/x86_64/7/mysql80-community/headers
http_caching = all
includepkgs = 
ip_resolve = 
keepalive = True
keepcache = False
mddownloadpolicy = sqlite
mdpolicy = group:small
mediaid = 
metadata_expire = 21600
metadata_expire_filter = read-only:present
metalink = 
minrate = 0
mirrorlist = 
mirrorlist_expire = 86400
name = MySQL 8.0 Community Server
old_base_cache_dir = 
password = 
persistdir = /var/lib/yum/repos/x86_64/7/mysql80-community
pkgdir = /var/cache/yum/x86_64/7/mysql80-community/packages
proxy = False
proxy_dict = 
proxy_password = 
proxy_username = 
repo_gpgcheck = False
retries = 10
skip_if_unavailable = False
ssl_check_cert_permissions = True
sslcacert = 
sslclientcert = 
sslclientkey = 
sslverify = True
throttle = 0
timeout = 30.0
ui_id = mysql80-community/x86_64
ui_repoid_vars = releasever,
   basearch
username = 

[[email protected] yum.repos.d]# 

方式二:配置

上面每個命令對應的都是修改配置檔案。
Besides using yum-config-manager or the dnf config-manager command, you can also select a release series by editing manually the/etc/yum.repos.d/mysql-community.repo file. This is a typical entry for a release series’ subrepository in the file:

[[email protected] yum.repos.d]# pwd
/etc/yum.repos.d
[[email protected] yum.repos.d]# ls -l
總用量 16
-rw-r–r– 1 root root 675 5月 30 11:47 CentOS-Base.repo
-rw-r–r– 1 root root 230 5月 30 11:47 epel.repo
-rw-r–r– 1 root root 1864 6月 23 16:54 mysql-community.repo
-rw-r–r– 1 root root 1885 2月 22 16:49 mysql-community-source.repo
[[email protected] yum.repos.d]#

這裡寫圖片描述

3、原理總結

我們知道了:如何增強yum源固有的庫?和如何自主選擇安裝庫中的版本?從中,我們很容易明白:當你執行yum -y install的時候,其實就是去Yum源的地方去下載rpm包安裝後的東東,所以如果我們需要yum源中本來不存在的或者未及時更新的包包,就要去官網下載rpm包,然後解壓安裝:

 sudo yum localinstall platform-and-version-specific-package-name.rpm

這個時候,yum源中就有了我們想要安裝的版本;如果是最新的,預設就是啟動的。如果你還想對安裝的版本”為所欲為“,那麼就需要enabled和disable部分包包:

yum-config-manager --disable mysql80-community
yum-config-manager --enable mysql80-community

或者去修改配置檔案:Besides using yum-config-manager or the dnf config-manager command, you can also select a release series by editing manually the/etc/yum.repos.d/mysql-community.repo file. This is a typical entry for a release series’ subrepository in the file:

,就是這樣的流程。

好了,晚安。