可以说大多数人都听过云计算,如阿里云、亚马逊云、华为云、腾讯云、百度云等。是不是觉得非常高大上呢?其实这些云厂商他们或自己开发平台或在openstack基础上二次开发,阿里自研开发的平台我们望尘莫及,但是其他国内厂商基本都是openstack基础上二次开发的,所以我们只要掌握了openstack的相关技术,自己就可以搭建一个自己的云平台。
下面我就给大家介绍一下如果在Linux环境用openstack搭建云平台。
一、Openstack基本概念
OpenStack是一个开源的云计算管理平台项目,由几个主要的组件组合起来完成:
Dashboard(web项目)Keystone(权限管理)Nova(管理虚拟机)Nova-network(管理网络流量和ip)Glance(镜像管理项目)Cinder(磁盘管理)Swift(网盘,对象)、
二、准备工作
需要准备3台linux的机器,配置IP地址,关闭防火墙,修改主机名。
• Controller Node: 1 processor, 2 GB memory, and 5 GB storage
• Compute01: 1 processor, 512 MB memory, and 5 GB storage
• Compute02 Node: 1 processor, 2 GB memory, and 10 GB storage
我这里controller的ip地址是:192.168.1.2
computer01:192.168.1.3
computer02:192.168.1.4
基本环境配置
以下内容是在controller机器上配置的。
1、数据库安装。
因为需要一个数据库,所以这里选用了mysql数据库。
yum install mysql mysql-server MySQL-python
编辑/etc/my.cnf文件,在里面添加如下内容,主要意思就是设置编码为utf-8。
default-storage-engine = innodbinnodb_file_per_tablecollation-server = utf8_general_ciinit-connect = 'SET NAMES utf8'character-set-server = utf8
然后启动服务,开机启动。
# service mysqld start# chkconfig mysqld on# mysql_install_db# mysql_secure_installation
赋权,使其可以远程登录。
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'a';
2、openstack基本包安装。
# yum install yum-plugin-priorities # yum install http://repos.fedorapeople.org/repos/openstack/openstackicehouse/rdo-release-icehouse-3.noarch.rpm # yum install http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm # yum install openstack-utils # yum install openstack-selinux
3、安装消息队列
yum install qpid-cpp-server
启动服务
service qpidd startchkconfig qpidd on
权限认证服务(keystone)
安装权限认证服务:
yum install openstack-keystone python-keystoneclient -y
创建用户,写入到配置文件中:
openstack-config --set /etc/keystone/keystone.conf \database connection mysql://keystone:KEYSTONE_DBPASS@controller/keystone
创建keystone数据库表:
$ mysql -u root -pmysql> CREATE DATABASE keystone;mysql> GRANT ALL PRIVILEGES ON keystone.* TO 'keystone'@'localhost' \IDENTIFIED BY 'KEYSTONE_DBPASS';mysql> GRANT ALL PRIVILEGES ON keystone.* TO 'keystone'@'%' \IDENTIFIED BY 'KEYSTONE_DBPASS';mysql> exit
自动生成表:
su -s /bin/sh -c "keystone-manage db_sync" keystone
设置用户环境变量:
ADMIN_TOKEN=$(openssl rand -hex 10)echo $ADMIN_TOKENopenstack-config --set /etc/keystone/keystone.conf DEFAULT \admin_token $ADMIN_TOKEN # keystone-manage pki_setup --keystone-user keystone --keystone-group keystone# chown -R keystone:keystone /etc/keystone/ssl# chmod -R o-rwx /etc/keystone/ssl
启动keystone服务:
service openstack-keystone startchkconfig openstack-keystone on
将admin_token设置到环境变量中去。
export OS_SERVICE_TOKEN=$ADMIN_TOKENexport OS_SERVICE_ENDPOINT=http://controller:35357/v2.0
创建管理员用户,默认的用户名为admin,密码为ADMIN_PASS,你可以自定义修改:
[root@controller keystone]# keystone user-create --name=admin --pass=ADMIN_PASS --email=ADMIN_EMAIL+----------+----------------------------------+| Property | Value |+----------+----------------------------------+| email | ADMIN_EMAIL|| enabled | True ||id| 332f5ecb18c64bf687b154facd629fb6 || name | admin || username | admin |+----------+----------------------------------+[root@controller keystone]# keystone role-create --name=admin+----------+----------------------------------+| Property | Value |+----------+----------------------------------+|id| ab5da2c50d7443efb0514e84c2b4adb7 || name | admin |+----------+----------------------------------+[root@controller keystone]# keystone tenant-create --name=admin --description="Admin Tenant"+-------------+----------------------------------+| Property | Value |+-------------+----------------------------------+| description | Admin Tenant || enabled | True || id | b89723a38b154eeea6416a83b293b0ad || name| admin |+-------------+----------------------------------+[root@controller keystone]# keystone user-role-add --user=admin --tenant=admin --role=admin[root@controller keystone]# keystone user-role-add --user=admin --role=_member_ --tenant=admin[root@controller keystone]#
创建一个权限认证服务,因为我这里的主机名是controller,所以下面有 http://controller:35357/v2.0 这些信息,可以自定义修改:
[root@controller keystone]# keystone service-create --name=keystone --type=identity \> --description="OpenStack Identity"+-------------+----------------------------------+| Property | Value |+-------------+----------------------------------+| description |OpenStack Identity|| enabled | True || id | 4bfd5f39b86c45edb92d5c0488987dd8 || name| keystone || type| identity |+-------------+----------------------------------+[root@controller keystone]# keystone endpoint-create \> --service-id=$(keystone service-list | awk '/ identity / {print $2}') \> --publicurl=http://controller:5000/v2.0 \> --internalurl=http://controller:5000/v2.0 \> --adminurl=http://controller:35357/v2.0+-------------+----------------------------------+| Property | Value |+-------------+----------------------------------+| adminurl | http://controller:35357/v2.0 || id | 0350b72901a141498fe48304b13a1b98 || internalurl | http://controller:5000/v2.0|| publicurl | http://controller:5000/v2.0||region |regionOne || service_id | 4bfd5f39b86c45edb92d5c0488987dd8 |+-------------+----------------------------------+[root@controller keystone]# keystone user-create --name=demo --pass=DEMO_PASS --email=DEMO_EMAIL+----------+----------------------------------+| Property | Value |+----------+----------------------------------+| email |DEMO_EMAIL|| enabled | True ||id| b44a9a1462d74f4e928b3b339289a2ae || name | demo || username | demo |+----------+----------------------------------+[root@controller keystone]# keystone tenant-create --name=demo --description="Demo Tenant"+-------------+----------------------------------+| Property | Value |+-------------+----------------------------------+| description | Demo Tenant|| enabled | True || id | 7bd79509ee184a2098ca0644679b60a8 || name| demo |+-------------+----------------------------------+[root@controller keystone]# keystone user-role-add --user=demo --role=_member_ --tenant=demo[root@controller keystone]#
为了方便我们取到token,我们可以vi admin-openrc.sh,然后添加如下内容:
export OS_USERNAME=adminexport OS_PASSWORD=ADMIN_PASSexport OS_TENANT_NAME=adminexport OS_AUTH_URL=http://controller:35357/v2.0
在每次关机重启之后都要重新执行下面的命令,让环境变量起作用。否则会报”Expecting an auth URL via either –os-auth-url or env[OS_AUTH_URL]”的错误:
source admin-openrc.sh
我们可以使用下面的命令查看keystone目前的用户有哪些:
keystone user-list
测试效果:
打开restclient-ui-3.5-jar-with-dependencies.jar来测试效果:
url地址是: http://192.168.1.2:5000/v2.0/