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

kolla-ansible部署openstack的ocata(附带的命令shell脚本)

2017-08-29 00:00 1496 查看

环境(离线部署https://my.oschina.net/u/857184/blog/1526474)

操作系统
CentOS Linux release 7.3.1611 (Core)
内核信息
Linux 3.10.0-514.el7.x86_64
硬件
虚拟机一台
网卡
2块
内存
8G //all-in-one建议16G
CPU
4 VCPU

安装epel-release ;安装python-pip,升级到最新

yum install epel-release
yum install python-pip
pip install -U pip

安装依赖包

yum install python-devel libffi-devel gcc openssl-devel libselinux-python

安装ansible

yum install ansible

安装docker

curl -sSL https://get.docker.io | bash
配置docker服务,这里的配置,根据官网的提示是为了防止kolla-ansible部署neutron-dhcp-agent 容器时候抛出 APIError/HTTPError

# Create the drop-in unit directory for docker.service
mkdir -p /etc/systemd/system/docker.service.d
# Create the drop-in unit file
tee /etc/systemd/system/docker.service.d/kolla.conf <<-'EOF'
[Service]
MountFlags=shared
EOF
重启dockers服务

systemctl daemon-reload
systemctl restart docker

安装docker python

pip install -U docker
安装 升级python jinja版本
pip install -U Jinja2

安装ntp

yum install ntp
systemctl enable ntpd.service
systemctl start ntpd.service

关闭libvirtd服务

系统可能默认开启了libvirtd服务,需要关闭

systemctl stop libvirtd.service
systemctl disable libvirtd.service

安装kolla-ansible

运行这个命令会安装最新稳定版本的kolla-ansible

pip install kolla-ansible
复制globals.yml 和 passwords.yml 到 /etc

cp -r /usr/share/kolla-ansible/etc_examples/kolla /etc/kolla/

复制inventory 文件 (all-in-one 和 multinode) 到 当前目录

cp /usr/share/kolla-ansible/ansible/inventory/* .

配置docker本地镜像仓库

默认Docker的Registry是使用5000端口,对于OpenStack来说,有端口冲突,所以需要改成4000。Pull并启动registry镜像。

docker run -d -v /opt/registry:/var/lib/registry -p 4000:5000 \
--restart=always --name registry registry:2.3
说明:

Docker容器启动的时候,如果要挂载宿主机的一个目录,可以用-v参数指定;这里表示将宿主机的

/opt/registry目录挂在到容器的/var/lib/registry目录

-p 4000:5000 表示将宿主机的4000映射到容器的5000端口

--name registry 是给这个容器起名为registry

registry:2.3表示docker拉取的镜像是版本为2.3的registry

将之前下载的kolla镜像解压到/opt/registry目录中

tar zxf centos-binary-registry-ocata.tar.gz -C /opt/registry/
查看镜像仓库是否正常,如果返回一个json数据表示正常工作,这里的ip替换为docker仓库所在的主机IP

curl http://xxx.xxx.xxx.xxx:4000/v2/_catalog
有时候会在准备运行kolla-ansible deploy -i出现这种报错

Error:server gave HTTP response to HTTPS client

需要配置,这里的ip就是registry所在的主机ip

tee /etc/docker/daemon.json <<-'EOF'
{ "insecure-registries":["xxx.xxx.xxx.xxx:4000"]}
EOF
重启Docker服务

systemctl daemon-reload
systemctl restart docker

配置kvm/qemu

检查系统是否支持硬件加速,如果返回为0,那么只能使用qemu

egrep -c '(vmx|svm)' /proc/cpuinfo
如果是在虚拟机里安装Kolla,希望可以在OpenStack平台上创建虚拟机,那么你需要把virt_type=qemu,默认是KVM。

mkdir -p /etc/kolla/config/nova
cat << EOF > /etc/kolla/config/nova/nova-compute.conf
[libvirt]
virt_type=qemu
EOF
部署kolla

生成密码文件

kolla-genpwd
行这个命令,将会为/etc/kolla/passwords.yml的配置项填充随机生成的密码;

可以在运行这个命令后,根据自己需要修改passwords.yml,设置自己的密码

例如

编辑 /etc/kolla/passwords.yml文件,配置keystone管理员用户的密码。

keystone_admin_password: admin

配置/etc/kolla/globals.yml

kolla_internal_vip_address: " 172.16.X.225" //访问Dashboard的地址
docker_registry: " 172.16.X.225:4000"
docker_namespace: "lokolla"
network_interface: "eth0" //IP地址为172.16.X.225
neutron_external_interface: "eth1" //该网卡不配置IP地址
openstack_release: “4.0.3”
kolla_base_distro: "centos" //默认为centos
kolla_install_type: "binary" //默认为binary
说明:

kolla_internal_vip_address:虚拟ip( VIP)会用于和 keepalived

docker_registry: 指定这个配置为本地仓库的话,kolla会从本地仓库下载镜像

docker_namespace: 指定了仓库的名称空间

network_interface: 指定当前用于kolla服务所在的管理主机的IP

neutron_external_interface: 用于neutron容器部署

openstack_release: 指定了kolla部署容器的时候从仓库获取的镜像版本,参考3. Kolla镜像获取

由于部署的是all-in-one单节点

编辑/usr/share/kolla-ansible/ansible/group_vars/all.yml

文件,设置enable_haproxy为no

enable_haproxy: "no"

开始部署

验证环境是否符合kolla要求

进入/root(即 复制inventory 文件 (all-in-one 和 multinode) 的目标目录)

kolla-ansible prechecks -i all-in-one
部署openstack

kolla-ansible deploy -i all-in-one
等待结束

结束后查看docker容器

docker ps

验证部署结果

创建环境变量文件

kolla-ansible post-deploy
这样就创建 了/etc/kolla/admin-openrc.sh 环境变量文件。

安装OpenStack client端

pip install python-openstackclient
这样就可以通过命令行执行openstack相关命令

整理的后的命令shell脚本:https://github.com/jannanlo/tools/blob/master/ocata-all-in-on.sh

参考文档:

https://docs.openstack.org/kolla-ansible/latest/quickstart.html

http://dockone.io/article/2476
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  kolla ocata shell