Cloudkitty 服务介绍
OpenStack 计费服务(CloudKitty)是一个用于云计算资源计费和成本管理的工具。
假设你去一家自助餐厅吃饭,餐厅提供了各种不同的食物和饮料选择。你可以根据自己的需求选择不同的食物和饮料,然后在结账时按照你所选择的食物和饮料的种类和数量付费。
OpenStack 就是这家自助餐厅,它提供了各种云计算资源,比如虚拟机、存储和网络等。你可以根据自己的需求选择使用这些资源。
而计费服务(CloudKitty)就像是这家自助餐厅的收银台。它会记录你使用的资源种类和数量,并根据预定的计费规则计算出相应的费用。这些计费规则可以根据不同的资源类型和使用方式进行定制,以确保计费的准确性。当你使用完资源后,计费服务会生成一份详细的费用报告,告诉你每个资源的使用情况和相应的费用。这样,你就可以清楚地知道自己使用了哪些资源以及需要支付多少费用。
CloudKitty 架构
CloudKitty 可以分为四大部分:
- Data retrieval (API) 数据检索
- Data collection (cloudkitty-processor) 数据收集
- Data rating 数据评级
- Data storage 数据存储
这些部分由两个进程处理:数据检索部分由进程cloudkitty-api处理,其他部分由 cloudkitty-processor 处理。
安装准备
在安装计费服务之前,你必须创建数据库、服务凭证和 API 端点
创建数据库
①连接数据库
代码语言:javascript复制[root@controller ~]# mysql -uroot -p000000
②创建cloudkitty数据库
代码语言:javascript复制MariaDB [(none)]> CREATE DATABASE cloudkitty;
③授权
代码语言:javascript复制MariaDB [(none)]> GRANT ALL PRIVILEGES ON cloudkitty.* TO 'cloudkitty'@'localhost' IDENTIFIED BY '000000';
MariaDB [(none)]> GRANT ALL PRIVILEGES ON cloudkitty.* TO 'cloudkitty'@'%' IDENTIFIED BY '000000';
加载admin user 环境变量
代码语言:javascript复制[root@controller ~]# source admin-openrc.sh
创建服务凭证
①创建cloudkitty
用户
[root@controller ~]# openstack user create --domain default --password 000000 cloudkitty
--------------------- ----------------------------------
| Field | Value |
--------------------- ----------------------------------
| domain_id | default |
| enabled | True |
| id | cc3f9652fe0a4d1c9dccbf5e8895fe4d |
| name | cloudkitty |
| options | {} |
| password_expires_at | None |
--------------------- ----------------------------------
②admin为用户添加角色cloudkitty
代码语言:javascript复制[root@controller ~]# openstack role add --project service --user cloudkitty admin
③创建cloudkitty服务实体
代码语言:javascript复制[root@controller ~]# openstack service create rating --name cloudkitty --description "OpenStack Rating Service"
------------- ----------------------------------
| Field | Value |
------------- ----------------------------------
| description | OpenStack Rating Service |
| enabled | True |
| id | 9ca3f04eed7a4adea7078dac141c2007 |
| name | cloudkitty |
| type | rating |
------------- ----------------------------------
创建计费服务的API端点
代码语言:javascript复制[root@controller ~]# openstack endpoint create rating --region RegionOne public http://localhost:8889
-------------- ----------------------------------
| Field | Value |
-------------- ----------------------------------
| enabled | True |
| id | a7ff561d0cb243d78c0e88da764263b9 |
| interface | public |
| region | RegionOne |
| region_id | RegionOne |
| service_id | 9ca3f04eed7a4adea7078dac141c2007 |
| service_name | cloudkitty |
| service_type | rating |
| url | http://localhost:8889 |
-------------- ----------------------------------
[root@controller ~]# openstack endpoint create rating --region RegionOne admin http://localhost:8889
-------------- ----------------------------------
| Field | Value |
-------------- ----------------------------------
| enabled | True |
| id | 51adf8bf193142be8f91f5b62fb3c03c |
| interface | admin |
| region | RegionOne |
| region_id | RegionOne |
| service_id | 9ca3f04eed7a4adea7078dac141c2007 |
| service_name | cloudkitty |
| service_type | rating |
| url | http://localhost:8889 |
-------------- ----------------------------------
[root@controller ~]# openstack endpoint create rating --region RegionOne internal http://localhost:8889
-------------- ----------------------------------
| Field | Value |
-------------- ----------------------------------
| enabled | True |
| id | 96611c2b428442578151859473d12e06 |
| interface | internal |
| region | RegionOne |
| region_id | RegionOne |
| service_id | 9ca3f04eed7a4adea7078dac141c2007 |
| service_name | cloudkitty |
| service_type | rating |
| url | http://localhost:8889 |
-------------- ----------------------------------
安装和配置Cloudkitty组件
安装软件
代码语言:javascript复制[root@controller ~]# yum install openstack-cloudkitty-api openstack-cloudkitty-processor openstack-cloudkitty-ui -y
配置文件
编辑/etc/cloudkitty/cloudkitty.conf
①在[DEFAULT]
部分
[DEFAULT]
verbose = true
debug = false
log_dir = /var/log/cloudkitty
transport_url = rabbit://openstack:000000@controller
auth_strategy = keystone
②在[keystone_authtoken] [ks_auth]
部分
[keystone_authtoken]
auth_section = ks_auth
[ks_auth]
www_authenticate_uri = http://controller:5000
auth_type = password
auth_protocol = http
auth_url = http://controller:5000/v3
identity_uri = http://controller:5000/
username = cloudkitty
password = 000000
project_name = service
user_domain_name = default
project_domain_name = default
region_name = RegionOne
③在[database]
部分
[database]
connection = mysql pymysql://cloudkitty:000000@controller/cloudkitty
④在[storage]
部分
[storage]
version = 2
backend = influxdb
⑤在[storage_influxdb]
部分
[storage_influxdb]
username = cloudkitty
password = 000000
database = cloudkitty
host = controller
⑥在[fetcher]
部分
[fetcher]
backend = gnocchi
⑦在[fetcher_gnocchi]
部分
[fetcher_gnocchi]
auth_section = ks_auth
region_name = RegionOne
⑧在[collect]
部分
[collect]
collector = gnocchi
⑨在[collector_gnocchi]
部分
[collector_gnocchi]
auth_section = ks_auth
region_name = RegionOne
influxdb安装配置
代码语言:javascript复制#下载软件
[root@controller ~]# yum install -y wget
[root@controller ~]# wget https://dl.influxdata.com/influxdb/releases/influxdb-1.8.0.x86_64.rpm
[root@controller ~]# yum localinstall influxdb-1.8.0.x86_64.rpm -y
#重启influxdb服务
root@controller ~]# systemctl restart influxdb.service && systemctl enable influxdb.service
#创建influxdb数据库和user
[root@controller ~]# influx -execute "create database cloudkitty"
[root@controller ~]# influx -execute "create user cloudkitty with password '000000' with all privileges"
运行数据库同步脚本和初始数据库
代码语言:javascript复制[root@controller ~]# cloudkitty-dbsync upgrade
[root@controller ~]# cloudkitty-storage-init
修改服务文件
代码语言:javascript复制[root@controller ~]# vim /usr/lib/systemd/system/cloudkitty-api.service
[Service]
....
ExecStart=/usr/bin/cloudkitty-api --port 8889 -- --logfile /var/log/cloudkitty/api.log --config-file /etc/cloudkitty/cloudkitty.conf
软链接
代码语言:javascript复制[root@controller ~]# ln -sf /usr/lib/python2.7/site-packages/cloudkittydashboard/enabled/_[0-9]*.py /usr/share/openstack-dashboard/openstack_dashboard/enabled/
# 将 CloudKitty 仪表盘的配置文件链接到 OpenStack Dashboard 中
# 使得可以在 OpenStack Dashboard 中访问和使用 CloudKitty 仪表盘的功能
重启HTTPD
代码语言:javascript复制[root@controller ~]# systemctl restart httpd
完成安装
代码语言:javascript复制[root@controller ~]# systemctl enable cloudkitty-api cloudkitty-processor && systemctl restart cloudkitty-api cloudkitty-processor
验证
列出可用模块
代码语言:javascript复制[root@controller ~]# cloudkitty module list
----------- --------- ----------
| Module | Enabled | Priority |
----------- --------- ----------
| noop | True | 1 |
| hashmap | True | 1 |
| pyscripts | False | 1 |
----------- --------- ----------
启用 hashmap 评分模块
代码语言:javascript复制[root@controller ~]# cloudkitty module enable hashmap
--------- --------- ----------
| Module | Enabled | Priority |
--------- --------- ----------
| hashmap | True | 1 |
--------- --------- ----------
禁用 pyscripts 评级模块
代码语言:javascript复制[root@controller ~]# cloudkitty module disable pyscripts
----------- --------- ----------
| Module | Enabled | Priority |
----------- --------- ----------
| pyscripts | False | 1 |
----------- --------- ----------
设置优先级
将 hashmap 评分模块优先级设置为 100
代码语言:javascript复制[root@controller ~]# cloudkitty module set priority hashmap 100
--------- --------- ----------
| Module | Enabled | Priority |
--------- --------- ----------
| hashmap | True | 100 |
--------- --------- ----------
案例
- 创建 volume_thresholds 组,创建服务匹配规则 volume.size,并设置每 GB 的价格为 0.01。
- 在组 volume_thresholds 中创建阈值,设置若超过 50GB 的阈值,应用 2%的折扣(0.98)。
创建hashmap service
代码语言:javascript复制[root@controller ~]# openstack rating hashmap service create volume.size
------------- --------------------------------------
| Name | Service ID |
------------- --------------------------------------
| volume.size | 0f91430f-e017-46ca-985f-b741fe73fd62 |
------------- --------------------------------------
创建hashmap service group
代码语言:javascript复制[root@controller ~]# openstack rating hashmap group create volume_thresholds
------------------- --------------------------------------
| Name | Group ID |
------------------- --------------------------------------
| volume_thresholds | 28c2699d-f8a9-4771-beeb-0c6c8f7d3352 |
------------------- --------------------------------------
创建volume单价
代码语言:javascript复制[root@controller ~]# openstack rating hashmap mapping create -s 0f91430f-e017-46ca-985f-b741fe73fd62 -g 28c2699d-f8a9-4771-beeb-0c6c8f7d3352 -t flat 0.01
-------------------------------------- ------- ------------ ------ ---------- -------------------------------------- -------------------------------------- ------------
| Mapping ID | Value | Cost | Type | Field ID | Service ID | Group ID | Project ID |
-------------------------------------- ------- ------------ ------ ---------- -------------------------------------- -------------------------------------- ------------
| 8976be2d-3a55-4c89-87a9-b63614d6a4e4 | None | 0.01000000 | flat | None | 0f91430f-e017-46ca-985f-b741fe73fd62 | 28c2699d-f8a9-4771-beeb-0c6c8f7d3352 | None |
-------------------------------------- ------- ------------ ------ ---------- -------------------------------------- -------------------------------------- ------------
创建service rule
代码语言:javascript复制[root@controller ~]# openstack rating hashmap threshold create -s 0f91430f-e017-46ca-985f-b741fe73fd62 -g 28c2699d-f8a9-4771-beeb-0c6c8f7d3352 -t rate 50 0.98
-------------------------------------- ------------- ------------ ------ ---------- -------------------------------------- -------------------------------------- ------------
| Threshold ID | Level | Cost | Type | Field ID | Service ID | Group ID | Project ID |
-------------------------------------- ------------- ------------ ------ ---------- -------------------------------------- -------------------------------------- ------------
| b054d060-4db1-4983-b0e3-7fa7bc6cb90b | 50.00000000 | 0.98000000 | rate | None | 0f91430f-e017-46ca-985f-b741fe73fd62 | 28c2699d-f8a9-4771-beeb-0c6c8f7d3352 | None |
-------------------------------------- ------------- ------------ ------ ---------- -------------------------------------- -------------------------------------- ------------
链接:https://blog.csdn.net/qq_52089863/article /details/131507272