Create a local YUM source in CentOS 7

Source: Internet
Author: User

Create a local YUM source in CentOS 7

The "Local YUM source" in this article includes three types: one is to directly use the CentOS CD as the local yum source, the advantage is simple and convenient, the disadvantage is that the CD software package may be incomplete (centos 7 Everything is only 6.57 GB in total); the second is to synchronize the CentOS official source to the local (equivalent to creating a public image), and the advantage is the most reliable, the disadvantage is that the traffic is occupied by space fees; the third is to create a fully customized local source, and the advantage is the maximum flexibility. The disadvantage is that it is only used as a supplement to other sources.

1. Use the CentOS CD as the local yum Source

(1) Put the disc directly on the Physical Machine
(2) VMware Workstation Virtual Machine: Virtual Machine --> Removable device --> CD/DVD --> connection

[Html] view plaincopy
  1. Mkdir/mnt/cdrom # create a directory
  2. Mount/dev/cdrom/mnt/cdrom # mount
  3. Umount/mnt/cdrom # uninstall

If you don't want to put the CD on each disk, copy the CD file to the local hard disk.

[Html] view plaincopy
  1. Cp-avf/mnt/cdrom/yum #-a: This option retains links and file attributes, and Recursively copies directories.
2. Create a repo file [html] view plaincopy
  1. Cat>/etc/yum. repos. d/CentOS-Local.repo <-EOF
  2. [Local]
  3. Name = LocalYum
  4. Baseurl = file: // yum/
  5. Gpgcheck = 1
  6. Gpgkey = file: // etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
  7. Enabled = 1

Q: Why can't I install the createrepo software?

The role of createrepo is to create an index file (in the repodata folder), with the GPG-KEY available on the disc.

Ii. How to create a public image for CentOS

For details, see the official Chinese document:

Http://wiki.centos.org/zh/HowTos/CreatePublicMirrors

Provide a SHELL script, and then cron runs automatically ~~

Http://wangyan.org/blog/centos-local-yum-repo.html

The script is slightly modified and replaced with the image source of HKUST. Available image list see: http://www.centos.org/download/mirrors/

[Html] view plaincopy
  1. Localpath = "/mirrors/CentOS"
  2. Mirror = "mirrors.hustunique.com: centos"
  3. Rsync = "rsync-avzH -- delete"
  4. Verlist = "7"
  5. Baselist = "centosplusextrasfasttrackosupdates"
  6. Archlist = "x86_64"
  7. Forverin $ verlist
  8. Do
  9. Forbasein $ baselist
  10. Do
  11. Forarchin $ archlist
  12. Do
  13. Remote = $ mirror/$ ver/$ base/$ arch/
  14. Mkdir-pv $ localpath/$ ver/$ base/$ arch/
  15. $ Rsync $ remote $ localpath/$ ver/$ base/$ arch/
  16. Done
  17. Done
  18. Done
3. Create a fully customized local source

Put some RPM software packages that are commonly added to your favorites in a directory, and they will become a custom source. You can use YUM for management, with great flexibility.

Official Tutorial: How to setup your own package repository

1. Create a local yum repository [html] view plaincopy
  1. Mkdir-p/yum/local # There can be N-level Directories
  2. Cp... # copy the RPM package to the above directory
2. Create a repo file [html] view plaincopy
  1. Cat>/etc/yum. repos. d/CentOS-Local.repo <-EOF
  2. [Local]
  3. Name = LocalYum
  4. Baseurl = file: // yum/
  5. Gpgcheck = 1
  6. Gpgkey = file: // etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
  7. Enabled = 1
3. Install createrepo [html] view plaincopy
  1. Yuminstallcreaterepo # Use yum to install createrepo
  2. Rpm-ivhhttp: // developer.centos.org/centos/7/ OS /x86_64/packages/createrepo-0.9.9-23.el7.noarch.rpm
