• 使用salt-cloud创建openstack虚拟机


    salt-cloud也是基于openstack来做的,它可以支持多种云的使用。比如:AliyunAzureDigitalOceanEC2Google Compute EngineHP CloudOpenStack、等等

    安装相关组件和依赖包

    [root@linux-node1 ~]# yum -y install salt-master salt-minion salt-cloud python-libcloud

    修改配置文件

    [root@linux-node1 ~]# cd /etc/salt/cloud.providers.d/
    [root@linux-node1 cloud.providers.d]# cat openstack.conf 
    my-openstack-config:
      # Set the location of the salt-master
      #
      minion:
        master: 192.168.56.11
    
      # Configure the OpenStack driver
      #
      identity_url: http://192.168.56.11:5000/v2.0/tokens
      compute_name: nova
      protocol: ipv4
    
      compute_region: RegionOne
      # 注意这里的类型可以通过openstack endpoint list 查看到
    
      # Configure Openstack authentication credentials
      #
      user: demo
      password: demo
      # tenant is the project name
      tenant: demo
      # 项目名称
    
      provider: openstack
    
      # skip SSL certificate validation (default false)
      insecure: false

    配置saltstack

    [root@linux-node1 cloud.providers.d]# systemctl start salt-master
    [root@linux-node1 cloud.providers.d]# vim /etc/salt/minion 
    master: 192.168.56.12
    [root@linux-node1 cloud.providers.d]# systemctl start salt-minion
    [root@linux-node1 cloud.providers.d]# salt-key 
    Accepted Keys:
    Denied Keys:
    Unaccepted Keys:
    linux-node1.oldboyedu.com
    Rejected Keys:
    [root@linux-node1 cloud.providers.d]# salt-key -A
    The following keys are going to be accepted:
    Unaccepted Keys:
    linux-node1.oldboyedu.com
    Proceed? [n/Y] y
    Key for minion linux-node1.oldboyedu.com accepted.

    [root@linux-node1 cloud.providers.d]# salt '*' test.ping
    linux-node1.oldboyedu.com:
        True

    测试salt-cloud能否连接上openstack

    ###### 列出所有云主机的镜像
    [root@linux-node1 cloud.providers.d]# salt-cloud --list-images openstack -l debug
    ...........................
    ............................
    ...........................
    my-openstack-config:
        ----------
        openstack:
            ----------
            cirros:
                ----------
                driver:
                extra:
                    ----------
                    created:
                        2015-12-23T16:47:33Z
                    metadata:
                        ----------
                    minDisk:
                        0
                    minRam:
                        0
                    progress:
                        100
                    serverId:
                        None
                    status:
                        ACTIVE
                    updated:
                        2015-12-23T16:47:33Z
                get_uuid:
                id:
                    90f1b52f-25dd-43f1-9f78-4d4de67aabfe
                name:
                    cirros
                uuid:
                    b22ad8d988b5925dc328cdc21a84a7670fbda0c4
    
    
    ##### 列出所有云主机的类型
    [root@linux-node1 cloud.providers.d]# salt-cloud --list-size openstack -l debug

    编写虚拟机的创建文件

    [root@linux-node1 cloud.profiles.d]# pwd
    /etc/salt/cloud.profiles.d
    
    [root@linux-node1 cloud.profiles.d]# cat web.conf 
    web-node:
      provider: my-openstack-config                 # /etc/salt/cloud.providers.d/openstack.conf的ID
      size: m1.tiny                                 # 云主机的类型
      image: cirros                                 # 使用的镜像名称
      ssh_key_file: /root/.ssh/id_rsa               # 密钥
      ssh_key_name: mykey                           # openstack页面中,访问安全里面找密钥对
      ssh_interface: private_ips
      networks:                                     # 设置使用的网络,可以从openstack页面的网络板块中找
        - fixed:
          - 8fb1d37e-414f-4f5d-89f7-8d20fa8fabed
      minion:
        master: 192.168.56.11
        grains:
          role: webserver
    +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    [root@linux-node1 cloud.profiles.d]# salt-cloud -p web-node node1 -l debug

    ########################################################################################################

    使用salt-cloud创建openstack虚拟机

        众所周知,saltstack有三大功能:远程执行、配置管理、云管理。其中的云管理就是通过salt-cloud完成的。salt-cloud能够管理很多云环境(公有云、私有云),连大名鼎鼎的阿里云也可以通过salt-cloud来创建虚拟机哦。

        本次主要讲解使用salt-cloud管理openstack(L版)私有云来创建虚拟机。(前提openstack环境运行正常,能正常创建虚拟机)

    1、 安装saltstack

    yum install salt-master salt-minion salt-cloud -y

     安装依赖包:

    yum install python-libcloud -y

    2、 创建provider配置文件,告诉salt-cloud如何连接openstack(yaml语法,注意空格

    [root@linux-node1 cloud.providers.d]# pwd
    /etc/salt/cloud.providers.d
    [root@linux-node1 cloud.providers.d]# vim openstack.conf 
    myopenstack:
      # Set the location of the salt-master
      #
      minion:
        master: 192.168.56.11
      # Configure the OpenStack driver
      #
      identity_url: http://192.168.56.11:5000/v2.0/tokens
      compute_name: nova
      protocol: ipv4
      compute_region: RegionOne
      # Configure Openstack authentication credentials
      #
      user: demo
      password: demo
      # tenant is the project name
      tenant: demo
     
      provider: openstack
      # skip SSL certificate validation (default false)
      insecure: false
     

    3 、检查配置:

    语法:

    salt-cloud --list-locations <provider_name>    查看可用的区域

    salt-cloud --list-p_w_picpaths <provider_name> 查看可用的镜像

    salt-cloud --list-sizes <provider_name> 查看可用的虚拟机大小

    例:查看可用的镜像

    salt-cloud --list-p_w_picpaths myopenstack -l debug

    myopenstack:provider配置文件中定义的ID

    -l debug :开启debug模式,方便定位和调试故障。

    [root@linux-node1 ~]# salt-cloud --list-p_w_picpaths myopenstack -l debug 
    [DEBUG   ] Reading configuration from /etc/salt/cloud
    [DEBUG   ] Reading configuration from /etc/salt/master
    [DEBUG   ] Using cached minion ID from /etc/salt/minion_id: linux-node1.example.com
    [DEBUG   ] Missing configuration file: /etc/salt/cloud.providers
    [DEBUG   ] Including configuration from '/etc/salt/cloud.providers.d/openstack.conf'
    [DEBUG   ] Reading configuration from /etc/salt/cloud.providers.d/openstack.conf
    [DEBUG   ] Missing configuration file: /etc/salt/cloud.profiles
    [DEBUG   ] Configuration file path: /etc/salt/cloud
    [WARNING ] Insecure logging configuration detected! Sensitive data may be logged.
    [INFO    ] salt-cloud starting
    [WARNING ] /usr/lib/python2.7/site-packages/novaclient/v1_1/__init__.py:30: UserWarning: Module novaclient.v1_1 is deprecated (taken as a basis for novaclient.v2). The preferable way to get client class or object you can find in novaclient.client module.
      warnings.warn("Module novaclient.v1_1 is deprecated (taken as a basis for "
    [DEBUG   ] Could not LazyLoad parallels.avail_sizes
     
    [DEBUG   ] LazyLoaded parallels.avail_locations
    [DEBUG   ] LazyLoaded proxmox.avail_sizes
    [DEBUG   ] Could not LazyLoad saltify.destroy
    [DEBUG   ] Could not LazyLoad saltify.avail_sizes
    [DEBUG   ] Could not LazyLoad saltify.avail_p_w_picpaths
    [DEBUG   ] Could not LazyLoad saltify.avail_locations
    [DEBUG   ] LazyLoaded rackspace.reboot
    [DEBUG   ] Could not LazyLoad openstack.list_locations
    [DEBUG   ] LazyLoaded rackspace.list_locations
    [DEBUG   ] OpenStack authenticating using password
    [DEBUG   ] LazyLoaded nested.output
    myopenstack:
        ----------
        openstack:
            ----------
            cirros:
                ----------
                driver:
                extra:
                    ----------
                    created:
                        2015-12-13T14:24:05Z
                    metadata:
                        ----------
                    minDisk:
                        0
     
                    minRam:
                        0
                    progress:
                        100
                    serverId:
                        None
                    status:
                        ACTIVE
                    updated:
                        2015-12-13T14:24:05Z
                get_uuid:
                id:
                    c503fb83-7d52-40e9-b1cc-4773e650986e
                name:
                    cirros
                uuid:
                    2986f30365f55599f838f656a51acdaec1fa81a2
            new:
                ----------
                driver:
                extra:
                    ----------
                    created:
                        2015-12-25T09:17:50Z
                    metadata:
                        ----------
                    minDisk:
     
                        0
                    minRam:
                        0
                    progress:
                        100
                    serverId:
                        None
                    status:
                        ACTIVE
                    updated:
                        2015-12-25T09:17:57Z
                get_uuid:
                id:
                    fdd664b3-ebf2-4904-815f-0d1cdf9955d4
                name:
                    new
                uuid:
                    9f4f8a437ebc8123c1a8725156ee91566928d9f0
     

    可以看到,当前有两个可用的镜像,cirros 和new ,并且可以看到更过镜像的信息。

    4、 编写profile配置文件,告诉salt-cloud创建虚拟机的细节,后期创建虚拟机时只需要调用该名字即可。

    [root@linux-node1 cloud.profiles.d]# vim openstack_web.conf
    web-node:
      provider: myopenstack
      size: m1.tiny
      p_w_picpath: new
      ssh_key_file: /root/.ssh/id_rsa
      ssh_key_name: mykey
      ssh_interface: private_ips
      networks:
        - fixed:
          - 2c4c9edc-dbb8-467c-bc67-a2c6ff23d885
      minion:
        master: 192.168.56.11
        grains: 
          role: webserver

     5 、创建虚拟机 

    [root@linux-node1 cloud.profiles.d]# salt-cloud -p web-node test -l debug

     -p 指定profile中虚拟机ID名称

     6 、查看验证:

    [root@linux-node1 ~]# nova list     
    --------------------+------+--------+------------+-------------+---------------------+
    | ID                              | Name | Status | Task State | Power State | Networks            |
    +-------------------+------+--------+------------+-------------+---------------------+
    | b4035529-6cd7-4b9b-a6e9-c63d5bfb2d4b | test | ACTIVE | -          | Running     | flat=192.168.56.118 |
    +-------------------+------+--------+------------+-------------+---------------------+

    通过上面的配置文件,salt-cloud不仅能够创建虚拟机,还能够在虚拟机里安装salt-minion,

    并自动添加到salt-master认证里面去(还设置了一个grains哦,很方便吧)

    ############################################################################################################3

    官方手册: https://docs.saltstack.com/en/latest/topics/cloud/openstack.html

    安装环境:
    172.16.1.211 salt-master服务器
    172.16.1.240 openstack控制节点

    ps: 下面都在salt-master操作

    1.安装插件:

    yum install salt-cloud python-libcloud

    2.创建salt-cloud配置文件:

    mkdir /etc/salt/cloud.providers.d/ 
    vim /etc/salt/cloud.providers.d/openstack.conf
    my-openstack-config:
    
      minion:
        master: 172.16.1.211
    
      identity_url: http://172.16.1.240:5000/v2.0/tokens
      compute_name: nova
      protocol: ipv4
    
      compute_region: RegionOne
    
      user: demo
      password: demo
    
      tenant: demo
    
      driver: openstack
      provider: openstack
    
      insecure: false

    3.查看镜像列表:

    salt-cloud --list-images openstack  #查看镜像列表
    salt-cloud --list-size openstack    #查看云主机类型

    4.创建Salt-cloud虚拟机模板文件:

    vim /etc/salt/cloud.profiles.d/web.conf
    web-node:                                     #虚拟机模板名称
      provider: my-openstack-config               #前面配置文件定义的
      size: m1.tiny                               #云主机类型
      image: cirros                               #镜像名称
      ssh_key_file: /root/.ssh/id_rsa             #公钥文件
      ssh_key_name: mykey                         #密钥对名称
      ssh_interface: private_ips
      networks:
        - fixed:
          - 69200e49-0f8b-47b6-9bb5-2db9bca9a393  #网络的ID
      minion:                                     #下面是自动给虚拟机安装salt-minion并配置
        master: 172.16.1.211
        grains:
          role: webserver-01

    4.通过Salt-cloud创建Openstack虚拟机:

    salt-cloud -p web-node web-test1 -l debug
    
    # -p: 虚拟机模板名称
    # web-test1: 创建虚拟机的名称
    # -l debug: 打印debug



  • 相关阅读:
    touch:创建文件及修改文件时间戳
    stat:查看文件时间参数
    获取二维数组里面实际存有数据的行数
    Math.Atan2 方法
    c#移位运算符("<<"及">>")
    c# 一维数组和二维数组的几种定义方式<转>
    C#异常处理总结
    C#图片灰度处理(位深度24→位深度8)、C#图片二值化处理(位深度8→位深度1)
    WinForm窗体及其控件的自适应
    C#的WinForm窗体美化
  • 原文地址:https://www.cnblogs.com/wuhg/p/10430940.html
Copyright © 2020-2023  润新知