一、openstack(ocata)本地yum源的建立:
1、配置yum缓存:
vi /etc/yum.conf 把yum.conf配置改为:[main]cachedir=/var/cache/yum/$basearch/$releaseverkeepcache=1
2、指定Ocata镜像源
yum install -y epel-releaseyum list all|grep openstackyum install centos-release-openstack-ocata.noarch -y
3、安装所有ocata版的软件包(下面有用python3脚本将源的文件全下载下来):
vi openstack_yum.sh#!/bin/bashyum installl -y createrepo yum-plugin-priorities yum install ntp rabbitmq-server memcached python-memcached -yyum install python-openstackclient openstack-selinux mariadb mariadb-server python2-PyMySQL -yyum install openstack-keystone httpd mod_wsgi -y yum -y install openstack-glance python-glanceclient -yyum 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 sysfsutilsyum install -y openstack-neutron openstack-neutron-ml2 python-neutronclient yum install -y ebtables openstack-neutron-openvswitch ipsetyum install -y openstack-dashboardyum install -y openstack-cinder targetcli python-oslo-db MySQL-python lvm2 python-keystoneyum install -y openstack-swift-proxy python-swiftclient python-keystoneauth-token \python-keystonemiddleware memcachedyum install -y xfsprogs rsync yum install -y openstack-swift-account openstack-swift-container \openstack-swift-objectyum install -y openstack-heat-api openstack-heat-api-cfn openstack-heatengine \python-heatclientyum install -y mongodb-server mongodbyum install -y openstack-ceilometer-api openstack-ceilometer-collector \openstack-ceilometer-notification openstack-ceilometer-central \openstack-ceilometer-alarm \python-ceilometerclientyum install -y openstack-ceilometer-compute python-ceilometerclient pythonpecanyum install -y openstack-trove python-troveclientyum install -y openstack-sahara python-saharaclient ./openstack_yum.sh
3、复制下载过来的软件包:
mkdir /opt/ocata_yumcp -R /var/cache/yum/x86_64/7/ /opt/ocata_yum/yum install createrepocreaterepo /opt/ocata_yum/
4、安装nginx:
1、安装依赖包:yum install -y pcre pcre-devel openssl openssl-devel gcc wgetgroupadd -r nginxuseradd -r -g nginx -s /bin/false -M nginx2、安装nginx:cd /usr/loca/srcwget http://nginx.org/download/nginx-1.8.0.tar.gztar -zxvf nginx-1.8.0.tar.gzcd 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-pcremake && make install3、配置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_rpmbaseurl=http://192.168.71.21/ocata_yum/enabled=1gpgcheck=0[updates]name=kevin updatebaseurl=http://192.168.71.21/ocata_yum/gpgcheck=0enabled=1mv CentOS-Base.repo CentOS-Base.repo.bakyum clean allyum makecache
python3下载网易源的软件包:
from html.parser import HTMLParserfrom urllib import requestimport urllibimport os,sysimport socketclass 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: passdef 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: passwhile 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])