拉不拉稀肚拉稀 发表于 2024-9-6 14:53:22

搭建本地yum源

一、环境预备

1.预备2-3台虚拟机,一台为服务端(安装yum源),别的的为客户端(测试yum源安装结果),最好是同网段的。
IP所在角色备注192.168.116.5服务端将完整镜像上传到这台机器192.168.116.15客户端192.168.116.25客户端 2.预备镜像文件,这里以CentOS-7-x86_64-2009,当然最好是利用CentOS-7-x86_64-Everything-2207-02.iso(这是完整版,包含了全部软件组件,当然体积也巨大,高达9.58G。对完整版安装盘的软件进行补充,集成全部软件;不要利用mini版)
3.预备长途软件,secucrt或者FinalShell、xshell都可
4.关闭防火墙,每一台都要关闭,包括selinux。
# systemctl stop firewalld
# systemctl disabled firewalld    //设置防火墙开机不自启
root@test1 yum.repos.d]# setenforce 0        //将selinux临时状态调解为开启
# getenforce        //查看selinux状态
Permissive
最好是进入设置文件将状态改为disabled
# vim /etc/selinux/config    //进入selinux的设置文件

# 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                    //此时状态由本来的enforcing改为了disabled
# SELINUXTYPE= can take one of three values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected. 
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted
https://i-blog.csdnimg.cn/direct/86d4974c0ac24c74a073e757cf6fcc11.png
//注,设置本地yum源要将网关改掉,使其不能联网
二、开始设置yum源

1.用xshell连上机器后,将镜像文件上传,起首点击图中所指标识
https://i-blog.csdnimg.cn/direct/72e0f199a7844f28a2f7ba37e0aa7e66.png
2.点击之后进入如下界面,此时找到你要上传的镜像
https://i-blog.csdnimg.cn/direct/9f9ff39bb4e24a508d979cef5cd08687.png
3.找到镜像之后,右击鼠标,然后点击传输
https://i-blog.csdnimg.cn/direct/5b50739ba02d489b9f4462bee94a0582.png
4.备份yum源
# cd /etc/yum.repos.d
/etc/yum.repos.d  //yum的设置文件所在
# mkdir bak
# ls
bak                    CentOS-Media.repo
CentOS-Base.repo       CentOS-Sources.repo
CentOS-CR.repo         CentOS-Vault.repo
CentOS-Debuginfo.repo  CentOS-x86_64-kernel.repo
CentOS-fasttrack.repo
# mv *.repo bak/
# ls
bak
//注每台机器都要进行这一步操作
5.创建yum_http.repo文件
# mkdir yum_http.repo
# vim yum_http.repo
将一下内容写入

name=centos       
baseurl=file:///opt/centos 
gpgcheck=0
enabled=1
https://i-blog.csdnimg.cn/direct/d58f5b42ad0b4738be437284b8746f53.png
# ls /opt/centos
ls: 无法访问/opt/centos: 没有谁人文件或目录
# mkdir  /opt/centos
# cd /opt/centos
# ls
# ls
CentOS-7-x86_64-DVD-2009.iso
# mount /opt/centos/CentOS-7-x86_64-DVD-2009.iso /opt/centos    //挂载镜像文件,简朴挂载mount: /dev/loop0 写保护,将以只读方式挂载
6.安装httpd服务
# yum -y install httpd
https://i-blog.csdnimg.cn/direct/8877c86150994df79532bd03c1d2aae3.png
7.设置httpd服务
# cd /var/www/html/            //进入到httpd的默认目录
# ll
总用量 0
# mkdir centos                      //创建一个centos目录
# ll
总用量 0
drwxr-xr-x. 2 root root 6 4月  23 10:37 centos
8.将将/opt/centos下挂载的文件软连接到http默认访问目录下,当然也可以利用cp命令,不过镜像文件较大,利用软连接更快
# ln -s /opt/centos/ /var/www/html/centos
# ll
总用量 4
lrwxrwxrwx 1 root root   12 7月   8 16:06 centos -> /opt/centos/
-rw-r--r-- 1 root root 1592 7月   8 15:50 index.html
drwxr-xr-x 2 root root   26 7月   8 16:01 test
9.启动httpd服务
# systemctl start httpd
10.修改http.repo(这里以自己创建的名字为准)文件中的baseurl为服务端ip
# vim http.repo 

name=centos
baseurl=http://192.168.168.5:8080/centos    //此处IP为服务端IP所在,假如修改了端口记得加上
gpgcheck=0
enabled=1
# yum -y install httpd
https://i-blog.csdnimg.cn/direct/9f91d711b7fd4fc58e0621e8ead3ac27.png
后续也可以进行其他测试

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
页: [1]
查看完整版本: 搭建本地yum源