4. Create an index [html] view plaincopy
  1. Createrepo/yum
  2. Yummakecache # update Cache
4. Add a yum Source

[Html] view plaincopy
  1. [1] AddRPMforgeRepositoryforyumbecausethathasmanyusefulpackages.
  2. [Root @ dlp ~] #
  3. Wgethttp: // pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm
  4. [Root @ dlp ~] #
  5. Rpm-Uvhrpmforge-release-0.5.3-1.el6.rf.x86_64.rpm
  6. Preparing... ###################################### [100%] 1: rpmforge-release ##################################### # [100%]
  7. [Root @ dlp ~] #
  8. Sed-I-e "s/enabled = 1/enabled = 0/g"/etc/yum. repos. d/rpmforge. repo
  9. [2] AddrepositoryEPELthatisprovidedfromFedoraproject.
  10. [Root @ dlp ~] #
  11. Wgethttp: // dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
  12. [Root @ dlp ~] #
  13. Rpm-Uvhepel-release-6-8.noarch.rpm
  14. Preparing... ###################################### [100%] 1: epel-release ##################################### # [100%]
  15. [Root @ dlp ~] #
  16. Sed-I-e "s/enabled = 1/enabled = 0/g"/etc/yum. repos. d/epel. repo

V. Reference http://m.oschina.net/blog/88071
Http://jingyan.baidu.com/article/e9fb46e1aed8207521f7662c.html
Http://blog.chinaunix.net/uid-28283843-id-3930474.html
Http://www.ibm.com/developerworks/cn/linux/l-lpic1-v3-102-5/
Vi. Other supplements

1. Use YUM to find the Software Package
Command: yum search
2. List all installable software packages
Command: yum list
3. list all updatable software packages
Command: yum list updates
4. list all installed software packages
Command: yum list installed
5. list all software packages installed but not in Yum Repository
Command: yum list extras
6. List the specified software packages
Command: yum list 7. Use YUM to obtain package information
Command: yum info 8. list information about all software packages
Command: yum info
9. list information of all updatable software packages
Command: yum info updates
10. list information about all installed software packages
Command: yum info installed
11. list information about all software packages installed but not in Yum Repository
Command: yum info extras
12. List the files provided by the Software Package
Command: yum provides

5. Clear YUM Cache
Yum stores the downloaded software package and header in the cache, but does not automatically delete it. If we think they occupy disk space, we can use the yum clean command to clear them. More accurately, we use yum clean headers to clear the header and yum clean packages to clear the downloaded rpm package, yum clean all clear all
1. Clear the software packages under the cache directory (/var/cache/yum)
Command: yum clean packages

2. Clear headers under the cache directory (/var/cache/yum)

Command: yum clean headers

3. Clear the old headers under the cache directory (/var/cache/yum)

Command: yum clean oldheaders

4. Clear the software packages and old headers in the cache directory (/var/cache/yum ).

Command: yum clean, yum clean all (= yum clean packages; yum clean oldheaders)

