CentOS7安裝OpenStack-10.安裝Telemetry服務組件


10. 0、概述

  • 早期OpenStack的計量功能由Ceilometer項目負責,后來Ceilometer一分為四,每個項目負責一個方面的工作。不得不說這是OpenStack開發中的一個特色,比如Cinder和Neutron也是從早期的Nova中拆分出來的。

OpenStack Telemetry體系的架構如下:

可以看到其由四個組件構成,包括:

  • Gnocchi:時間序列數據庫,保存計量數據。
  • Panko:事件數據庫,保存事件數據。
  • Ceilometer:數據采集服務,采集資源使用量相關數據,並推送到Gnocchi;采集操作事件數據,並推送到Panko。
  • Aodh:告警服務,基於計量和事件數據提供告警通知功能。

四個組件分工明確,各司其職,使得計量系統結構清晰明了。

另外,早期Ceilometer將原始計量數據保存到MongoDB,性能之差可以說幾乎不可用。Gnocchi的出現使計量服務不論是在性能還是空間消耗上都有了質的飛躍,功不可沒。也因為Gnocchi的先進性,它已經脫離OpenStack成為了一個獨立項目,似有追趕其他時間序列數據庫的態勢。

 10.1、Gnocchi -- 時間序列數據庫服務

  • Gnocchi接收來自Ceilometer的原始計量數據,進行聚合運算后保存到持久化后端。

1) 三類存儲后端

Gnocchi中保存與資源使用量相關的計量數據,為了提高檢索效率,額外將計量數據的元數據信息單獨存儲。另外由於從原始輸入數據到最終存儲的聚合數據,需要進行大量計算,為了緩沖輸入與處理間的速率,引入緩存后端。因此Gnocchi中涉及三種存儲后端:

  • 索引后端:存儲計量對象和采集項的基礎屬性,比如對象類型(虛擬機、硬盤、網絡)、原始資源uuid等。索引數據量不大,一半用MySQL。
  • 聚合數據后端:存儲經過聚合計算的計量數據,比如cpu使用率的平均值、最大值、最小值等。推薦用Ceph,可以支持多實例共享數據。
  • 傳入數據后端:保存來自Ceilometer的原始計量數據。默認與聚合后端一致,推薦使用Redis。

2) 部署配置

2.1)配置Keystone

# 創建gnocchi用戶並添加角色

openstack user create --domain default --password gnocchi gnocchi
openstack role add --project service --user gnocchi admin

# 創建gnocchi服務

openstack service create --name gnocchi --description "Metric Service" metric

# 創建endpoints

openstack endpoint create --region RegionOne metric public http://controller:8041
openstack endpoint create --region RegionOne metric internal http://controller:8041
openstack endpoint create --region RegionOne metric admin http://controller:8041

2.2)配置Ceph

# Ceph集群安裝部署文檔:https://www.cnblogs.com/liugp/p/12513702.html

# 將聚合數據保存到Ceph后端,預先在ceph中分配存儲池和權限

# 分配存儲池
ceph osd pool create gnocchi 128 128

# 分配權限 ceph auth get-or-create client.gnocchi mon 'allow r' osd 'allow rw pool=gnocchi'

# 保存keyring文件。
ceph auth get-or-create client.gnocchi | tee ceph.client.gnocchi.keyring

把/etc/ceph/ceph.conf和/etc/ceph/ceph.client.gnocchi.keyring拷貝到Gnocchi節點上。

2.3)配置MySQL

# 使用MySQL保存索引數據,預先創建數據庫和用戶

mysql -u root -p
CREATE DATABASE gnocchi;
GRANT ALL PRIVILEGES ON gnocchi.* TO 'gnocchi'@'localhost' IDENTIFIED BY 'gnocchi';
GRANT ALL PRIVILEGES ON gnocchi.* TO 'gnocchi'@'%' IDENTIFIED BY 'gnocchi';

2.4)安裝redis

