1、centos6创建仓库
[root@centos6 app]#cd /etc/yum.repos.d/
[root@centos6 yum.repos.d]#ls
CentOS-Base.repo CentOS-fasttrack.repo CentOS-Vault.repo
CentOS-Debuginfo.repo CentOS-Media.repo
[root@centos6 yum.repos.d]#mkdir backup
[root@centos6 yum.repos.d]#ls
backup CentOS-Debuginfo.repo CentOS-Media.repo
CentOS-Base.repo CentOS-fasttrack.repo CentOS-Vault.repo
[root@centos6 yum.repos.d]#mv *.repo backup
[root@centos6 yum.repos.d]#ls
backup
[root@centos6 yum.repos.d]#vim base.repo
1 [centos6]
2 name=centos6 repo
3 baseurl=file:///misc/cd ---路径为repodata的父目录,三个///最后一个表示的是根
4 gpgcheck=0
[root@centos6 yum.repos.d]#yum repolist
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
centos6 | 4.0 kB 00:00 ...
centos6/primary_db | 4.7 MB 00:00 ...
repo id repo name
centos6 centos6 repo 6,706
repolist: 6,706
[root@centos6 yum.repos.d]#rpm -e tree
[root@centos6 yum.repos.d]#tree
-bash: /usr/bin/tree: No such file or directory
[root@centos6 yum.repos.d]#yum install tree
总结:创建仓库时要先进入/etc/yum.repos.d/ ,查看有没有其他以.repo结尾的文件,如果有要把他们删除,或者移动到一个新建的目录下,避免仓库之间的互相干扰;仓库的路径为repodata的父目录。
2、centos7创建仓库
[root@centos7 yum.repos.d]#cat base.repo
[centos7]
name=centos7.3
baseurl=http://172.16.0.1/centos/7/
gpgcheck=1
gpgkey=http://172.16.0.1/centos/7/RPM-GPG-KEY-CentOS-7 ---如果已经通过rpm--import导入了公钥,此行不要再写
enabled=0
[base]
name=base
baseurl=file:///misc/cd
gpgcheck=0
[epel]
name=epel for centos7
baseurl=http://172.16.0.1/fedora-epel/7/x86_64/
gpgcheck=0
enabled=0
总结:一个文件中可以创建多个仓库,用enabled=0可以禁用某个仓库,实验环境下最好使用本地光盘,速度比较稳定,生产中没有本地光盘,只能使用网络路径。
3、yum静默和自动回答yes
[root@centos7 test]#rpm -e tree ---用rpm卸载
[root@centos7 test]#yum -y -q install tree ---无法静默安装
Warning: RPMDB altered outside of yum.
[root@centos7 test]#rpm -e tree
[root@centos7 test]#yum -q -y install tree
Warning: RPMDB altered outside of yum.
[root@centos7 test]#yum remove tree--用yum卸载
yum -y -q install tree ---可以静默和自动回答yes安装
总结:用yum自动回答yes和静默安装可以用脚本中,-y和-q哪个在前面都可以,前提是这包之前是用yum卸载的或者之前就没有这个包