(1) repodata is used as the software warehouse. There are four necessary files in the directory: filelists. xml. [gz], other. xml. [gz], primary. xml. [gz] And repomd. xml (md indicates metadata), the most important of which is repomd. xml file, because we use a CD or ISO file to create the local source often see the following similar errors: * c5-media:
File: // media/CentOS/repodata/repomd. xml: [Errno 5] OSError: [Errno 2] does not have that file or directory: '/media/CentOS/repodata/repomd. xml'
Trying other mirror.
File: // media/cdrecorder/repodata/repomd. xml: [Errno 5] OSError: [Errno 2] does not have that file or directory: '/media/cdrecorder/repodata/repomd. xml'
Trying other mirror.
File: // media/cdrom/repodata/repomd. xml: [Errno 5] OSError: [Errno 2] does not have that file or directory: '/media/cdrom/repodata/repomd. xml'
Trying other mirror.
Error: Cannot retrieve repository metadata (repomd. for repository: c5-media. the preceding errors in Please verify its path and try again indicate that the repodata directory or file cannot be found. There are usually three reasons for the error: first, the path problem; the second is that the repodate directory is not generated; the third is *. repo configuration file conflict (this requires special attention ). Since CentOS 5 (or rhel5), most of the system CDs or ISO files have helped us generate the repodata directory (but it is not excluded), while those earlier than 5.0 do not, we need to use createrepo to generate the corresponding repodata directory (software repository) based on the dependency of the rpm package. This directory is a very important directory with a fixed name, these four files are saved: filelists. xml. [gz], other. xml. [gz], primary. xml. [gz] And repomd. xml. [gz] (usually comps. xml file, as mentioned below ). For the above error example, we can see from the c5-media that the system is more than 5.0, the system disk is self-contained repodata directory, so it is obvious that the path or *. repo file problems, but it is not ruled out that there is no repodata directory. Is there a specific problem? Open the CD and check it. If it does not exist, it will generate it, as mentioned below. Now let's take a look at/etc/yum. repos. d/CentOS-Media.repo configuration file: [c5-media]
Name = CentOS-$ releasever-Media # name indicates the name. Its format indicates "operating system name and release version"-"base" indicates that this segment is used for base package information.
Baseurl = file: // media/CentOS/
File: // media/cdrom/
File: // media/cdrecorder/# "baseurl" indicates the link address yum searches for on the Internet. Here we need to explain
# "$ Basearch" indicates the folder location where the system's architecture format is "i386" and "repodata" stores the repomd. xml file.
The downloaded information and SHA verification value for updating .xml.gz are listed in the following code.
# Here, "repomd. xml" contains three files: other.xml.gz?#filelists.xml.gz?#primary.xml.gz"
# Obviously, "Other update package list", "Update file centralized list", and "Main update package list"
Gpgcheck = 1 # gpgcheck check, you need to specify the location of the GPG-RPM-KEY in the configuration file.
Enabled = 1
Gpgkey = file: // etc/pki/rpm-gpg/RPM-GPG-KEY-beta # the location of the GPG-RPM-KEY from baseurl specifies the locate location and error message: file: /// media/CentOS/repodata/repomd. xmlfile: // media/cdrom/repodata/repomd. xmlfile: // media/cdrecorder/repodata/repomd. xml shows that yum will try to find the repodata directory from the directory specified by baseurl. Its essence is to find repomd. xml file, since the repodata directory cannot be found, why repomd. what about xml files? Therefore, an error is reported, indicating that "directories and files cannot be found". The solution is very simple. For Versions later than 5.0, there is a repodate directory under the root directory of the CD or ISO file, centOS/
Images/
IsoLinux/
Repodata/
. Discinfo
. Treeinfo. You can set the correct mounting path for the disc. Note: If the disk is automatically mounted by the system, it is usually automatically mounted to the/media directory, and the path is incorrect. You can also copy the entire CentOS directory and use the creatarepo software repository. For/etc/yum. repos. d/CentOS-Media.repo content, can be mounted to any directory below mkdir-v/media/{CentOS, cdrom, cdrecorder} mount-t iso9660/dev/cdrom/media/CentOSmount-t iso9660/dev/cdrom/media/cdrommount-t iso9660/dev/cdrom/media/cdrecorder (select either) just fine, in this way, yum can search for the repodata directory. The CentOS directory stores the rpm file package, and the files in the repodata directory record the dependencies of all the packages in CentOS, file Location and other information. If the location specified by the baseurl is uncomfortable, you can change it to its location. You only need to find the repodata directory under the directory specified by the baseurl. At the same time, after the repodata directory is generated, as long as the directory location of the rpm package is unchanged (CentOS directory in the above example), repodata can be stored anywhere. For baseurls that specify other protocols, such as http: // ftp: //, the essence is to find the repodata directory at the location specified by baseurl, for example: baseurl = http://centos.ustc.edu.cn/centos/5/ OS /i386/RELEASE-NOTES-ro
RELEASE-NOTES-ro.html
RPM-GPG-KEY-CentOS-5
RPM-GPG-KEY-beta
Images/
Isolinux/
Repodata/its directory contains the repodata directory; Name
Parent Directory/
RPMS. lvn/
SRPMS. lvn/
SRPMS. lvn-testing/
Debug/
Repodata/
SDL_sound-1.0.1-0.lvn.1.4.i386.rpm
SDL_sound-devel-1.0.1-0.lvn.1.4.i386.rpm
A52dec-0.7.4-0.lvn.7.4.i386.rpm
A52dec-devel-0.7.4-0.lvn.7.4.i386.rpm above two repodata directories, one in the "Install rpm package directory" directory of the same level, and make a put in the same directory where the rpm package is installed, this indicates that the repodata can be generated anywhere. baseurl points to the location of the repodata directory. When a new source is added and the software is updated or installed using yum, download the text in the repodata directory and analyze it. Then you can know the detailed information and dependency of the software package, and install and update the software. It is very important to understand this, so I have pointed out multiple times that "a valid baseurl is characterized by the location indicated by baseurl IN THE repodata directory, and the directory named repomd. after understanding the xml file, you can download the software package as you like, and then create your own local source. For the yum localinstall command, it is said that you can solve the package dependency problem on your own, but the essence is to use the existing software warehouse to solve the package dependency, so there is no warehouse, and this command is useless...
CentOS/
Images/
Isolinux/
NOTES/
SRPMS/
. Discinfo
Centosdocs-man.css
GPL
RELEASE-NOTES-en
RELEASE-NOTES-en.html
RPM-GPG-KEY
RPM-GPG-KEY-centos4
RPM-GPG-KEY-CentOS-4
Yumgroups. xml note that the CentOS directory here is not a pure rpm file, but contains two subdirectories base and RPMS. All RPMS are packaged in the RPMS directory, and what is the base installed? As shown in :..
Comps. rpm
Comps. xml
Hdlist
Hdlist4
Hdstg2.img
Netstg2.img
Product. img
Stage2.img files also store important information such as the dependency between all rpm packages in RPMS, but they are mainly used for operating system installation. If you want to customize your own operating system installation disk, or release version, you need to generate these files. For details, refer to release? So an error is reported. At this time, it does not search for other local sources. The solution is: connect to the network, and enable/etc/yum. repos. d/The directory contains only the local source configuration file, and the third is to use the command yum-disablerepo = *-enablerepo = {local source ID, for example, c5-media} install {soft_names}-nogpgcheck may be a local ftp or http source, the problem should be resolved, but there is no specific practice, so there is no say. Finally, we will introduce the useful commands and options: 1. createrepo-update: Sometimes your software warehouse contains many software packages. Although only a small part of the packages have been changed, you do not have to re-generate metadata for each software package, this is a waste of time. This is why the re-update option was created. You run the createrepo command as before but added the-update option. for example: createrepo-update/srv/my/repo now createrepo only updates the items that have been changed, added, or deleted since the metadata was generated last time. 2. verifytree if you have just made a repo and you want to verify that everything in your repo is correct and can complete its functions, you can run the erifytree command to check all the repodata and software packages. Example: $ verifytree/home/skvidal/tmp/empty-repoverifytree/home/skvidal/tmp/empty-repo/Checking repodata: verifying repomd. xml with yumverifying filelists checksumverifying primary checksumverifying primary_db checksumverifying other_db checksumverifying other checksumverifying filelists_db checksumChecking groups (comps. xml): verifying comps. xml with yumcomps file missing or unparseable The following example shows how to create the local data source. I forgot to record the source information. Sorry. 1) first take the rhel-5-server-i386-dvd.iso as an example, before making a look at the directory structure of the rhel5 image file ,../
Cluster/
ClusterStorage/
Images/
Isolinux/
Server/
VT/
. Discinfo
. Treeinfo mainly includes the Cluster, ClusterStorage, Server, and VT directories. In addition to the rpm package files, the directory also contains a repodata Directory, which is equivalent to grouping the packages, therefore, when writing baseurl paths, you must write their paths. However, the software packages used in normal times are in the Server directory, and the software packages in other directories are rarely used. Note: In the repodata directory, in addition to the four basic files, the corresponding comps. xml group files are added. 2) Create the local source and use createrepo to generate the repodata directory. Use the optical drive as the source. In order to avoid problems such as incomplete software packages, slow downloading speed, and network faults that may occur when downloading software packages from the network, we strongly recommend that you use a local DVD/CD iso to create a yum repository, which is fast during installation and ensures smooth installation of all software packages. If you have a yum repository in the LAN, you can use it directly without repeating the steps below. The following operations are performed after you have installed the RHEL/CentOS system. 1. first install the createrepo tool from a CD or an existing YUM Repository: Shell command: # rpm-ivh createrepo-x.y.z.rpmcreaterepo command to generate some information required by the yum repository, this information is stored under the repodata/directory. You can open it and see what it has done. 2. use the ISO file to create a yum repository 2.1 DVD ISO2.1.1 if you are using a DVD disc, you can directly mount the disc and then create a yum Repository: Shell command: # mkdir/mnt/dvd/# mount/dev/cdrom/mnt/dvd/# cd/mnt # createrepo. 2.1.2 If you are using the official dvd iso, copy it to the system, mount it, and create a yum Repository: Shell command: # mkdir/mnt/dvd/# mount-o loop/root/rhel5.1-dvd. iso/mnt/dvd # cd/mnt # createrepo. 2.2 CD ISO2.2.1 if you are using multiple CD iso files, you must first copy them to the system, mount them, and then create a yum repository. You can create several directories with several ISO files and mount the corresponding ISO files to: Shell command: # mkdir-p/mnt/{1, 2, 3, 4, 5, 6} # mount-o loop rhel5.1-disc1.iso/mnt/1 # mount-o loop rhel5.1-disc2.iso/mnt/2 # mount-o loop rhel5.1-disc3.iso/mnt/3 # mount -o loop rhel5.1-disc4.iso/mnt/4 # mount-o loop rhel5.1-disc5.iso/mnt/5 create a yum Repository: shell Command: # cd/mnt/# createrepo. 3. definition file for creating a yum repository in the yum Repository:/etc/yum. repos. d/dvdiso. repo, and then add the following content: Shell command: [DVDISO] name = DVD I SObaseurl = file: // mnt/enabled = 1 gpgcheck = 04. to test the yum repository, we strongly recommend that you run the 'yum clean all' command to clear all information such as yum metadata and obtain the latest repository information again: Shell command: # yum clean all # yum list if you can see the software package name in the repository you just created in the output of the 'yum list' command, it is OK. Try again to install a software package to see if it is successful: Shell command: # yum install cyrus-sasl.i386 if it is an x86_64 platform, then change the i386 to x86_64: Shell command: # yum install cyrus-sasl.x86_64 if the installation is successful, indicates that the yum repository and RPM package are correct. 3) set up an ftp yum server. 1. Prepare for the operation. 1. Start REDHAT Linux and mount/dev/cdrom/mnt on the installation disc. 3. Install the FTP service. if you only use the YUM source on your local machine, you can omit this step. cd/mnt/Server rpm-ivh vsftpd * chkconfig vsftpd on service vsftpd start 4, install the createrepo Software Package rpm-ivh createrepo * 5, copy the files in the system disk, and set up YUM 1 in the system cp-R/mnt/Server/var/ftp/pub 2. generate dependency Createrepo-g/var/ftp/pub/Server/repodata/comps-rhel5-server-core.xml/var/ftp/pub/Server/This place should note that comps-rhel5-ser Ver-core.xml must not be manually generated, the default installation on the CD already has 2. after completing the preceding steps, an error message is displayed, "cocould not remove old metadata dir :. olddata "says there is a directory problem. Delete the directory rm-rf/var/ftp/pub/Server /. olddata 3. perform createrepo-g/var/ftp/pub/Server/repodata/comps-rhel5-server-core.xml/var/ftp/pub/Server/4.cd/etc/yum again. repos. d vim yum. repo (create a new warehouse file. The name can start at will and write the following content in the file) [base] name = base baseurl = ftp: // 192.168.0.6/pub/Server #192.168.0.6 is your YUM source address enabled = 1 # Whether to enable source gpgcheck = 1 # Whether to verify, do not gpgkey = file: /// etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release # verify the KEY. (optional) RHEL5.1 uses a CD as the yum source.
RHEL5.4 can directly use the disc as the yum source, while RHEL5.1 cannot directly use the source in the disc. Otherwise, urlopen error unknown url type: media may occur, which needs to be modified, note that the method provided here does not need to copy a large number of files from the CD. 1. attach the CD image to the/media/RHEL/directory.
[root@Blinux Desktop]#mkdir /media/RHEL
[Root @ Blinux Desktop] # mount/root/rhel5.1.iso/media/RHEL-o loop2. generate the library file
[root@Blinux Desktop]#mkdir /media/yum/
[root@Blinux Desktop]#rpm -ivh /media/RHEL/Server/createrepo-0.4.4-2.fc6.noarch.rpm
[root@Blinux Desktop]createrepo -o /media/yum/ -g /media/RHEL/Server/repodata/comps-rhel5-server-core.xml /media/RHEL/Server/
[root@Blinux Desktop]mount --bind /media/yum/repodate/ /media/RHEL/Server/repodate/
3. generate dependency [root @ Blinux Desktop] # vim/etc/yum. repos. d/rhel-debuginfo.repo modified to something similar to [rhel] name = Redbaseurl = file: // media/RHEL/Server/enabled = 1 gpgcheck = 0 gpgkey = file: /// etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release [root @ Blinux Desktop] # yum clean all; the local yum source under YUM makecacheRHEL5.1 is so OK. Note that a large number of files are not copied but mounted.


