一、openstack(ocata)本地yum源的建立:
1、配置yum缓存:
vi /etc/yum.conf 把yum.conf配置改为: [main] cachedir=/var/cache/yum/$basearch/$releasever keepcache=1
2、指定Ocata镜像源
yum install -y epel-release yum list all|grep openstack yum install centos-release-openstack-ocata.noarch -y
3、安装所有ocata版的软件包(下面有用python3脚本将源的文件全下载下来):
vi openstack_yum.sh #!/bin/bash yum installl -y createrepo yum-plugin-priorities yum install ntp rabbitmq-server memcached python-memcached -y yum install python-openstackclient openstack-selinux mariadb mariadb-server python2-PyMySQL -y yum install openstack-keystone httpd mod_wsgi -y yum -y install openstack-glance python-glanceclient -y yum install -y openstack-nova-api openstack-nova-placement-api openstack-novaconductor \ openstack-nova-console openstack-nova-novncproxy openstack-novascheduler \ python-novaclient yum install -y openstack-nova-compute sysfsutils yum install -y openstack-neutron openstack-neutron-ml2 python-neutronclient yum install -y ebtables openstack-neutron-openvswitch ipset yum install -y openstack-dashboard yum install -y openstack-cinder targetcli python-oslo-db MySQL-python lvm2 python-keystone yum install -y openstack-swift-proxy python-swiftclient python-keystoneauth-token \ python-keystonemiddleware memcached yum install -y xfsprogs rsync yum install -y openstack-swift-account openstack-swift-container \ openstack-swift-object yum install -y openstack-heat-api openstack-heat-api-cfn openstack-heatengine \ python-heatclient yum install -y mongodb-server mongodb yum install -y openstack-ceilometer-api openstack-ceilometer-collector \ openstack-ceilometer-notification openstack-ceilometer-central \ openstack-ceilometer-alarm \ python-ceilometerclient yum install -y openstack-ceilometer-compute python-ceilometerclient pythonpecan yum install -y openstack-trove python-troveclient yum install -y openstack-sahara python-saharaclient
./openstack_yum.sh
3、复制下载过来的软件包:
mkdir /opt/ocata_yum cp -R /var/cache/yum/x86_64/7/ /opt/ocata_yum/ yum install createrepo createrepo /opt/ocata_yum/
4、安装nginx:
1、安装依赖包: yum install -y pcre pcre-devel openssl openssl-devel gcc wget groupadd -r nginx useradd -r -g nginx -s /bin/false -M nginx 2、安装nginx: cd /usr/loca/src wget http://nginx.org/download/nginx-1.8.0.tar.gz tar -zxvf nginx-1.8.0.tar.gz cd nginx-1.8.0 ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_flv_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre make && make install 3、配置nginx.conf
user nginx; worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; charset utf-8; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; sendfile on; gzip on; include vhosts/*.conf; }
mkdir /usr/local/nginx/conf/vhosts/
vi /usr/local/nginx/conf/vhosts/ocata.conf
server { listen 80; server_name localhost; index index.html index.php index.htm; access_log /var/log/nginx/access.log main; error_log /var/log/nginx/error.log; location /{ root /opt/; autoindex on; autoindex_exact_size off; autoindex_localtime on; } }
4、启动nginx
/usr/local/nginx/sbin/nginx -t
/usr/local/nginx/sbin/nginx
echo "/usr/local/nginx/sbin/nginx" >> /etc/rc.local
5、配置使用yum源的机器:
配置yum源: vi /etc/yum.repos.d/openstack_ocata.repo [ocata] name=ocata_rpm baseurl=http://192.168.71.21/ocata_yum/ enabled=1 gpgcheck=0 [updates] name=kevin update baseurl=http://192.168.71.21/ocata_yum/ gpgcheck=0 enabled=1 mv CentOS-Base.repo CentOS-Base.repo.bak yum clean all yum makecache
python3下载网易源的软件包:
from html.parser import HTMLParser from urllib import request import urllib import os,sys import socket class myparser(HTMLParser): '''找到a标签并把属性的值放到列表里''' def __init__(self): HTMLParser.__init__(self) self.links = [] def handle_starttag(self, tag, attrs): if tag == 'a': if len(attrs) == 0: pass else: for (variable,value) in attrs: # print(value) if variable == 'href': self.links.append(value)
def callbackfunc(blocknum, blocksize, totalsize): '''回调函数,打印下载进度 @blocknum: 已经下载的数据块 @blocksize: 数据块的大小 @totalsize: 远程文件的大小 ''' percent = int(100.0 * blocknum * blocksize / totalsize) if totalsize > 505528: pass else: percent = 100 sys.stdout.write('\r') sys.stdout.write(file_name + percent * '>' + str(percent) + '%') sys.stdout.flush() def create_dir(root_tree,catalog): '''根据url的目录结构在本地穿件文件夹''' os.chdir(root_tree) try: os.makedirs(catalog) except FileExistsError as e: pass def download_file(url,down_path): '''下载文件保存到相应的目录,并把下载失败的放在一个字典里''' global file_name global error_download file_name = url.split('/')[-1] error_download = {} socket.setdefaulttimeout(30) try: request.urlretrieve(url,down_path,callbackfunc) except socket.gaierror as e: error_download[url] = down_path print('socket.gaierror' , url) except urllib.error.URLError as e: error_download[url] = down_path print('urllib.error.URLError',url) sys.stdout.write('\n') def get_url_tree(url_tree): '''获取一个字典,链接:目录,并把文件夹创建及把文件下载''' url_tree_dict = {} level = 0 for url in url_tree: response = request.urlopen(url) page = response.read().decode('utf-8') hp = myparser() hp.feed(page) hp.close() try: hp.links.remove("../") except ValueError as e: pass for file in hp.links: if '/' in file: create_dir(url_tree[url], file) url_tree_dict[url+file] = url_tree[url]+file else: download_file(url+file,url_tree[url]+file) if file.find('/') > 0: level += 1 return url_tree_dict , level
url_tree = {"http://mirrors.163.com/centos/7/cloud/x86_64/openstack-ocata/":'/centos/7/cloud/x86_64/openstack-ocata/'} try: os.makedirs('/centos/7/cloud/x86_64/openstack-ocata/') except FileExistsError as e: pass while True: url_tree,level = get_url_tree(url_tree) if level == 0: break print(url_tree,level) for key in error_download: download_file(key,error_download[key])