1. yum基础
1.1 yum命令
1.1.1 安装卸载服务
- 安装
# yum install httpd “mysql*” -y
- 升级
# yum update xxx -y
- 卸载
# yum remove xxx -y
谨慎使用,会卸载依赖
- 清空缓存
# yum clean all**
1.1.2 查看
# yum repolist
# yum list
# yum list 包名
# yum info 包名
# yum provides /usr/bin/scp
1.1.3 包组的使用
# yum grouplist
# yum groupinstall xxx
1.2 指定yum源
# vim /etc/yum.repos.d/test.repo
[test]
name=test
enabled=1
gpgcheck=0
#baseurl=file:///media/cd/
baseurl=file:///data/ftp/yum_data
# baseurl=ftp://172.16.8.100/centos6u6
说明:
[test] 仓库ID,有唯一性,随意起
name=test 仓库名
enabled=1 1,激活仓库
gpgcheck=0 0,不检查软件包签名
baseurl=file:///media/cd/ 指定光盘
baseurl=file:///data/ftp/yum_data 指定本地目录为yum源
baseurl=ftp://172.16.8.100/centos6.6 指定ftp服务器
1.3 常用yum源
1.3.1 163源
● CentOS 6
# curl -o /etc/yum.repos.d/CentOS-Base-163.repo http://mirrors.163.com/.help/CentOS6-Base-163.repo
# wget -O /etc/yum.repos.d/CentOS-Base-163.repo http://mirrors.163.com/.help/CentOS6-Base-163.repo
● CentOS 7
# curl -o /etc/yum.repos.d/CentOS-Base-163.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo
# wget -O /etc/yum.repos.d/CentOS-Base-163.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo
1.3.2阿里源
● CentOS 6
# wget -O /etc/yum.repos.d/CentOS-Base-ali.repo http://mirrors.aliyun.com/repo/Centos-6.repo
# curl -o /etc/yum.repos.d/CentOS-Base-ali.repo http://mirrors.aliyun.com/repo/Centos-6.repo
● CentOS 7
# wget -O /etc/yum.repos.d/CentOS-Base-ali.repo http://mirrors.aliyun.com/repo/Centos-7.repo
# curl -o /etc/yum.repos.d/CentOS-Base-ali.repo http://mirrors.aliyun.com/repo/Centos-7.repo
1.3.3 清华源
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client. You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#
[base]
name=CentOS-$releasever - Base
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/os/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#released updates
[updates]
name=CentOS-$releasever - Updates
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/updates/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/extras/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/centosplus/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
1.3.4 epel
wget http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -ivh epel-release-latest-7.noarch.rpm
2. 自建yum仓库
思路:
1)搭建ftp服务器提供资源下载,服务目录为/data/ftp
2)将yum源所需的rpm包下载到 /data/ftp/yum_data
3)将/data/ftp/yum_data目录做成yum源
2.1 安装ftp服务器
2.1.1 准备
1)创建根目录
# mkdir /data/ftp/yum_data
# useradd liuwei
2)将修改根目录权限
#chmode 755 /data/ftp
说明:如果根目录有写权限,匿名用户登录检查会报错,然后不再允许匿名用户登录
3)创建匿名默认用户
# useradd liuwei
2.1.2 安装vsftp
# yum install -y vsftpd
2.1.3 修改配置文件
# vim /etc/vsftpd/vsftpd.conf
anonymous_enable=YES
####修改根目录#####
chroot_local_user=YES
allow_writeable_chroot=YES
local_root=/data/ftp
anon_root=/data/ftp
####设置匿名登录用户####
nopriv_user=liuwei
2.1.3 启动服务
# systemctl restart vsftpd.service
# systemctl enable vsftpd.service
测试
# wget ftp://127.0.0.1/
2.2 下载rpm文件
2.2.1 yum-plugin-downloadonly插件
# yum install yum-plugin-downloadonly
2.2.1 允许插件
# vim /etc/yum/pluginconf.d/downloadonly.conf
[main]
enabled=1
2.2.1 下载rpm文件
# yum install --downloadonly --downloaddir=/data/ftp/yum_data/httpd httpd
说明:
上边指定的目录执行命令时会自动创建
如果不制定下载目录,则默认为 /var/cache/yum/{RepositoryName}/packages/
2.3 创建yum源
2.3.1 创建依赖
# yum -y install createrepo
# createrepo -v /data/ftp/yum_data/
2.3.2 权限修改
# chmod 755 /data/ftp/yum_data -R
说明:每次下载的yum源或执行创建依赖后都需要执行该步骤。
因为2.2步骤新下载的目录和2.3.1中创建的依赖文件目录都是750 权限,匿名用户登录后不能读取或下载文件,客户端yum会报错。
2.4客户端使用yum源
2.4.1 制定yum源
# vim /etc/yum.repos.d/liuwei.repo
[liuwei]
name=liuwei
enabled=1
gpgcheck=0
baseurl=ftp://10.252.97.213/yum_data
2.4.2 测试
# yum repolist
# yum list httpd
# yum install httpd
3. yum的一些操作
3.1 yum缓存的配置
[main]
cachedir=/var/cache/yum #yum下载的RPM包的缓存目录
keepcache=0 #缓存是否保存,1保存,0不保存。
debuglevel=2 #调试级别(0-10),默认为2(并不知道具体作用)。
logfile=/var/log/yum.log #yum的日志文件所在的位置
exactarch=1 #在更新的时候,是否允许更新不同版本的RPM包,比如是否在i386上更新i686的RPM包。
obsoletes=1 #相当于upgrade,允许更新陈旧的RPM包。
gpgcheck=1 #是否检查GPG(GNU Private Guard),一种密钥方式签名。
plugins=1 #是否允许使用插件,默认是0不允许,但是我们一般会用yum-fastestmirror这个插件。
installonly_limit=3 #允许保留多少个内核包。
exclude=selinux* #屏蔽不想更新的RPM包,可用通配符,多个RPM包之间使用空格分离
metadata_expire=90m #设定保存时长
3.2 yum设置代理
#vim /etc/yum.conf
proxy=http://代理服务器ip:port
3.3 yum只下载不安装
见本章2.2
4.FAQ
Transaction check error
-
报错
输出如下:
Transaction check error:
file /usr/bin/docker from install of docker-ce-18.06.0.ce-3.el7.x86_64 conflicts with file from package docker-ce-cli-1:19.03.8-3.el7.x86_64
file /usr/share/bash-completion/completions/docker from install of docker-ce-18.06.0.ce-3.el7.x86_64 conflicts with file from package docker-ce-cli-1:19.03.8-3.el7.x86_64
-
解决
和前边的版本冲突,卸载一个版本再安装即可。(前边19.03安装失败)
rpm -e docker-ce-cli-1:19.03.8-3.el7.x86_64
yum install docker-ce-18.06.0.ce-3.el7.x86_64