- - - 外網(wǎng)也可以用、也可以定時(shí)更新同步 - - -
由于內(nèi)網(wǎng)沒有互聯(lián)網(wǎng)絡(luò),沒法使用網(wǎng)上的各種YUM源,來回拷貝rpm包安裝麻煩,還得解決依賴問題。所以搭建個(gè)本地/局域網(wǎng)YUM源,方便自己跟同事安裝軟件。(我的系統(tǒng)為? centos 7.3)
一、根據(jù)實(shí)際情況,拿出一臺服務(wù)器作為yum倉庫。
1、關(guān)閉 防火墻、selinux防火墻
[root@129 ~]# yum -y install createrepo
(內(nèi)網(wǎng)安裝先在外網(wǎng)下載后,把createrepo包和依賴包拷貝到內(nèi)網(wǎng),< rpm -vi 包名稱 > 完成安裝)
2、準(zhǔn)備測試用的 rpm 包(自己確定依賴包)、倉庫目錄。這里用tree演示
[root@129 ~]# mkdir -pv /yum/yum-custom/packages
[root@129 ~]# cp tree-1.6.0-10.e17.x86_64.rpm /yum/yum-custom/packages
3、創(chuàng)建及自定義 repo
[root@129 ~]# createrepo -pdo /yum/yum-custom/ /yum/yum-custom/????????創(chuàng)建repo數(shù)據(jù)庫
Spawning worker 0 with 1 pkgs
Spawning worker 1 with 0 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete
[root@129 ~]# ll /yum/yum-custom
--total 4
? drwxr-xr-x. 2 root root? 41 Dec 20 07:03 packages
? drwxr-xr-x. 2 root root 4096 Dec 20 07:08 repodata--
清空或者備份出 /etc/yum.repos.d 下所有的源。
[root@129 ~]# vim /etc/yum.repos.d/CentOS-Media.repo
添加如下內(nèi)容:
[c7-media]
name=CentOS-$releasever - Media
baseurl=file:///yum/yum-custom/
gpgcheck=0
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
4、制作cache
[root@129 ~]# yum clean all
Loaded plugins: fastestmirror
Cleaning repos: c7-media
Cleaning up everything
Cleaning up list of fastest mirrors
[root@129 ~]# yum makecache
Loaded plugins: fastestmirror
c7-media? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? | 2.9 kB? 00:00:00
(1/3): c7-media/primary_db? ? ? ? ? ? ? ? ? ? ? | 1.8 kB? 00:00:00
(2/3): c7-media/filelists_db? ? ? ? ? ? ? ? ? ? ? ?|? 880 B? 00:00:00
(3/3): c7-media/other_db? ? ? ? ? ? ? ? ? ? ? ? ? | 1.3 kB? 00:00:00
Determining fastest mirrors
Metadata Cache Created
5、使用 repo
[root@129 ~]# yum -y install tree????????下載成功,測試完成
6、下載、配置vsftpd,本機(jī)作為整個(gè)局域網(wǎng)的源倉庫,供其他機(jī)器下載軟件
[root@129 ~]# yum -y install vsftpd
(內(nèi)網(wǎng)安裝先在外網(wǎng)下載后,把vsftpd包拷貝到內(nèi)網(wǎng),< rpm -vi 包名稱 > 完成安裝)
[root@129 ~]# vim /etc/vsftpd/vsftpd.conf
添加如下內(nèi)容:
anon_root=/yum/????????????????????增加匿名用戶root目錄(默認(rèn)已經(jīng)啟用匿名訪問)
[root@129 ~]# ll -a /yum/????????注意目錄權(quán)限如下
total 0
drwxr-xr-x? 3 root root? 24 Oct 12 11:09 .
dr-xr-xr-x. 18 root root 255 Oct 12 11:09 ..
drwxr-xr-x? 4 root root? 38 Oct 12 11:38????yum-custom
7、啟動 vsftp
[root@129 ~]# systemctl start vsftpd
[root@129 ~]# systemctl enable vsftpd
Created symlink from /etc/systemd/system/multi-user.target.wants/vsftpd.service to /usr/lib/systemd/system/vsftpd.service.
二、內(nèi)網(wǎng)其他服務(wù)器
1、清空或者備份出 /etc/yum.repos.d 下所有的源。
[root@135 ~]# vim /etc/yum.repos.d/CentOS-Media.repo
添加如下內(nèi)容:
[c7-media]
name=CentOS-$releasever - Media
baseurl=ftp://192.168.0.129/yum-custom????????# 192.168.0.129為上面vsftp服務(wù)器地址
gpgcheck=0
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
2、啟動內(nèi)網(wǎng)的 repo
[root@135 ~]# yum clean all
Loaded plugins: fastestmirror
Cleaning repos: c7-media
Cleaning up everything
Cleaning up list of fastest mirrors
[root@135 ~]# yum makecache
Loaded plugins: fastestmirror
c7-media? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? | 2.9 kB? 00:00:00
(1/3): c7-media/filelists_db? ? ? ? ? ? ? ? ? ? ?|? 880 B? 00:00:00
(2/3): c7-media/other_db? ? ? ? ? ? ? ? ? ? ? ? | 1.3 kB? 00:00:00
(3/3): c7-media/primary_db? ? ? ? ? ? ? ? ? ? | 1.8 kB? 00:00:00
Determining fastest mirrors
Metadata Cache Created
3、使用內(nèi)網(wǎng)源倉庫
[root@135 ~]# yum -y install tree????????下載成功,測試完成
三、從阿里服務(wù)器將rpm同步到本地
這一步是在外網(wǎng)操作,我用的阿里源,所以同步的是阿里所有的rpm包;也可以同步163或者其他源的(把自己機(jī)器上的源改為想同步的源就行)。
[root@kkk ~]# yum repolist????????查看阿里的可用倉庫,有啟用的表示已經(jīng)成功了
1、從阿里服務(wù)器將rpm同步到本地需要兩個(gè)rpm軟件:createrepo 和 yum-utils
[root@kkk ~]# yum -y install createrepo yum-utils
[root@kkk ~]# mkdir /yum? ? ? ? ? ? ? ? ? ? ? ? ? 創(chuàng)建rpm包存放目錄
[root@kkk ~]# reposync -r base -p /yum????將已經(jīng)配置好的阿里倉庫鏡像內(nèi)的rpm包拉到本地,base為本地已經(jīng)配置好的倉庫名,可以用yum repolist查看到
四、同步完之后把所有的 rpm 包拷貝到內(nèi)網(wǎng)源倉庫目錄
拷貝完之后,在內(nèi)網(wǎng)源倉庫那臺服務(wù)器上執(zhí)行
createrepo -pdo /yum/yum-custom/ /yum/yum-custom/????????????更新repo數(shù)據(jù)庫
局域網(wǎng)自建源倉庫? OK ~
五、如果是外網(wǎng),配置下定時(shí)更新
[root@kkk ~]# vim /cron/repository.sh????????????????編寫同步腳本
reposync -r base -p /mirrors/Packege -d????????????# 來刪除本地老舊
reposync -r base -p /mirrors/Packege
[root@kkk ~]# crontab -e????????????????添加定時(shí)任務(wù)
添加:
0 0 1 * * sh /yum/repository.sh????????# 每月1日0時(shí)更新yum倉庫