2341rtw 发表于 2016-1-22 09:16:55

使用salt-cloud创建openstack虚拟机

众所周知,saltstack有三大功能:远程执行、配置管理、云管理。其中的云管理就是通过salt-cloud完成的。salt-cloud能够管理很多云环境(公有云、私有云),连大名鼎鼎的阿里云也可以通过salt-cloud来创建虚拟机哦。    本次主要讲解使用salt-cloud管理openstack(L版)私有云来创建虚拟机。(前提openstack环境运行正常,能正常创建虚拟机)

1 安装saltstack

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





安装依赖包:

1
yum install python-libcloud -y




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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# pwd
/etc/salt/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





1
2
3
provider: openstack
# skip SSL certificate validation (default false)
insecure: false





3
检查配置:
语法:
salt-cloud --list-locations <provider_name>    查看可用的区域
salt-cloud --list-images <provider_name>       查看可用的镜像
salt-cloud --list-sizes <provider_name>               查看可用的虚拟机大小

例:查看可用的镜像

1
salt-cloud --list-images myopenstack -l debug




        myopenstack:provider配置文件中定义的ID
        -l debug :开启debug模式,方便定位和调试故障。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# salt-cloud --list-images myopenstack -l debug
Reading configuration from /etc/salt/cloud
Reading configuration from /etc/salt/master
Using cached minion ID from /etc/salt/minion_id: linux-node1.example.com
Missing configuration file: /etc/salt/cloud.providers
Including configuration from '/etc/salt/cloud.providers.d/openstack.conf'
Reading configuration from /etc/salt/cloud.providers.d/openstack.conf
Missing configuration file: /etc/salt/cloud.profiles
Configuration file path: /etc/salt/cloud
Insecure logging configuration detected! Sensitive data may be logged.
salt-cloud starting
/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 "
Could not LazyLoad parallels.avail_sizes





1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
LazyLoaded parallels.avail_locations
LazyLoaded proxmox.avail_sizes
Could not LazyLoad saltify.destroy
Could not LazyLoad saltify.avail_sizes
Could not LazyLoad saltify.avail_images
Could not LazyLoad saltify.avail_locations
LazyLoaded rackspace.reboot
Could not LazyLoad openstack.list_locations
LazyLoaded rackspace.list_locations
OpenStack authenticating using password
LazyLoaded nested.output
myopenstack:
    ----------
    openstack:
      ----------
      cirros:
            ----------
            driver:
            extra:
                ----------
                created:
                  2015-12-13T14:24:05Z
                metadata:
                  ----------
                minDisk:
                  0





1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
                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:





1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
                  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创建虚拟机的细节,后期创建虚拟机时只需要调用该名字即可。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# vim openstack_web.conf
web-node:
provider: myopenstack
size: m1.tiny
image: 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 创建虚拟机

1
# salt-cloud -p web-node test -l debug




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

6 查看验证:

1
2
3
4
5
6
# 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哦,很方便吧)

更多细节请看官网地址:https://docs.saltstack.com/en/latest/topics/cloud/openstack.html

页: [1]
查看完整版本: 使用salt-cloud创建openstack虚拟机