1. 程式人生 > >OpenStack 簡單指令碼命令操作

OpenStack 簡單指令碼命令操作

剛剛開始嘗試用指令碼建立批量 使用者 和專案,出現錯誤 “Missing parameter(s): Set a username with --os-username, OS_USERNAME, or auth.username Set an authen”

解決辦法:

登入到 horizon 的web 介面
在 project -> compute->access&security 下 找到 API Access 下載 Download OpenStack RC File v3

 

API Access.png

將下載的檔案的內容複製, 回到終端
建立 admin-openrc.sh 檔案,貼上進去剛剛複製的內容。

#建立檔案並且 貼上內容
[email protected]:~/Basic/openstack-data$ ls
admin-openrc.sh
# source 命令後 將提示輸入 OpenStack的管理員密碼
[email protected]:~/Basic/openstack-data$ source admin-openrc.sh
#提示輸入管理員密碼
Please enter your OpenStack Password for project admin as user admin:
#輸入成功之後, 可以 檢視資訊
[email protected]
:~/Basic/openstack-data$ echo $OS_USERNAME admin [email protected]:~/Basic/openstack-data$

先 source

source admin-openrc.sh

建立管理員租戶、使用者、角色

1 建立admin租戶

openstack project create --description "Admin Project" admin

2 建立admin使用者

openstack user create --password-prompt admin
# 輸入密碼和確認
User Password:
Repeat User Password:

3 建立admin角色

openstack role create admin

4 新增 admin 角色到 admin 租戶和使用者

openstack role add --project admin --user admin admin

建立一個service租戶, 此服務用來管理nova,neuturn,glance等元件的服務

openstack project create --description "Service Project" service

建立非管理員 what 租戶

1 建立what租戶, 例如 密碼是what 使用者名稱也是 what

# usage: openstack project create --domain default   --description "Demo Project"  專案名稱
# 示例 建立  project  -- what
openstack project create --domain default --description "Demo Project"  what

2 建立 what 使用者

openstack user create --domain default --password what what    

3 建立 user 角色

openstack role create user

4 將what 使用者 新增到 user 角色 和 what 租戶

openstack role add --project what --user what user

註冊keystone服務,雖然keystone本身是搞註冊的,但是自己也需要註冊服務

建立keystone認證

openstack service create --name keystone --description "OpenStack Identity" identity

分別建立三種類型的endpoint,分別為public:對外可見,internal內部使用,admin管理使用

openstack endpoint create --region RegionOne identity public http://controller:5000/v3/

openstack endpoint create --region RegionOne identity internal http://controller:5000/v3/

openstack endpoint create --region RegionOne identity admin http://controller:5000/v3/

常用命令

檢視建立的使用者

openstack user list

檢視建立的專案

openstack project list

檢視建立的用角色

openstack role list

檢視建立的endpoint

openstack endpoint list

檢視預設的計算配額

nova quota-defaults

+-----------------------------+-------+
| Quota                       | Limit |
+-----------------------------+-------+
| instances                   | 10    |
| cores                       | 20    |
| ram                         | 51200 |
| metadata_items              | 128   |
| injected_files              | 5     |
| injected_file_content_bytes | 10240 |
| injected_file_path_bytes    | 255   |
| key_pairs                   | 100   |
| server_groups               | 10    |
| server_group_members        | 10    |
+-----------------------------+-------+
[email protected]:~/Basic/openstack-data$

更新預設 quota-defaults

# usage : nova quota-class-update default key value
# example 
nova quota-class-update default --instances 1
nova quota-class-update default --ram 5120
nova quota-class-update default --cores 2

+-----------------------------+-------+
| Quota                       | Limit |
+-----------------------------+-------+
| instances                   | 1     |
| cores                       | 2     |
| ram                         | 5120  |
| metadata_items              | 128   |
| injected_files              | 5     |
| injected_file_content_bytes | 10240 |
| injected_file_path_bytes    | 255   |
| key_pairs                   | 100   |
| server_groups               | 10    |
| server_group_members        | 10    |
+-----------------------------+-------+
[email protected]:~/Basic/openstack-data$

檢視 Project -- what 的 quota

 openstack quota show what
+----------------------+----------------------------------+
| Field                | Value                            |
+----------------------+----------------------------------+
| cores                | 2                                |
| fixed-ips            | -1                               |
| floating-ips         | 20                               |
| injected-file-size   | 10240                            |
| injected-files       | 5                                |
| injected-path-size   | 255                              |
| instances            | 1                                |
| key-pairs            | 100                              |
| networks             | 2                                |
| ports                | 5                                |
| project              | f74ac6c95ffa4ade907f609d559da13a |
| properties           | 128                              |
| ram                  | 5120                             |
| rbac-policies        | 10                               |
| routers              | 3                                |
| secgroup-rules       | 100                              |
| secgroups            | 10                               |
| server-group-members | 10                               |
| server-groups        | 10                               |
| subnetpools          | -1                               |
| subnets              | 1                                |
+----------------------+----------------------------------+
[email protected]:~/Basic/openstack-data$

更新指定 project 的 quota value

# example 更改 floating-ips 為 20
openstack quota set --floating-ips 20 f74ac6c95ffa4ade907f609d559da13a 
# 檢視更改結果
 openstack quota show what
+----------------------+----------------------------------+
| Field                | Value                            |
+----------------------+----------------------------------+
| cores                | 2                                |
| fixed-ips            | -1                               |
| floating-ips         | 20                               |
| injected-file-size   | 10240                            |
| injected-files       | 5                                |
| injected-path-size   | 255                              |
| instances            | 1                                |
| key-pairs            | 100                              |
| networks             | 2                                |
| ports                | 5                                |
| project              | f74ac6c95ffa4ade907f609d559da13a |
| properties           | 128                              |
| ram                  | 5120                             |
| rbac-policies        | 10                               |
| routers              | 3                                |
| secgroup-rules       | 100                              |
| secgroups            | 10                               |
| server-group-members | 10                               |
| server-groups        | 10                               |
| subnetpools          | -1                               |
| subnets              | 1                                |
+----------------------+----------------------------------+

如果覺得我的文章對你有幫助,請隨意打賞。您的支援將鼓勵我繼續創



作者:2010jing
連結:https://www.jianshu.com/p/fa06810d1d8f
來源:簡書
簡書著作權歸作者所有,任何形式的轉載都請聯絡作者獲得授權並註明出處。