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. 18、通过yum命令只下载rpm包不安装

    18.1.说明: 经常遇到服务器没有网络的情况下部署环境,或者创建自己的 yum 仓库等,这时就需要下载 rpm 包. 18.2.方法一,yumdownloader(推荐): 如果只想通过 yum 下 ...

  2. 28、windows下通过MSI图形界面方式安装mysql

    28.1.下载mysql: 1. www.mysql.com 2. 3. https://dev.mysql.com/downloads/mysql/ 4. 5. 28.2.安装: 双击下载的&quo ...

  3. FastDFS文件系统迁移和数据恢复

    迁移步骤 打包旧服务器文件的所有文件 定位到旧服务器的tracker和Storage目录,将整个文件夹打包 tar -zcf fdfs-storage-data.tar.gz /fastdfs/sto ...

  4. 1.5Java、万维网以及其他

    要点提示:Java是一种功能强大和多用途的编程语言,可用于开发运行在移动设备.台式计算机以及服务器端的软件.

  5. Parrot os 安装vmtools

    1.更新源(这步个人觉得官方源还可以,没网上说的那么慢) vim /etc/apt/sources.list.d/parrot.list linux命令 ,按i进入修改模式,修改结束,之后先按esc, ...

  6. 咋滴,不就是面试总考Spring的AOP吗,办它!

    作者:小傅哥 博客:https://bugstack.cn 沉淀.分享.成长,让自己和他人都能有所收获! 一.前言 为什么,你的代码总是糊到猪圈上? 怎么办,知道你在互联网,不知道你在哪个大厂.知道你 ...

  7. Android单元测试问题解决

    1.'java.lang.RuntimeException: Method isEmpty in android.text.TextUtils not mocked'报错 https://www.ji ...

  8. C语言常用函数笔记

    strcmp 比较字符串: sscanf 读取格式化的字符串中的数据: memset 初始化内存的"万能函数",通常为新申请的内存进行初始化工作.对一段内存空间全部设置为某个字符, ...

  9. MQTT介绍与使用(转载)

    物联网是新一代信息技术的重要组成部分,也是"信息化"时代的重要发展阶段.其英文名称是:"Internet of things(IoT)".顾名思义,物联网就是物 ...

  10. qtscrcpy使用

    点击"USB线"一栏中的"刷新设备列表"按钮,随后设备序列号会显示出来: ·点击"获取设备IP",随后在"无线"一栏中会 ...