centos7、8搭建私用yum仓库

1、下载镜像并将centos 7镜像copy到机器上,版本自选,本教程以7举例(本方法好处是速度快,在局域网里。因为有些生产环境禁止连接外网)

下载地址:http://isoredirect.centos.org/centos/7/isos/x86_64/

1.2CentOS 初始化

1、最小化安装
2、关闭防火墙:  [17:46:01 root@centos7 ~]#systemctl disable --now firewalld
3、关闭SELinux: [17:46:01 root@centos7 ~]#vim /etc/selinux/config
SELINUX=disabled
4、实现邮件通信yum -y install postfix mailx systemctl enable --now postfix
5、yum 源 baseOS appstream,epel
6、常用软件: yum -y install lrzsz tree screen tmux man-pages strace redhat-lsb-core
7、网卡NAT地址:10.0.0.X/24 GATEWAY:10.0.0.2,dns:10.0.0.2,180.76.76.76名称修改:ethX
8、时间同步

2.挂载镜像

将镜像挂在在一个目录中,df 可以查看是否挂载成功。

[17:34:02 root@centos7 ~]#mkdir yum
[17:34:06 root@centos7 ~]#ll yum
total 0
[17:35:21 root@centos7 ~]#mount CentOS-7-x86_64-Minimal-2009.iso yum/
mount: /dev/loop0 is write-protected, mounting read-only
[17:36:22 root@centos7 ~]#df -h
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        869M     0  869M   0% /dev
tmpfs           879M     0  879M   0% /dev/shm
tmpfs           879M  528K  878M   1% /run
tmpfs           879M     0  879M   0% /sys/fs/cgroup
/dev/vda1        55G  4.6G   49G   9% /
tmpfs           176M     0  176M   0% /run/user/0
/dev/loop0      973M  973M     0 100% /root/yum              #看这里,我们已经挂载成功,你可以使用ls查看的

3、网络yum源配置
配置网络yum源,使我们建立的yum仓库可以共享到网络上,可以是基于httpd服务,也可以基于ftp服务。这里使用httpd服务,httpd是Apache超文本传输协议。
3.1安装软件

[17:45:42 root@centos7 ~]#yum -y install httpd

先安装提供http服务的httpd软件,也可以验证刚才本地yum源配置是否成功。安装成功,本地yum源配置正确。

3.2启动httpd

[17:45:42 root@centos7 ~]#systemctl enable --now httpd

3.2打开浏览器输入ip测试下http服务器
在这里插入图片描述

3.3参考网易、阿里、腾讯的地址格式:如网易格式(因为看起来比较正规)如: http://mirrors.163.com/centos/7.9.2009/os/x86_64/Packages/
打开存放网页的文件夹:/var/www/html并创建两个文件夹(我这里只是举例,具体格式你自己搞)

[17:47:59 root@centos7 ~]#cd /var/www/html/
[17:53:08 root@centos7 html]#ls
[17:55:23 root@centos7 html]#mkdir centos/{7,8} -pv
mkdir: created directory ‘centos’
mkdir: created directory ‘centos/7’
mkdir: created directory ‘centos/8’
[17:55:50 root@centos7 html]#tree centos/
centos/
├── 7
└── 8


2 directories, 0 files
[17:56:04 root@centos7 html]#

3.4将已经挂载的镜像重新挂载到我们刚刚创建的目录,如下

[17:47:59 root@centos7 ~]# mount /dev/loop0 /var/www/html/centos/7

3.5打开浏览器检查是否成功,哈哈成功了
在这里插入图片描述

4.将刚刚搭建的yum源配置在机器上试试效果
更改机器源配置

[18:05:50 root@centos7 ~]#vim /etc/yum.repos.d/base.repo
[base]
name=CentOS
baseurl=http://36.xxx.xxx.159/centos/7/       #这里新添一行,写我们刚刚搭建的yum源,注释掉原来的
#baseurl=https://mirrors.aliyun.com/centos/$releasever/os/$basearch
#        https://mirrors.cloud.tencent.com/centos/$releasever/os/$basearch
#        https://repo.huaweicloud.com/centos/8/os/x86_64/os/
#        https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/os/$basearch
gpgcheck=0

[extras]
name=extras
baseurl=https://mirrors.aliyun.com/centos/$releasever/extras/$basearch
        https://mirrors.cloud.tencent.com/centos/$releasever/extras/$basearch
        https://repo.huaweicloud.com/centos/$releasever/extras/$basearch
        https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/extras/$basear    ch
gpgcheck=0
enable=1


[epel]
name=EPEL
baseurl=http://mirrors.aliyun.com/epel/$releasever/$basearch
        https://mirrors.cloud.tencent.com/epel/$releasever/$basearch
        https://repo.huaweicloud.com/epel/$releasever/$basearch
        https://mirrors.tuna.tsinghua.edu.cn/epel/$releasever/$basearch

gpgcheck=0
enable=1

测试效果:随便安装个软件

[18:08:59 root@centos7 ~]#yum install vsftpd

centos 8搭建方法类似,挂载另一个文件下,但是有个重要的地方注意,就是机器的配置文件,格式如下:

[18:05:50 root@centos7 ~]#vim /etc/yum.repos.d/base.repo
[BaseOS]
name=BaseOS
baseurl=http://39.99.229.159/centos/8/BaseOS       #这里新添一行,写我们刚刚搭建的yum源,注释掉原来的
#baseurl=https://mirrors.aliyun.com/centos/$releasever/os/$basearch
#        https://mirrors.cloud.tencent.com/centos/$releasever/os/$basearch
#        https://repo.huaweicloud.com/centos/8/os/x86_64/os/
#        https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/os/$basearch
gpgcheck=0


[Appstream]
name=Appstream
baseurl=http://39.99.229.159/centos/8/AppStream/       
gpgcheck=0

验证:
[18:24:10 root@centos7 ~]#yum repolist
自己再安装软件试试,

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值