201912231620 公司内网搭建各种同步源centos/epel/ubuntu/pypi
3年前 (2020-02-16) 作者:iMoke 分类:原创·技术 阅读次数:4143 评论(0)本教程是为了那些企业,在公司内网搭建源,实现节省企业流量用途。
本案例包含centos/epel/ubuntu/pypi,其他的逐步增加
一、参考资料
本文最后更新时间:2020年02月15日 23:34:23
二、脚本(含CentOS6/7/8,epel6/7/8,ubuntu)
#centos6/7/8(仅同步包,不同步ISO,最小节省空间,约129G,更新时间:2020年02月16日 22:51:21)
#epel6/7/8(仅同步包,最小节省空间,约58G,更新时间:2020年02月16日 22:52:17)
#ubuntu(仅同步包,不同步ISO,最小节省空间,约1.4T,更新时间:2020年02月16日 23:05:40)
pkill rsync #dir dirs='centos epel ubuntu' for dir in $dirs do #echo $dir nohup rsync -dvlt --delete-after rsync://mirrors4.tuna.tsinghua.edu.cn/$dir/ /www/wwwroot/mirrors.mmoke.com/$dir/ &>>/www/wwwroot/${dir//\//.}.dir.$(date "+%Y%m%d%H%M%S").log & done #repo repos='centos/6/os centos/6/updates centos/6/extras centos/6/centosplus centos/6/contrib centos/7/os centos/7/updates centos/7/extras centos/7/centosplus centos/8/BaseOS/x86_64/os centos/8/extras/x86_64/os centos/8/centosplus/x86_64/os epel/6/x86_64 epel/7/x86_64 epel/8/Everything/x86_64 ubuntu/pool ubuntu/dists' for repo in $repos do echo $repo mkdir -p /www/wwwroot/mirrors.mmoke.com/$repo/ nohup rsync -alvrt --delete-after rsync://mirrors4.tuna.tsinghua.edu.cn/$repo/ /www/wwwroot/mirrors.mmoke.com/$repo/ &>>/www/wwwroot/${repo//\//.}.$(date "+%Y%m%d%H%M%S").log & done
#pypi(与官方相同完整同步,约1.4T,更新时间:2019年12月23日 16:31:44)
1.安装bandersnatch
#!/bin/bash cd /opt virtualenv --python=/usr/bin/python3 bandersnatch cd bandersnatch source ./bin/activate pip install -r https://bitbucket.org/pypa/bandersnatch/raw/stable/requirements.txt ln -s /opt/bandersnatch/bin/bandersnatch /usr/local/bin/bandersnatch
2.使用清华源脚本
TUNASYNC_WORKING_DIR=/www/wwwroot/repo/pypi BANDERSNATCH=${BANDERSNATCH:-"/usr/local/bin/bandersnatch"} TUNASYNC_UPSTREAM=${TUNASYNC_UPSTREAM:-"https://pypi.org"} CONF="/tmp/bandersnatch.conf" INIT=${INIT:-"0"} if [ ! -d "$TUNASYNC_WORKING_DIR" ]; then mkdir -p $TUNASYNC_WORKING_DIR INIT="1" fi echo "Syncing to $TUNASYNC_WORKING_DIR" if [[ $INIT == "0" ]]; then cat > $CONF << EOF [mirror] directory = ${TUNASYNC_WORKING_DIR} master = ${TUNASYNC_UPSTREAM} json = true timeout = 15 workers = 10 hash-index = false stop-on-error = false delete-packages = true EOF /usr/bin/timeout -s INT 36000 $BANDERSNATCH -c $CONF mirror if [[ $? == 124 ]]; then echo 'Sync timeout (/_\\)' exit 1 fi else cat > $CONF << EOF [mirror] directory = ${TUNASYNC_WORKING_DIR} master = ${TUNASYNC_UPSTREAM} json = true timeout = 15 workers = 10 hash-index = false stop-on-error = false delete-packages = false EOF $BANDERSNATCH -c $CONF mirror fi TODOFILE="${TUNASYNC_WORKING_DIR}/todo" if [[ -f $TODOFILE ]]; then rsize=`stat -c "%s" ${TODOFILE}` if [[ "$rsize" != "0" ]]; then echo "Sync Failed T_T" exit 1 fi fi echo "Sync Done ^_-" exit 0
三、使用宝塔面板,搭建WEB页面
本案例使用apache,目录别名的方式
四、(可选)公司内网DNS劫持
本案例中,服务器地址为10.170.133.23,那么使用dnsmasq强制解析以下域名
vi /etc/dnsmasq.conf #加入以下行 #############repolist###################### address=/mirrorlist.centos.org/10.170.133.23 address=/download.fedoraproject.org/10.170.133.23 #address=/mirrors.aliyun.com/10.170.133.23 #address=/mirrors.aliyuncs.com/10.170.133.23 #address=/mirrors.cloud.aliyuncs.com/10.170.133.23 #address=/mirrors.163.com/10.170.133.23 address=/mirror.centos.org/10.170.133.23 address=/wildcard.fedoraproject.org/10.170.133.23 address=/us.archive.ubuntu.com/10.170.133.23 address=/cn.archive.ubuntu.com/10.170.133.23 address=/security.ubuntu.com/10.170.133.23
除非注明,发表在“傲孤漠客”的文章『201912231620 公司内网搭建各种同步源centos/epel/ubuntu/pypi』版权归iMoke所有。
转载请注明出处为“本文转载于『傲孤漠客』原地址https://www.imoke.org/post/20191223976.html”
评论
发表评论