# 安裝包
yum install redis -y

# 修改配置/etc/redis.conf
# 1)將這部注釋掉,否則只有本機才能訪問
bind 127.0.0.1
# 2)保護模式修改為no
protected-mode no
# 啟動服務 systemctl start redis.service systemctl status redis.service systemctl enable redis.service

2.5)安裝Gnocchi

yum install centos-release-openstack-rocky
yum install openstack-gnocchi-api openstack-gnocchi-metricd python-gnocchiclient ceph-common -y

2.6)編輯配置

# /etc/gnocchi/gnocchi.conf:服務運行參數

[DEFAULT]
debug = true
verbose = true
log_dir = /var/log/gnocchi
parallel_operations = 4
coordination_url = redis://controller:6379

[api]
auth_mode = keystone
host = 0.0.0.0
port = 8041
uwsgi_mode = http-socket

[keystone_authtoken]
region_name = RegionOne
www_authenticate_uri = http://controller:5000
auth_url = http://controller:5000/v3
memcached_servers = controller:11211
auth_type = password
project_domain_name = default
user_domain_name = default
project_name = service
username = gnocchi
password = gnocchi
service_token_roles_required = true

[archive_policy]
default_aggregation_methods = mean,min,max,sum,std,count

[indexer]
url = mysql+pymysql://gnocchi:gnocchi@controller/gnocchi

[metricd]
workers = 4
metric_processing_delay = 60
greedy = true
metric_reporting_delay = 120
metric_cleanup_delay = 300

[storage]
#driver = file
driver = ceph
ceph_pool = gnocchi
ceph_username = gnocchi
ceph_keyring = /etc/ceph/ceph.client.gnocchi.keyring
ceph_timeout = 30
ceph_conffile = /etc/ceph/ceph.conf
file_basepath = /var/lib/gnocchi
file_subdir_len = 2

[cors]
allowed_origin = http://controller:3000

# 初始化數據庫

gnocchi-upgrade

# 安裝uwsgi(這里僅僅提供python2.7環境的安裝方法)

# 1、setuptools的安裝
wget --no-check-certificat  https://pypi.python.org/packages/source/s/setuptools/setuptools-2.0.tar.gz
tar zxf setuptools-2.0.tar.gz
cd setuptools-2.0
python setup.py install

# 2、pip的安裝
wget https://pypi.python.org/packages/source/p/pip/pip-1.3.1.tar.gz --no-check-certificate
tar -xzvf pip-1.3.1.tar.gz
cd pip-1.3.1
python setup.py install

# 3、修改環境變量
# vi /etc/profile # 在最后的export PATH一行的最后面添加:
export PATH=$PATH:/usr/bin

# 4、安裝依賴包
yum install gcc* libssl-devel libffi-devel python-devel build-essential libxml2-devel libxslt1-devel

# 5、安裝uwsgi
pip install uwsgi

# 啟動服務

systemctl restart openstack-gnocchi-api.service openstack-gnocchi-metricd.service
systemctl status openstack-gnocchi-api.service openstack-gnocchi-metricd.service
systemctl enable openstack-gnocchi-api.service openstack-gnocchi-metricd.service

2.7)驗證使用

# 查看歸檔策略

openstack metric archive-policy list

歸檔策略指定計量數據的聚合計算方式,包括聚合方法(mean、min、max、sum、std、count),和計量數據的統計時間粒度、數據點數。根據時間粒度和統計點數可以確定計量的時間跨度,根據一個數據點的大小在0.05 bytes~8.04 bytes,就可以確定一個metric需要使用的存儲空間大小。Gnocchi內置了bool、low、medium、high四種歸檔策略。

# 歸檔策略的作用單位是計量項(metric)。查看歸檔策略規則

openstack metric archive-policy-rule list

默認規則將所有metric關聯到low策略,metric使用通配符匹配。

# 查看資源列表

openstack metric resource list

