目录
目录一、如何利用阿里云镜像站配置yum源1.1 什么是yum1.2 阿里云镜像站地址1.3 配置yum1.4 yum命令使用小技巧,特别有用1.5 yum在一些官网软件安装的应用(举例MYSQL)
一、如何利用阿里云镜像站配置yum源
1.1 什么是yum
Yum(全称为 Yellow dog Updater, Modified)是一个在Fedora和RedHat以及CentOS中的Shell前端软件包管理器。基于RPM包管理,能够从指定的服务器自动下载RPM包并且安装,可以自动处理依赖性关系,并且一次安装所有依赖的软件包,无须繁琐地一次次下载、安装。(百度百科)
1.2 阿里云镜像站地址
https://opsx.alibaba.com/mirror
1.3 配置yum
#如何查看yum的帮助
[root@cs ~]# man -k yum
find-repos-of-install (1) - report which Yum repository a package was installed from
repo-rss (1) - generates an RSS feed from one or more Yum repositories
repoclosure (1) - display a list of unresolved dependencies for a yum repository
repodiff (1) - list differences between two or more Yum repositories
repoquery (1) - query information from Yum repositories
reposync (1) - synchronize yum repositories to a local directory
verifytree (1) - verify that a local yum repository is consistent
yum (8) - Yellowdog Updater Modified
yum-builddep (1) - install missing dependencies for building an RPM package
yum-complete-transaction (8) - attempt to complete failed or aborted Yum transactions
yum-config-manager (1) - manage yum configuration options and yum repositories
yum-debug-dump (1) - write system RPM configuration to a debug-dump file
yum-debug-restore (1) - replay Yum transactions captured in a debug-dump file
yum-groups-manager (1) - create and edit yum's group metadata
yum-langpacks (8) - Plugin for yum
yum-shell (8) - Yellowdog Updater Modified shell
yum-utils (1) - tools for manipulating repositories and extended package management
yum.conf (5) - Configuration file for yum(8).
yumdb (8) - query and alter the Yum database
yumdownloader (1) - download RPM packages from Yum repositories
#这个里面有很多说明,及配置例子,可以参考。为什么都习惯把配置放在/etc/yum.repos.d目录下呢。这是由于yum.conf里面注释有条意见:
[root@cs yum.repos.d]# vim yum.conf
# PUT YOUR REPOS HERE OR IN separate files named file.repo
# in /etc/yum.repos.d 可以看到要求:将您的REPOS放在这里或单独的文件file.repo中,路径在/etc/yum.repos.d
#现在去配置文件要求的目录下配置yum repo
#备份本地yum目录下的文件
[root@cs ~]# cd /etc/yum.repos.d/
[root@cs yum.repos.d]# ls
CentOS-Base.repo CentOS-CR.repo CentOS-Debuginfo.repo CentOS-fasttrack.repo CentOS-Media.repo CentOS-Sources.repo CentOS-Vault.repo
[root@cs yum.repos.d]# mkdir backup
[root@cs yum.repos.d]# mv *.repo backup/
[root@cs yum.repos.d]# ls
backup
#创建repo文件,kubernetes为例。里面的选项可以参考man yum.conf
[root@cs yum.repos.d]# vim kubernetes.repo
[kubernetes] #软件源仓库的名称,这个会被yum识别
name=Kubernetes #也是定义名称,没什么用,起标识作用
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/ #镜像仓库地址
enabled=1 #表示这个软件仓库源被启用
gpgcheck=1 #用于开启校验软件包的合法性
repo_gpgcheck=1
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg #用于校验的gpg密钥
man yum.config的解释如下:
gpgecheck Either `1' or `0'. This tells yum whether or not it should perform a GPG signature check on packages. When this is set in the [main] section it sets the default for all repositories. The default is `0'.
epo_gpgcheck Either `1' or `0'. This tells yum whether or not it should perform a GPG signature check on the repodata. When this is set in the [main] section it sets the default for all repositories. The default is `0'.
gpgkey A URL pointing to the ASCII-armored GPG key file for the repository. This option is used if yum needs a public key to verify a package and the required key hasn't been imported into the RPM database. If this option is set, yum will automatically import the key from the specified URL. You will be prompted before the key is installed unless the assumeyes option is set.
#清除缓存数据
[root@cs yum.repos.d]# yum clean all
Loaded plugins: fastestmirror, langpacks
Cleaning repos: epel kubernetes
Cleaning up everything
Cleaning up list of fastest mirrors
#生成元数据缓存
[root@cs backup]# yum makecache
#测试我刚刚搭建的yum源是否成功。下面已经看到kubernetes的软件包。如果要安装指定版本的kubectl需要在安装的时候指定版本。可以参考我之前的kubernetes安装一文。
[root@cs backup]# yum list kube*
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.huaweicloud.com
* extras: mirrors.huaweicloud.com
* updates: mirrors.aliyun.com
Available Packages
kubeadm.x86_64 1.14.1-0 kubernetes
kubectl.x86_64 1.14.1-0 kubernetes
kubelet.x86_64 1.14.1-0 kubernetes
kubernetes.x86_64 1.5.2-0.7.git269f928.el7 extras
kubernetes-client.x86_64 1.5.2-0.7.git269f928.el7 extras
kubernetes-cni.x86_64 0.7.5-0 kubernetes
kubernetes-master.x86_64 1.5.2-0.7.git269f928.el7 extras
kubernetes-node.x86_64 1.5.2-0.7.git269f928.el7 extras
1.4 yum命令使用小技巧,特别有用
#安装系统的时候经常最小化安装,很多时候发现命令不能使用,这时候yum就很有用了
比如说我要通过命令iostat对I/O的输入输出做统计,监控系统磁盘的操作活动,及CPU使用情况
#发现没有这个命令
[root@cs ~]# iostat
-bash: /usr/bin/iostat: No such file or directory
#很多人会直接通过这种方法安装,会发现没有iostat的包
[root@cs ~]# yum install iostat
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.huaweicloud.com
* extras: mirrors.huaweicloud.com
* updates: mirrors.aliyun.com
No package iostat available.
Error: Nothing to do
#上面情况很容易出现,如何定位iostat包含在那个包里面呢
[root@cs ~]# yum provides iostat
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.huaweicloud.com
* extras: mirrors.huaweicloud.com
* updates: mirrors.aliyun.com
sysstat-10.1.5-17.el7.x86_64 : Collection of performance monitoring tools for Linux
Repo : base
Matched from:
Filename : /usr/bin/iostat
#上面使用了provides参数,找到了iostat属于那个包。现在安装一下测试是否正确
[root@cs ~]# yum -y install sysstat-10.1.5-17.el7.x86_64
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.huaweicloud.com
* extras: mirrors.huaweicloud.com
* updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package sysstat.x86_64 0:10.1.5-17.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
==========================================================================================================================
Package Arch Version Repository Size
==========================================================================================================================
Installing:
sysstat x86_64 10.1.5-17.el7 base 315 k
Transaction Summary
==========================================================================================================================
Install 1 Package
Total download size: 315 k
Installed size: 1.1 M
Downloading packages:
No Presto metadata available for base
sysstat-10.1.5-17.el7.x86_64.rpm | 315 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : sysstat-10.1.5-17.el7.x86_64 1/1
Verifying : sysstat-10.1.5-17.el7.x86_64 1/1
Installed:
sysstat.x86_64 0:10.1.5-17.el7
Complete!
[root@cs ~]# iostat
Linux 3.10.0-327.el7.x86_64 (cs.upsoft.com) 04/18/2019 _x86_64_ (2 CPU)
avg-cpu: %user %nice %system %iowait %steal %idle
0.05 0.00 0.03 0.00 0.00 99.91
Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn
sda 0.06 0.04 0.33 449785 3609588
scd0 0.00 0.00 0.00 44 0
dm-0 0.07 0.04 0.33 439022 3605241
dm-1 0.00 0.00 0.00 1268 0
dm-2 0.00 0.00 0.00 3522 2188
#看到没有,就是这样操作。如果你想用命令的时候发现系统没有安装对应的包,可以通过这个命令来查找然后解决。特别对最小化安装系统的时候很有用。
#通过yum info可以看到包的详细信息。可以看到这个包不止给我们提供了iostat这个工具。还包括sar, sadf, mpstat, iostat, pidstat, nfsiostat-sysstat等。
[root@cs ~]# yum info sysstat-10.1.5-17.el7.x86_64
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.huaweicloud.com
* extras: mirrors.huaweicloud.com
* updates: mirrors.aliyun.com
Installed Packages
Name : sysstat
Arch : x86_64
Version : 10.1.5
Release : 17.el7
Size : 1.1 M
Repo : installed
From repo : base
Summary : Collection of performance monitoring tools for Linux
URL : http://sebastien.godard.pagesperso-orange.fr/
License : GPLv2+
Description : The sysstat package contains sar, sadf, mpstat, iostat, pidstat, nfsiostat-sysstat,
: tapestat, cifsiostat and sa tools for Linux.
: The sar command collects and reports system activity information. This
: information can be saved in a file in a binary format for future inspection. The
: statistics reported by sar concern I/O transfer rates, paging activity,
: process-related activities, interrupts, network activity, memory and swap space
: utilization, CPU utilization, kernel activities and TTY statistics, among
: others. Both UP and SMP machines are fully supported.
: The sadf command may be used to display data collected by sar in various formats
: (CSV, XML, etc.).
: The iostat command reports CPU utilization and I/O statistics for disks.
: The tapestat command reports statistics for tapes connected to the system.
: The mpstat command reports global and per-processor statistics.
: The pidstat command reports statistics for Linux tasks (processes).
: The nfsiostat-sysstat command reports I/O statistics for network file systems.
: The cifsiostat command reports I/O statistics for CIFS file systems.
1.5 yum在一些官网软件安装的应用(举例MYSQL)
现在很多软件都支持yum在线安装。
来源:https://dev.mysql.com/doc/mysql-yum-repo-quick-guide/en/
shell> sudo rpm -Uvh mysql80-community-release-el6-n.noarch.rpm
shell> yum repolist all | grep mysql
shell> sudo yum-config-manager --disable mysql80-community
shell> sudo yum-config-manager --enable mysql57-community #这里就是下面的enabled设置为0或1.开启mysql5.7的安装
[mysql80-community]
name=MySQL 8.0 Community Server
baseurl=http://repo.mysql.com/yum/mysql-8.0-community/el/6/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
# Enable to use MySQL 5.7
[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/6/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
shell> yum repolist enabled | grep mysql
shell> sudo yum install mysql-community-server
shell> sudo systemctl start mysqld.service
shell> sudo systemctl status mysqld.service
shell> sudo grep 'temporary password' /var/log/mysqld.log
shell> mysql -uroot -p
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';
shell> mysql_secure_installation
#Installing Additional MySQL Products and Components
shell> yum --disablerepo=\* --enablerepo='mysql*-community*' list available
shell> sudo yum install package-name
shell> sudo dnf install mysql-workbench-community
#Upgrading MySQL with the MySQL Yum Repository
#1.Selecting a Target Series
Important
For important information about upgrading from MySQL5.6 to 5.7, see Upgradingfrom MySQL 5.6 to5.7.
For important information about upgrading from MySQL5.7 to 8.0, see Upgradingfrom MySQL 5.7 to8.0.
In-place downgrading of MySQL is not supported by theMySQL Yum repository. Follow the instructions in Downgrading MySQL.
shell> sudo yum update mysql-server
shell> sudo dnf --refresh upgrade mysql-server
shell> sudo yum update
shell> sudo dnf upgrade
shell> sudo yum list installed | grep "^mysql"
shell> sudo yum update package-name
shell> sudo dnf upgrade package-name
文章转载自请叫我水哥,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




