您的位置:首页 > 运维架构

[准备篇4]VMWare搭建Openstack——配置OpenStack镜像源

2015-06-07 11:42 447 查看
我们在安装Openstack时,需要安装很多组件,这些组件并不是我一开始想象中的安装部署包,也没有任何地方可以下载一个类似压缩包的,我们需要在一个可以连接互联网的环境下,直接进行在线安装,安装的命令为:

sudo apt-get install XXXX(包的名称)

但是很多情况下,用户的环境并不支持能够连接互联网,那么我们就需要事先将这些包下载到一个可以联网的环境下,也就是配置一个源,那么其他环境只需要连接该源地址,就可以安装相关的软件包了。所以说虽然该博客的名称为配置openStack镜像源,其实任何软件包都可以配置,配置软件源的名称更为合适。

机器1:192.168.195.138(可以连接互联网)

机器2:192.168.195.144(不可以连接互联网),但是可以连接机器1.

首先我们需要在机器1进行如下操作:

1、创建管理用户

我们可以创建一个.sh文件,将如下操作命令添加进去,然后执行即可

history -w
user=zrepo
pass=zrepo@openstack
useradd -m -d /home/${user} -k /etc/skel -s /bin/bash ${user}
printf "${user}:${pass}" | chpasswd
echo "${user} ALL = (root) NOPASSWD:ALL" | sudo tee /etc/sudoers.d/${user}
chmod 0440 /etc/sudoers.d/${user}
history -c


2、安装软件包

apt-get install dpkg-dev nginx wget -y


3、创建相关文件夹

/data/repo/openstack/dists/trusty/icehouse/binary-amd64

/data/repo/openstack/dists/trusty/icehouse-ext/binary-amd64

/data/repo/openstack/dists/trusty/os/binary-amd64

可选

/data/repo/openstack/dists/trusty/icehouse/binary-i386

/data/repo/openstack/dists/trusty/icehouse-ext/binary-i386

/data/repo/openstack/dists/trusty/os/binary-i386

其实这个路径标识用户可以自定义来设定,之所以创建的比较深,主要是将openstack、操作系统、openstack版本、操作系统版本、32/64位说明清楚,当然如果偷懒完全可以放在一起。

例如同步 deb 包到 binary-amd64 目录下, 其中 icehouse 目录下存放原生 OpenStack 软件包, icehouse-ext 目录下存放 openstack 定制包 (含 API Extension)

4、创建SH可执行文件/data/repo/openstack/dpkg-scanpackages.sh

cd /data/repo/openstack
#dpkg-scanpackages dists/trusty/icehouse/binary-i386/ > dists/trusty/icehouse/binary-i386/Packages
dpkg-scanpackages dists/trusty/icehouse/binary-amd64/ > dists/trusty/icehouse/binary-amd64/Packages

#dpkg-scanpackages dists/trusty/icehouse-ext/binary-i386/ > dists/trusty/icehouse-ext/binary-i386/Packages
dpkg-scanpackages dists/trusty/icehouse-ext/binary-amd64/ > dists/trusty/icehouse-ext/binary-amd64/Packages
~


我只考虑了openstack的64bit 包,其他操作系统还有32位的,用户自行添加即可。

我们可以执行如下SH文件,自动实现以上步骤

repo_server=http://192.168.195.138
repo_rootdir=/data/repo 
repo_name=openstack
repo_version=icehouse
release_codename=trusty

repo_ext_dir=${repo_rootdir}/${repo_name}/dists/${release_codename}/{$repo_version,$repo_version-ext}/{binary-amd64,binary-i386}
eval echo ${repo_ext_dir} | xargs mkdir -p

cat > ${repo_rootdir}/${repo_name}/dpkg-scanpackages.sh <<EOF
cd ${repo_rootdir}/${repo_name}
#dpkg-scanpackages dists/${release_codename}/${repo_version}/binary-i386/ > dists/${release_codename}/${repo_version}/binary-i386/Packages
dpkg-scanpackages dists/${release_codename}/${repo_version}/binary-amd64/ > dists/${release_codename}/${repo_version}/binary-amd64/Packages
vi 
#dpkg-scanpackages dists/${release_codename}/${repo_version}-ext/binary-i386/ > dists/${release_codename}/${repo_version}-ext/binary-i386/Packages
dpkg-scanpackages dists/${release_codename}/${repo_version}-ext/binary-amd64/ > dists/${release_codename}/${repo_version}-ext/binary-amd64/Packages
EOF


5、发布http apt源

这一步是可选项,不过我们可以在web浏览器查看deb的信息,这样做非常便于查询和远程操作

创建一个日志文件/data/logs/nginx/repo.example.cn_access.log

执行如下SH文件

nginx_rootdir=/data/repo

cat > /etc/nginx/sites-available/repo.conf <<EOF
# repo from ${nginx_rootdir}
server {
    listen 80;
    charset utf-8;
    server_name repo.example.cn;

    location / {
        root ${nginx_rootdir};
        autoindex on;
        autoindex_localtime on;
        autoindex_exact_size off;

        #allow 127.0.0.1/32;
        #deny all;
    }

    access_log /data/logs/nginx/repo.example.cn_access.log;
}
EOF

