(1)yum基础源
1)国内yum源地址
mirrors.aliyun.com //阿里有基础源和epel源
mirrors.163.com
查看使用帮助
2)更换yum源为阿里云(Centos7为例),默认是国外源;基础包
yum repolist //查看yum源
mkdir /etc/yum.repos.d/backup
mv /etc/yum.repos.d/{*.repo,backup}
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
或:curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum clean all //清除原来旧的yum数据库信息
yum makecache //更新新的yum仓库信息
3)epel源,扩展包
yum install epel-release -y //国外的epel源
mv /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo.backup
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo //使用阿里云的epel源
(2)软件包官方源
1)使用nginx的yum源
#vim /etc/yum.repos.d/nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1
2)使用mysql的官方yum源,centos7例子
https://dev.mysql.com/downloads/repo/yum/
#yum install https://repo.mysql.com//mysql80-community-release-el7-1.noarch.rpm -y
#vim /etc/yum.repos.d/mysql-community.repo 如果想使用5.5或者5.6那么启用对应版本enabled参数,关闭不需要的版本即可
[mysql55-community]
name=MySQL 5.5 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.5-community/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
# Enable to use MySQL 5.6
[mysql56-community]
name=MySQL 5.6 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
(3)yum管理软件包
1)查看可用仓库
yum repolist //查询可用仓库
yum clean all //清空缓存及其它文件
yum makecache //重建缓存
2)安装(yum安装,url安装,本地安装)
yum -y install httpd vsftpd samba* //从yum源中安装软件
yum -y install https://repo.mysql.com//mysql57-community-release-el7-11.noarch.rpm //从url安装rpm包
yum -y install /root/mysql57-community-release-el7-11.noarch.rpm //从本地安装
yum -y reinstall httpd //重新安装httpd
yum -y update httpd //更新httpd软件
yum -y update //更新系统内核和所有软件,不建议操作
yum -y groupinstall "Compatibility Libraries" //组安装,yum grouplist
3)查询(从本地rpm数据和yum源中查询)
yum list httpd //查询httpd软件是否安装,同时会从本地rpm数据和yum源中查询
yum list | grep httpd
yum list installed //查询已安装的软件
yum info httpd //查询软件信息
yum grouplist //查询组软件(已安装和未安装)
yum groupinfo "Compatibility Libraries"
yum search httpd //search可以从包名和包描述中查找带有关键字httpd的包
yum provides */vsftpd.conf //查找vsftpd.conf是由哪个包提供
yum provides vim //可以查找命令是由哪个包提供
4)卸载
yum -y remove httpd //如果安装时有安装其它的依赖包,卸载的时候不会卸载依赖包;
yum -y groupremove "Compatibility Libraries"
5)history:牛逼的玩意
yum history //查询执行过的yum命令
yum history info 4 //查询第4个id详细的yum命令信息
yum history undo 4 //如果第4个id执行过yum install httpd ,可以使用这个命令卸载掉依赖包