openstack制作离线yum源

openstack制作离线yum源

离线yum源比较适合手动部署openstack时使用,离线yum源制作流程:

  • 执行reposync同步官方yum仓库到本地
  • 执行createrepo生成rpm包索引
  • nginx容器作为yum源服务器

在线节点执行

安装docker

#下载安装脚本并执行
curl -fsSL https://get.docker.com -o get-docker.sh 
sh get-docker.sh --mirror Aliyun

#配置镜像加速
mkdir -p /etc/docker
tee /etc/docker/daemon.json <<-'EOF'
{
     
  "registry-mirrors": ["https://uyah70su.mirror.aliyuncs.com"]
}
EOF

#启动docker服务
systemctl restart docker && systemctl enable docker

安装docker-compose

version=1.26.2
curl -L https://get.daocloud.io/docker/compose/releases/download/${version}/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose

创建docker-compose文件

运行centos和nginx服务,共享同一个卷rpm-data,centos image版本需要根据离线环境操作系统进行自定义。

cat > docker-compose.yml <version: '3.8'

services:
  centos:
    image: centos:7.8.2003
    container_name: centos
    command: sleep infinity
    volumes:
      - rpm-data:/rpms

  nginx:
    image: nginx:alpine
    container_name: nginx
    ports:
      - "8001:80"
    volumes:
      - rpm-data:/usr/share/nginx/html/rpms
      - /etc/nginx/nginx.conf:/etc/nginx/conf.d/default.conf:ro 
    depends_on:
      - centos

volumes:
  rpm-data:
    name: rpm-data
EOF

本地创建nginx配置文件

mkdir /etc/nginx

cat > /etc/nginx/nginx.conf <<EOF
server {
    listen       80;
    server_name  localhost;

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
        autoindex on;
        autoindex_exact_size off;
        autoindex_format html;
        autoindex_localtime on;
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
}
EOF

运行容器

#启动容器
[root@localhost ~]# docker-compose up -d

#查看运行状态
[root@localhost ~]# docker-compose ps
 Name               Command               State          Ports        
----------------------------------------------------------------------
centos   sleep infinity                   Up                          
nginx    /docker-entrypoint.sh ngin ...   Up      0.0.0.0:8001->80/tcp

在centos容器中同步官方yum仓库到本地

docker exec -it centos bash

#以下所有命令在容器中执行
yum install -y reposync createrepo

#安装openstack源
yum install -y centos-release-openstack-train
yum repolist

#同步rpm包到容器rpm-data卷中
reposync -p /rpms

#创建索引
createrepo /rpms

查看本地卷中的rpm包

[root@localhost ~]# ll /var/lib/docker/volumes/rpm-data/_data/
total 4
drwxr-xr-x 3 root root   22 Jul 16 22:11 base
drwxr-xr-x 3 root root   22 Jul 16 22:33 centos-ceph-nautilus
drwxr-xr-x 3 root root   22 Jul 16 22:38 centos-nfs-ganesha28
drwxr-xr-x 3 root root   22 Jul 16 22:38 centos-openstack-train
drwxr-xr-x 3 root root   22 Jul 16 22:43 centos-qemu-ev
drwxr-xr-x 3 root root   22 Jul 16 22:43 extras
drwxr-xr-x 2 root root 4096 Jul 16 23:08 repodata
drwxr-xr-x 3 root root   22 Jul 16 22:45 updates

#总大小约16G
[root@localhost ~]# du -sh /var/lib/docker/volumes/rpm-data/_data/
16G     /var/lib/docker/volumes/rpm-data/_data/

同步完成后重启容器

docker-compose restart

验证nginx访问是否正常:
openstack制作离线yum源_第1张图片
后续同步更新官方yum源:

docker exec -it centos bash
reposync -p /rpms
createrepo --update /rpms
docker-compose restart

离线节点执行

离线节点创建yum repo文件

mkdir -p /etc/yum.repos.d/bak
mv /etc/yum.repos.d/{
     *.repo,bak}

cat > /etc/yum.repos.d/local.repo <<EOF
[local]
name=local
baseurl=http://192.168.93.10:8001/rpms
gpgcheck=0
enabled=1
EOF

安装软件包测试

yum clean all && yum makecache

yum install -y python-openstackclient

参考:https://blog.csdn.net/u013469753/article/details/106274126

你可能感兴趣的:(OpenStack,openstack)