หลังจากเตรียมความพร้อมก่อนติดตั้งกันไปแล้ว เรามาต่อในส่วน keystone กัน OpenStack Keystone เป็นบริการสำหรับการยืนยันตัวตน ก่อนที่เราจะทำอะไรเกี่ยวกับ OpenStack Components ต่าง ๆ เราต้องมีสิทธิ์ในการเข้าถึงก่อน โดย keystone เองก็มีส่วนประกอบ ดังนี้
- Endpoints : บริการ OpenStack ทุกส่วน(Nova, Swift, Glance) ต้องรันผ่าน URL , port ซึ่งการเข้าถึงผ่าน URL และ Port นั้น เราเรียกว่า endpoint
- User : User ที่มีสิทธิ์ในการเข้าถึงบริการ OpenStack
- Token : ชุดตัวอักษรหรือตัวเลขที่จะช่วยให้เข้าถึงแต่ละบริการ โดยจะขึ้นอยู่กับ role ของ user
- Service : แต่ละ component ที่มีการเชื่อมต่อผ่าน keystone
- Tenant : เป็นกลุ่มของ user
- Role: ระดับการเข้าถึงของแต่ละ user
เมื่อเรารู้จักส่วนประกอบของ keystone แล้วก็มาเริ่มติดตั้งกัน คำสั่งสำหรับติดตั้ง keystone คือ
sudo apt-get install keystone python-keystone python-keystoneclient
หลังจากติดตั้งเรียบร้อยแล้วก็มาแก้ไขค่า keystone.conf กัน โดยเข้าไปแก้ไขใน /etc/keystone/keystone.conf ดังนี้
- เปิดคอมเมนต์ admin_token = ADMIN และแก้ไขค่า admin_token เป็นอะไรก็ได้ ในที่นี้จะใช้ admin admin_token = admin
- เนื่องจากเราใช้ MySQL Database ให้แก้ไขค่า connection เพื่อเชื่อมต่อ database โดยแก้ไขค่าจาก
- Tenants
- Users
- Roles
- Role ของ User ใน Tenants
- Services
- Endpoint ของ service
connection = sqlite:////var/lib/keystone/keystone.db
เป็น
connection=mysql://KEYSTONE_USER:KEYSTONE_DBPASS@IPADDRESS/keystone
ดังตัวอย่าง
connection = mysql://keystonedbadmin:keystonesecret@192.168.102.137/keystone
หลังจากแก้ไขค่าคอนฟิกไฟล์แล้วก็ต้องรีสตาร์ท service เพื่อปรับค่าที่ได้แก้ไขไปโดย
sudo service keystone restart
จากนั้นสร้าง keystone database schema โดยใช้คำสั่ง
sudo keystone-manage db_sync
และทำการเซตค่า environment ในไฟล์ ~/.bashrc โดย default admin port คือ 35357 ดังนี้
export SERVICE_TOKEN=admin
export SERVICE_ENDPOINT="http://localhost:35357/v2.0"
เมื่อติดตั้งปรับแต่ง keystone เรียบร้อยแล้วต่อไปเราต้องใส่ข้อมูลให้กับ keystone โดยมี 6 ส่วนดังที่ได้อธิบายไปด้านบน ดังนี้
การสร้าง Tenants
การสร้าง Tenants ทำได้โดยใช้คำสั่ง keystone tenant-create –name TENANT_NAME ซึ่งตัวอย่างจะสร้าง 2 tenants คือ admin และ service
สร้าง tenants admin โดยใช้คำสั่ง ดังรูป
สร้าง tenants service โดยใช้คำสั่ง ดังรูป
การสร้าง User
ในตัวอย่างเราจะสร้าง users 4 user ได้แก่ admin, nova, glance และ swift โดยใช้คำสั่งดังนี้
keystone user-create --name admin --pass admin --email admin@osdev.co.th
keystone user-create --name nova --pass nova --email nova@osdev.co.th
keystone user-create --name glance --pass glance --email glance@osdev.co.th
keystone user-create --name swift --pass swift --email swift@osdev.co.th
รูปด้านล่างคือตัวอย่างการสร้าง User
การสร้างกฏ (Roles)
ในตัวอย่างจะทำการสร้างกฏ 2 กฏ คือ admin และ Member ดังนี้
keystone role-create --name admin
keystone role-create --name Member
รูปแสดงตัวอย่างการสร้างกฏ
การแสดงรายการ Tenants, Users และ Roles
เราสามารถเรียกดู Tenants, Users และ Roles ที่สร้างได้โดยใช้คำสั่ง ดังนี้
List Tenants:
List Users:
List Roles:
*** ให้สังเกตเลข id ซึ่งเราจะใช้เมื่อระบุ role ให้ user ในแต่ละ tenant
การเพิ่ม Roles สำหรับ Users ใน Tenants
ต่อไปเราจะมาเพิ่ม role ให้กับ user ที่เราสร้างขึ้น โดยการใช้คำสั่ง ดังนี้
keystone user-role-add --user $USER_ID --role $ROLE_ID --tenant_id $TENANT_ID
จะเห็นว่าเราต้องใช้ค่า “id” ซึ่งเราได้มาจากคำสั่ง keystone user-list, keystone tenant-list, keystone role-list ที่แสดงให้ดูก่อนหน้านี้
โดยเราจะเพิ่มกฏ ‘admin’ ให้กับ user ‘admin’ ใน tenant ‘admin’ ดังตัวอย่าง
keystone user-role-add --user b69096ec14a5495ebedb4abf0cf9dade --role 29517c06e7024316a1d47a23787b3943 --tenant_id c82a58d2957d43c2a86a7aadbf16f031
ต่อไปเราจะเพิ่ม role admin ให้ user ‘nova’, ‘glance’ และ ‘swift’ ใน tenant service จะใช้คำสั่งดังนี้
การสร้าง Services
ต่อไปเราจะมาสร้าง services ซึ่ง user จะตรวจสอบก่อนใช้บริการ ในตัวอย่างจะสร้าง service nova-compute, nova-volume, glance, swift, keystone และ ec2 โดยคำสั่งที่จะใช้ คือ
keystone service-create --name service_name --type service_type --description ’Description of the service’
ดังนี้
keystone service-create --name nova --type compute --description 'OpenStack Compute Service'
keystone service-create --name volume --type volume --description 'OpenStack Volume Service'
keystone service-create --name glance --type image --description 'OpenStack Image Service'
keystone service-create --name swift --type object-store --description 'OpenStack Storage Service'
keystone service-create --name keystone --type identity --description 'OpenStack Identity Service'
keystone service-create --name ec2 --type ec2 --description 'EC2 Service'
แต่ละ service ที่สร้างก็จะได้ ‘id’ เฉพาะ เพื่อใช้ระบุ endpoint ของ service แต่ละตัว โดยใช้คำสั่ง keystone service-list ดังนี้
การสร้าง Endpoint สำหรับ Service
endpoint สำหรับ service สร้างโดยใช้คำสั่งดังนี้
keystone endpoint-create --region region_name --service_id service_id --publicurl public_url --adminurl admin_url --internalurl internal_url
การสร้าง endpoint สำหรับ nova-compute ใช้คำสั่งดังนี้
keystone endpoint-create --region myregion --service_id 5013c9cfcd344ed6a3f11a098b20dd10 --publicurl 'http://192.168.0.102:8776/v1/$(tenant_id)s' --adminurl 'http://192.168.0.102:8774/v2/$(tenant_id)s' --internalurl 'http://192.168.0.102:8774/v2/$(tenant_id)s'
ตัวอย่าง ดังรูป
จากนั้นก็สร้าง endpoint ของ service แต่ละอันให้ครบ ดังนี้
endpoint สำหรับ nova-volume:
keystone endpoint-create --region myregion --service_id d842895c8e144a428b70a48fbf57d04e --publicurl 'http://192.168.0.102:8776/v1/$(tenant_id)s' --adminurl 'http://192.168.0.102:8774/v2/$(tenant_id)s' --internalurl 'http://192.168.0.102:8774/v2/$(tenant_id)s'
endpoint สำหรับ glance:
keystone endpoint-create --region myregion --service_id 4588944458bc482f83d897fe97157fb2 --publicurl 'http://192.168.0.102:8776/v1/$(tenant_id)s' --adminurl 'http://192.168.0.102:8774/v2/$(tenant_id)s' --internalurl 'http://192.168.0.102:8774/v2/$(tenant_id)s'
endpoint สำหรับ swift:
keystone endpoint-create --region myregion --service_id b60e854ac822454dac56563b13ce8717 --publicurl 'http://192.168.0.102:8776/v1/$(tenant_id)s' --adminurl 'http://192.168.0.102:8774/v2/$(tenant_id)s' --internalurl 'http://192.168.0.102:8774/v2/$(tenant_id)s'
endpoint สำหรับ keystone:
keystone endpoint-create --region myregion --service_id 9337b0a9102a4e6195013ae42eb6f446 --publicurl 'http://192.168.0.102:8776/v1/$(tenant_id)s' --adminurl 'http://192.168.0.102:8774/v2/$(tenant_id)s' --internalurl 'http://192.168.0.102:8774/v2/$(tenant_id)s'
endpoint สำหรับ ec2:
keystone endpoint-create --region myregion --service_id bdc9d51883584837b75f59ab7ad16703 --publicurl 'http://192.168.0.102:8776/v1/$(tenant_id)s' --adminurl 'http://192.168.0.102:8774/v2/$(tenant_id)s' --internalurl 'http://192.168.0.102:8774/v2/$(tenant_id)s'
เรียบร้อยสำหรับ keystone ในบทความต่อไปเราจะมาติดตั้ง Glance กันต่อ