搭建本地yum源和局域網yum源linux
因爲不少客戶環境是專網,不容許連網,沒法使用網上的各類yum源,來回拷貝rpm包安裝麻煩,還得解決依賴問題。因此想着搭建個本地/局域網YUM源,方便安裝軟件。sql
環境:第一臺VM IP:192.168.10.81centos
第二臺VM IP:192.168.10.82緩存
虛擬機掛載鏡像包CentOS-7-x86_64-Everything-1511.iso 開機啓動ide
掛載鏡像:url
[root@centos7-81 ~]# mount /dev/sr0 /mnt/centos7
mount: /dev/sr0 is write-protected, mounting read-onlyspa
[root@centos7-81 ~]# mkdir -p /yum/yum-iso #新建本地路徑/yum/yum-isosqlite
把掛載的鏡像裏面全部文件都拷貝到本地目錄/yum/yum-isoblog
[root@centos7-81 ~]# cp -r /mnt/* /yum/yum-iso/
[root@centos7-81 ~]# cd /etc/yum.repos.d/
[root@centos7-81 yum.repos.d]# tar czvf 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@centos7-81 yum.repos.d]# rm -rf *.repo
[root@centos7-81 yum.repos.d]# vi CentOS-Media.repo
[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路徑、關閉gbp校驗、啓用這個repo
[root@centos7-81 yum.repos.d]# yum clean all
Loaded plugins: fastestmirror
Cleaning repos: c7-media
Cleaning up everything
Cleaning up list of fastest mirrors
[root@centos7-81 yum.repos.d]# yum makecache
Loaded plugins: fastestmirror
c7-media | 3.6 kB 00:00:00
(1/4): c7-media/group_gz | 3.5 kB 00:00:00
(2/4): c7-media/primary_db | 679 kB 00:00:00
(3/4): c7-media/other_db | 174 kB 00:00:00
(4/4): c7-media/filelists_db | 258 kB 00:00:00
Determining fastest mirrors
Metadata Cache Created
[root@centos7-81 yum.repos.d]#
這樣就可使用yum安裝軟件了
[root@centos7-81 ~]# yum install -y tree
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package tree.x86_64 0:1.6.0-10.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
==============================================================================================================================
Package Arch Version Repository Size
==============================================================================================================================
Installing:
tree x86_64 1.6.0-10.el7 c7-media 46 k
Transaction Summary
==============================================================================================================================
Install 1 Package
Total download size: 46 k
Installed size: 87 k
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
Installing : tree-1.6.0-10.el7.x86_64 1/1
Verifying : tree-1.6.0-10.el7.x86_64 1/1
Installed:
tree.x86_64 0:1.6.0-10.el7
Complete!
[root@centos7-81 ~]#
[root@centos7-81 ~]# yum install createrepo -y
準備RPM包
本身肯定rpm包,目錄,這裏使用tree作演示
[root@centos7-81 ~]# mkdir -p /yum/yum-custom/packages
[root@centos7-81 ~]# cp /yum/yum-iso/Packages/tree-1.6.0-10.el7.x86_64.rpm /yum/yum-custom/packages/
[root@centos7-81 ~]# createrepo -u -d /yum/yum-custom/
Spawning worker 0 with 1 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete
[root@centos7-81 ~]# ll /yum/yum-custom/
total 4
drwxr-xr-x 2 root root 42 Oct 20 23:46 packages
drwxr-xr-x 2 root root 4096 Oct 20 23:46 repodata
配置自定義repo
[root@centos7-81 ~]# vi /etc/yum.repos.d/CentOS-Media.repo
[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
將repo文件改成
[root@centos7-81 ~]# cat /etc/yum.repos.d/CentOS-Media.repo
[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
從新生成緩存
[root@centos7-81 ~]# yum clean all
[root@centos7-81 ~]# yum makecache
安裝vsftp
[root@centos7-81 ~]# yum install vsftpd -y
關閉selinux和防火牆
[root@centos7-81 ~]# getenforce
Disabled
[root@centos7-81 ~]# cat /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three two values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
[root@centos7-81 ~]# systemctl stop firewalld
[root@centos7-81 ~]# systemctl disable firewalld
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
Removed symlink /etc/systemd/system/basic.target.wants/firewalld.service.
修改vsftp配置文件
[root@centos7-81 ~]# vi /etc/vsftpd/vsftpd.conf
在最末尾加上
anon_root=/yum/yum-custom/
啓動vsftp並設置開機啓動
[root@centos7-81 ~]# systemctl start vsftpd
[root@centos7-81 ~]# systemctl enable vsftpd
本地電腦訪問ftp://192.168.10.81
關鍵步驟:
生成repodata目錄,自動建立索引信息
[root@centos7-81 yum]# createrepo -pdo /yum/yum-custom/ /yum/yum-custom/
不然安裝tree的時候會出現報錯:
Error downloading packages:
tree-1.6.0-10.el7.x86_64: failed to retrieve packages/tree-1.6.0-10.el7.x86_64.rpm from c7-media
error was [Errno 2] Local file does not exist: /etc/yum.repos.d/-d/packages/tree-1.6.0-10.el7.x86_64.rpm
[root@centos7-82 yum.repos.d]# yum clean all
[root@centos7-82 yum.repos.d]# yun makecache
在另外一臺VM上設置repo文件
[root@centos7-82 ~]# cd /etc/yum.repos.d/
[root@centos7-82 yum.repos.d]# rm -rf *
從第一臺VM上將repo文件傳到第二臺VM上
[root@centos7-81 ~]# scp /etc/yum.repos.d/CentOS-Media.repo root@192.168.10.82:/etc/yum.repos.d/
The authenticity of host '192.168.10.82 (192.168.10.82)' can't be established.
ECDSA key fingerprint is 32:c1:45:16:b2:a8:b2:25:22:58:02:11:a2:a3:54:90.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.10.82' (ECDSA) to the list of known hosts.
root@192.168.10.82's password:
CentOS-Media.repo 100% 143 0.1KB/s 00:00
[root@centos7-81 ~]#
在第二臺VM上修改repo文件
[c7-media]
name=CentOS-$releasever-Media
#baseurl=file:///yum/yum-iso/
baseurl=ftp://192.168.10.81
gpgcheck=0
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
[root@centos7-82 yum.repos.d]# yum install -y tree
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package tree.x86_64 0:1.6.0-10.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
==============================================================================================================================
Package Arch Version Repository Size
==============================================================================================================================
Installing:
tree x86_64 1.6.0-10.el7 c7-media 46 k
Transaction Summary
==============================================================================================================================
Install 1 Package
Total download size: 46 k
Installed size: 87 k
Downloading packages:
tree-1.6.0-10.el7.x86_64.rpm | 46 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : tree-1.6.0-10.el7.x86_64 1/1
Verifying : tree-1.6.0-10.el7.x86_64 1/1
Installed:
tree.x86_64 0:1.6.0-10.el7
Complete!
就可使用了