資源對於OpenStack各個項目中的邏輯資源,比如實例、端口、鏡像、卷等。由於還沒有對接Ceilometer,所以列表為空。在Ceilometer章節部分可以看到最終結果。

# 查看metric列表

openstack metric list

Metric是資源統計的基本單位,一個資源會有多個metrics,比如實例資源有cpu_util、memory.usage、disk.root.size等。

# 查看計量數據

openstack metric measures show {metric_uuid}

Measures就是Gnocchi中最終保存的計量數據,即每個metric的數據點。

10.2、Panko -- 事件存儲服務

Panko接收來自Ceilometer的事件數據,並提供查詢接口。

1)主要組件

  • panko-api: 提供事件數據的插入和查詢接口。

2)部署配置

2.1)配置Keystone

# 創建panko用戶並添加角色

openstack user create --domain default --password panko panko
openstack role add --project service --user panko admin

# 創建panko服務

openstack service create event --name panko --description "Panko Service"

# 創建endpoints

openstack endpoint create --region RegionOne event admin http://controller:8977
openstack endpoint create --region RegionOne event public http://controller:8977
openstack endpoint create --region RegionOne event internal http://controller:8977

2.2)安裝配置MongoDB

# 安裝MongoDB,配置yum源

cat << EOF > /etc/yum.repos.d/mongodb-org-4.0.repo
[mngodb-org]
name=MongoDB Repository
baseurl=http://mirrors.aliyun.com/mongodb/yum/redhat/7Server/mongodb-org/4.0/x86_64/
gpgcheck=0
enabled=1
EOF
yum clean all
yum makecache
yum update

# 安裝包

yum -y install mongodb-org

# 修改配置

sed -i 's/127.0.0.1/0.0.0.0/' /etc/mongod.conf

# 啟動服務

systemctl start mongod.service
systemctl enable mongod.service

# 使用MongoDB保存事件數據,預先創建數據庫和用戶

# 連接mongo
mongo
# 切換到panko數據庫 use panko
# 創建用戶,角色 db.createUser({user: "panko",pwd: "panko",roles: [ "readWrite", "dbAdmin" ]})

2.3)安裝Panko

yum install openstack-panko-api python2-pankoclient -y

# 編輯配置,/etc/panko/panko.conf:服務運行參數

[DEFAULT]
debug = true
log_dir = /var/log/panko

[database]
connection = mongodb://panko:panko@controller:27017/panko

[keystone_authtoken]
region_name = RegionOne
www_authenticate_uri = http://controller:5000
auth_url = http://controller:5000/v3
memcached_servers = controller:11211
auth_type = password
project_domain_name = default
user_domain_name = default
project_name = service
username = panko
password = panko

# 初始化數據庫

panko-dbsync

# 建立服務文件

Panko安裝包內沒有包含服務文件,為了便於管理,手動創建panko-api的服務文件

$ cat /usr/lib/systemd/system/openstack-panko-api.service
[Unit]
Description=OpenStack Event API service
After=syslog.target network.target

[Service]
Type=simple
User=panko
ExecStart=/usr/bin/panko-api --port 8977 -- --logfile /var/log/panko/api.log
Restart=on-failure

[Install]
WantedBy=multi-user.target

# 啟動服務

systemctl daemon-reload
systemctl enable openstack-panko-api.service
systemctl start openstack-panko-api.service

2.4)驗證使用

# 查看事件列表

openstack event list

由於還沒有對接Ceilometer,所以列表為空。

10.3、Ceilometer -- 數據采集服務

Ceilometer是OpenStack計量體系中的數據采集組件,主要功能有:

  • 采集其他OpenStack服務的計量數據,比如虛擬機創建、刪除操作等。
  • 從消息隊列中讀取其他服務發送的計量數據,比如虛擬機的CPU使用率、IO等。
  • 將采集到的數據發送到后端存儲,比如Gnocchi、MongoDB、RabbitMQ等。

