@
前言
什麼是CloudKitty?
CloudKitty是OpenStack等的評級即服務專案。該專案旨在成為雲的退款和評級的通用解決方案。從歷史上看,它只能在OpenStack上下文中執行它,但現在可以在獨立模式下執行CloudKitty。
CloudKitty允許進行基於指標的評級:它輪詢終端節點以檢索有關特定指標的度量值和後設資料,將評級規則應用於收集的資料,並將評級資料推送到其儲存後端。
CloudKitty是高度模組化的,這使得新增新功能變得容易。
架構
CloudKitty可以分為四大部分:
- Data retrieval (API) 資料檢索
- Data collection (cloudkitty-processor) 資料收集
- Data rating 資料評級
- Data storage 資料儲存
這些部分由兩個程式處理:和 。資料檢索部分由程式處理,其他部分由 處理。cloudkitty-apicloudkitty-processorcloudkitty-apicloudkitty-processor
以下是 CloudKitty 架構的概述:
安裝
yum install openstack-cloudkitty-api openstack-cloudkitty-processor openstack-cloudkitty-ui
配置
編輯/etc/cloudkitty/cloudkitty.conf
以配置 CloudKitty
[DEFAULT]
verbose = True
log_dir = /var/log/cloudkitty
[oslo_messaging_rabbit]
rabbit_userid = openstack
rabbit_password = RABBIT_PASSWORD
rabbit_hosts = RABBIT_HOST
[auth]
username = cloudkitty
password = CK_PASSWORD
tenant = service
region = RegionOne
url = http://localhost:5000/v2.0
[keystone_authtoken]
username = cloudkitty
password = CK_PASSWORD
project_name = service
region = RegionOne
auth_url = http://localhost:5000/v2.0
auth_plugin = password
[database]
connection = mysql://cloudkitty:CK_DBPASS@localhost/cloudkitty
[keystone_fetcher]
username = admin
password = ADMIN_PASSWORD
tenant = admin
region = RegionOne
url = http://localhost:5000/v2.0
[ceilometer_collector]
username = cloudkitty
password = CK_PASSWORD
tenant = service
region = RegionOne
url = http://localhost:5000
設定資料庫和儲存後端
[root@controller ~]# mysql -uroot -p000000
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 374
Server version: 10.1.20-MariaDB MariaDB Server
Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> CREATE DATABASE cloudkitty;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> GRANT ALL PRIVILEGES ON cloudkitty.* TO 'cloudkitty'@'localhost' IDENTIFIED BY '000000';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> GRANT ALL PRIVILEGES ON cloudkitty.* TO 'cloudkitty'@'%' IDENTIFIED BY '000000';
Query OK, 0 rows affected (0.00 sec)
執行資料庫同步指令碼
[root@controller ~]# cloudkitty-dbsync upgrade
INFO [alembic.runtime.migration] Context impl MySQLImpl.
INFO [alembic.runtime.migration] Will assume non-transactional DDL.
INFO [alembic.runtime.migration] Running upgrade -> 464e951dc3b8, Initial migration
INFO [alembic.runtime.migration] Running upgrade 464e951dc3b8 -> 2ac2217dcbd9, Added support for meta collector
INFO [alembic.runtime.migration] Running upgrade 2ac2217dcbd9 -> 385e33fef139, Added priority to modules_state.
INFO [alembic.runtime.migration] Context impl MySQLImpl.
INFO [alembic.runtime.migration] Will assume non-transactional DDL.
INFO [alembic.runtime.migration] Running upgrade -> 3dd7e13527f3, Initial migration
INFO [alembic.runtime.migration] Running upgrade 3dd7e13527f3 -> 4fa888fd7eda, Added threshold support.
INFO [alembic.runtime.migration] Running upgrade 4fa888fd7eda -> 54cc17accf2c, Fixed constraint name.
INFO [alembic.runtime.migration] Running upgrade 54cc17accf2c -> 10d2738b67df, Rename mapping table to hashmap_mappings.
INFO [alembic.runtime.migration] Running upgrade 10d2738b67df -> f8c799db4aa0, Fix unnamed constraints.
INFO [alembic.runtime.migration] Running upgrade f8c799db4aa0 -> c88a06b1cfce, Clean hashmap fields constraints.
/usr/lib64/python2.7/site-packages/sqlalchemy/engine/default.py:507: Warning: Duplicate index `uniq_field_per_service`. This is deprecated and will be disallowed in a future release.
cursor.execute(statement, parameters)
INFO [alembic.runtime.migration] Running upgrade c88a06b1cfce -> 4da82e1c11c8, Add per tenant hashmap support
INFO [alembic.runtime.migration] Context impl MySQLImpl.
INFO [alembic.runtime.migration] Will assume non-transactional DDL.
INFO [alembic.runtime.migration] Running upgrade -> 4f9efa4601c0, Initial migration.
初始化儲存後端
[root@controller ~]# cloudkitty-storage-init
No handlers could be found for logger "cloudkitty.utils"
INFO [alembic.runtime.migration] Context impl MySQLImpl.
INFO [alembic.runtime.migration] Will assume non-transactional DDL.
INFO [alembic.runtime.migration] Running upgrade -> 17fd1b237aa3, Initial migration
INFO [alembic.runtime.migration] Running upgrade 17fd1b237aa3 -> 792b438b663, added tenant informations
INFO [alembic.runtime.migration] Running upgrade 792b438b663 -> 307430ab38bc, improve qty precision
INFO [alembic.runtime.migration] Running upgrade 307430ab38bc -> c703a1bad612, improve_qty_digit
CloudKitty 使用 Keystone 進行身份驗證,並提供rating
服務。
[root@controller ~]# openstack user create --domain demo --password 000000 cloudkitty
+---------------------+----------------------------------+
| Field | Value |
+---------------------+----------------------------------+
| domain_id | d5db5c4ee4a14492b69408f63107d11f |
| enabled | True |
| id | f1dea9309b834edba3aa4c1b8607dc16 |
| name | cloudkitty |
| options | {} |
| password_expires_at | None |
+---------------------+----------------------------------+
[root@controller ~]# openstack role add --project service --user cloudkitty admin
對於應由 CloudKitty處理的每個租戶,將rating
角色賦予 cloudkitty :
[root@controller ~]# openstack role create rating
+-----------+----------------------------------+
| Field | Value |
+-----------+----------------------------------+
| domain_id | None |
| id | ee01d36a397b4b0ebcb579044c32a73c |
| name | rating |
+-----------+----------------------------------+
建立rating
服務及其端點:
[root@controller ~]# openstack service create --name cloudkitty --description "OpenStack rating" rating
+-------------+----------------------------------+
| Field | Value |
+-------------+----------------------------------+
| description | OpenStack rating |
| enabled | True |
| id | 78f3d51cf74843cd8d325b790e0c2b1c |
| name | cloudkitty |
| type | rating |
+-------------+----------------------------------+
openstack endpoint create --region RegionOne rating public http://controller:9292
openstack endpoint create --region RegionOne rating internal http://controller:9292
openstack endpoint create --region RegionOne rating admin http://controller:9292
[root@controller ~]# openstack endpoint create --region RegionOne rating public http://controller:9292
+--------------+----------------------------------+
| Field | Value |
+--------------+----------------------------------+
| enabled | True |
| id | 48b75b9d2d764b56a5bee00ff75b03b1 |
| interface | public |
| region | RegionOne |
| region_id | RegionOne |
| service_id | 78f3d51cf74843cd8d325b790e0c2b1c |
| service_name | cloudkitty |
| service_type | rating |
| url | http://controller:9292 |
+--------------+----------------------------------+
[root@controller ~]# openstack endpoint create --region RegionOne rating internal http://controller:9292
+--------------+----------------------------------+
| Field | Value |
+--------------+----------------------------------+
| enabled | True |
| id | b4f7fffa539441a68506db90b3ae89ce |
| interface | internal |
| region | RegionOne |
| region_id | RegionOne |
| service_id | 78f3d51cf74843cd8d325b790e0c2b1c |
| service_name | cloudkitty |
| service_type | rating |
| url | http://controller:9292 |
+--------------+----------------------------------+
[root@controller ~]# openstack endpoint create --region RegionOne rating admin http://controller:9292
+--------------+----------------------------------+
| Field | Value |
+--------------+----------------------------------+
| enabled | True |
| id | a607a077f119417d9e650c16dcd61f10 |
| interface | admin |
| region | RegionOne |
| region_id | RegionOne |
| service_id | 78f3d51cf74843cd8d325b790e0c2b1c |
| service_name | cloudkitty |
| service_type | rating |
| url | http://controller:9292 |
+--------------+----------------------------------+
啟動
[root@controller ~]# systemctl start cloudkitty-processor.service
[root@controller ~]# cloudkitty-api -p 8889 #臨時啟動API
No handlers could be found for logger "cloudkitty.utils"
/usr/lib/python2.7/site-packages/pecan/__init__.py:122: RuntimeWarning: `static_root` is only used when `debug` is True, ignoring
RuntimeWarning
********************************************************************************
STARTING test server cloudkitty.api.app.build_wsgi_app
Available at http://controller:8889/
DANGER! For testing only, do not use in production
********************************************************************************
192.168.200.1 - - [29/Apr/2022 15:06:41] "GET / HTTP/1.1" 200 209
檢索並安裝 CloudKitty 的儀表板
git clone https://opendev.org/openstack/cloudkitty-dashboard.git
python setup.py install
yum install -y wget
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
yum -y install python-pip
PY_PACKAGES_PATH=`pip --version | cut -d' ' -f4`
ln -s $PY_PACKAGES_PATH/cloudkittydashboard/enabled/_[0-9]*.py /usr/share/openstack-dashboard/openstack_dashboard/enabled/
[root@controller bin]# systemctl restart httpd.service memcached.service