1.背景
這幾天一直在學(xué)習(xí)在CentOS7.0創(chuàng)建本地yum源和局域網(wǎng)yum源,準(zhǔn)備兩臺CentOS7.0虛擬機饺蔑,一個做服務(wù)器锌介,一個做客戶端;由于開發(fā)環(huán)境只有局域網(wǎng),沒法使用網(wǎng)上的各種yum源孔祸,來回拷貝rpm包安裝麻煩隆敢,還得解決依賴問題。
2.環(huán)境
[root@min-base ~]# 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@min-base ~]# mkdir /mnt/yum-iso
[root@min-base ~]# mount /dev/cdrom /mnt/yum-iso/mount: /dev/sr0 is write-protected, mounting read-only
[root@min-base ~]# mkdir /yum/
[root@min-base ~]# cp -a /mnt/yum-iso/ /yum/
[root@min-base ~]# ll /yum/total 4dr-xr-xr-x. 8 root root 4096 Dec 10 2015 yum-iso
[root@min-base ~]# ll /yum/yum-iso/total 640-r--r--r--. 1 root root 14 Dec 10 2015 CentOS_BuildTagdr-xr-xr-x. 3 root root 33 Dec 10 2015 EFI-r--r--r--. 1 root root 215 Dec 10 2015 EULA-r--r--r--. 1 root root 18009 Dec 10 2015 GPLdr-xr-xr-x. 3 root root 69 Dec 10 2015 imagesdr-xr-xr-x. 2 root root 4096 Dec 10 2015 isolinuxdr-xr-xr-x. 2 root root 41 Dec 10 2015 LiveOSdr-xr-xr-x. 2 root root 483328 Dec 10 2015 Packagesdr-xr-xr-x. 2 root root 4096 Dec 10 2015 repodata-r--r--r--. 1 root root 1690 Dec 10 2015 RPM-GPG-KEY-CentOS-7-r--r--r--. 1 root root 1690 Dec 10 2015 RPM-GPG-KEY-CentOS-Testing-7-r--r--r--. 1 root root 2883 Dec 10 2015 TRANS.TBL
[root@min-base ~]#
備份、移除其他repo
[root@min-base ~]# cd /etc/yum.repos.d/
[root@min-base yum.repos.d]# ll-rw-r--r--. 1 root root 1664 Dec 9 2015 CentOS-Base.repo-rw-r--r--. 1 root root 1309 Dec 9 2015 CentOS-CR.repo-rw-r--r--. 1 root root 649 Dec 9 2015 CentOS-Debuginfo.repo-rw-r--r--. 1 root root 290 Dec 9 2015 CentOS-fasttrack.repo-rw-r--r--. 1 root root 630 Dec 9 2015 CentOS-Media.repo-rw-r--r--. 1 root root 1331 Dec 9 2015 CentOS-Sources.repo-rw-r--r--. 1 root root 1952 Dec 9 2015 CentOS-Vault.repo
[root@min-base yum.repos.d]# tar zcvf repo-bk.tar.gz CentOS-*CentOS-Base.repoCentOS-CR.repoCentOS-Debuginfo.repoCentOS-fasttrack.repoCentOS-Media.repoCentOS-Sources.repoCentOS-Vault.repo
[root@min-base yum.repos.d]# rm -f CentOS-Base.repo CentOS-CR.repo CentOS-Debuginfo.repo CentOS-fasttrack.repo CentOS-Sources.repo CentOS-Vault.repo
配置本地repo
[root@min-base yum.repos.d]# vi CentOS-Media.repo
填入如下內(nèi)容
[c7-media]
name=CentOS-$releasever - Media
baseurl=file:///yum/yum-iso/
gpgcheck=0
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
注釋:配置repo路徑惶室、關(guān)閉gbp校驗温自、啟用這個repo
制作cache
[root@min-base yum.repos.d]# yum clean allLoaded plugins: fastestmirrorCleaning repos: c7-mediaCleaning up everythingCleaning up list of fastest mirrors
[root@min-base yum.repos.d]# yum makecacheLoaded plugins: fastestmirrorc7-media | 3.6 kB 00:00:00 (1/4): c7-media/group_gz | 155 kB 00:00:00 (2/4): c7-media/primary_db | 5.3 MB 00:00:00 (3/4): c7-media/filelists_db | 6.2 MB 00:00:00 (4/4): c7-media/other_db | 2.3 MB 00:00:00 Determining fastest mirrorsMetadata Cache Created
[root@min-base yum.repos.d]#
這樣就可以使用yum安裝軟件啦
[root@min-base yum.repos.d]# yum groupinstall "Development tools"Loaded plugins: fastestmirrorThere is no installed groups file.Maybe run: yum groups mark convert (see man yum)Loading mirror speeds from cached hostfileResolving Dependencies--> Running transaction check---> Package autoconf.noarch 0:2.69-11.el7 will be installed--> Processing Dependency: perl >= 5.006 for package: autoconf-2.69-11.el7.noarch--> Processing Dependency: m4 >= 1.4.14 for package: autoconf-2.69-11.el7.noarch--> Processing Dependency: perl(warnings) for package: autoconf-2.69-11.el7.noarch
或者
[root@min-base yum.repos.d]# yum install treeLoaded plugins: fastestmirrorLoading mirror speeds from cached hostfileResolving Dependencies--> Running transaction check---> Package tree.x86_64 0:1.6.0-10.el7 will be installed--> Finished Dependency Resolution
3.1.2 自定義YUM源
[root@min-base yum.repos.d]# yum -y install createrepo
準(zhǔn)備rpm包
(需要自己確定依賴包)、目錄拇涤。這里使用tree做演示捣作。
[root@min-base ~]# mkdir -p /yum/yum-custom/packages[root@min-base ~]# cp tree-1.6.0-10.el7.x86_64.rpm /yum/yum-custom/packages/
創(chuàng)建repo
[root@min-base ~]# createrepo -u -d /yum/yum-custom/Spawning worker 0 with 1 pkgsSpawning worker 1 with 0 pkgsWorkers FinishedSaving Primary metadataSaving file lists metadataSaving other metadataGenerating sqlite DBsSqlite DBs complete
[root@min-base ~]# ll /yum/yum-custom/total 4drwxr-xr-x. 2 root root 41 Dec 20 07:03 packagesdrwxr-xr-x. 2 root root 4096 Dec 20 07:08 repodata[root@min-base ~]#
配置自定義repo
[root@min-base ~]# vi /etc/yum.repos.d/CentOS-Media.repo
填入如下內(nèi)容
[c7-media]name=CentOS-$releasever - Mediabaseurl=file:///yum/yum-custom/gpgcheck=0enabled=1gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
制作cache
[root@min-base ~]# yum clean allLoaded plugins: fastestmirrorCleaning repos: c7-mediaCleaning up everythingCleaning up list of fastest mirrors
[root@min-base ~]# [root@min-base ~]# yum makecacheLoaded plugins: fastestmirrorc7-media | 3.0 kB 00:00:00 (1/3): c7-media/filelists_db | 880 B 00:00:00 (2/3): c7-media/primary_db | 1.8 kB 00:00:00 (3/3): c7-media/other_db | 1.3 kB 00:00:00 Determining fastest mirrorsMetadata Cache Created
[root@min-base ~]#
使用自定義repo
[root@min-base ~]# yum install treeLoaded plugins: fastestmirrorLoading mirror speeds from cached hostfileResolving Dependencies--> Running transaction check---> Package tree.x86_64 0: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@min-base ~]# yum -y install vsftpd
配置vsftpd
編輯vsftp.conf
[root@min-base ~]# vi /etc/vsftpd/vsftpd.conf
并增加匿名用戶root目錄(默認(rèn)已經(jīng)啟用匿名訪問)
anon_root=/yum/
注意目錄權(quán)限如下
[root@min-base ~]# ll -a /yum/total 8drwxr-xr-x. 4 root root 37 Dec 20 07:37 .dr-xr-xr-x. 18 root root 4096 Dec 20 06:32 ..drwxr-xr-x. 4 root root 36 Dec 20 07:08 yum-customdr-xr-xr-x. 8 root root 4096 Dec 10 2015 yum-iso
** 關(guān)閉selinux**
臨時
[root@min-base ~]# setenforce 0
或者鹅士,永久:
編輯config
[root@min-base ~]# vi /etc/selinux/config
設(shè)置
SELINUX=disabled
重啟
[root@min-base ~]# reboot
啟用vsftp
[root@min-base ~]# systemctl start vsftpd
[root@min-base ~]# systemctl enable vsftpdCreated symlink from /etc/systemd/system/multi-user.target.wants/vsftpd.service to /usr/lib/systemd/system/vsftpd.service.[root@min-base ~]#
局域網(wǎng)使用
局域網(wǎng)另外一臺機器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-custom
gpgcheck=0
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
其中192.168.118.133為上面vsftp服務(wù)器地址
啟用這個局域網(wǎng)的repo
[root@min-client ~]# yum clean allLoaded plugins: fastestmirrorCleaning repos: c7-mediaCleaning up everything
[root@min-client ~]# yum makecacheLoaded plugins: fastestmirrorc7-media | 3.0 kB 00:00(1/3): c7-media/filelists_db | 880 B 00:00(2/3): c7-media/other_db | 1.3 kB 00:00(3/3): c7-media/primary_db | 1.8 kB 00:00Determining fastest mirrorsMetadata Cache Created
[root@min-client ~]#
使用
[root@min-base ~]# yum -y install treeLoaded plugins: fastestmirrorLoading mirror speeds from cached hostfileResolving Dependencies--> Running transaction check---> Package tree.x86_64 0:1.6.0-10.el7 will be installed--> Finished Dependency Resolution