title: CentOS配置本地yum源
categories:
- [CentOS]
tags: - CentOS
top: 20
CentOS配置本地yum源
为了方便测试与开发,常常需要在虚拟机上安装各种开发环境,如果没有yum源,安装rpm需要解决各种依赖关系非常麻烦
环境
[root@master01 ~]# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)
1. 创建挂载目录
mkdir /mnt/yum
2.挂载OS文件
将iso文件上传至虚拟机中,也可以直接通过虚拟机挂载iso
[root@master01 /]# mount -t iso9660 -o loop /guqi/CentOS-6.5-x86_64-bin-DVD1.iso /mnt/yum
ls /mnt/yum
# CentOS_BuildTag EULA images Packages repodata RPM-GPG-KEY-CentOS-Debug-6 RPM-GPG-KEY-CentOS-Testing-6
# EFI GPL isolinux RELEASE-NOTES-en-US.html RPM-GPG-KEY-CentOS-6 RPM-GPG-KEY-CentOS-Security-6 TRANS.TBL
3. 修改yum配置文件
ls -l /etc/yum.repos.d/
# total 16
# -rw-r--r--. 1 root root 1926 Nov 27 2013 CentOS-Base.repo
# -rw-r--r--. 1 root root 638 Nov 27 2013 CentOS-Debuginfo.repo
# -rw-r--r--. 1 root root 630 Nov 27 2013 CentOS-Media.repo
# -rw-r--r--. 1 root root 3664 Nov 27 2013 CentOS-Vault.repo
将其他yum源方式禁用,将.repo文件备份,创建bak文件夹
mkdir /etc/yum.repos.d/bak
mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/bak
4. 配置本地yum源
cat >> /etc/yum.repos.d/CentOS-Media-local.repo <<EOF
[c6-media]
name=CentOS-$releasever - Media
baseurl=file:///mnt/yum/ #iso挂载目录
gpgcheck=1
enabled=1 #设置为1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
EOF
5. 清除原有的yum信息,生成yum元数据
[root@master01 /]# yum clean all
Loaded plugins: fastestmirror, security
Cleaning repos: c6-media
Cleaning up Everything
[root@master01 /]# yum makecache
6.将本地源给其他内网服务器使用
- (1).基于ftp方式配置本地yum发布源
为本机配置ftp服务器,将其发布供网络其它客户端作为yum源
yum安装或者rpm -ivh安装vsftpd
[root@master01 ~] # yum -y install vsftpd
关闭Seliunx
[root@master01 ~] # sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
[root@master01 ~] # setenforce 0
修改ftp配置文件
[root@master01 ~] # vi /etc/vsftpd/vsftpd.conf
anon_root=/mnt/yum
启动ftp设置开机自启
[root@master01 ~]# systemctl start vsftpd
[root@master01 ~]# systemctl enable vsftpd
测试ftp服务可用性
[root@master01 ~]# ftp localhost
# Trying ::1...
# Connected to localhost (::1).
# 220 (vsFTPd 3.0.2)
# Name (localhost:root): anonymous
# 331 Please specify the password.
# Password:
# 230 Login successful.
# Remote system type is UNIX.
# Using binary mode to transfer files.
ftp> ls
# 229 Entering Extended Passive Mode (|||41973|).
# 150 Here comes the directory listing.
# -r--r--r-- 1 0 0 14 Sep 14 09:06 CentOS_BuildTag
# dr-xr-xr-x 3 0 0 33 Sep 14 09:06 EFI ### Author : Leshami
# -r--r--r-- 1 0 0 215 Sep 14 09:06 EULA ### Blog : # # # http://blog.csdn.net/leshami
# -r--r--r-- 1 0 0 18009 Sep 14 09:06 GPL
# dr-xr-xr-x 2 0 0 41 Sep 14 09:06 LiveOS
# dr-xr-xr-x 2 0 0 200704 Sep 14 09:08 Packages
# -r--r--r-- 1 0 0 1690 Sep 14 09:08 RPM-GPG-KEY-CentOS-7
# -r--r--r-- 1 0 0 1690 Sep 14 09:08 RPM-GPG-KEY-CentOS-Testing-7
# -r--r--r-- 1 0 0 2883 Sep 14 09:08 TRANS.TBL
# dr-xr-xr-x 3 0 0 54 Sep 14 09:06 images
# dr-xr-xr-x 2 0 0 4096 Sep 14 09:06 isolinux
# dr-xr-xr-x 2 0 0 4096 Sep 14 09:08 repodata
# 226 Directory send OK.
配置防火墙或者关闭防火墙
# 配置防火墙
[root@master01 ~]# firewall-cmd --add-service=ftp --permanent
[root@master01 ~]# firewall-cmd --add-service=ftp
[root@master01 ~]# systemctl reload firewalld.service
# 关闭防火墙
[root@master01 ~]# systemctl stop firewalld
[root@master01 ~]# systemctl disable firewalld
- (2).基于http方式配置本地yum发布源
除了支持ftp方式外,也可以通过http方式将其发布供网络其它客户端作为yum源
安装httpd或者python搭建简单的文件共享服务
# 安装httpd
[root@master01 ~]# yum install httpd
[root@master01 ~]# systemctl enable httpd
[root@master01 ~]# systemctl start httpd
# python搭建简单的文件共享服务
cd /mnt/yum
# 80端口容易冲突,所以选用8001端口
nohup python -m SimpleHTTPServer 8001 &
配置防火墙或者关闭防火墙
# 配置防火墙
[root@master01 ~]# firewall-cmd --add-service=http --permanent
[root@master01 ~]# firewall-cmd --add-service=http
[root@master01 ~]# systemctl reload firewalld.service
# 关闭防火墙
[root@master01 ~]# systemctl stop firewalld
[root@master01 ~]# systemctl disable firewalld
将CentOS 光盘文件copy到/var/www/html/repo
此处使用了链接方式,将其链接到已经在本地磁盘的/mnt/yum
[root@master01 ~]# ln -sv /mnt/yum /var/www/html/repo
/var/www/html/repo -> /mnt/yum
[root@master01 ~]# ls /var/www/html/repo
# CentOS_BuildTag EULA images LiveOS repo RPM-GPG-KEY-CentOS-7 TRANS.TBL
# EFI GPL isolinux Packages repodata RPM-GPG-KEY-CentOS-Testing-7
通过浏览器校验,此时应该可以看到文件列表(此处略) http://192.168.1.1/repo
配置客户端repo文件
[root@centos7-web ~]# mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/bak/
[root@centos7-web ~]# yum-config-manager --add-repo=http://192.168.1.1/repo
# Loaded plugins: fastestmirror, langpacks
# adding repo from: http://192.168.1.1/repo
[192.168.1.1_repo]
name=added from: http://192.168.1.175/repo
baseurl=http://192.168.1.175/repo
enabled=1
[root@centos7-web ~]# yum clean all
# Loaded plugins: fastestmirror, langpacks
# Cleaning repos: 192.168.1.175_repo
# Cleaning up everything
# Cleaning up list of fastest mirrors
[root@centos7-web ~]# yum makecache
# Loaded plugins: fastestmirror, langpacks
# 192.168.1.1_repo | 3.6 kB 00:00:00
# (1/4): 192.168.1.1_repo/group_gz | 155 kB 00:00:00
# (2/4): 192.168.1.1_repo/primary_db | 2.8 MB 00:00:00
# (3/4): 192.168.1.1_repo/other_db | 1.2 MB 00:00:00
# (4/4): 192.168.1.1_repo/filelists_db | 2.9 MB 00:00:01
# Determining fastest mirrors
# Metadata Cache Created
[root@centos7-web ~]# yum repolist
# Loaded plugins: fastestmirror, langpacks
# Loading mirror speeds from cached hostfile
# repo id repo name status
# 192.168.1.1_repo added from: http://192.168.1.1/repo 3,723
# repolist: 3,723
7.本地源更新
将rpm包放入package,执行createrepo
createrepo --update /mnt/yum
标签:CentOS,--,master01,repo,yum,本地,root
From: https://www.cnblogs.com/warren6/p/16775452.html