centos7使用镜像作为本地yum源

搭建本地yum源

  1. 配置网络
##配置网络命令,可使用Tab键辅助
nmcli connection modify "ens33" ipv4.method manual ipv4.addresses "192.168.131.161/24" ipv4.gateway "192.168.131.2" ipv4.dns "114.114.114.114" connection.autoconnect yes

##关闭网络并重新启动生效
nmcli con down  ens33
nmcli con up  ens33

##验证网络是否ping通
[root@localhost ~]# ping www.baidu.com
PING www.a.shifen.com (36.152.44.95) 56(84) bytes of data.
64 bytes from 36.152.44.95 (36.152.44.95): icmp_seq=1 ttl=128 time=35.8 ms
64 bytes from 36.152.44.95 (36.152.44.95): icmp_seq=2 ttl=128 time=35.6 ms
^C
--- www.a.shifen.com ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1004ms
rtt min/avg/max/mdev = 35.627/35.727/35.827/0.100 ms

  1. 关闭防火墙及开机自启
systemctl stop firewalld.service
systemctl disable firewalld.service
  1. 关闭SELinux
##临时关闭
setenforce 0

##开机关闭,需要重启才能生效
sed -i '/SELINUX/{s/permissive/disabled/}' /etc/selinux/config 
或	vim /etc/selinux/config		
		SELINUX=disabled

  1. 挂载镜像
mount /dev/sr0 /mnt/	#临时挂载

vim /etc/fstab 	##开机自启挂载;进入配置文件,并在最后一行添加下面的命令
/dev/cdrom /mnt iso9660 defaults 0 0

  1. 配置本地yum
mkdir /tmp/repo							#创建存放原先的repo文件目录
mv /etc/yum.repos.d/CentOS-* /tmp/repo/	#把原先的repo文件全部移到/tmp/repo/下
vim /etc/yum.repos.d/centos7.repo		#创建本地repo文件
	[centos]
	name=centos
	baseurl=file:///mnt
	enabled=1
	gpgcheck=0
  1. 检验本地yum源是否成功
[root@localhost ~]# yum clean all;yum repolist 
已加载插件:fastestmirror, langpacks
Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
正在清理软件源: centos
Cleaning up list of fastest mirrors
已加载插件:fastestmirror, langpacks
Determining fastest mirrors
centos                                                 | 3.6 kB     00:00     
(1/2): centos/group_gz                                   | 165 kB   00:00     
(2/2): centos/primary_db                                 | 3.2 MB   00:00     
源标识                              源名称                               状态
centos                              centos                               4,067
repolist: 4,067

猜你喜欢

转载自blog.csdn.net/weixin_46329906/article/details/112134415