1.三台虚拟机设置

ansible

内存    2GB
处理器 4
硬盘 40GB
光盘iso centos1804
网络适配器 仅主机模式
显示器 自动检测

controller

内存    5.3GB
处理器 4
硬盘 100GB
光盘iso centos1804
网络适配器 仅主机模式
网络适配器 NAT模式
显示器 自动检测

compute

内存    5.3GB
处理器 4
硬盘 100GB
硬盘2 100GB
光盘iso centos1804
网络适配器 仅主机模式
网络适配器 NAT模式
显示器 自动检测

密码必须是000000

2.配置三台虚拟机的网络,主机名,域名解析

使用192.168.100.0网段

主机名 ansible controller compute

域名解析: (三台都需要配置)

[root@ansible ansible]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 192.168.100.128 ansible
192.168.100.130 controller
192.168.100.129 compute
[root@ansible ansible]#

3.下载ansible并配置免密登录

上传ansible.tar.gz 解压

[root@ansible ansible]# cd /opt/
[root@ansible opt]# ls
ansible ansible.tar.gz CentOS-7-x86_64-DVD-1804.iso chinaskills_cloud_iaas.iso rh
[root@ansible opt]#
[root@ansible opt]# tar -xzvf ansible.tar.gz -C ./

配置yum源安装ansible

配置列表清单

[root@ansible ansible]# cat hosts
controller
Compute

配置ansible

1.不检查公钥

2.hosts主机清单与roles在当前目录

3.远程用户为root

生成秘钥ssh-keygen使用

ssh-copy-id使ansible能够免密登录 compute controller

4.上传文件iaas镜像与centos1804镜像至ansible ansible将文件发送给被控节点

windows cmd上传镜像

scp  CentOS-7-x86_64-DVD-1804.iso  root@192.168.100.128:/opt

scp  chinaskills_cloud_iaas.iso  root@192.168.100.128:/opt

ansible 将文件传给被控节点

ansible  all  -m copy -a 'src=/opt/chinaskills_cloud_iaas.iso  dest=/opt/'  &&  ansible  all  -m copy  -a  'src=/opt/CentOS-7-x86_64-DVD-1804.iso  dest=/opt/'

5.ansible-playbook初始化操作

Controller

(1).挂载镜像拷贝出镜像的文件到/opt/iaas /opt/centos

(2).配置yum源

(3).下载vsftpd开启服务并共享/opt目录

Compute

(1).配置ftp yum源

(2).分区sdb

Controller/Compute

(1).关闭防火墙,不自启

(2).永久关闭selinux

(3).下载xiandian

生成init角色

ansible-galaxy init roles/init

编写playbook openstack_start.yml

- hosts: all
roles:
- init

编写roles init

- name: if
block:
- name: centos
file:
state: directory
name: /opt/centos - name: mountchinaskills
mount:
path: /media
src: /opt/chinaskills_cloud_iaas.iso
state: mounted
fstype: iso9660 - name: mv
shell: "cp -rvf /media/* /opt/" - name: umount
mount:
path: /media
state: unmounted
fstype: iso9660 - name: mountcentos
mount:
path: /media
src: /opt/CentOS-7-x86_64-DVD-1804.iso
state: mounted
fstype: iso9660 - name: mv
shell: "cp -rvf /media/* /opt/centos" - name: umount
mount:
path: /media
state: unmounted
fstype: iso9660 - name: mv yum_all
shell: "mv /etc/yum.repos.d/* /tmp" - name: yumrepo
yum_repository:
name: centos
description: centos repo
file: local
baseurl: file:///opt/centos
gpgcheck: no
enabled: yes
- name: yumrepo2
yum_repository:
name: iaas
description: iaas repo
file: local
baseurl: file:///opt/iaas-repo
gpgcheck: no
enabled: yes - name: installvsftpd
yum:
name: vsftpd
state: present
- name: share
shell: 'sed -i "1ianon_root=/opt" /etc/vsftpd/vsftpd.conf' - name: vsftpdstart
systemd:
name: vsftpd
state: restarted
enabled: yes - name: input
debug:
msg: "controller is already"
when: ansible_hostname == 'controller'
- name: if2
block: - name: mv yum_all
shell: "mv /etc/yum.repos.d/* /tmp" - name: yumcompute
yum_repository:
name: iaas
description: iaas repo
file: local
baseurl: ftp://192.168.100.130/iaas-repo
gpgcheck: no
enabled: yes - name: yumcompute2
yum_repository:
name: centos
description: centos repo
file: local
baseurl: ftp://192.168.100.130/centos
gpgcheck: no
enabled: yes
- name: part
parted:
device: /dev/sdb
number: 1
state: present
part_end: 40GiB
- name: part
parted:
device: /dev/sdb
number: 2
state: present
part_start: 42GiB
part_end: 92GiB - name: input
debug:
msg: "compute is already" when: ansible_hostname == 'compute' - name: down firewalld
systemd:
name: firewalld
state: stopped
enabled: no
- name: shutdown setenforce
shell: setenforce 0
shell: 'sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config'
- name: install
yum:
name: iaas-xiandian
state: present

