(一)简述
公司通过新进了一批服务器,通过VMware的Vsphere企业级的虚拟化解决方案创建了一批虚拟机,只供内网访问,所有的虚拟机无法上外网,所以造成了原先的yum源通过外网的方式安装软件包而无法安装,所以为了日常的软件包的安装,只能在内网创建新的yum源来进行安装。
环境介绍:
名称 | IP地址 | 功能 |
yum源服务端 | 172.22.11.108 | yum源的服务端 |
yum客户端(使用者) | 172.22.11.103 | yum源的使用者 |
(二)yum源服务端的配置
首先查看一下服务端的yum的相关信息
- [root@GVPA02-011108cdrom]#rpm-qa|grepyum
- yum-plugin-security-1.1.30-14.el6.noarch
- yum-plugin-fastestmirror-1.1.30-14.el6.noarch
- yum-Metadata-parser-1.1.2-16.el6.x86_64
- yum-3.2.29-40.el6.centos.noarch
- yum-utils-1.1.30-14.el6.noarch
2,安装createrepo,repo下的xml生成工具
- [root@GVPA02-011108cdrom]#yuminstall-ycreaterepo
3,制作yum源
3.1,随意创建一个文件夹作为yum的仓库名称,用来存放RPM包
- [root@GVPA02-011108cdrom]#mkdir/yumrepo
3.2,挂载光盘并把光盘里边RPM包都拷到/yumrepo文件夹里
- [root@GVPA02-011108cdrom]#mount/dev/cdrom/mnt
- mount:blockdevice/dev/sr0iswrite-protected,mountingread-only
- [root@GVPA02-011108cdrom]#cp-r/mnt/
- CentOS_BuildTagGPLRELEASE-NOTES-en-US.htmlRPM-GPG-KEY-CentOS-Security-6
- .discinfoimages/repodata/RPM-GPG-KEY-CentOS-Testing-6
- EFI/isolinux/RPM-GPG-KEY-CentOS-6TRANS.TBL
- EULAPackages/RPM-GPG-KEY-CentOS-Debug-6.treeinfo
- [root@GVPA02-011108cdrom]#cp-r/mnt/Packages/*/yumrepo/
3.3把密钥也拷贝到/yumrepo文件夹里
- [root@GVPA02-011108cdrom]#cp/etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6/yumrepo/
4,执行命令生成repodata,创建主目录文件索引。-v参数后边跟你的RPM包的文件夹。
- [root@GVPA02-011108cdrom]#createrepo-v/yumrepo
- Worker0:readingkernel-devel-2.6.32-431.el6.x86_64.rpm
- Worker0:readingsamyak-gujarati-fonts-1.2.1-9.el6.noarch.rpm
- Worker0:readingsrptools-0.0.4-15.el6.x86_64.rpm
- Worker0:readingkdenetwork-4.3.4-11.el6_0.1.x86_64.rpm
- WorkersFinished
- Gatheringworkerresults
- SavingPrimaryMetadata
- SavingfilelistsMetadata
- SavingotherMetadata
- GeneratingsqliteDBs
- Startingotherdbcreation:WedNov118:53:222017
- Endingotherdbcreation:WedNov118:53:232017
- Startingfilelistsdbcreation:WedNov118:53:232017
- Endingfilelistsdbcreation:WedNov118:53:282017
- Startingprimarydbcreation:WedNov118:53:282017
- Endingprimarydbcreation:WedNov118:53:312017
- sqliteDBscomplete
5,制作本地yum源文件,要以.repo为结尾的。配置好目前还不能用,要用httpd来代理出来
- [root@GVPA02-011108yumrepo]#vim/etc/yum.repos.d/localyum.repo
- [base]
- name=localyum
- baseurl=http://172.22.11.108
- gpgcheck=0
- gpgkey=file:///yumrepo/RPM-GPG-KEY-CentOS-6
6,基于http的yum源相关配置
6.1,安装apache软件
- [root@GVPA02-011108yumrepo]#yuminstallhttpd-y
- Loadedplugins:fastestmirror,security
- Loadingmirrorspeedsfromcachedhostfile
- SettingupInstallProcess
- ResolvingDependencies
- -->Runningtransactioncheck
- --->Packagehttpd.x86_640:2.2.15-29.el6.centoswillbeinstalled
- -->FinishedDependencyResolution
- DependenciesResolved
- ==========================================================================================================================
- PackageArchVersionRepositorySize
- ==========================================================================================================================
- Installing:
- httpdx86_642.2.15-29.el6.centosbase821k
- TransactionSummary
- ==========================================================================================================================
- Install1Package(s)
- Totaldownloadsize:821k
- Installedsize:2.9M
- DownloadingPackages:
- Runningrpm_check_debug
- RunningTransactionTest
- TransactionTestSucceeded
- RunningTransaction
- Installing:httpd-2.2.15-29.el6.centos.x86_641/1
- Verifying:httpd-2.2.15-29.el6.centos.x86_641/1
- Installed:
- httpd.x86_640:2.2.15-29.el6.centos
- Complete!
6.2,修改httpd.conf配置文件的DocumentRoot 和<Directory "/yumrepo">两个配置
- [root@GVPA02-011108yumrepo]#vim/etc/httpd/conf/httpd.conf
- #DocumentRoot:Thedirectoryoutofwhichyouwillserveyour
- #documents.Bydefault,allrequestsaretakenfromthisdirectory,but
- #symboliclinksandaliasesmaybeusedtopointtootherlocations.
- #
- DocumentRoot"/yumrepo"
- <Directory"/yumrepo">
- #PossiblevaluesfortheOptionsdirectiveare"None","All",#oranycombinationof:
- #IndexesIncludesFollowSymLinksSymLinksifOwnerMatchExecCGIMultiViews
- #
- #Notethat"MultiViews"mustbenamed*explicitly*---"OptionsAll"
- #doesn'tgiveittoyou.
- #
- #TheOptionsdirectiveisbothcomplicatedandimportant.Pleasesee
- #http://httpd.apache.org/docs/2.2/mod/core.html#options
- #formoreinformation.
- #
- OptionsIndexesFollowSymLinks
- #
- #AllowOverridecontrolswhatdirectivesmaybeplacedin.htaccessfiles.
- #Itcanbe"All","None",oranycombinationofthekeywords:
- #OptionsFileInfoAuthConfigLimit
- #
- AllowOverrideNone
- #
- #Controlswhocangetstufffromthisserver.
- #
- Orderallow,deny
- Allowfromall
- </Directory>
6.3,删除欢迎页面welcome.conf,并给/yumrepo赴权限
- [root@GVPA02-011108yumrepo]#rm/etc/httpd/conf.d/welcome.conf
- rm:removeregularfile`/etc/httpd/conf.d/welcome.conf'?y
6.4,关闭selinux并重启下httpd服务
访问界面如下即可:
7,如果yum包需要更新的话,可以直接在阿里云或163上进行更新,并执行如下命令
- [root@GVPA02-011108conf]#wget-np-t1-nH�Ccut-dirs=1-r-c-L�Cexclude-directories=repodata�Caccept=rpm,zip,gz,xmlhttp://mirrors.163.com/centos/6.5/os/x86_64/Packages/-P/yumrepo###下载最新的rpm包
- [root@GVPA02-011108conf]#createrepo--update/yumrepo####更新yum源
- ###客户端只需要yumcleanall和yummakecache即可就能直接使用了
(三)yum客户端配置
1,在yum客户端172.22.11.104上将默认 的yum源关闭,并设置epel.repo将enables 为0
- [root@SIPA01-011104yum.repos.d]#vimepel.repo
- [epel]
- name=ExtraPackagesforEnterpriseLinux6-$basearch
- #baseurl=http://download.fedoraproject.org/pub/epel/6/$basearch
- mirrorlist=https://mirrors.fedoraproject.org/Metalink?repo=epel-6&arch=$basearch
- failovermethod=priority
- enabled=0
- gpgcheck=1
- gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
2,创建自己的localyum.repo文件
- [root@SIPA01-011104yum.repos.d]#vimlocalyum.repo
- [base]
- name=localyum
- baseurl=http://172.22.11.108
- gpgcheck=0
- gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
3,清除和加载rpm包
- [root@SIPA01-011104yum.repos.d]#yumcleanall
- Loadedplugins:fastestmirror,security
- Cleaningrepos:base
- CleaningupEverything
- Cleaninguplistoffastestmirrors
- [root@SIPA01-011104yum.repos.d]#yummakecache
- Loadedplugins:fastestmirror,security
- Determiningfastestmirrors
- base|2.9kB00:00
- base/filelists_db|4.1MB00:00
- base/primary_db|3.3MB00:00
- base/other_db|1.8MB00:00
4,客户端执行完成,就可以直接使用yum install命令了。