by 无若

1. 先建立局域网内使用的CentOS7源

这个参看 http://www.cnblogs.com/gleaners/p/5735472.html

2. 抓取所有OpenStack的包,文件夹完全对应。
这里专门写了一个snatch_repo.py
代码如下:

#coding=utf-8
import requests
import re
import string
import urllib2 as url
import urllib
import Queue
import os
import sys
from contextlib import closing class ProgressBar(object):
def __init__(self, title, count=0.0, run_status=None, fin_status=None, total=100.0, unit='', sep='/', chunk_size=1.0):
super(ProgressBar, self).__init__()
self.info = '[%s] %s %.2f %s %s %.2f %s'
self.title = title
self.total = total
self.count = count
self.chunk_size = chunk_size
self.status = run_status or ''
self.fin_status = fin_status or ' ' * len(self.statue)
self.unit = unit
self.seq = sep def __get_info(self):
# [名称]状态 进度 单位 分割线 总数 单位
_info = self.info % (self.title, self.status, self.count/self.chunk_size, self.unit, self.seq, self.total/self.chunk_size, self.unit)
return _info def refresh(self, count=1, status=None):
self.count += count
# if status is not None:
self.status = status or self.status
end_str = '\r'
if self.count >= self.total:
end_str = '\n'
self.status = status or self.fin_status sys.stdout.flush()
sys.stdout.write(self.__get_info()+end_str)
sys.stdout.flush() def get_regex_outcome_list(text, regex):
"""
获取文本的正则表达式截取
"""
lst = []
reobj = re.compile(regex)
for match in reobj.finditer(text):
#match.start()
#match.end()
lst.append(match.group())
return lst def wget_file(url, file_name):
"""
下载文件
"""
#r = requests.get(url)
#with open(file_name, 'wb') as code:
# code.write(r.content) with closing(requests.get(url, stream=True)) as response:
chunk_size = 1024
content_size = float(response.headers['content-length'])
'''
需要根据 response.status_code 的不同添加不同的异常处理
'''
print('content_size', content_size,response.status_code , )
progress = ProgressBar('processing:'
, total=content_size
, unit='KB'
, chunk_size=chunk_size
, run_status='download...'
, fin_status='download ok!')
# chunk_size = chunk_size < content_size and chunk_size or content_size
with open(file_name, 'wb') as file:
for data in response.iter_content(chunk_size=chunk_size):
file.write(data)
progress.refresh(count=len(data)) print('download ok!', ) def page_to_url(url, html):
"""
解析页面上的html,提取href中的url
"""
lst = get_regex_outcome_list(html, 'href=".*"')
context = ''
path_lst = []
for item in lst:
item = item.replace('"','')
item = item.replace('href=', '')
path_lst.append((url+item, item))
return path_lst def parser_path_list(init_url, path_lst, deep_queue):
"""
解析路径列表,对路径做对应处理
"""
for item in path_lst:
url = item[0]
file_name = item[1]
if file_name[-1] == '/' and file_name != '../':
deep_queue.put(url)
dir_name = url[len(init_url):-1]
try:
os.mkdir(dir_name)
except Exception, e:
print e
else:
#pass
file_path = url[len(init_url):-1]
print file_path
try:
wget_file(url, file_path)
except Exception, e:
print e def visit_all_path(init_url):
"""
遍历所有路径
"""
r = requests.get(init_url)
path_lst = page_to_url(init_url, r.text)
deep_queue = Queue.Queue()
parser_path_list(init_url, path_lst, deep_queue) while not deep_queue.empty():
print deep_queue.qsize()
url = deep_queue.get()
r = requests.get(url)
path_lst = page_to_url(url, r.text)
parser_path_list(init_url, path_lst, deep_queue) return path_lst if __name__ == '__main__':
init_url = 'http://mirrors.aliyun.com/centos/7.2.1511/cloud/x86_64/openstack-liberty/'
visit_all_path(init_url)

# 代码里面使用的是阿里云的openstack-liberty。

# 在做源的服务器(192.168.29.94)上建立对应的目录

mkdir -p /var/ftp/pub/cloud/openstack-liberty

# 将此代码(snatch_repo.py)拷贝至/var/ftp/pub/cloud/openstack-liberty/目录下

cp snatch_repo.py /var/ftp/pub/cloud/openstack-liberty/

# 由于snatch_repo.py中使用了requests模块,所以需要先安装requests模块

pip install requests

# 执行此脚本,下载,静静等待所有下载完毕

python snatch_repo.py

3. 清除老的repodata,生成新的repodata

cp /var/ftp/pub/cloud/openstack-liberty/repodata/repomd.xml /tmp/

yum -y install createrepo

cd /var/ftp/pub/cloud/openstack-liberty/

createrepo -g /tmp/repomd.xml .

4. 配置客户机(假设:192.168.29.80)的源设置

cd /etc/yum.repos.d/
nano loacl_network_openstack_liberty.repo

# 编辑如下内容

[loacl_network_openstack_liberty]
name=ftpyum
baseurl=ftp://192.168.29.94/pub/cloud/openstack-liberty
enabled=1
gpgcheck=1
gpgkey=ftp://192.168.29.94/pub/centos7/RPM-GPG-KEY-CentOS-7

# 重新设定repo

yum clean all
yum makecache

5. 客户机(假设:192.168.29.80)验证

yum install openstack-keystone

