安装OpenStack Zaqar服务

关于什么是Zaqar,有什么作用。国内已有介绍读者可以自行Google查阅。若在此再阐述,已显多余。由于安装Zaqar服务官方文档还有坑且国内无资料,故这里就写一写吧。

依赖服务

  • 一个基本的OpenStack正常运行环境
  • MongoDB(必须大于或等于2个节点,否则会报错)
  • Memcache

说明

本环境,MongoDB和memcache已有kolla-ansible事先安装好。所以,这里只需要安装配置zaqar服务即可。

1.创建keystone认证信息

1
2
3
4
5
6
7
8
# source admin-openrc.sh
# useradd zaqar
# openstack user create --domain default --password-prompt zaqar
# openstack role add --project service --user zaqar admin
# openstack service create --name zaqar --description "Messaging" messaging
# openstack endpoint create --region RegionOne messaging public http://172.17.223.21:8888
# openstack endpoint create --region RegionOne messaging internal http://172.17.223.21:8888
# openstack endpoint create --region RegionOne messaging admin http://172.17.223.21:8888

2.安装zaqar,这里使用queens版本

1
2
3
4
# git clone https://git.openstack.org/openstack/zaqar.git -b stable/queens
# cd zaqar
# pip install . -r ./requirements.txt --upgrade --log /tmp/zaqar-pip.log
# pip install --upgrade pymongo gevent uwsgi

3.创建zaqar配置目录

1
2
3
# mkdir /etc/zaqar
# oslopolicy-sample-generator --config-file etc/oslo-config-generator/zaqar-policy-generator.conf
# cp etc/zaqar.policy.yaml.sample /etc/zaqar/policy.yaml

4.创建zaqar的log文件

1
2
3
# touch /var/log/zaqar-server.log
# chown zaqar:zaqar /var/log/zaqar-server.log
# chmod 600 /var/log/zaqar-server.log

5.创建/srv/zaqar目录

1
2
3
4
5
# mkdir /srv/zaqar
# vim /srv/zaqar/zaqar_uwsgi.py
from keystonemiddleware import auth_token
from zaqar.transport.wsgi import app
app = auth_token.AuthProtocol(app.app, {})

说明

注意,下面的参数“listen = 1024”,超过了系统的默认值128,会报错。因此需要修改默认值,如这里的2048。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# echo "net.core.somaxconn=2048" | sudo tee --append /etc/sysctl.conf
# echo 2048 > /proc/sys/net/core/somaxconn
# echo 2048 > /proc/sys/net/ipv4/tcp_max_syn_backlog

# vim /srv/zaqar/uwsgi.ini
[uwsgi]
http = 172.17.223.21:8888
pidfile = /var/run/zaqar.pid
gevent = 2000
gevent-monkey-patch = true
listen = 1024
enable-threads = true
chdir = /srv/zaqar
module = zaqar_uwsgi:app
workers = 4
harakiri = 60
add-header = Connection: close

6.创建pid文件

1
2
# touch /var/run/zaqar.pid
# chown zaqar:zaqar /var/run/zaqar.pid

7.编辑zaqar配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# vim /etc/zaqar/zaqar.conf
[DEFAULT]
pooling = True
admin_mode = True
debug = True
log_file = /var/log/zaqar-server.log
;auth_strategy = keystone
[keystone_authtoken]
auth_uri = http://172.17.223.20:5000
auth_url = http://172.17.223.20:35357
auth_type = password
project_domain_id = default
user_domain_id = default
project_name = service
username = zaqar
password = zaqar
memcache_security_strategy = ENCRYPT
memcache_secret_key = wRJgCSJjqUT5JWlGVyvSygovRiyXFgJg7kYz1sXX
memcached_servers = 172.17.223.21:11211,172.17.223.26:11211
[cache]
backend = oslo_cache.memcache_pool
enabled = True
memcache_servers = 172.17.223.21:11211,172.17.223.26:11211
[drivers]
transport = wsgi
message_store = mongodb
management_store = mongodb
[drivers:management_store:mongodb]
uri = mongodb://172.17.223.21,172.17.223.26:27017/?replicaSet=rs0&w=2&readPreference=secondaryPreferred
database = zaqarmanagementstore
partitions = 8
;max_attempts = 1000
;max_retry_sleep = 0.1
;max_retry_jitter = 0.005
;gc_interval = 5 * 60
;gc_threshold = 1000
[drivers:message_store:mongodb]
database = zaqarmessagestore
uri = mongodb://172.17.223.21,172.17.223.26:27017/?replicaSet=rs0&w=2&readPreference=secondaryPreferred
[drivers:transport:wsgi]
bind = 0.0.0.0
[transport]
max_queues_per_page = 1000
max_queue_metadata = 262144
max_mesages_per_page = 10
max_messages_post_size = 262144
max_message_ttl = 1209600
max_claim_ttl = 43200
max_claim_grace = 43200
[signed_url]
secret_key = SOMELONGSECRETKEY