1)主要組件

  • ceilometer-agent-compute:運行在計算節點上,使用libvirt接口采集虛擬機和宿主機的資源消耗數據,並發送到消息隊列。
  • ceilometer-agent-central:運行在中心節點上,采集服務層面的計量數據,並發送到消息隊列。
  • ceilometer-agent-notification:運行在中心節點上,從消息隊列讀取計量數據和事件,並將它們發送到后端存儲。

2)部署配置

1)配置Keystone

# 創建ceilometer用戶並添加角色

openstack user create --domain default --password ceilometer ceilometer
openstack role add --project service --user ceilometer admin

2)部署控制節點

# 安裝中心組件

yum install openstack-ceilometer-notification openstack-ceilometer-central -y

# 修改配置

  1. /etc/ceilometer/polling.yaml:配置采集項和采集時間間隔。
  2. /etc/ceilometer/pipeline.yaml:計量數據推送后端,默認是gnocchi://。
  3. /etc/ceilometer/event_pipeline.yaml:事件數據推送后端,默認是gnocchi://,修改為panko://。

# /etc/ceilometer/ceilometer.conf:主要配置文件,服務運行參數。

[DEFAULT]
debug = false
auth_strategy = keystone
transport_url = rabbit://openstack:openstack@controller

[service_credentials]
auth_type = password
auth_url = http://controller:5000/v3
project_domain_id = default
user_domain_id = default
project_name = service
username = ceilometer
password = ceilometer
interface = internalURL
region_name = RegionOne

[notification]
store_events = true
messaging_urls = rabbit://openstack:openstack@controller

3)初始化數據庫

# 在Gnocchi上創建資源,要求Gnocchi已運行並在Keystone配置了endpoint

ceilometer-upgrade

# 啟動服務

systemctl enable openstack-ceilometer-notification.service openstack-ceilometer-central.service
systemctl start openstack-ceilometer-notification.service openstack-ceilometer-central.service

3)部署計算節點

1)安裝計算節點組件

yum install openstack-ceilometer-compute -y

2)修改配置

/etc/ceilometer/polling.yaml:配置采集項和采集時間間隔。

/etc/ceilometer/ceilometer.conf:主要配置文件,服務運行參數。

[DEFAULT]
auth_strategy = keystone
transport_url = rabbit://openstack:openstack@controller

[service_credentials]
auth_type = password
auth_url = http://controller:5000/v3
project_domain_id = default
user_domain_id = default
project_name = service
username = ceilometer
password = ceilometer
interface = internalURL
region_name = RegionOne

3)修改nova配置

# /etc/nova/nova.conf中一下計量相關配置

[DEFAULT]
instance_usage_audit = true
instance_usage_audit_period = hour

[notifications]
notify_on_state_change = vm_and_task_state
notification_format = unversioned

[oslo_messaging_notifications]
driver = messagingv2

其中要注意notification_format = unversioned,因為目前ceilometer只支持解析unversioned格式的計量消息,所以必須這樣配置。

4)啟動服務

systemctl start openstack-ceilometer-compute.service
systemctl status openstack-ceilometer-compute.service
systemctl enable openstack-ceilometer-compute.service

systemctl restart openstack-nova-compute.service

4)驗證使用(控制節點

配置了Ceilometer將計量數據存儲到Gnocchi,事件數據存儲到Panko,Ceilometer啟動后,可以看到相關數據。

# 查看metric列表

openstack metric list --limit 10

# 查看計量數據

openstack metric measures show 01c64435-e1d8-47d2-8b2c-8745b2ab5ca7 --start 2020-03-15T14:40:00

# 查看事件列表

openstack event list --limit 1

10.4、Aodh -- 告警服務

Aodh根據Gnocchi和Panko中存儲的計量和事件數據,提供告警通知功能。

1)主要組件

  • aodh-api:運行在中心節點上,提供警告CRUD接口。
  • aodh-evaluator:運行中心節點上,根據計量數據判斷告警是否觸發。
  • aodh-listener:運行在中心節點上,根據事件數據判斷告警是否觸發。
  • aodh-notifier:運行在中心節點上,當告警被觸發時執行預設的通知動作。

