salt-cloud也是基于openstack来做的,它可以支持多种云的使用。比如:Aliyun、Azure、DigitalOcean、EC2、Google Compute Engine、HP Cloud、OpenStack、等等
废话不说直接看如何部署
安装相关组件和依赖包
[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
执行后,可以在web界面看见创建的虚拟机node1,但是有个问题没有解决,就是可以远程,但是6080 vnc不能使用。。。。。。。。后续解决。。。。
参考内容
https://docs.saltstack.com/en/latest/topics/cloud/openstack.html#configuration