rm -f /etc/nginx/sites-enabled/default
ln -sf ${repo_rootdir} ${nginx_rootdir}
ln -sf /etc/nginx/sites-available/repo.conf /etc/nginx/sites-enabled/


查看nginx -t信息

root@python1:~# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful


重启nginx服务

root@python1:~# /etc/init.d/nginx restart
 * Restarting nginx nginx                                                                                      [ OK ]


设置请求

root@python1:~# curl -I http://192.168.195.138/openstack/dpkg-scanpackages.sh HTTP/1.1 200 OK
Server: nginx/1.4.6 (Ubuntu)
Date: Tue, 26 May 2015 03:38:51 GMT
Content-Type: application/octet-stream
Content-Length: 439
Last-Modified: Tue, 26 May 2015 03:03:57 GMT
Connection: keep-alive
ETag: "5563e29d-1b7"
Accept-Ranges: bytes


在机器2(客户端)操作

在机器2的操作其实非常简单,就是修改机器2的sources.list文件

sm@python2:~$ cat /etc/apt/sources.list

deb http://192.168.195.138/openstack trusty icehouse
deb http://192.168.195.138/openstack trusty icehouse-ext


怎么操作呢?

相关配置已经配置好了,接下来就是怎么实现操作了

1、如果需要安装什么组件,我们需要在机器1上,直接执行sudo apt-get install XXX -d

添加一个-d参数,也就是该软件包只下载,并不在机器1安装。

默认软件包的下载路径会存储在机器1的如下路径:

root@python1:/var/cache/apt/archives# ls
fontconfig-config_2.11.0-0ubuntu4.1_all.deb  libxpm4_1%3a3.5.10-1_amd64.deb
fonts-dejavu-core_2.34-1ubuntu1_all.deb      lock
libfontconfig1_2.11.0-0ubuntu4.1_amd64.deb   nginx_1.4.6-1ubuntu3.2_all.deb
libgd3_2.1.0-3_amd64.deb                     nginx-common_1.4.6-1ubuntu3.2_all.deb
libjbig0_2.0-2ubuntu4.1_amd64.deb            nginx-core_1.4.6-1ubuntu3.2_amd64.deb
libtiff5_4.0.3-7ubuntu0.3_amd64.deb          partial
libvpx1_1.3.0-2_amd64.deb                    wget_1.15-1ubuntu1.14.04.1_amd64.deb


2、假设上面的软件包都是我们所需要的,我们需要将这些软件包,手动迁移到我们指定的文件夹中

root@python1:/var/cache/apt/archives# mv *.deb /data/repo/openstack/dists/trusty/icehouse/binary-amd64


这时候,如果你认为是OS的,你可以放OS的相应的文件夹(本例并没有创建),如果是OpenStack的,就放在相应的文件夹中。

3、然后执行dpkg-scanpackages.sh

root@python1:/data/repo/openstack# sh dpkg-scanpackages.sh
dpkg-scanpackages: info: Wrote 12 entries to output Packages file.
dpkg-scanpackages: info: Wrote 0 entries to output Packages file.


注意:以后每次需要安装新的软件包,都需要重复1.2.3的操作。

这时候,我们可以访问机器1的IP地址,也可以通过浏览器查看相应包的信息



机器2的软件安装

1、首先更新一下源列表

sm@python2:~$ sudo apt-get update
Ign http://192.168.195.138 trusty InRelease
Ign http://192.168.195.138 trusty Release.gpg
Ign http://192.168.195.138 trusty Release
Get:1 http://192.168.195.138 trusty/icehouse amd64 Packages [14.7 kB]
Get:2 http://192.168.195.138 trusty/icehouse-ext amd64 Packages
Ign http://192.168.195.138 trusty/icehouse Translation-en_US
Ign http://192.168.195.138 trusty/icehouse Translation-en
Ign http://192.168.195.138 trusty/icehouse-ext Translation-en_US
Ign http://192.168.195.138 trusty/icehouse-ext Translation-en
Fetched 14.7 kB in 0s (148 kB/s)
sm@python2:~$


2、安装软件即可

sm@python2:~$ sudo apt-get install nginx
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
  fontconfig-config fonts-dejavu-core libfontconfig1 libgd3 libjbig0 libtiff5 libvpx1 libxpm4
  nginx-common nginx-core
Suggested packages:
  libgd-tools fcgiwrap nginx-doc
The following NEW packages will be installed:
  fontconfig-config fonts-dejavu-core libfontconfig1 libgd3 libjbig0 libtiff5 libvpx1 libxpm4 nginx
  nginx-common nginx-core
0 upgraded, 11 newly installed, 0 to remove and 1 not upgraded.
Need to get 2,453 kB of archives.
After this operation, 8,193 kB of additional disk space will be used.
Do you want to continue? [Y/n]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: