设为首页 收藏本站
查看: 421|回复: 0

[经验分享] Linux-测试环境构建本地YUM全类型仓库(Base,Extras,epel)

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2015-4-2 08:10:08 | 显示全部楼层 |阅读模式
1.同步yum源的脚本
#cat /data/yum_repo/rsync_yum_shell/rsync_yumrepo.sh
#!/bin/bash
#script name:rsync_yumrepo.sh
RsyncBin="/usr/bin/rsync"
RsyncPerm='-avrt --delete --no-iconv --bwlimit=100000'
Centos_7_base='/data/yum_repo/Centos-7/Base/'
Centos_7_epel='/data/yum_repo/Centos-7/Epel/'
Centos_7_extras='/data/yum_repo/Centos-7/extras/'
Centos_6_base='/data/yum_repo/Centos-6/Base/'
Centos_6_epel='/data/yum_repo/Centos-6/Epel/'
Centos_6_extras='/data/yum_repo/Centos-6/extras/'
LogFile='/data/yum_repo/rsync_yum_log'
Date=`date +%Y-%m-%d`
#check
function check {
if [ $? -eq 0 ];then
    echo -e "\033[1;32mRsync is success!\033[0m" >>$LogFile/$Date.log
else
    echo -e "\033[1;31mRsync is fail!\033[0m" >>$LogFile/$Date.log
fi
}
if [ ! -d "$Centos_7_base" ];then
    mkdir -pv $Centos_7_base
fi
if [ ! -d "$Centos_7_epel" ];then
    mkdir -pv $Centos_7_epel
fi
if [ ! -d "$Centos_7_extras" ];then
    mkdir -pv  $Centos_7_extras
fi
if [ ! -d "$Centos_6_base" ];then
    mkdir -pv $Centos_6_base
fi
if [ ! -d "$Centos_6_epel" ];then
    mkdir -pv $Centos_6_epel
fi
if [ ! -d "$Centos_6_extras" ];then
    mkdir -pv  $Centos_6_extras
fi
if [ ! -d "$LogFile" ];then
    mkdir $LogFile
fi
#rsync centos 6 base
echo 'Now start to rsync centos 6 base!' >>$LogFile/$Date.log
$RsyncBin $RsyncPerm --exclude=i386/ rsync://mirrors.yun-idc.com/centos/6/os/ $Centos_6_base >>$LogFile/$Date.log
check
#rsync centos 6 epel
echo 'Now start to rsync centos 6 epel!' >>$LogFile/$Date.log
$RsyncBin  $RsyncPerm --exclude=SRPMS/ --exclude=ppc64/ --exclude=i386/ rsync://mirrors.yun-idc.com/epel/6/ $Centos_6_epel  >>$LogFile/$Date.log
check
#rsync centos 6 extras
echo 'Now start to rsync centos 6  extras!' >>$LogFile/$Date.log
$RsyncBin $RsyncPerm --exclude=i386/ rsync://mirrors.yun-idc.com/centos/6/extras/ $Centos_6_extras >>$LogFile/$Date.log
check
#rsync centos 7 base
echo 'Now start to rsync centos 7 base!' >>$LogFile/$Date.log
$RsyncBin $RsyncPerm rsync://mirrors.yun-idc.com/centos/7/os/ $Centos_7_base >>$LogFile/$Date.log
check
#rsync centos 7 epel
echo 'Now start to rsync centos 7 epel!' >>$LogFile/$Date.log
$RsyncBin $RsyncPerm --exclude=SRPMS/ --exclude=ppc64/ rsync://mirrors.yun-idc.com/epel/7/ $Centos_7_epel >>$LogFile/$Date.log
check
#rsync centos 7 extras
echo 'Now start to rsync centos 7 extras!' >>$LogFile/$Date.log
$RsyncBin $RsyncPerm rsync://mirrors.yun-idc.com/centos/7/extras/ $Centos_7_extras >>$LogFile/$Date.log
check




任务计划:
周六的凌晨0点20分开始执行更新
20 00 * * 6 /bin/bash /data/yum_repo/rsync_yum_shell/rsync_yumrepo.sh
趁周末下载的,大概46GB。