ansible-playbook openstack_start.yml

运行剧本

6.编写jinjia2模板 渲染openrc.sh文件

(1).创建角色jinja2

ansible-galaxy  init  roles/jinja2

(2).控制节点Ansible下载iaas-xiandian并把openrc.sh做成模板文件

openrc.sh需要复制到jinji2角色的templates目录下

注意配置yum获取controller的ftp仓库

[root@ansible templates]# cp /etc/xiandian/openrc.sh ./openrc.sh.j2
[root@ansible templates]# ls
openrc.sh.j2

(3).去除变量信息的#

sed -i 's/^#//g' openrc.sh.j2

(4).写入变量

#--------------------system Config--------------------##
#Controller Server Manager IP. example:x.x.x.x
HOST_IP={{controller_ip}} #Controller HOST Password. example:000000
HOST_PASS={{PASSWD}} #Controller Server hostname. example:controller
HOST_NAME={{controller_name}} #Compute Node Manager IP. example:x.x.x.x
HOST_IP_NODE={{compute_ip}} #Compute HOST Password. example:000000
HOST_PASS_NODE={{PASSWD}} #Compute Node hostname. example:compute
HOST_NAME_NODE={{compute_name}} #--------------------Chrony Config-------------------##
#Controller network segment IP. example:x.x.0.0/16(x.x.x.0/24)
network_segment_IP={{network_segment_IP}}/24 #--------------------Rabbit Config ------------------##
#user for rabbit. example:openstack
RABBIT_USER=openstack #Password for rabbit user .example:000000
RABBIT_PASS={{PASSWD}} #--------------------MySQL Config---------------------##
#Password for MySQL root user . exmaple:000000
DB_PASS={{PASSWD}} #--------------------Keystone Config------------------##
#Password for Keystore admin user. exmaple:000000
DOMAIN_NAME=demo
ADMIN_PASS={{PASSWD}}
DEMO_PASS={{PASSWD}} #Password for Mysql keystore user. exmaple:000000
KEYSTONE_DBPASS={{PASSWD}} #--------------------Glance Config--------------------##
#Password for Mysql glance user. exmaple:000000
GLANCE_DBPASS={{PASSWD}} #Password for Keystore glance user. exmaple:000000
GLANCE_PASS={{PASSWD}} #--------------------Nova Config----------------------##
#Password for Mysql nova user. exmaple:000000
NOVA_DBPASS={{PASSWD}} #Password for Keystore nova user. exmaple:000000
NOVA_PASS={{PASSWD}} #--------------------Neturon Config-------------------##
#Password for Mysql neutron user. exmaple:000000
NEUTRON_DBPASS={{PASSWD}} #Password for Keystore neutron user. exmaple:000000
NEUTRON_PASS={{PASSWD}} #metadata secret for neutron. exmaple:000000
METADATA_SECRET={{PASSWD}} #Tunnel Network Interface. example:x.x.x.x
{% if ansible_hostname == 'controller' %}
INTERFACE_IP={{controller_ip}}
{% elif ansible_fqdn == 'compute' %}
INTERFACE_IP={{compute_ip}}
{% endif %} #External Network Interface. example:eth1
INTERFACE_NAME={{External_Network}} #External Network The Physical Adapter. example:provider
Physical_NAME={{Physical_NAME}} #First Vlan ID in VLAN RANGE for VLAN Network. exmaple:101
minvlan=101 #Last Vlan ID in VLAN RANGE for VLAN Network. example:200
maxvlan=200 #--------------------Cinder Config--------------------##
#Password for Mysql cinder user. exmaple:000000
CINDER_DBPASS={{PASSWD}} #Password for Keystore cinder user. exmaple:000000
CINDER_PASS={{PASSWD}} #Cinder Block Disk. example:md126p3
BLOCK_DISK={{cinder_disk}} #--------------------Swift Config---------------------##
#Password for Keystore swift user. exmaple:000000
SWIFT_PASS={{PASSWD}} #The NODE Object Disk for Swift. example:md126p4.
OBJECT_DISK={{swift_disk}} #The NODE IP for Swift Storage Network. example:x.x.x.x.
STORAGE_LOCAL_NET_IP={{STORAGE_LOCAL_NET_IP}} #--------------------Heat Config----------------------##
#Password for Mysql heat user. exmaple:000000
HEAT_DBPASS={{PASSWD}} #Password for Keystore heat user. exmaple:000000
HEAT_PASS={{PASSWD}} #--------------------Zun Config-----------------------##
#Password for Mysql Zun user. exmaple:000000
ZUN_DBPASS={{PASSWD}} #Password for Keystore Zun user. exmaple:000000
ZUN_PASS={{PASSWD}} #Password for Mysql Kuryr user. exmaple:000000
KURYR_DBPASS={{PASSWD}} #Password for Keystore Kuryr user. exmaple:000000
KURYR_PASS={{PASSWD}} #--------------------Ceilometer Config----------------##
#Password for Gnocchi ceilometer user. exmaple:000000
CEILOMETER_DBPASS={{PASSWD}} #Password for Keystore ceilometer user. exmaple:000000
CEILOMETER_PASS={{PASSWD}} #--------------------AODH Config----------------##
#Password for Mysql AODH user. exmaple:000000
AODH_DBPASS={{PASSWD}} #Password for Keystore AODH user. exmaple:000000
AODH_PASS={{PASSWD}} #--------------------Barbican Config----------------##
#Password for Mysql Barbican user. exmaple:000000
BARBICAN_DBPASS={{PASSWD}} #Password for Keystore Barbican user. exmaple:000000
BARBICAN_PASS={{PASSWD}}

