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. 配置Oracle遇到问题<一>

    1, 将D:\app\product\11.2.0\dbhome_1\NETWORK复制到D:\app\product\instantclient_11_2.为了处理: 12154错误,不过没有解决. ...

  2. Java数据库开发(二)之——DBCP连接数据库

    1.载入jar包 DBCP需要以下几个jar包,可到apache及mysql的官网下载 2.程序编写 public static BasicDataSource ds = null; static f ...

  3. JUnit5的Tag、Filter、Order、Lifecycle

    Tag JUnit5可以使用@Tag注解给测试类和测试方法打tag,这些tag能用来在执行时进行过滤,它跟group有点类似. tag应该遵循以下规则: 不能为null或者为空. 不能包含空格. 不能 ...

  4. php错误处理,自动加载,以及栈堆内存和运行模式堆浅解 (转)

    Php错误处理 Php错误级别: E_ERROR 致命错误,会终止脚本运行.值为1 E_WARNING 警告错误,给出提示,不会终止运行值为2 E_PARSE 编译时的语法解析错误,解析错误仅仅由分析 ...

  5. Python获取list中指定元素的索引

    在平时开发过程中,经常遇到需要在数据中获取特定的元素的信息,如到达目的地最近的车站,橱窗里面最贵的物品等等.怎么办?看下面 方法一: 利用数组自身的特性 list.index(target), 其中a ...

  6. Pycharm上python运行和unittest运行两种执行方式解析

    前言 经常有人在群里反馈,明明代码一样的啊,为什么别人的能出报告,我的出不了报告,为什么别人运行结果跟我的不一样啊... 这种问题先检查代码,确定是一样的,那就是运行姿势不对了,一旦导入unittes ...

  7. 简单设计一个onedata指标管理体系

    以阿里云的maxcompute的数据仓库架构为例, 从上往下定义, dwp的数据,来源是dws+dim,最主要是dws.这里不讨论dim的作用. dws的数据来源于dwd. dwd的数据来源于ods. ...

  8. 数组去重汇总—v客学院技术分享

    上周基础班结束了数组的学习内容,这几天有时间整理了下几种比较常用的数组去重的方法供大家查阅!!!!! 话不多说,直接贴代码吧~~~~~~~ 欢迎大家指正,共同学习,一同进步!!! (php开发,web ...

  9. spring-4-申明事务

    categories: spring5 事务回顾 事务在项目开发过程非常重要,涉及到数据的一致性的问题,不容马虎! 事务管理是企业级应用程序开发中必备技术,用来确保数据的完整性和一致性. 事务就是把一 ...

  10. 《PHP 实现 Base64 编码/解码》笔记

    前言 早在去年 11 月底就已经看过<PHP 实现 Base64 编码/解码>这篇文章了,由于当时所掌握的位运算知识过于薄弱,所以就算是看过几遍也是囫囵吞枣一般,不出几日便忘记了其滋味. ...