2.配置nginx服务器
我的nginx配置文件:
server {
    listen       8000;
    server_name yum.stu15.cn;
    index index.html index.htm;
    root  /data/yum_repo/;
    location / {
     autoindex on;
     autoindex_exact_size off;
     autoindex_localtime on;
    }
    error_page 502 = /502.html;
    log_format  access  '$remote_addr - $remote_user [$time_local] "$request" '
        '$status $body_bytes_sent "$http_referer" '
        '"$http_user_agent" $http_x_forwarded_for';
   access_log  /var/log/nginx/access.log  access;
}

3.配置repo文件
CentOS-Base-6.repo
[Base]
name=CentOS-Base6 $basearch
enable=1
gpgcheck=1
gpgkey=http://192.168.1.15:8000/Centos-6/Base/$basearch/RPM-GPG-KEY-CentOS-6

[extras]
name=CentOS-Base6 $basearch
enable=1
gpgcheck=0
[Epel]
name=CentOS-Base6 $basearch
enable=1
gpgcheck=0

CentOS-Base-7.repo
[Base]
name=CentOS-Base7 $basearch
enable=1
gpgcheck=1
gpgkey=http://192.168.1.15:8000/Centos-7/Base/$basearch/RPM-GPG-KEY-CentOS-7
[extras]
name=CentOS-Base6 $basearch
enable=1
gpgcheck=0
[Epel]
name=CentOS-Base6 $basearch
enable=1
gpgcheck=0

根据需要选择repo文件。

然后进行下面操作:
按照不同的系统选择不同的repo文件,放到服务器的/etc/yum.repos.d里;
删除之前/etc/yum.repos.d里的repo;
清理缓存yum clean all;
将服务器上的软件包信息先在本地缓存,以提高搜索安装软件的速度 yum makecache.
现在本地yum源就已经完成,可以控制软件源,并且由于走内网所有不浪费机房公网网络流量。

批量重命名系统已经存在的repo文件:
1
2
3
4
5
# ls
CentOS-Base.repo  CentOS-Debuginfo.repo  CentOS-Media.repo  CentOS-Vault.repo  epel-aliyun.repo
#  for i in `ls`; do mv -f $i `echo $i".bak"`; done
# ls
CentOS-Base.repo.bak  CentOS-Debuginfo.repo.bak  CentOS-Media.repo.bak  CentOS-Vault.repo.bak  epel-aliyun.repo.bak



或者删除目录下面的repo文件:
1
#ansible all -m shell -a 'find /etc/yum.repos.d/ -name"*.bak" -exec rm -f {} \; '






4.脚本批量更新测试环境的所有服务器的yum源为本地15的:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#cat createrepo.sh
#!/bin/bash
cd /etc/yum.repos.d/
for i in `ls`; do mv -f $i `echo $i".bak"`; done
cat
<<EOF>>CentOS-Base-6.repo
[Base]
name=CentOS-Base6 \$basearch
baseurl=http://192.168.1.15:8000/Centos-6/Base/\$basearch
enable=1
gpgcheck=1
gpgkey=http://192.168.1.15:8000/Centos-6/Base/\$basearch/RPM-GPG-KEY-CentOS-6
[extras]
name=CentOS-Base6 \$basearch
baseurl=http://192.168.1.15:8000/Centos-6/extras/\$basearch
enable=1
gpgcheck=0
[Epel]
name=CentOS-Base6 \$basearch
baseurl=http://192.168.1.15:8000/Centos-6/Epel/\$basearch
enable=1
gpgcheck=0
EOF
yum clean all
yum makecache
find /etc/yum.repos.d/ -name "*.bak" -exec rm -f {} \;






5.在15上使用ansible批量推送脚本到服务器,然后执行脚本:
# ansible all -m copy -a 'src="./createrepo.sh" dest="/root/createrepo.sh"'
# ansible all -m shell -a 'bash /root/createrepo.sh'
测试使用本地yum源安装zsh,然后卸载:
# ansible all -m yum -a "name=zsh state=present"
# ansible all -m yum -a "name=zsh state=removed"


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-52970-1-1.html 上篇帖子: centos 7.0 ks文件 下篇帖子: Linux 系统之扩展表达式 --egrep Linux 仓库
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表