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系统安装-C7

    1.安装部署操作系统 (1)创建虚拟机,加载系统镜像 (2)进入系统引导界面进行配置 补充:centos7系统网卡名称 默认系统的网卡名称为 eth0 eth1 –centos6 默认系统的网卡名称为 ...

  2. 22、编译安装nginx及性能优化

    22.1.编译安装nginx: 1.下载nginx: [root@slave-node1 ~]# mkdir -p /tools/ [root@slave-node1 ~]# cd /tools/ [ ...

  3. Exponentiation java大数

    Exponentiation 大数a的n次幂,直到读到EOF(文件结尾)为止,其中忽略小数后面的0 1 import java.util.*; 2 import java.math.*; 3 impo ...

  4. SPF Tarjan算法求无向图割点(关节点)入门题

    SPF 题目抽象,给出一个连通图的一些边,求关节点.以及每个关节点分出的连通分量的个数 邻接矩阵只要16ms,而邻接表却要32ms,  花费了大量的时间在加边上. //   time  16ms 1 ...

  5. python二进制读写及特殊码同步

    python对二进制文件的操作需要使用bytes类,直接写入整数是不行的,如果试图使用f.write(123)向文件中以二进制写入123,结果提示参数不是bytes类型. import os impo ...

  6. XCTF Guess-the-Number

    一.发现是jar文件,一定想到反汇编gdui这个工具,而且运行不起来,可能是我电脑问题,我就直接反编译出来了. 也发现了flag,和对应的算法,直接拉出来,在本地运行,后得到flag 二.java代码

  7. ARTS第六周

    第六周.后期补完,太忙了. 1.Algorithm:每周至少做一个 leetcode 的算法题2.Review:阅读并点评至少一篇英文技术文章3.Tip:学习至少一个技术技巧4.Share:分享一篇有 ...

  8. GitBook在Windows上安装及使用

    GitBook是基于Nodejs,使用Git/Github和Markdown制作电子书的命令行工具. 1.安装Nodejs 首先,安装Nodejs,官网地址:https://nodejs.org/en ...

  9. C语言入门思路

    C语言编程入门 0.数学中的常数在编程语言中称为常量,是一直不变的.如1,2,'a',"abc",3456,34.56等1.变量:类似于数学中的未知数.实际上就是指可用内存的一块区 ...

  10. 【redis前传】redis整数集为什么不能降级

    前言 整数集合相信有的同学没有听说过,因为redis对外提供的只有封装的五大对象!而我们本系列主旨是学习redis内部结构.内部结构是redis五大结构重要支撑! 前面我们分别从redis内部结构分析 ...