(5).渲染变量

被定义的变量放进jinja2角色模板里的vars

剧本运行时playbook的template模块用vars里的变量渲染jinja2模板

[root@ansible ansible]# cat roles/jinja2/vars/main.yml
controller_ip: 192.168.100.130
controller_name: controller
compute_ip: 192.168.100.129
compute_name: compute
PASSWD: '000000'
cinder_disk: sdb1
swift_disk: sdb2
network_segment_IP: 192.168.100.0
External_Network: ens33
Physical_NAME: provider
STORAGE_LOCAL_NET_IP: 192.168.100.129
[root@ansible ansible]#

(6).编写并运行playbook

[root@ansible ansible]# cat jinja2.yml
- hosts: all
roles:
- jinja2
[root@ansible ansible]# ansible-playbook jinja2.yml

7.跑xiandian里的脚本完成openstack的安装

(1).生成所需要的角色

[root@ansible ansible]# for i in {mariadb,keystone,glance,nova-controller,neutron-controller,dashboard,cinder-controller,swift-controller,heat,nova-compute,neutron-compute,cinder-compute,swift-compute};do ansible-galaxy init roles/$i ;done
- Role roles/mariadb was created successfully
- Role roles/keystone was created successfully
- Role roles/glance was created successfully
- Role roles/nova-controller was created successfully
- Role roles/neutron-controller was created successfully
- Role roles/dashboard was created successfully
- Role roles/cinder-controller was created successfully
- Role roles/swift-controller was created successfully
- Role roles/heat was created successfully
- Role roles/nova-compute was created successfully
- Role roles/neutron-compute was created successfully
- Role roles/cinder-compute was created successfully
- Role roles/swift-compute was created successfully
[root@ansible ansible]#

每个角色对应着自己的名字的脚本任务

(2).写上每个角色对应的命令

controller

mariadb/tasks/main.yml
- name: install mysql
shell: iaas-install-mysql.sh
keystone/tasks/main.yml
- name: install keystone
shell: iaas-install-keystone.sh
glance/tasks/main.yml
- name: install glance
shell: iaas-install-glance.sh
nova-controller/tasks/main.yml
- name: install nova-controller
shell: iaas-install-nova-controller.sh
neutron/tasks/main.yml
- name: install neutron-controller
shell: iaas-install-neutron-controller.sh
dashboard/tasks/main.yml
- name: install dashboard
shell: iaas-install-dashboard.sh
cinder/tasks/main.yml
- name: install cinder-controller
shell: iaas-install-cinder-controller.sh
swift/tasks/main.yml
- name: install swift-controller
shell: iaas-install-swift-controller.sh
heat/tasks/main.yml
- name: install heat
shell: iaas-install-heat.sh

compute

nova/tasks/main.yml
- name: install nova-compute
shell: iaas-install-nova-compute.sh
neutron/tasks/main.yml
- name: install neutron-compute
shell: iaas-install-neutron-compute.sh
cinder/tasks/main.yml
- name: install cinder-compute
shell: iaas-install-cinder-compute.sh
swift/tasks/main.yml
- name: install swift-compute
shell: iaas-install-swift-compute.sh

