使用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-images <provider_name> 查看可用的镜像
salt-cloud --list-sizes <provider_name> 查看可用的虚拟机大小
例:查看可用的镜像
salt-cloud --list-images myopenstack -l debug
myopenstack:provider配置文件中定义的ID
-l debug :开启debug模式,方便定位和调试故障。
[root@linux-node1 ~]# salt-cloud --list-images 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_images [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 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 创建虚拟机
[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哦,很方便吧)
更多细节请看官网地址:https://docs.saltstack.com/en/latest/topics/cloud/openstack.html
本文出自 “linux飞龙在天” 博客,转载请与作者联系!