建立局域网内使用的CentOS7-OpenStack源的更多相关文章

  1. 建立局域网内使用的CentOS7源

    建立局域网内使用的CentOS7源 by 无若    1. 在CentOS下建立匿名的FTP访问服务 CentOS 7下安装配置pure-ftpd,并使用匿名用户登录 Pure-FTPd是Linux上 ...

  2. 使用apt-mirror建立局域网内的Debian/Ubuntu源镜像

    转:http://forum.ubuntu.org.cn/viewtopic.php?t=41791 第一次翻译,翻译得不好还请大家见谅,多多指出错误~!:) 原文可以见如下的贴子:http://fo ...

  3. #centos7 创建内网yum源 OpenStack源部署

    #centos7 创建内网yum源#centos7 自动化安装 本地 内网 web源创建.更新 createrepo http OpenStack源部署 Elven原创 http://www.cnbl ...

  4. 局域网内yum源搭建

    在一些环境下,服务器不能连接互联网,但是我们又偏偏需要安装一些软件,此时有点麻烦了.通过使用centos镜像文件,搭建yum本地源,局域网内所有服务器都可以连接这一本地源进行软件的下载和安装,下面具体 ...

  5. 局域网内利用gitlab,jenkins自动生成gitbook并发布(nginx)

    安装了GitBook,内网使用,没法用上gitbook的网页. 用gitbook serve只能展示一本书,而且也不利于长期维护. 于是使用gitlab,jenkins,和nginx配合gitbook ...

  6. 怎么查询局域网内全部电脑IP和mac地址等信息?

    在局域网内查询在线主机的IP一般比较简单,但局域网内全部电脑的IP怎么才能够查到呢?查询到IP后我还要知道对方的一些详细信息(如MAC地址.电脑名称等)该怎么查询呢??? 工具/原料 Windows ...

  7. 怎么查询局域网内全部电脑IP和mac地址..

    在局域网内查询在线主机的IP一般比较简单,但局域网内全部电脑的IP怎么才能够查到呢?查询到IP后我还要知道对方的一些详细信息(如MAC地址.电脑名称等)该怎么查询呢??? 工具/原料 Windows ...

  8. arp命令(windows ),nmap查看局域网内所有主机IP和MAC

    ARP命令详解 ARP是一个重要的TCP/IP协议,并且用于确定对应IP地址的网卡物理地址.实用arp命令,我们能够查看本地计算机或另一台计算机的ARP高速缓存中的当前内容.此外,使用arp命令,也可 ...

  9. 创建局域网内远程git仓库,并将本地仓库push推到远程仓库中

    转载请注明出处 http://www.goteny.com/articles/2014/06/136.html http://www.cnblogs.com/zjjne/p/3778640.html ...

随机推荐

  1. Linux中curl的用法

    一.简介:在Linux中curl是一个利用URL规则在命令行下工作的文件传输工具,是一款强大的http命令行工具.支持文件的上传和下载,是综合传输工具. 二.语法:curl [option] [url ...

  2. POJ 3449 Geometric Shapes 判断多边形相交

    题意不难理解,给出多个多边形,输出多边形间的相交情况(嵌套不算相交),思路也很容易想到.枚举每一个图形再枚举每一条边 恶心在输入输出,不过还好有sscanf(),不懂可以查看cplusplus网站 根 ...

  3. java_线程创建的三种方式及区别

    java中关于线程的创建有三种: (1)通过继承Thread类创建线程. (2)通过实现Runnable接口创建线程. (3)通过Callable 和 Future 接口创建线程. * * * * * ...

  4. HCNA Routing&Switching之静态路由

    前文我们聊到了路由的相关概念和路由基础方面的话题,回顾请参考https://www.cnblogs.com/qiuhom-1874/p/14947897.html:今天我们聊聊静态路由相关话题: 回顾 ...

  5. ESP32低功耗模式

    1.ESP32 系列芯片提供三种可配置的睡眠模式,针对这些睡眠模式,我们提供了了多种低功耗解决方案,用户可以结合具体需求选择睡眠模式并进行配置.三种睡眠模式如下: Modem-sleep 模式:CPU ...

  6. ffiddler抓取手机(app)https包

    很多同学有看过原文,但是按照原文还是没有设置成功(我就是其中一个)然后查了网上资料,在某些选项上进行增加,填写,配置通过.(和原文略有不同) 安装Fiddler,我们正常的流程在feiddler中设置 ...

  7. SuperEdge 易学易用系列-SuperEdge 简介

    关于 SuperEdge SuperEdge 是由腾讯.Intel.VMware.虎牙直播.寒武纪.首都在线和美团等多家公司共同发起的边缘容器管理系统,它基于原生 Kubernetes.针对边缘计算和 ...

  8. WIN10技巧

    1.快速打开"开始---自动启动"文件夹:开始--支行--shell:startup 2

  9. C语言变量类型

    #include <stdio.h> // C 语言中,任何数据类型都不可以直接存储一个字符串.那么字符串如何存储? //在 C 语言中,字符串有两种存储方式,一种是通过字符数组存储,另一 ...

  10. MQTT 1——物联网集成项目技术选型与说明

    最近做的JAVA项目与物联网设备有集成,记录一下从技术选型到实现,整合: 1.通信协议技术选型,MQTT技术介绍2.MQTT服务端安装,客户端测试3.MQTT客户端与Spring MVC整合 1.项目 ...