一. 基础环境
1.1环境介绍
- linux-node1(控制节点)
#系统版本
[root@linux-node1 ~]# cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)
#内核版本
[root@linux-node1 ~]# uname -r
3.10.-327.36..el7.x86_64
#主机名
[root@linux-node1 ~]# hostname
linux-node1.example.com
#IP地址
[root@linux-node1 ~]# ifconfig eth0 |awk -F '[ :]+' 'NR ==2 {print $3}'
192.168.56.11
- linux-node2(计算节点)
#系统版本
[root@linux-node2 ~]# cat /etc/redhat-release
CentOS Linux release 7.2. (Core)
#内核版本
[root@linux-node2 ~]# uname -r
3.10.-327.36..el7.x86_64
#主机名
[root@linux-node2 ~]# hostname
linux-node2.example.com
#IP地址
[root@linux-node2 ~]# ifconfig eth0 |awk -F '[ :]+' 'NR ==2 {print $3}'
192.168.56.12
1.2准备环境
1.2.1安装在两个节点
#openstack N版 仓库
[root@linux-node1 ~]# yum install centos-release-openstack-newton –y
#openstack客户端
[root@linux-node1 ~]# yum install python-openstackclient –y
#如果没有关闭selinux安装这个包会自动设置selinux支持openstack
[root@linux-node1 ~]# yum install openstack-selinux –y
1.2.2node1上安装数据库、消息队列、缓存
#安装数据库
[root@linux-node1 ~]# yum install mariadb mariadb-server python2-PyMySQL –y
#安装rabbitMQ消息队列
[root@linux-node1 ~]# yum install rabbitmq-server
#安装缓存
[root@linux-node1 ~]# yum install memcached python-memcached
1.2.3配置mariadb数据库
#编辑数据库配置文件
[root@linux-node1 ~]# vim /etc/my.cnf.d/openstack.cnf
[mysqld]
#监听地址
bind-address = 192.168.56.11
#默认引擎
default-storage-engine = innodb
innodb_file_per_table
#最大连接数
max_connections =
#核对字符集
collation-server = utf8_general_ci
#字符集
character-set-server = utf8
#启动数据库
[root@linux-node1 ~]# systemctl start mariadb.service
#设置密码并配置
[root@linux-node1 ~]# mysql_secure_installation
1.2.4配置rabbitMQ消息队列
#允许开机自启
[root@linux-node1 ~]# systemctl enable rabbitmq-server.service
#启动
[root@linux-node1 ~]# systemctl start rabbitmq-server.service
#添加用户
[root@linux-node1 ~]# rabbitmqctl add_user openstack openstack
Creating user "openstack" ...
#设置权限
[root@linux-node1 ~]# rabbitmqctl set_permissions openstack ".*" ".*" ".*"
Setting permissions for user "openstack" in vhost "/" ...
#重启
[root@linux-node1 ~]# rabbitmq-plugins enable rabbitmq_management
1.2.5配置memcache缓存
#修改memcache配置文件
[root@linux-node1 ~]# vim /etc/sysconfig/memcached
#memcache连接地址
OPTIONS="-l 192.168.56.11,::1"
#重启memcache
[root@linux-node1 ~]# systemctl restart memcached
注意:两个节点必须时间同步
#同步时间
[root@linux-node1 ~]# ntpdate time1.aliyun.com
二.openstack认证服务keystone
2.1keystone介绍
- keystone
Keystone(OpenStack Identity Service)是 OpenStack 框架中负责管理身份验证、服务规则和服务令牌功能的模块。用户访问资源需要验证用户的身份与权限,服务执行操作也需要进行权限检测,这些都需要通过 Keystone 来处理。
用户认证:用户权限与用户行为跟踪
服务目录:提供一个服务目录,包括所有服务项与相关API的端点
主要涉及如下概念:
User: 用户
Project: 项目(老版本中tenant:租户)
Token: 令牌
Role: 角色
2.2keystone配置
2.2.1安装keystone及其组件
#安装keystone、wsgi模块、http
[root@linux-node1 ~]# yum install openstack-keystone httpd mod_wsgi –y
2.2.2创建库及用户并授权
#登陆数据库
[root@linux-node1 ~]# mysql -uroot –p
#创建keystone库
MariaDB [(none)]> create database keystone;
#创建keystone用户并授权
MariaDB [(none)]> grant all privileges on keystone.* to keystone@'localhost' identified by 'keystone';
Query OK, rows affected (0.00 sec)
MariaDB [(none)]> grant all privileges on keystone.* to keystone@'%' identified by 'keystone';
Query OK, rows affected (0.00 sec)
2.2.3编辑keystone配置文件
#编辑配置文件
[root@linux-node1 ~]# vim /etc/keystone/keystone.conf
#database标签下添加内容
[database]
#数据库连接
connection = mysql+pymysql://keystone:keystone@192.168.56.11/keystone
#在memcache标签下添加内容
[memcache]
#memcache服务IP
servers = 192.168.56.11:
#配置令牌
provider = fernet
#选择driver为memcache默认是sql
driver = memcache
2.2.4导入数据库
#将表导入数据库中
[root@linux-node1 ~]# su -s /bin/sh -c "keystone-manage db_sync" keystone
#检查导入结果
[root@linux-node1 ~]# mysql -h 192.168.56.11 -ukeystone -pkeystone -e "use keystone;show tables;"
+------------------------+
| Tables_in_keystone |
+------------------------+
| access_token |
| assignment |
| config_register |
| consumer |
| credential |
| endpoint |
| endpoint_group |
| federated_user |
| federation_protocol |
| group |
| id_mapping |
| identity_provider |
| idp_remote_ids |
| implied_role |
| local_user |
| mapping |
| migrate_version |
| nonlocal_user |
| password |
| policy |
| policy_association |
| project |
| project_endpoint |
| project_endpoint_group |
| region |
| request_token |
| revocation_event |
| role |
| sensitive_config |
| service |
| service_provider |
| token |
| trust |
| trust_role |
| user |
| user_group_membership |
| whitelisted_config |
+------------------------+
2.2.5初始化key并创建endpoint
#初始化令牌
[root@linux-node1 keystone]# keystone-manage fernet_setup --keystone-user keystone --keystone-group keystone
[root@linux-node1 keystone]# keystone-manage credential_setup --keystone-user keystone --keystone-group keystone
#引导身份服务,创建endpoint
[root@linux-node1 keystone]# keystone-manage bootstrap --bootstrap-password admin \
--bootstrap-admin-url http://192.168.56.11:35357/v3/ \
--bootstrap-internal-url http://192.168.56.11:35357/v3/ \
--bootstrap-public-url http://192.168.56.11:5000/v3/ \
--bootstrap-region-id RegionOne
2.2.6配置apache
#编辑配置文件
[root@linux-node1 keystone]# vim /etc/httpd/conf/httpd.conf
#服务监听地址
ServerName 192.168.56.11:
#软连接配置文件
[root@linux-node1 ~]# ln -s /usr/share/keystone/wsgi-keystone.conf /etc/httpd/conf.d/
#设置开机自启
[root@linux-node1 ~]# systemctl enable httpd.service
#启动apache
[root@linux-node1 ~]# systemctl start httpd.service
2.2.7添加环境变量
#编辑环境变量
[root@linux-node1 ~]# vim /root/.openstackrc
export OS_USERNAME=admin
export OS_PASSWORD=admin
export OS_PROJECT_NAME=admin
export OS_USER_DOMAIN_NAME=Default
export OS_PROJECT_DOMAIN_NAME=Default
export OS_AUTH_URL=http://192.168.56.11:35357/v3
export OS_IDENTITY_API_VERSION=
2.2.8查看列表
#刷新环境变量
[root@linux-node1 ~]# source /root/.openstackrc
#查看用户列表
[root@linux-node1 ~]# openstack user list
+----------------------------------+---------+
| ID | Name |
+----------------------------------+---------+
| 45b086bdc6b746c5b0bfd62f779fe6a5 | admin |
+----------------------------------+---------+
#查看角色列表
[root@linux-node1 ~]# openstack role list
+----------------------------------+----------+
| ID | Name |
+----------------------------------+----------+
| 44246e18d57b4f0ea6470aa56951bc08 | admin |
+----------------------------------+----------+
#查看项目列表
[root@linux-node1 ~]# openstack project list
+----------------------------------+---------+
| ID | Name |
+----------------------------------+---------+
| d24a61dd3ecb43cb9e8a5f6539c6a2bb | admin |
+----------------------------------+---------+
#查看端点列表
[root@linux-node1 ~]# openstack endpoint list
+----------------------------------+-----------+--------------+--------------+---------+-----------+----------------------------------------------+
| ID | Region | Service Name | Service Type | Enabled | Interface | URL |
+----------------------------------+-----------+--------------+--------------+---------+-----------+----------------------------------------------+
| 46bb270ff4f04b0da6a69a554322bc27 | RegionOne | keystone | identity | True | public | http://192.168.56.11:5000/v3/ |
| 77bca853dafb413da29dcbac4bed9305 | RegionOne | keystone | identity | True | admin | http://192.168.56.11:35357/v3/ |
| 7cc4f83fc4f34cf9b1ec5033739aefc1 | RegionOne | keystone | identity | True | internal | http://192.168.56.11:35357/v3/ |
+----------------------------------+-----------+--------------+--------------+---------+-----------+----------------------------------------------+
三.创建项目、角色
3.1创建服务项目
#创建service项目
[root@linux-node1 ~]# openstack project create --domain default --description "Service Project" service
+-------------+----------------------------------+
| Field | Value |
+-------------+----------------------------------+
| description | Service Project |
| domain_id | default |
| enabled | True |
| id | 1c86a7e5bd014ef98b13a88c94a5fbda |
| is_domain | False |
| name | service |
| parent_id | default |
+-------------+----------------------------------+
#查看项目列表
[root@linux-node1 ~]# openstack project list
+----------------------------------+---------+
| ID | Name |
+----------------------------------+---------+
| 1c86a7e5bd014ef98b13a88c94a5fbda | service |
| d24a61dd3ecb43cb9e8a5f6539c6a2bb | admin |
+----------------------------------+---------+
3.2创建角色
#创建user角色
[root@linux-node1 ~]# openstack role create user
+-----------+----------------------------------+
| Field | Value |
+-----------+----------------------------------+
| domain_id | None |
| id | e01254bb6613443895d33af96faa3fe9 |
| name | user |
+-----------+----------------------------------+
#查看角色列表
[root@linux-node1 ~]# openstack role list
+----------------------------------+----------+
| ID | Name |
+----------------------------------+----------+
| 44246e18d57b4f0ea6470aa56951bc08 | admin |
| e01254bb6613443895d33af96faa3fe9 | user |
+----------------------------------+----------+
四.keystone常见错误介绍
401 :验证失败,keystone相关用户账户密码设置错误,时间不同步,或者输入的项目名称不对
403 :可能未初始化OS_token变量,需要使用source命令使其生效,也可能是配置的配置文件未生效,需要重启相关服务
409 :keystone创建用户,用户已存在
500 :服务器内部错误,服务配置有问题,看日志,检查配置
503 :keystone相关账户密码设置有问题,请将相关的glance账户删除,重新创建即可
【开源是一种精神,分享是一种美德】
— By GoodCook
— 笔者QQ:253097001
— 欢迎大家随时来交流
—原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。