(3).剧本内容

[root@ansible ansible]# cat openstack_shell.yml

- hosts: controller
remote_user: root
pre_tasks:
- name: init
shell: iaas-pre-host.sh
roles:
- mariadb
- keystone
- glance
- nova-controller
- neutron-controller
- dashboard
- cinder-controller
- swift-controller
- heat - hosts: compute
remote_user: root
pre_tasks:
- name: init
shell: iaas-pre-host.sh
roles:
- nova-compute
- neutron-compute
- cinder-compute
- swift-compute

7.合并剧本

[root@ansible ansible]# cat final.yml

- hosts: all
tasks:
- name: cp iaas
copy:
src: /opt/chinaskills_cloud_iaas.iso
dest: /opt/
- name: cp centos
copy:
src: /opt/CentOS-7-x86_64-DVD-1804.iso
dest: /opt/ # 这一步可以代替第标题4的ansible - hosts: all
roles:
- init - hosts: all
roles:
- jinja2 - hosts: controller
remote_user: root
pre_tasks:
- name: init
shell: iaas-pre-host.sh
roles:
- mariadb
- keystone
- glance
- nova-controller
- neutron-controller
- dashboard
- cinder-controller
- swift-controller
- heat - hosts: compute
remote_user: root
pre_tasks:
- name: init
shell: iaas-pre-host.sh
roles:
- nova-compute
- neutron-compute
- cinder-compute
- swift-compute

ansible-playbook final.yml

至此一键部署openstack完成

被控节点只需要修改主机名,配好网络,密码000000,可以被ansible免密登录

8.验证

[root@compute ~]# systemctl status openstack* | grep active
Active: active (running) since Thu 2022-04-14 04:49:24 EDT; 22min ago
Active: active (running) since Thu 2022-04-14 04:49:11 EDT; 23min ago
Active: active (running) since Thu 2022-04-14 04:49:24 EDT; 22min ago
Active: active (running) since Thu 2022-04-14 04:49:22 EDT; 22min ago
Active: active (running) since Thu 2022-04-14 04:49:23 EDT; 22min ago
Active: active (running) since Thu 2022-04-14 04:49:23 EDT; 22min ago
Active: active (running) since Thu 2022-04-14 04:49:24 EDT; 22min ago
Active: active (running) since Thu 2022-04-14 04:49:23 EDT; 22min ago
Active: active (running) since Thu 2022-04-14 04:49:22 EDT; 22min ago
Active: active (running) since Thu 2022-04-14 04:49:22 EDT; 22min ago
Active: active (running) since Thu 2022-04-14 04:49:22 EDT; 22min ago
Active: active (running) since Thu 2022-04-14 04:49:18 EDT; 22min ago
Active: active (running) since Thu 2022-04-14 04:49:24 EDT; 22min ago
Active: active (running) since Thu 2022-04-14 04:49:23 EDT; 22min ago
[root@compute ~]# [root@controller ~]# systemctl status openstack* | grep active
Active: active (running) since Thu 2022-04-14 16:45:57 CST; 26min ago
Active: active (running) since Thu 2022-04-14 16:45:34 CST; 27min ago
Active: active (running) since Thu 2022-04-14 16:43:23 CST; 29min ago
Active: active (running) since Thu 2022-04-14 16:46:38 CST; 26min ago
Active: active (running) since Thu 2022-04-14 16:42:29 CST; 30min ago
Active: active (running) since Thu 2022-04-14 16:43:26 CST; 29min ago
Active: active (running) since Thu 2022-04-14 16:45:34 CST; 27min ago
Active: active (running) since Thu 2022-04-14 16:43:26 CST; 29min ago
Active: active (running) since Thu 2022-04-14 16:46:37 CST; 26min ago
Active: active (running) since Thu 2022-04-14 16:46:38 CST; 26min ago
Active: active (running) since Thu 2022-04-14 16:43:26 CST; 29min ago
Active: active (running) since Thu 2022-04-14 16:45:34 CST; 27min ago
Active: active (running) since Thu 2022-04-14 16:42:29 CST; 30min ago
[root@controller ~]#

