OpenStack学习之三——控制节点安装身份验证服务keystone

153 阅读4分钟

KeyStone服务安装于控制节点

The Identity service is typically the first service a user interacts with. Once authenticated, an end user can use their identity to access other OpenStack services. Likewise, other OpenStack services leverage the Identity service to ensure users are who they say they are and discover where other services are within the deployment. The Identity service can also integrate with some external user management systems (such as LDAP).

身份验证服务通常是用户与之交互的第一个服务。一旦通过身份验证,最终用户就可以使用他们的身份访问其他 OpenStack 服务。同样,其他 OpenStack 服务利用身份验证服务来确保用户的身份,并发现部署中其他服务的位置。身份验证服务还可以与一些外部用户管理系统(比如 LDAP)集成。

换句话说,keystone服务是整个openstack集群的大门。


下面开始安装keystone服务,(For scalability purposes, this configuration deploys Fernet tokens and the Apache HTTP server to handle requests.) 出于可伸缩性的考虑,这种配置使用 Fernet 令牌和 Apache HTTP Server 来处理请求。


安装之前的配置

在安装之前,必须要现在mysql数据库中床创建名为keystone的数据库,并且设置用户及其密码。

1、连接数据库

mysql -u root -p
# 由于测试环境的mysql没有设置root密码,也可以用下面命令进入mysql
mysql

2、创建数据库

MariaDB [(none)]> CREATE DATABASE keystone;

3、设置keystone数据库的用户名和密码,在此我设置为123456

MariaDB [(none)]> GRANT ALL PRIVILEGES ON keystone.* TO 'keystone'@'localhost' \
IDENTIFIED BY '123456';
MariaDB [(none)]> GRANT ALL PRIVILEGES ON keystone.* TO 'keystone'@'%' \
IDENTIFIED BY '123456';

这些操作完成之后,就可以开始安装keystone了。

开始安装

1、安装keystone服务和apache的wsgi模块。 openstack的keystone是使用python2开发的,所以使用wsgi来管理服务

yum install openstack-keystone httpd mod_wsgi

2、对keystone服务进行配置,配置文件位于/etc/keystone/keystone.conf,修改内容如下

[database]
# ...
connection = mysql+pymysql://keystone:123456@controller/keystone  # 记得将数据库密码换成上面设置的密码
[token]
# ...
provider = fernet

3、配置修改完成之后,将数据库初始化

su -s /bin/sh -c "keystone-manage db_sync" keystone

完成后查看数据库,发现keystone数据库中会新建一些表,如图:

image.png

4、初始化Fernet密钥仓库

keystone-manage fernet_setup --keystone-user keystone --keystone-group keystone
keystone-manage credential_setup --keystone-user keystone --keystone-group keystone

5、初始化认证服务,切记将--bootstrap-password参数的值设置为文章开始设置的数据库密码

keystone-manage bootstrap --bootstrap-password 123456 \
  --bootstrap-admin-url http://controller:5000/v3/ \
  --bootstrap-internal-url http://controller:5000/v3/ \
  --bootstrap-public-url http://controller:5000/v3/ \
  --bootstrap-region-id RegionOne

6、配置httpd(apached)服务。修改/etc/httpd/conf/httpd.conf,写入如下内容

ServerName controller

然后将keystone的wsgi配置文件软连接到httpd的配置文件中。

ln -s /usr/share/keystone/wsgi-keystone.conf /etc/httpd/conf.d/

7、设置httpd开机启动,并启动服务,由于keystone服务由httpd的wsgi_mod管理,所以启动httpd后,会调起keystone服务,并且httpd将管理keystone服务的生命周期。在openstack中,很多服务都是由此种方式运行及管理的。

systemctl enable httpd.service
systemctl start httpd.service

执行上述命令后,执行systemctl status httpd 即可查看服务状态,如果安装成功,则如下图所示,其中红框部分,即为httpd-wsgi管理的keystone服务

2d6c579c0f9e72d3b80b8d640a39d7d.jpg 8、配置授权文件, 这是最后一步,将下面内容写入/root/admin-openrc记得将OS_PASSWORD项的值,也就是第二行设置为文章开始设置的数据库密码

export OS_USERNAME=admin
export OS_PASSWORD=123456
export OS_PROJECT_NAME=admin
export OS_USER_DOMAIN_NAME=Default
export OS_PROJECT_DOMAIN_NAME=Default
export OS_AUTH_URL=http://controller:5000/v3
export OS_IDENTITY_API_VERSION=3

至此,安装完成


KeyStone简单使用

1、创建一个domain(域)

openstack domain create --description "An Example Domain" example

1660926493557.png 如上图所示即为成功

2、创建一个项目,该项目属于default域 his guide uses a service project that contains a unique user for each service that you add to your environment. Create the service project:(本指南使用一个服务项目,该项目为您添加到环境中的每个服务都包含一个唯一的用户。创建服务项目:)

openstack project create --domain default --description "Service Project" service

1660926660309.png

3、创建非管理员项目和用户

 openstack project create --domain default --description "Demo Project" myproject

执行openstack project list可看到如下输出,有admin、myproject、service三个项目

image.png

4、创建用户

openstack user create --domain default --password-prompt myuser

image.png 如上图,创建用户时需要设置密码,并且需要输入两次以确保输入无误,为方便测试,我将密码设为了123456

5、创建一个角色

openstack role create myrole

6、授权myproject项目给myuser用户和myrole组

openstack role add --project myproject --user myuser myrole

彻底完结撒花