Additional:
1. yum configuration file (/etc/yum. conf) and repo file (/etc/yum. repos. d)

Http://www.centos.org/docs/5/html/5.1/Deployment_Guide/c1-yum.html

2. Special yum Parameters

-- Installroot = root specifies the root directory for Software Installation
-- Enablerepo = repoidglob temporarily enable a download Source
-- Disablerepo = repoidglob temporarily disables a download Source
-- Exclude = package: exclude a software package.
-- Noplugins temporarily disable all plug-ins
-- Disableplugin = plugin temporarily disables the specified plug-in.

3. Case 1: Disable a source

Why is the source banned?

"NOTE: If you are considering using third-party software libraries, you should think carefully about how to prevent" Updates "from these software libraries from being replaced by the core components of CentOS inadvertently. One of these methods defaults to disabled and enable them if necessary ", http://wiki.centos.org/zh/AdditionalResources/Repositories? Action = show & redirect = zh % 2 FRepositories

Edit/etc/yum. repos. d/example. repo
Enabled = 0

Or

Yum -- disablerepo = some-repository install some-package
Yum -- enablerepo = some-disabled-repository install some-package

YUM Remove Repo (Repository)-YUM Disable Repo (Repository), http://www.if-not-true-then-false.com/2010/yum-remove-repo-repository-yum-disable-repo-repository/

4. software library used by CentOS

Http://wiki.centos.org/zh/AdditionalResources/Repositories? Action = show & redirect = zh % 2 FRepositories

Well-known third-party software libraries: RPMforge, ELRepo, ATrpms, EPEL, and RPMfusion


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.