#### yum配置解析
影响yum使用的主要文件
基本设置:/etc/yum.conf
仓库配置:/etc/yum.repos.d/*.repo #大部分情况使用修改此配置即可,注意此目录下配置文件有其中一个配置错误会导致其他yum库不可用
日志文件:/var/log/yum.log
yum仓分类
本地yum仓:file://...
ftp的yum仓:ftp://...
http的yum仓:http://
yum仓库配置文件*.repo配置内容
[源名称] #自定义名称,具有唯一性
name= #本软件源的描述字串
baseurl= #指定yum服务端的URL地址
enabled=1 #是否启用此频道,1代表启用,0不启用
gpgcheck=0 #是否验证待安装的rpm包红帽签名认证,0不检验,1校验
gpgkey #用于rpm包验证的密钥文件
配置示例
[root@hl yum.repos.d]# cat test.repo
[test]
name=test
enabled=1 #是否启用,1启用
baseurl=file:///dvd #此处将光驱镜像挂载到了/dvd路径下,为本地yum仓
gpgcheck=0 #不作红帽签名校验,则密钥文件配置项gpgkey可省略
```
#### yum使用
| 选项 | 说明 | 示例 |
| :-------------------: | :----------------------------------: | :----------------: |
| yum install 软件名 | 安装指定软件包 | yum install gcc |
| yum clean all | 清空所有缓存 | |
| yum list | 再次查询时更新 | |
| yum repolist | 生成缓存并读取当前yum仓存在多少rpm包 | |
| yum -y install 软件名 | 安装指定软件包,自动确认安装 | yum -y install gcc |
| yum remove 软件名 | 卸载软件包 | yum remove gcc |
| yum makecache | 生成缓存 | |
| yum search 软件名 | 列出与...有关的软件包 | yum search firefox |
| yum info 软件名 | 查看软件相关信息 | yum info vsftpd |
| yum -qc 软件名 | 查看软件相关配置文件 | yum -qc vsftpd |
#### 源码编译安装
##### 主要优点

```
例:
[root@svr7 other]# yum -y install gcc make 提前安装需要的软件包gcc、make
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
软件包 gcc-4.8.5-28.el7.x86_64 已安装并且是最新版本
软件包 1:make-3.82-23.el7.x86_64 已安装并且是最新版本
无须任何处理
```
##### 基本实现过程

```
[root@svr7 tools]# ls
inotify-tools-3.13 inotify-tools-3.13.tar.gz other
[root@svr7 tools]#
[root@svr7 tools]# cd inotify-tools-3.13/#进入解压之后文件夹
[root@svr7 inotify-tools-3.13]# ls
aclocal.m4 ChangeLog config.h.in configure COPYING INSTALL libinotifytools Makefile.am man NEWS src
AUTHORS config.guess config.sub configure.ac depcomp install-sh ltmain.sh Makefile.in missing README
[root@svr7 inotify-tools-3.13]# ./configure -- prefix=/opt/myRpm #自定义安装路径为/opt/myRpm
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make sets $(MAKE)... (cached) yes
checking for gcc... gcc
[root@svr7 inotify-tools-3.13]# make #编译
make all-recursive
make[1]: 进入目录“/tools/inotify-tools-3.13”
Making all in libinotifytools
make[2]: 进入目录“/tools/inotify-tools-3.13/libinotifytools”
make[3]: 进入目录“/tools/inotify-tools-3.13”
make[3]: 离开目录“/tools/inotify-tools-3.13”
Making all in src
......
[root@svr7 inotify-tools-3.13]# make install #编译安装
Making install in libinotifytools
make[1]: 进入目录“/tools/inotify-tools-3.13/libinotifytools”
make[2]: 进入目录“/tools/inotify-tools-3.13”
make[2]: 离开目录“/tools/inotify-tools-3.13”
Making install in src
......
[root@svr7 inotify-tools-3.13]# ls -l /opt/myRpm/ #查看安装完之后的内容
总用量 0
drwxr-xr-x 2 root root 45 5月 23 11:35 bin
drwxr-xr-x 3 root root 26 5月 23 11:35 include
drwxr-xr-x 2 root root 143 5月 23 11:35 lib
drwxr-xr-x 4 root root 28 5月 23 11:35 share
```
#### 自定义本地yum仓
```
前提:在路径下有自己的rpm包,进入包所在路径,createrepo 生成repodata数据文件,yum配置文件baseurl配置repodata所在路径
例:
[root@svr7 tools]# cd other/
[root@svr7 other]# ls
boxes-1.1.1-4.el7.x86_64.rpm ntfs-3g-2014.2.15-6.el6.x86_64.rpm sl-5.02-1.el7.x86_64.rpm
cmatrix-1.2a-1.i386.rpm oneko-1.2-19.fc24.x86_64.rpm
[root@svr7 other]# pwd
/tools/other
[root@svr7 other]# createrepo /tools/
Spawning worker 0 with 5 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete
[root@svr7 other]# vim /etc/yum.repos.d/test.repo 修改配置文件增加myYum相关配置
[root@svr7 other]# cat /etc/yum.repos.d/test.repo
[test]
name=test
enabled=1
baseurl=file:///var/ftp/Centos7
gpgcheck=0
[myYum]
name=myYum
enabled=1
baseurl=file:///tools
gpgcheck=0
[root@svr7 other]# yum clean all
已加载插件:fastestmirror, langpacks
正在清理软件源: myYum test
Cleaning up everything
Maybe you want: rm -rf /var/cache/yum, to also free up space taken by orphaned data from disabled or removed repos
Cleaning up list of fastest mirrors
[root@svr7 other]# yum repolist
已加载插件:fastestmirror, langpacks
Determining fastest mirrors
myYum | 2.9 kB 00:00:00
test | 3.6 kB 00:00:00
(1/3): myYum/primary_db | 4.8 kB 00:00:00
(2/3): test/group_gz | 166 kB 00:00:01
(3/3): test/primary_db | 5.9 MB 00:00:01
源标识 源名称 状态
myYum myYum 5
test test 9,911
repolist: 9,916 #比9911多了5个包
```