ansible 一键部署openstack (双节点)的更多相关文章

  1. ansible一键部署k8s单机环境

    一.虚拟机准备 干净的Centsot7.4.4G内存.2个CPU 最小化安装,最好带虚拟化 二.执行初始化脚本 注意:脚本中配置静态网卡根据实际网卡名称配置,我用的是ens33 可以用 sed -i ...

  2. OpenStack(四)——使用Kolla部署OpenStack多节点云

    (1).实验环境 主机名 IP地址 角色 内存 网卡 CPU 磁盘 OpenStack-con 192.168.128.110 controller(控制) 8G 桥接网卡ens32和ens33 4核 ...

  3. kolla部署openstack多节点高可用并对接ceph后端存储(17)

    部署节点执行: 安装基础包和docker yum install python-devel libffi-devel gcc openssl-devel git python-pip -y 升级一下 ...

  4. fuel一键部署openstack

    一.安装环境: 1. 所需物理主机的要求如下 内存:8GB+,推荐16GB:(少于8GB的就免谈了) 磁盘:500GB+: 物理机OS:ubuntu-desktop-amd64 14.04(推荐) 或 ...

  5. centos6.5部署OpenStack单节点

    环境 最小化安装的centos6.5 设置如下: 一.修改基本配置 1.修改主机名为controller [root@localhost ~]# hostname controller [root@l ...

  6. 使用openshit在ubuntu14.04下一键部署openstack(juno版本)

    一.基本介绍 本实验是在vmware workstation上虚拟机ubuntu14.04(64bit,desktop)上部署openstack(Juno版本).采用的工具是openshit.open ...

  7. ansible一键部署LAMP

    一.实现ansible跟节点间无密码访问,不会配置的请看 文章 . 二.创建目录 $ mkdir -p playbooks/{files,templates}   三.创建php测试文件index.p ...

  8. 通过ansible一键部署集群ntp时间同步

    环境准备 [root@server ~]# cat /etc/redhat-release CentOS Linux release (Core) [root@server ~]# uname -r  ...

  9. ansible 一键部署

    start install: rpm   -Uvh   https://mirrors.aliyun.com/epel/epel-release-latest-7.noarch.rpm yum  in ...

  10. 使用Ansible部署openstack平台

    使用Ansible部署openstack平台 本周没啥博客水了,就放个云计算的作业上来吧(偷个懒) 案例描述 1.了解高可用OpenStack平台架构 2.了解Ansible部署工具的使用 3.使用A ...

随机推荐

  1. 【译】使用 .NET Aspire 和 Visual Studio 开发云原生应用

    我们很高兴地向大家介绍 .NET Aspire,它旨在简化 .NET 云原生应用程序的构建和管理方式..NET Aspire 为像您这样的开发人员提供了一个改进的.有主见的框架,用于构建分布式应用程序 ...

  2. FFMPEG 信息查询

    一.问题描述 最近测试反馈一个隐私模式的问题,主播端启用隐私模式之后,在观看端发现画面转菊花并且还有回跳的现象 二.问题分析: 从网上下载了直播的视频文件,进行了一下分析,发现视频长度和音频长度不匹配 ...

  3. 获得centos7网络yum源

    获得centos73网络yum源 wget http://mirrors.163.com/.help/CentOS7-Base-163.repo 网易 wget -O /etc/yum.repos.d ...

  4. 虚拟机ping不通物理机 PING 192.168.10.1 (192.168.10.1) 56(84) bytes of data.

    准备做samba服务配置的时候 ping 192.168.10.1 (物理机地址) PING 192.168.10.1 (192.168.10.1) 56(84) bytes of data. 查看自 ...

  5. maven常用命令大全(附详细解释)

    1.常用打包命令 mvn clean package -Dmaven.test.skip=true -- 跳过单测打包mvn clean install -Dmaven.test.skip=true ...

  6. work11

    1,简述String类中的equals方法与Object类中的equals方法的不同点. /* Object 类 1,它是所有类的一个根类 2,其他类默认继承Object类 常用方法: 1,toStr ...

  7. 牛客网在线编程-语法篇-基础语法——C 语言解题集

    前言 牛客网在线编程-语法篇-基础语法--C 语言解题集. 点击下方超链接跳转至对应编程题目,文章包含解析及源码. 01-基础语法 简单输出 BC1-Hello Nowcoder BC2-小飞机 基本 ...

  8. linux命令查看内存命令free -h whereis locate find查找命令

    linux命令查看内存命令free -h  whereis locate find查找命令 1.free -h root@hz-auto-eureka-test-03:/usr/local/tomca ...

  9. Illegal character ((CTRL-CHAR, code 31))问题排查 gzip接口返回 RestTemplate GET POST请求

    Illegal character ((CTRL-CHAR, code 31))问题排查 gzip接口返回 #接口返回gzip方式 private static final String ENCODI ...

  10. 1024程序员节,写最棒的coding,做最靓的仔

    Tips:当你看到这个提示的时候,说明当前的文章是由原emlog博客系统搬迁至此的,文章发布时间已过于久远,编排和内容不一定完整,还请谅解` 1024程序员节,写最棒的coding,做最靓的仔 日期: ...