2)部署配置

2.1)配置Keystone

# 創建aodh用戶並添加角色

openstack user create --domain default --password aodh aodh
openstack role add --project service --user aodh admin

# 創建aodh服務

openstack service create --name aodh --description "Telemetry Alarm" alarming

# 創建endpoints

openstack endpoint create --region RegionOne alarming public http://controller:8042
openstack endpoint create --region RegionOne alarming internal http://controller:8042
openstack endpoint create --region RegionOne alarming admin http://controller:8042

2.2)配置MySQL

# 使用MySQL保存索引數據,預先創建數據庫和用戶

mysql -u root -p

CREATE DATABASE aodh;
GRANT ALL PRIVILEGES ON aodh.* TO 'aodh'@'localhost' IDENTIFIED BY 'aodh';
GRANT ALL PRIVILEGES ON aodh.* TO 'aodh'@'%' IDENTIFIED BY 'aodh';

# 安裝Aodh

yum install openstack-aodh-api openstack-aodh-evaluator openstack-aodh-notifier openstack-aodh-listener openstack-aodh-expirer python-aodhclient -y

# 編輯配置,/etc/aodh/aodh.conf:服務運行參數

[DEFAULT]
auth_strategy = keystone
transport_url = rabbit://openstack:openstack@controller

[database]
connection = mysql+pymysql://aodh:aodh@controller/aodh

[keystone_authtoken]
www_authenticate_uri = http://controller:5000
auth_url = http://controller:5000
memcached_servers = controller:11211
auth_type = password
project_domain_id = default
user_domain_id = default
project_name = service
username = aodh
password = aodh

[service_credentials]
auth_type = password
auth_url = http://controller:5000/v3
project_domain_id = default
user_domain_id = default
project_name = service
username = aodh
password = aodh
interface = internalURL
region_name = RegionOne

# 初始化數據庫

aodh-dbsync

# 修改服務文件

# Aodh服務默認監聽8000端口,但幫助文檔中描述的是8042端口。從Gnocchi監聽8041端口來看,Aodh監聽8042比較有延續性。修改aodh的服務文件,在啟動命令中添加--port 8042參數:

$ cat /usr/lib/systemd/system/openstack-aodh-api.service
[Unit]
Description=OpenStack Alarm API service
After=syslog.target network.target

[Service]
Type=simple
User=aodh
ExecStart=/usr/bin/aodh-api --port 8042 -- --logfile /var/log/aodh/api.log
Restart=on-failure

[Install]
WantedBy=multi-user.target

# 啟動服務

systemctl start openstack-aodh-api.service openstack-aodh-evaluator.service openstack-aodh-notifier.service openstack-aodh-listener.service
systemctl status openstack-aodh-api.service openstack-aodh-evaluator.service openstack-aodh-notifier.service openstack-aodh-listener.service
systemctl enable openstack-aodh-api.service openstack-aodh-evaluator.service openstack-aodh-notifier.service openstack-aodh-listener.service

# 驗證使用

openstack alarm create --name cpu_high \
--type gnocchi_resources_threshold \
--description 'Instance Running HOT' \
--metric cpu_util --threshold 65 \
--comparison-operator ge \
--aggregation-method mean \
--granularity 300 --resource-id 5204dcff-c148-406c-a8ce-dcae8f128e50 \
--resource-type instance --alarm-action 'log://' --ok-action 'log://'

這里設置觸發器狀態變為alarm和ok時都執行log動作,即記錄到aodh-notifier日志中。可以將log://替換為外部告警接口,觸發郵件、短信等通知,或者heat、senlin的擴容接口,實現服務自動擴容。

~~~至此OpenStack計量體系的四個組件就部署完成了。~~~

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM