自建yum 源,解决内网服务器安装依赖问题

本期跟为小伙伴们,带来的技术是 自建 yum,当你听到自建yum源的时候,你一定 会感觉到烦或者困惑,但是本期一定是不一样的自建yum 源。

1、通过iso 搭建yum 源

将iso 文件 挂载到服务器或者上传至服务器上,(注意一般我们都是使用的常规的DVD)

mkdir -p /data/centos/mirrors  #创建目录

mount -o loop CentOS-7-x86_64-DVD-2003.iso /media  #将iso文件挂载到/media目录下,文件时只读,如果你以及将iso挂载就不需要执行这步

cp -rf /media/* /data/centos/mirrors/  将iso的文件拷贝到我们创建的目录上

cd /etc/yum.repos.d/

rm -rf ./*

cat > CentOS-Base.repo <<EOF
[centos]
name=CentOS - Base
baseurl=file:///data/centos/mirrors/
gpgcheck=0
enabled=1
EOF

yum clean all  #清理yum缓存
yum makecache  #建立新的缓存

此时我们构建的yum源只可以本地使用,因此我们将这种本地的设置为web的,这样所有内网的服务器都可以使用。

安装nginx ,如果不会的可以查看一下文件来部署。

(3条消息) nginx 部署_趴着的猫的博客-优快云博客_nginx 部署

安装成功后对 nginx 服务进行配置

cp -f conf/nginx.conf conf/nginx.conf-bak

vim conf/nginx.conf

http {
    include       mime.types;
    default_type  application/octet-stream;

    autoindex on;
    autoindex_exact_size on;
    autoindex_localtime on;

server {
        listen       80;
        server_name  localhost;
        root         /data/centos/;

}
}

./sbin/nginx -t  #检查配置文件
./sbin/nginx  启动

 访问 一下试试,没问题

在客户端设置:

cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# rm -rf ./*
[root@localhost yum.repos.d]# cat >/etc/yum.repos.d/CentOS-Base.repo<<EOF
[centos]
name=CentOS-$releasever - Base
baseurl=http://192.168.0.101/mirrors/
gpgcheck=0
enabled=1
EOF

yum clean all  #清理yum缓存
yum makecache  #建立新的缓存

2、使用RPM包搭建YUM仓库

在 nginx 服务端 执行

 wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo  #换成公网源

yum clean all #清理缓存
yum makecache #创建新缓存

#假如我们要安装httpd 服务
mkdir -p  /data/newcentos/
yum install --downloadonly --downloaddir=/data/newcentos/ httpd #只下载不安装


yum -y install createrepo #安装createrepo软件,用于生成yum仓库数据库的软件
createrepo -pdo /data/newcentos/ /data/newcentos/  #初始化repodata索引文件
createrepo --update /data/newcentos/ #每加入或者更新一个rpm包就要更新一下

将nginx 配置文件里的  “root    /data/centos/; ” 更改为 “root /data/newcentos/;” 重启nginx 并更改 客户端 的  CentOS-Base.repo 

cat CentOS-Base.repo

[centos]
name=CentOS- - Base
baseurl=http://192.168.0.101/
gpgcheck=0
enabled=1

这种方式 需要客户端和服务端的环境是一致的,如果环境不一致,则又可能 客户端的依赖比服务端的依赖多。

3、企业级YUM仓库搭建

在服务端设置

yum -y install  rsync git vim  #安装部署

mkdir -p /data/mirrors #创建yum仓库目录

rsync -avzuP rsync://mirrors.tuna.tsinghua.edu.cn/centos/ /data/mirrors/centos/
rsync -avzuP rsync://mirrors.tuna.tsinghua.edu.cn/epel/ /data/mirrors/epel/

#将公网(清华源)的yum源 同步到 自己的服务端,如果磁盘小的话需要扩容
如果你还需 同步Ubuntu的 可以根据上面的格式自动同步,然后写成脚本 每日自动同步即可

服务端的nginx 配置文件更改为

root         /data/mirrors/;

客户端的yum 配置文件为

[centos]
name=CentOS- - Base
baseurl=http://192.168.0.101/centos/$releasever/os/$basearch/
gpgcheck=0
enabled=1

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值