《云操作系统(OpenStack)第二版》学习笔记04-第四章:认证服务Keystone

《云操作系统(OpenStack)第二版》学习笔记04-第四章:认证服务Keystone

对着《云操作系统(OpenStack)》第四章做的。

一、4.1 Keystone基本概念

应该是只用在控制节点上安装,因为要用到数据库,而数据库只在控制节点上安装了。

二、4.2 keystone数据库操作

前面环境准备的时候给数据库设置的密码是123456,但是书上的密码是000000,为了保持统一,使用mysql_secure_installation重新配置密码,设置为000000
a## 登录MySQL数据库

  1. mysql -uroot -p000000 

这个密码是在安装数据库的时候创建的。

1. 创建Keystone数据库

  1. CREATE DATABASE keystone; 

enter description here
enter description here

2. 设置授权用户和密码

  1. GRANT ALL PRIVILEGES ON keystone.* TO 'keystone'@'%' IDENTIFIED BY '000000'; 
  2. GRANT ALL PRIVILEGES ON keystone.* TO 'keystone'@'localhost' IDENTIFIED BY '000000'; 
  3. exit 

enter description here
enter description here

三、4.3 安装并配置Keystone

1. 安装Keystone所需软件包

  1. yum install openstack-keystone httpd mod_wsgi -y 

enter description here
enter description here

2. 编辑/etc/keystone/keystone.conf文件

进行如下配置

2-1. 配置数据库连接

文件的600行左右

  1. [database] 
  2. connection = mysql+pymysql://keystone:000000@controller/keystone 

2-2. 配置provider

文件的2109行左右

  1. [token] 
  2. provider = fernet 

2-3. 同步数据库

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

2-4. 进入Keystone数据库查看数据表

  1. mysql -uroot -p000000; 
  2. use keystone; 
  3. show tables; 
  4. exit 

enter description here
enter description here

看到有数据表,说明同步成功。

2-5. 初始化密钥

  1. keystone-manage fernet_setup --keystone-user keystone --keystone-group keystone 
  2. keystone-manage credential_setup --keystone-user keystone --keystone-group keystone 

2-6. 引导开启身份服务

  1. keystone-manage bootstrap --bootstrap-password 000000 --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 

enter description here
enter description here

四、4.4 配置Apache服务

1. 编辑/etc/httpd/conf/httpd.conf文件

1-1. 添加ServerName

在96行左右

  1. ServerName controller 

1-2. 创建/usr/share/keystone/wsgi-keystone.conf文件链接

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

会在etc/httpd/confi.d/下面创建一个wsgi-keystone.conf的文件链接。
enter description here

1-3. 启动Apache HTTP服务并设置开机自启动

  1. systemctl enable httpd 
  2. systemctl start httpd 

五、4.5 初次验证

1. 配置环境变量

以下配置的是临时变量

  1. export OS_PROJECT_DOMAIN_NAME=Default 
  2. export OS_USER_DOMAIN_NAME=Default 
  3. export OS_PROJECT_NAME=admin 
  4. export OS_USERNAME=admin 
  5. export OS_PASSWORD=000000 
  6. export OS_AUTH_URL=http://controller:5000/v3 
  7. export OS_IDENTITY_API_VERSION=3 
  8. export OS_IMAGE_API_VERSION=2 

2. 首次验证

  1. openstack token issue 

enter description here
enter description here

六、4.6 创建Domain、Project、User、Role

1. 创建新域(Domain)

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

enter description here
enter description here

2. 创建新项目(Project)

2-1. 创建Service项目

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

enter description here
enter description here

2-2. 创建普通项目

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

enter description here
enter description here

3. 创建新用户(User)

执行以下命令,然后要给这个用户创建密码,我这里设置的密码是000000

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

enter description here
enter description here

4. 创建新角色(Role)

  1. openstack role create myrole 

enter description here
enter description here

5. 进行关联

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

enter description here
enter description here

七、4.7 验证keystone服务

1. 使用以下命令使指定的临时环境变量不生效

  1. unset OS_TOKEN OS_URL 

2. 使用admin用户来请求身份验证令牌

执行以下命令,书上说然后需要输入两遍密码,就是上面配置环境变量时给admin所设置的密码,我这里是000000,但是实际中我这里并没有让我输入密码。

  1. openstack --os-auth-url http://controller:5000/v3 --os-project-domain-name Default --os-user-domain-name Default --os-project-name admin --os-username admin token issue 

enter description here
enter description here

3. 编写OpenStack客户端变量脚本

3-1. 创建/root/admin-openrc文件,添加如下内容:

  1. export OS_PROJECT_DOMAIN_NAME=default 
  2. export OS_USER_DOMAIN_NAME=default 
  3. export OS_PROJECT_NAME=admin 
  4. export OS_USERNAME=admin 
  5. export OS_PASSWORD=000000 
  6. export OS_AUTH_URL=http://controller:5000/v3 
  7. export OS_IDENTITY_API_VERSION=3 
  8. export OS_IMAGE_API_VERSION=2 

3-2. 创建/root/demo-openrc.sh文件,添加如下内容:

  1. export OS_PROJECT_DOMAIN_NAME=default 
  2. export OS_USER_DOMAIN_NAME=default 
  3. export OS_PROJECT_NAME=myproject 
  4. export OS_USERNAME=myuser 
  5. export OS_PASSWORD=000000 
  6. export OS_AUTH_URL=http://controller:5000/v3 
  7. export OS_IDENTITY_API_VERSION=3 
  8. export OS_IMAGE_API_VERSION=2 

4. 生效并验证

  1. cd /root 
  2. chmod +x admin-openrc 
  3. ./admin-openrc 
  4. openstack token issue 

enter description here
enter description here

第四章结束。

posted @ 2024-04-03 16:16  南宫二狗  阅读(374)  评论(0)    收藏  举报