搭建yum源

同步官方yum仓库

[root@yum-server ~]# cat  /yum/scripts/
centos6.yum.update.log        rsync_centos6_yumrepo.sh      
createrepo-wyny.sh            rsync_centos6_yumrepo.sh.bak  
[root@yum-server yum.repos.d]# cat  /yum/scripts/rsync_centos6_yumrepo.sh
#!/bin/bash
/usr/bin/rsync  -avrtH  --delete  --bwlimit=20480  rsync://mirrors.kernel.org/centos/6.9/os/x86_64/Packages/    /yum/repos/centos6/os/x86_64/Packages/ >       /yum/log/centos6-os-x86_64.log
createrepo  --update   /yum/repos/centos6/os/x86_64
/usr/bin/rsync  -avrtH  --delete  --bwlimit=20480  rsync://mirrors.kernel.org/centos/6.9/os/i386/Packages/    /yum/repos/centos6/os/i386/Packages/     >  /yum/log/centos6-os-i386.log
createrepo  --update    /yum/repos/centos6/os/i386
/usr/bin/rsync  -avrtH  --delete  --bwlimit=20480  rsync://mirrors.kernel.org/centos/6.9/updates/x86_64/Packages/    /yum/repos/centos6/updates/x86_64/Packages/       >       /yum/log/centos6-updates-x86_64.log
createrepo  --update    /yum/repos/centos6/updates/x86_64
/usr/bin/rsync  -avrtH  --delete  --bwlimit=20480  rsync://mirrors.kernel.org/centos/6.9/updates/i386/Packages/    /yum/repos/centos6/updates/i386/Packages/   >       /yum/log/centos6-updates-i386.log
createrepo  --update    /yum/repos/centos6/updates/i386
/usr/bin/rsync  -avrtH  --delete  --bwlimit=20480  rsync://mirrors.kernel.org/centos/6.9/extras/x86_64/Packages/    /yum/repos/centos6/extras/x86_64/Packages/ >       /yum/log/centos6-extras-x86_64.log
createrepo  --update    /yum/repos/centos6/extras/x86_64
/usr/bin/rsync  -avrtH  --delete  --bwlimit=20480  rsync://mirrors.kernel.org/centos/6.9/extras/i386/Packages/    /yum/repos/centos6/extras/i386/Packages/  >          /yum/log/centos6-extras-i386.log
createrepo  --update    /yum/repos/centos6/extras/i386
/usr/bin/rsync  -avrtH  --delete  --bwlimit=20480  rsync://mirrors.kernel.org/centos/6.9/centosplus/x86_64/Packages/    /yum/repos/centos6/centosplus/x86_64/Packages/ >       /yum/log/centos6-centosplus-x86_64.log
createrepo  --update    /yum/repos/centos6/centosplus/x86_64
/usr/bin/rsync  -avrtH  --delete  --bwlimit=20480  rsync://mirrors.kernel.org/centos/6.9/centosplus/i386/Packages/    /yum/repos/centos6/centosplus/i386/Packages/     >       /yum/log/centos6-centosplus-i386.log
createrepo  --update    /yum/repos/centos6/centosplus/i386

配置web服务器

显示文件目录

[root@yum-server ~]# cat /etc/nginx/conf.d/yum-server.conf
server {
    listen       80;
server_name   yum.in.chinawyny.com;
    #charset koi8-r;
    #access_log  /var/log/nginx/host.access.log  main;
    root  /yum/repos;
    location / {
        autoindex on;
        autoindex_exact_size on;
        autoindex_localtime on;


}

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    #    root           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #    include        fastcgi_params;
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}

编辑yum-repo配置文件

预留非官方仓库软件包路径

# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client.  You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the 
# remarked out baseurl= line instead.
#
#

[base]
name=CentOS-$releasever - Base - hwj 
failovermethod=priority
baseurl=http://1.1.1.18/centos6/os/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
gpgcheck=1
gpgkey=http://1.1.1.18/centos6/RPM-GPG-KEY-CentOS-6

#released updates 
[updates]
name=CentOS-$releasever - Updates - hwj
failovermethod=priority
baseurl=http://1.1.1.18/centos6/updates/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
gpgcheck=1
gpgkey=http://1.1.1.18/centos6/RPM-GPG-KEY-CentOS-6

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - hwj
failovermethod=priority
baseurl=http://1.1.1.18/centos6/extras/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
gpgcheck=1
gpgkey=http://1.1.1.18/centos6/RPM-GPG-KEY-CentOS-6

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus - hwj
failovermethod=priority
baseurl=http://1.1.1.18/centos6/centosplus/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
gpgcheck=1
gpgkey=http://1.1.1.18/centos6/RPM-GPG-KEY-CentOS-6

# 自定义包,拷贝至相应目录后需  createrepo --update
[wyny]
name=CentOS-$releasever - Plus - hwj
failovermethod=priority
baseurl=http://1.1.1.18/centos6/wyny/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
gpgcheck=0
gpgkey=http://1.1.1.18/centos6/RPM-GPG-KEY-CentOS-6

非官方yum仓库软件包

将软件包下载至相应路径

[root@yum-server ~]# ll /yum/repos/centos6/wyny/x86_64/Packages/
total 916
-rw-r--r--. 1 root root 936884 Apr 13 00:01 nginx-1.12.0-1.el6.ngx.x86_64.rpm

更新repo数据库

[root@yum-server ~]# cat  /yum/scripts/createrepo-wyny.sh 
#!/bin/bash
createrepo  --update    /yum/repos/centos6/wyny/i386
createrepo  --update    /yum/repos/centos6/wyny/x86_64

使用yum源

执行以下命令

#!/bin/bash
cd /etc/yum.repos.d/
gzip  ./*
wget http://1.1.1.18/centos6/centos6.repo  
yum clean all 
yum makecache
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
搭建yum源是为了方便系统管理员进行软件包的管理和安装。在搭建yum源之前,我们需要一个可以作为服务器的机器,并且已经安装了Apache软件。 首先,我们需要下载所需的软件包,并将其放置在适当的位置。可以从官方网站上获取RPM包,也可以从其他渠道获取。下载好的软件包需要放置在一个统一的目录下,比如"/var/www/html/yum"。 接下来,我们需要配置Apache服务器,让其能够提供所需的软件包。可以通过编辑Apache配置文件来实现,该文件位于"/etc/httpd/conf/httpd.conf"。我们需要添加一些新的配置项,比如: Alias /yum /var/www/html/yum <Directory /var/www/html/yum> Options Indexes FollowSymLinks AllowOverride None Require all granted </Directory> 然后,我们需要为每个软件包创建一个.repo文件,并将其放置在"/etc/yum.repos.d/"目录下。该文件中包含了软件包的详细信息和源码位置。可以使用任何文本编辑器来创建.repo文件。一个例子如下: [myrepo] name=My Yum Repository baseurl=http://your-server-ip/yum/ enabled=1 gpgcheck=0 确保将"your-server-ip"替换为你的服务器IP地址。 最后,我们需要更新yum缓存以使其能够读取新的源文件。可以运行以下命令: sudo yum clean all sudo yum makecache 现在,我们已经成功搭建了一个yum源。系统管理员可以使用yum命令来管理和安装软件包,并从自己的yum源中获取所需的软件。 总结起来,搭建yum源需要下载所需的软件包,配置Apache服务器,创建.repo文件并更新yum缓存。这样就可以方便地使用yum管理和安装软件包了。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值