User、Credentials、Authentication、Token、Project、Service、Endpoint、Role
部署openstack过程中需先部署Keystone
继OpenStack环境部署-初步搭建进一步部署
[root@ct ~]# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 28
Server version: 10.3.20-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> create database keystone;
Query OK, 1 row affected (0.003 sec)
MariaDB [(none)]> GRANT ALL PRIVILEGES ON keystone.* TO 'keystone'@'localhost' IDENTIFIED BY 'KEYSTONE_DBPASS';
Query OK, 0 rows affected (0.013 sec)
MariaDB [(none)]> GRANT ALL PRIVILEGES ON keystone.* TO 'keystone'@'%' IDENTIFIED BY 'KEYSTONE_DBPASS';
Query OK, 0 rows affected (0.000 sec)
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.004 sec)
MariaDB [(none)]> exit
Bye
1. 安装keystone、httpd、mod_wsgi
[root@ct ~]# yum -y install openstack-keystone httpd mode_wsgi
[root@ct ~]# cp -a /etc/keystone/keystone.conf{
,.bak}
[root@ct ~]# grep -Ev "^$|#" /etc/keystone/keystone.conf.bak > /etc/keystone/keystone.conf //通过pymysql模块访问mysql,指定用户名密码、数据库的域名、数据库名
[root@ct ~]# openstack-config --set /etc/keystone/keystone.conf database connection mysql+pymysql://keystone:KEYSTONE_DBPASS@ct/keystone //指定token的提供者;提供者就是keystone自己本身
[root@ct ~]# openstack-config --set /etc/keystone/keystone.conf token provider fernet
//Fernet:一种安全的消息传递格式
2. 初始化认证服务数据库
[root@ct ~]# su -s /bin/sh -c "keystone-manage db_sync" keystone
3. 初始化fernet 密钥存储库(以下命令会生成两个密钥,生成的密钥放于/etc/keystone/目录下,用于加密数据)
[root@ct ~]# keystone-manage fernet_setup --keystone-user keystone --keystone-group keystone
[root@ct ~]# keystone-manage credential_setup --keystone-user keystone --keystone-group keystone
4. 配置bootstrap身份认证服务
[root@ct ~]# keystone-manage bootstrap --bootstrap-password ADMIN_PASS \
> --bootstrap-admin-url http://ct:5000/v3/ \
> --bootstrap-internal-url http://ct:5000/v3/ \
> --bootstrap-public-url http://ct:5000/v3/ \
> --bootstrap-region-id RegionOne //指定一个区域名称
5. 配置Apache HTTP服务器
[root@ct ~]# echo "ServerName controller" >> /etc/httpd/conf/httpd.conf
6. 创建配置文件
安装完mod_wsgi包后,会生成 wsgi-keystone.conf 这个文件,文件中配置了虚拟主机及监听了5000端口,mod_wsgi就是python的网关
[root@ct ~]# ln -s /usr/share/keystone/wsgi-keystone.conf /etc/httpd/conf.d/
7. 开启服务
[root@ct ~]# systemctl enable httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
[root@ct ~]# systemctl start httpd
[root@ct ~]# systemctl status httpd
● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
Active: active (running) since 四 2021-02-18 16:04:16 CST; 14s ago
Docs: man:httpd(8)
man:apachectl(8)
Main PID: 21557 (httpd)
Status: "Total requests: 0; Current requests/sec: 0; Current traffic: 0 B/sec"
CGroup: /system.slice/httpd.service
├─21557 /usr/sbin/httpd -DFOREGROUND
├─21558 (wsgi:keystone- -DFOREGROUND
├─21559 (wsgi:keystone- -DFOREGROUND
├─21560 (wsgi:keystone- -DFOREGROUND
├─21561 (wsgi:keystone- -DFOREGROUND
├─21562 (wsgi:keystone- -DFOREGROUND
├─21567 /usr/sbin/httpd -DFOREGROUND
├─21570 /usr/sbin/httpd -DFOREGROUND
├─21574 /usr/sbin/httpd -DFOREGROUND
├─21578 /usr/sbin/httpd -DFOREGROUND
└─21582 /usr/sbin/httpd -DFOREGROUND
2月 18 16:04:16 ct systemd[1]: Starting The Apache HTTP Server...
2月 18 16:04:16 ct systemd[1]: Started The Apache HTTP Server.
8. 配置管理员账户的环境变量
[root@ct ~]# cat >> ~/.bashrc << EOF
> export OS_USERNAME=admin //控制台登陆用户名
> export OS_PASSWORD=ADMIN_PASS //控制台登陆密码
> export OS_PROJECT_NAME=admin
> export OS_USER_DOMAIN_NAME=Default
> export OS_PROJECT_DOMAIN_NAME=Default
> export OS_AUTH_URL=http://ct:5000/v3
> export OS_IDENTITY_API_VERSION=3
> export OS_IMAGE_API_VERSION=2
> EOF
[root@ct ~]# source ~/.bashrc
9. 通过配置环境变量,可以使用openstack命令进行一些操作,示例:
[root@ct ~]# openstack user list
+----------------------------------+-------+
| ID | Name |
+----------------------------------+-------+
| 09a752a6b18d48f2ae1f472599e94c5a | admin |
+----------------------------------+-------+
1. 创建一个项目(project),创建在指定的domain(域)中,指定描述信息,project名称为service(可使用openstack domain list 查询)
[root@ct ~]# openstack project create --domain default --description "Service Project" service
+-------------+----------------------------------+
| Field | Value |
+-------------+----------------------------------+
| description | Service Project |
| domain_id | default |
| enabled | True |
| id | 70a6fc6eb82f48dfa3d66d5389dcea3e |
| is_domain | False |
| name | service |
| options | {
} |
| parent_id | default |
| tags | [] |
+-------------+----------------------------------+
2. 创建角色(可使用openstack role list查看)
[root@ct ~]# openstack project create --domain default --description "Service Project" service
+-------------+----------------------------------+
| Field | Value |
+-------------+----------------------------------+
| description | Service Project |
| domain_id | default |
| enabled | True |
| id | 70a6fc6eb82f48dfa3d66d5389dcea3e |
| is_domain | False |
| name | service |
| options | {
} |
| parent_id | default |
| tags | [] |
+-------------+----------------------------------+
[root@ct ~]# openstack role create user
+-------------+----------------------------------+
| Field | Value |
+-------------+----------------------------------+
| description | None |
| domain_id | None |
| id | d0e42f995f29415c87705af0e7754ddc |
| name | user |
| options | {
} |
+-------------+----------------------------------+
3. 查看openstack 角色列表
[root@ct ~]# openstack role list
+----------------------------------+--------+
| ID | Name |
+----------------------------------+--------+
| 06feb1be0b964169bffa214af2435c56 | reader |
| 34755268537741189a3f9242010e1e68 | member |
| d0e42f995f29415c87705af0e7754ddc | user |
| d9523d7587d54236ab48b6e9f1e7462f | admin |
+----------------------------------+--------+
admin为管理员
member为 租户
user:用户
4. 查看是否可以不指定密码就可以获取到token信息(验证认证服务)
[root@ct ~]# openstack token issue
+------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Field | Value |
+------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| expires | 2021-02-18T09:27:10+0000 |
| id | gAAAAABgLiTedvBu5lIbeJPJ-gUoWoIJx_NpRWcaTFjWf-oN_x5q6AhkYN0WUBvlLKR8nO9RJRJmczdvOlD9h7Kl-Cp-d3Fvd3knzrhY8nEKKW2TA16JTd6KmN9UeczQtQL9nLJn5wnum8AQ6OLp_mfYukFMC7tlBKDfYa8Eugxoj164BwTfeTg |
| project_id | 667d2c1d9fca46a690b830e6864580c9 |
| user_id | 09a752a6b18d48f2ae1f472599e94c5a |
+------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
至此,keystone部署完成
Keystone 组件是作为OpenStack 集群中统一认证、授权的模块,其核心功能就是针对于User(用户)、Tenant(租户)、Role(角色)、Token(令牌/凭证)的控制(手工编译部署即围绕此功能展开的)