1背景
由于開發(fā)環(huán)境只有局域網(wǎng)颤芬,沒法使用網(wǎng)上的各種YUM源蔓姚,來(lái)回拷貝rpm包安裝麻煩,還得解決依賴問題纺裁。想著在CentOS7.2搭建個(gè)本地/局域網(wǎng)YUM源,方便自己跟同事安裝軟件。
2環(huán)境
[root@linuxidc.com ~]#cat/etc/RedHat-release
CentOS Linux release 7.2.1511(Core)
并且是Minimal Install欺缘。
3安裝
3.1本地YUM源
3.1.1 ISO源
準(zhǔn)備rpm包?
掛載CentOS-7-x86_64-Everything-1511.iso栋豫,把里面所有文件都拷貝到本地目錄/yum/yum-iso
[root@linuxidc.com ~]#mkdir/mnt/yum-iso
[root@linuxidc.com~]#mount/dev/cdrom /mnt/yum-iso/mount: /dev/sr0 iswrite-protected, mounting read-only
[root@linuxidc.com~]#mkdir/yum/[root@linuxidc.com~]#cp-a /mnt/yum-iso/ /yum/[root@linuxidc.com~]# ll /yum/total 4dr-xr-xr-x.8root root4096Dec102015yum-iso
[root@linuxidc.com~]# ll /yum/yum-iso/total 640-r--r--r--.1root root14Dec102015 CentOS_BuildTag
dr-xr-xr-x.3root root33Dec102015 EFI-r--r--r--.1root root215Dec102015 EULA-r--r--r--.1root root18009Dec102015 GPL
dr-xr-xr-x.3root root69Dec102015 images
dr-xr-xr-x.2root root4096Dec102015 isolinux
dr-xr-xr-x.2root root41Dec102015 LiveOS
dr-xr-xr-x.2root root483328Dec102015 Packages
dr-xr-xr-x.2root root4096Dec102015 repodata-r--r--r--.1root root1690Dec102015RPM-GPG-KEY-CentOS-7-r--r--r--.1root root1690Dec102015RPM-GPG-KEY-CentOS-Testing-7-r--r--r--.1root root2883Dec102015 TRANS.TBL
[root@linuxidc.com~]#
備份、移除其他repo
[root@linuxidc.com ~]# cd /etc/yum.repos.d/[root@linuxidc.comyum.repos.d]# ll-rw-r--r--.1root root1664Dec92015CentOS-Base.repo-rw-r--r--.1root root1309Dec92015CentOS-CR.repo-rw-r--r--.1root root649Dec92015CentOS-Debuginfo.repo-rw-r--r--.1root root290Dec92015CentOS-fasttrack.repo-rw-r--r--.1root root630Dec92015CentOS-Media.repo-rw-r--r--.1root root1331Dec92015CentOS-Sources.repo-rw-r--r--.1root root1952Dec92015CentOS-Vault.repo
[root@linuxidc.comyum.repos.d]#tarzcvf repo-bk.tar.gz CentOS-*CentOS-Base.repo
CentOS-CR.repo
CentOS-Debuginfo.repo
CentOS-fasttrack.repo
CentOS-Media.repo
CentOS-Sources.repo
CentOS-Vault.repo
[root@linuxidc.comyum.repos.d]#rm-f CentOS-Base.repo CentOS-CR.repo CentOS-Debuginfo.repo CentOS-fasttrack.repo CentOS-Sources.repo CentOS-Vault.repo
配置本地repo
[root@linuxidc.comyum.repos.d]#viCentOS-Media.repo
填入如下內(nèi)容
[c7-media]
name=CentOS-$releasever - Media
baseurl=file:///yum/yum-iso/gpgcheck=0enabled=1gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
注釋:配置repo路徑谚殊、關(guān)閉gbp校驗(yàn)丧鸯、啟用這個(gè)repo
制作cache
[root@linuxidc.comyum.repos.d]#yum clean all
Loaded plugins: fastestmirror
Cleaning repos: c7-media
Cleaning up everything
Cleaning up list of fastest mirrors
[root@linuxidc.comyum.repos.d]#yum makecache
Loaded plugins: fastestmirror
c7-media? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? |3.6kB00:00:00? ?
(1/4): c7-media/group_gz? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? |155kB00:00:00? ?
(2/4): c7-media/primary_db? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? |5.3MB00:00:00? ?
(3/4): c7-media/filelists_db? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? |6.2MB00:00:00? ?
(4/4): c7-media/other_db? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? |2.3MB00:00:00? ?
Determining fastest mirrors
Metadata Cache Created
[root@linuxidc.comyum.repos.d]#
這樣就可以使用yum安裝軟件啦
[root@linuxidc.comyum.repos.d]#yumgroupinstall"Development tools"Loaded plugins: fastestmirror
There is no installed groupsfile.
Maybe run: yumgroupsmark convert (seemanyum)
Loading mirror speeds from cached hostfile
Resolving Dependencies--> Running transaction check---> Package autoconf.noarch0:2.69-11.el7 will be installed--> Processing Dependency:perl>=5.006forpackage: autoconf-2.69-11.el7.noarch--> Processing Dependency: m4 >=1.4.14forpackage: autoconf-2.69-11.el7.noarch--> Processing Dependency:perl(warnings)forpackage: autoconf-2.69-11.el7.noarch
或者
[root@linuxidc.comyum.repos.d]#yuminstall tree
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Resolving Dependencies--> Running transaction check---> Package tree.x86_640:1.6.0-10.el7 will be installed--> Finished Dependency Resolution
3.1.2 自定義YUM源
[root@linuxidc.comyum.repos.d]#yum-yinstallcreaterepo
準(zhǔn)備rpm包
(需要自己確定依賴包)、目錄嫩絮。這里使用tree做演示丛肢。
[root@linuxidc.com ~]#mkdir-p /yum/yum-custom/packages
[root@linuxidc.com~]#cptree-1.6.0-10.el7.x86_64.rpm /yum/yum-custom/packages/
創(chuàng)建repo
[root@linuxidc.com ~]# createrepo -u -d? /yum/yum-custom/Spawning worker 0with1 pkgs
Spawning worker 1with0 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete
[root@linuxidc.com~]# ll /yum/yum-custom/total 4drwxr-xr-x.2root root41Dec2007:03 packages
drwxr-xr-x.2root root4096Dec2007:08 repodata
[root@linuxidc.com~]#
配置自定義repo
[root@linuxidc.com ~]#vi/etc/yum.repos.d/CentOS-Media.repo
填入如下內(nèi)容
[c7-media]
name=CentOS-$releasever - Media
baseurl=file:///yum/yum-custom/gpgcheck=0enabled=1gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
制作cache
[root@linuxidc.com ~]#yum clean all
Loaded plugins: fastestmirror
Cleaning repos: c7-media
Cleaning up everything
Cleaning up list of fastest mirrors
[root@linuxidc.com~]#
[root@linuxidc.com~]#yum makecache
Loaded plugins: fastestmirror
c7-media? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? |3.0kB00:00:00? ?
(1/3): c7-media/filelists_db? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? |880B00:00:00? ?
(2/3): c7-media/primary_db? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? |1.8kB00:00:00? ?
(3/3): c7-media/other_db? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? |1.3kB00:00:00? ?
Determining fastest mirrors
Metadata Cache Created
[root@linuxidc.com~]#
使用自定義repo
[root@linuxidc.com ~]#yuminstall tree
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Resolving Dependencies--> Running transaction check---> Package tree.x86_640:1.6.0-10.el7 will be installed--> Finished Dependency Resolution
3.2 局域網(wǎng)YUM源
局域網(wǎng)YUM源可以配成:本地YUM源?+?FTP服務(wù)器
這里使用自定義源yum-custom(見上面) + VSFTP演示。
下載vsftpd
[root@linuxidc.com ~]#yum-yinstallvsftpd
配置vsftpd
編輯vsftp.conf
[root@linuxidc.com ~]#vi/etc/vsftpd/vsftpd.conf
并增加匿名用戶root目錄(默認(rèn)已經(jīng)啟用匿名訪問)
anon_root=/yum/
注意目錄權(quán)限如下
[root@linuxidc.com ~]# ll -a /yum/total 8drwxr-xr-x.4root root37Dec2007:37 .
dr-xr-xr-x.18root root4096Dec2006:32 ..
drwxr-xr-x.4root root36Dec2007:08yum-custom
dr-xr-xr-x.8root root4096Dec102015yum-iso
?關(guān)閉selinux
臨時(shí)
[root@linuxidc.com ~]# setenforce0
或者絮记,永久:
編輯config
[root@linuxidc.com ~]#vi/etc/selinux/config
設(shè)置
SELINUX=disabled
重啟
[root@linuxidc.com ~]# reboot
啟用vsftp
[root@linuxidc.com ~]# systemctl start vsftpd
[root@linuxidc.com~]# systemctl enable vsftpd
Created symlink from /etc/systemd/system/multi-user.target.wants/vsftpd.service to /usr/lib/systemd/system/vsftpd.service.
[root@linuxidc.com~]#
局域網(wǎng)使用
局域網(wǎng)另外一臺(tái)機(jī)器min-client摔踱,
配置repo
編輯repo
[root@min-client ~]# vim /etc/yum.repos.d/CentOS-Media.repo
內(nèi)容如下
[c7-media]
name=CentOS-$releasever - Media
baseurl=ftp://192.168.118.133/yum-customgpgcheck=0enabled=1gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
其中192.168.118.133為上面vsftp服務(wù)器地址
啟用這個(gè)局域網(wǎng)的repo
[root@min-client ~]#yum clean all
Loaded plugins: fastestmirror
Cleaning repos: c7-media
Cleaning up everything
[root@min-client ~]#yum makecache
Loaded plugins: fastestmirror
c7-media? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? |3.0kB00:00(1/3): c7-media/filelists_db? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? |880B00:00(2/3): c7-media/other_db? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? |1.3kB00:00(3/3): c7-media/primary_db? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? |1.8kB00:00Determining fastest mirrors
Metadata Cache Created
[root@min-client ~]#
使用
[root@linuxidc.com ~]#yum-yinstall tree
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Resolving Dependencies--> Running transaction check---> Package tree.x86_640:1.6.0-10.el7 will be installed--> Finished Dependency Resolution
目前差不多這些就夠用了。以后有時(shí)間把163的YUM源爬下來(lái)怨愤,當(dāng)本地源用。