8.编辑uwsgi服务启动文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# vim /etc/systemd/system/zaqar.uwsgi.service
[Unit]
Description=uWSGI Zaqar
After=syslog.target
[Service]
ExecStart=/usr/bin/uwsgi --ini /srv/zaqar/uwsgi.ini
# Requires systemd version 211 or newer
RuntimeDirectory=uwsgi
Restart=always
KillSignal=SIGQUIT
Type=notify
StandardError=syslog
NotifyAccess=all
User=zaqar
Group=zaqar
[Install]
WantedBy=multi-user.target

启动uwsgi服务

1
2
# systemctl start zaqar.uwsgi.service
# systemctl enable zaqar.uwsgi.service

说明,如果报错可以查看日志。

1
# tailf /var/log/messages

9.配置Pool

生成一个UUID

1
2
# uuidgen
7289f400-2439-4822-9e3a-928af262d843

运行cURL命令去请求一个keystone token。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# cat auth_token.json 
{
"auth": {
"identity": {
"methods": [
"password"
],
"password": {
"user": {
"name": "zaqar",
"domain": {
"id": "default",
"name": "Default"
},
"password": "zaqar"
}
}
},
"scope": {
"project": {
"name": "service",
"domain": {"id": "default"}
}
}
}
}

比如,这里获取到的token是

1
2
# curl -i -s -d@auth_token.json -H "Content-Type: application/json" http://172.17.223.21:5000/v3/auth/tokens  |grep 'X-Subject-Token'
X-Subject-Token: 7212ad333e6d4a1781974f8e203bf555

配置Pool

1
2
3
4
5
6
# curl -i -X PUT http://172.17.223.21:8888/v2/pools/testpool -d '{"weight": 100, "uri": "mongodb://172.17.223.21,172.17.223.26:27017/?replicaSet=rs0&w=2&readPreference=secondaryPreferred", "options": {"partitions": 8}}' -H "Client-ID: 7289f400-2439-4822-9e3a-928af262d843" -H "X-Auth-Token: eb7e4d966aef4648a1f57a91e4abaa6b" -H "Content-type: application/json"
HTTP/1.1 201 Created
content-length: 0
content-type: application/json; charset=UTF-8
location: http://172.17.223.21:8888/v2/pools/testpool
Connection: close

  1. 验证操作

    1
    2
    3
    4
    5
    6
    7
    8
    # curl -i -X POST http://172.17.223.21:8888/v2/queues/samplequeue/messages -d '{"messages": [{"body": {"event": 1}, "ttl": 600}, {"body": {"event": 2}, "ttl": 600}]}' -H "Content-type: application/json" -H "Client-ID: 7289f400-2439-4822-9e3a-928af262d843" -H "X-Auth-Token: eb7e4d966aef4648a1f57a91e4abaa6b"
    HTTP/1.1 201 Created
    content-length: 135
    content-type: application/json; charset=UTF-8
    location: http://172.17.223.21:8888/v2/queues/samplequeue/messages?ids=5b0bb7289140d605340bf3a6,5b0bb7289140d605340bf3a7
    Connection: close

    {"resources": ["/v2/queues/samplequeue/messages/5b0bb7289140d605340bf3a6", "/v2/queues/samplequeue/messages/5b0bb7289140d605340bf3a7"]}
  2. 安装Zaqar UI

    1
    2
    3
    4
    5
    6
    # git clone https://github.com/openstack/zaqar-ui -b stable/queens
    # docker cp zaqar-ui horizon:/home
    # docker exec -u root -it horizon bash
    # cd /home && pip install -e zaqar-ui/
    # cp zaqar-ui/zaqar_ui/enabled/_1510_project_messaging_group.py /var/lib/kolla/venv/lib/python2.7/site-packages/openstack_dashboard/local/enabled
    # cp zaqar-ui/zaqar_ui/enabled/_1520_project_queues.py /var/lib/kolla/venv/lib/python2.7/site-packages/openstack_dashboard/local/enabled

最后,你就可以愉快的使用Zaqar服务啦。当然,由于该项目目前尚不成熟,参阅资料很少,希望你能一边使用一边填坑。

0%