OpenStack Yoga版安装笔记(十)placement练习

1、练习场景说明

 在OpenStack Yoga版安装笔记(九)中,placement已经在controller node虚拟机上安装完成,并且已经成功拍摄了快照。

此时,controller node虚机已经安装了keystone、keystone DB、glance、glance DB、OpenStackClient、memcache、placement、placement DB等组件:

(上图中,由于本次练习不涉及glance,所以未画出) 

 将controller node虚机转到此快照然后开机,在后面将在这台虚机上执行以下命令:

openstack --os-placement-api-version 1.2 resource class list --sort-column name

观察OpenStack组件之间完整交互过程。

2、查看OpenStack服务相关进程和TCP连接情况

2.1 查看相关进程

root@controller:~# ps -aux | grep -E 'keystone|placement|glance|rabbitmq|memcache|apache2|mysql'
memcache     811  0.0  0.0 411376  4152 ?        Ssl  Jul31   0:01 /usr/bin/memcached -m 64 -p 11211 -u memcache -l 10.0.20.11 -P /var/run/memcached/memcached.pid
rabbitmq     814  0.1  1.5 2634844 123880 ?      Ssl  Jul31   0:28 /usr/lib/erlang/erts-12.2.1/bin/beam.smp -W w -MBas ageffcbf -MHas ageffcbf -MBlmbcs 512 -MHlmbcs 512 -MMmcs 30 -P 1048576 -t 5000000 -stbt db -zdbbl 128000 -sbwt none -sbwtdcpu none -sbwtdio none -- -root /usr/lib/erlang -progname erl -- -home /var/lib/rabbitmq -- -pa  -noshell -noinput -s rabbit boot -boot start_sasl -syslog logger [] -syslog syslog_error_logger false
root         869  0.0  0.0  14052  6820 ?        Ss   Jul31   0:00 /usr/sbin/apache2 -k start
mysql        966  0.0  1.1 1337780 92048 ?       Ssl  Jul31   0:01 /usr/sbin/mariadbd
rabbitmq    1003  0.0  0.0   2780  1432 ?        Ss   Jul31   0:00 erl_child_setup 65536
rabbitmq    1339  0.0  0.0   3740  1276 ?        Ss   Jul31   0:00 inet_gethost 4
rabbitmq    1340  0.0  0.0   3740   108 ?        S    Jul31   0:00 inet_gethost 4
glance      1358  0.9  1.4 168668 120948 ?       Ss   Jul31   2:37 /usr/bin/python3 /usr/bin/glance-api --config-file=/etc/glance/glance-api.conf --config-dir=/etc/glance/ --log-file=/var/log/glance/glance-api.log
glance      1370  0.0  1.2 168668 105164 ?       S    Jul31   0:00 /usr/bin/python3 /usr/bin/glance-api --config-file=/etc/glance/glance-api.conf --config-dir=/etc/glance/ --log-file=/var/log/glance/glance-api.log
glance      1371  0.0  1.2 168668 105168 ?       S    Jul31   0:00 /usr/bin/python3 /usr/bin/glance-api --config-file=/etc/glance/glance-api.conf --config-dir=/etc/glance/ --log-file=/var/log/glance/glance-api.log
glance      1372  0.0  1.2 168668 105168 ?       S    Jul31   0:00 /usr/bin/python3 /usr/bin/glance-api --config-file=/etc/glance/glance-api.conf --config-dir=/etc/glance/ --log-file=/var/log/glance/glance-api.log
glance      1373  0.0  1.2 168668 105168 ?       S    Jul31   0:00 /usr/bin/python3 /usr/bin/glance-api --config-file=/etc/glance/glance-api.conf --config-dir=/etc/glance/ --log-file=/var/log/glance/glance-api.log
keystone    6449  0.0  0.1 108884 11456 ?        Sl   00:00   0:00 (wsgi:keystone-pu -k start
keystone    6450  0.0  0.1 108884 11456 ?        Sl   00:00   0:00 (wsgi:keystone-pu -k start
keystone    6451  0.0  0.1 108884 11456 ?        Sl   00:00   0:00 (wsgi:keystone-pu -k start
keystone    6452  0.0  0.1 108892 11456 ?        Sl   00:00   0:00 (wsgi:keystone-pu -k start
keystone    6453  0.0  0.1 108884 11460 ?        Sl   00:00   0:00 (wsgi:keystone-pu -k start
placeme+    6454  0.0  0.1 108884 11460 ?        Sl   00:00   0:00 (wsgi:placement-a -k start
placeme+    6455  0.0  0.1 108884 11460 ?        Sl   00:00   0:00 (wsgi:placement-a -k start
placeme+    6456  0.0  0.1 108884 11460 ?        Sl   00:00   0:00 (wsgi:placement-a -k start
placeme+    6457  0.0  0.1 108884 11460 ?        Sl   00:00   0:00 (wsgi:placement-a -k start
placeme+    6458  0.0  0.1 108892 11460 ?        Sl   00:00   0:00 (wsgi:placement-a -k start
www-data    6459  0.0  0.1 2009808 12280 ?       Sl   00:00   0:00 /usr/sbin/apache2 -k start
www-data    6460  0.0  0.1 1944272 12280 ?       Sl   00:00   0:00 /usr/sbin/apache2 -k start
root       15673  0.0  0.0   4180  2428 pts/3    S+   02:53   0:00 grep --color=auto -E keystone|placement|glance|rabbitmq|memcache|apache2|mysql
root@controller:~# 

ps -aux | grep -E 'keystone|placement|glance|rabbitmq|memcache|apache2|mysql'命令解释:

ps -aux 来列出所有运行中的进程,并通过管道 | 将输出传递给 grep 命令。grep -E 表示使用扩展正则表达式,'keystone|placement|glance|rabbitmq|memcache|apache2|mysql' 是一个正则表达式,用于匹配包含 keystoneplacementglancerabbitmq、memcache 、 apache2 、mysql中任意关键词的行。

这里是命令的详细解释:

  • ps -aux: 显示系统上所有运行的进程的详细信息。
  • grep -E: 使用扩展正则表达式来搜索文本。
  • 'keystone|placement|glance|rabbitmq|memcache|apache2|mysql': 这是一个正则表达式,| 是逻辑或运算符,表示匹配列表中的任意一个字符串。

这个命令的输出将包括所有包含上述关键词之一的进程。OpenStack 的 Keystone 认证服务、Glance 镜像服务、Placement 服务、RabbitMQ 消息队列、Memcached 缓存服务、 Apache WEB服务、MySQL 数据库服务相关的进程都会被列出。

 2.2 查看相关TCP监听端口

1、查看所以监听端口信息:

root@controller:~# ss -lnp | grep -E "memcached|beam\.smp|apache2|mariadbd|glance\-api"         
u_str LISTEN 0      869                       /run/mysqld/mysqld.sock 34903                  * 0    users:(("mariadbd",pid=966,fd=97))                                                                                                                                      
u_str LISTEN 0      100            /var/run/apache2/wsgi.869.2.1.sock 48420                  * 0    users:(("apache2",pid=6453,fd=17),("apache2",pid=6452,fd=17),("apache2",pid=6451,fd=17),("apache2",pid=6450,fd=17),("apache2",pid=6449,fd=17),("apache2",pid=869,fd=17))
u_str LISTEN 0      100            /var/run/apache2/wsgi.869.2.2.sock 48421                  * 0    users:(("apache2",pid=6458,fd=19),("apache2",pid=6457,fd=19),("apache2",pid=6456,fd=19),("apache2",pid=6455,fd=19),("apache2",pid=6454,fd=19),("apache2",pid=869,fd=19))
u_dgr UNCONN 0      0                                               * 28652                  * 0    users:(("beam.smp",pid=814,fd=17))                                                                                                                                      
tcp   LISTEN 0      1024                                   10.0.20.11:11211            0.0.0.0:*    users:(("memcached",pid=811,fd=22))                                                                                                                                     
tcp   LISTEN 0      4096                                      0.0.0.0:9292             0.0.0.0:*    users:(("glance-api",pid=1373,fd=4),("glance-api",pid=1372,fd=4),("glance-api",pid=1371,fd=4),("glance-api",pid=1370,fd=4),("glance-api",pid=1358,fd=4))                
tcp   LISTEN 0      128                                       0.0.0.0:25672            0.0.0.0:*    users:(("beam.smp",pid=814,fd=18))                                                                                                                                      
tcp   LISTEN 0      869                                    10.0.20.11:3306             0.0.0.0:*    users:(("mariadbd",pid=966,fd=96))                                                                                                                                      
tcp   LISTEN 0      128                                             *:5672                   *:*    users:(("beam.smp",pid=814,fd=33))                                                                                                                                      
tcp   LISTEN 0      511                                             *:8778                   *:*    users:(("apache2",pid=6460,fd=8),("apache2",pid=6459,fd=8),("apache2",pid=869,fd=8))                                                                                    
tcp   LISTEN 0      511                                             *:5000                   *:*    users:(("apache2",pid=6460,fd=6),("apache2",pid=6459,fd=6),("apache2",pid=869,fd=6))                                                                                    
tcp   LISTEN 0      511                                             *:80                     *:*    users:(("apache2",pid=6460,fd=4),("apache2",pid=6459,fd=4),("apache2",pid=869,fd=4))                                                                                    
root@controller:~# 

2、只看tcp相关的监听端口信息:

root@controller:~# ss -tlnp | grep -E "memcached|beam\.smp|apache2|mariadbd|glance\-api"
LISTEN 0      1024      10.0.20.11:11211      0.0.0.0:*    users:(("memcached",pid=811,fd=22))                                                                                                                     
LISTEN 0      4096         0.0.0.0:9292       0.0.0.0:*    users:(("glance-api",pid=1373,fd=4),("glance-api",pid=1372,fd=4),("glance-api",pid=1371,fd=4),("glance-api",pid=1370,fd=4),("glance-api",pid=1358,fd=4))
LISTEN 0      128          0.0.0.0:25672      0.0.0.0:*    users:(("beam.smp",pid=814,fd=18))                                                                                                                      
LISTEN 0      869       10.0.20.11:3306       0.0.0.0:*    users:(("mariadbd",pid=966,fd=96))                                                                                                                      
LISTEN 0      128                *:5672             *:*    users:(("beam.smp",pid=814,fd=33))                                                                                                                      
LISTEN 0      511                *:8778             *:*    users:(("apache2",pid=6460,fd=8),("apache2",pid=6459,fd=8),("apache2",pid=869,fd=8))                                                                    
LISTEN 0      511                *:5000             *:*    users:(("apache2",pid=6460,fd=6),("apache2",pid=6459,fd=6),("apache2",pid=869,fd=6))                                                                    
LISTEN 0      511                *:80               *:*    users:(("apache2",pid=6460,fd=4),("apache2",pid=6459,fd=4),("apache2",pid=869,fd=4))     

ss -lnp | grep -E "memcached|beam\.smp|apache2|mariadbd|glance\-api"命令解释:

使用 ss -lnp 命令过滤特定服务(memcached, beam.smp, apache2, mariadbd, glance-api)后的结果。这里是对输出中每部分的解释:

  1. Unix 域套接字监听状态 (u_str LISTEN):

    • /run/mysqld/mysqld.sock: MariaDB 或 MySQL 服务的 Unix 域套接字,正在监听连接。
    • /var/run/apache2/wsgi.869.2.1.sock 和 /var/run/apache2/wsgi.869.2.2.sock: Apache2 用于 WSGI 应用程序的 Unix 域套接字。
  2. UDP 未连接状态 (u_dgr UNCONN):

    • 显示了一个与 beam.smp 进程(Erlang 虚拟机)相关的 UDP 套接字,但因为状态是 UNCONN,它还没有连接。
  3. TCP 监听状态 (tcp LISTEN):

    • 10.0.20.11:11211: memcached 服务监听在特定的 IP 地址和端口上。
    • 0.0.0.0:9292: Glance API 服务监听在所有 IPv4 地址的 9292 端口上。
    • 0.0.0.0:25672: 另一个 beam.smp 进程监听在所有 IPv4 地址的 25672 端口上,可能用于 RabbitMQ 消息队列或其他 Erlang 应用。
    • 10.0.20.11:3306: MariaDB 或 MySQL 服务监听在特定的 IP 地址和端口上,通常用于数据库服务。
    • *:5672: 通常用于 RabbitMQ 服务的 AMQP 协议,监听在所有地址的 5672 端口上。
    • *:8778 和 *:5000: 这些端口上的监听服务与 Apache2 相关,分别用于 placement 服务和keystone服务。
    • *:80: Apache2 Web 服务器监听在所有地址的 80 端口上,这是 HTTP 的默认端口。

users 部分列出了使用这些套接字的进程信息,包括进程名称、PID(进程ID)和文件描述符(fd)。

例如,users:(("apache2",pid=6453,fd=17)) 表示 PID 为 6453 的 Apache2 进程使用了文件描述符 17。

这些输出行提供了系统上关键服务的网络监听状态的快照,包括它们监听的协议、地址、端口和关联的进程信息。

 2.3 查看已建立的相关TCP连接

root@controller:~# ss -tp | grep -E "memcached|beam\.smp|apache2|mariadbd|glance\-api"
ESTAB 0      0               127.0.0.1:54684          127.0.0.1:epmd  users:(("beam.smp",pid=814,fd=19))

 抓包过程中,将执行此命令,观察TCP建立情况。

3、Wireshark抓包

3.1 抓包目的

通过执行openstack --os-placement-api-version 1.2 resource class list --sort-column name查看OpenStack各组件之间的完整交互情况。

3.2 抓包方式

1、建议在Windows 11(10.0.20.1)上使用MobaXterm软件,登录到10.0.20.11,运行Wireshark,并捕获“Loopback: lo”端口的流量。

2、执行openstack命令

在win11(10.0.20.1)上使用SecureCRT软件打开一个新窗口,通过ssh连接到10.0.20.11,在osclient上执行相应操作:

root@controller:~# . admin-openrc 
root@controller ~(admin/amdin)# openstack --os-placement-api-version 1.2 resource class list --sort-column name

3、同时,在win11(10.0.20.1)上使用SecureCRT软件通过SSH登录到10.0.20.11,以监控TCP连接的建立情况。

root@controller:~# ss -tp | grep -E "memcached|beam\.smp|apache2|mariadbd|glance\-api|openstack"

 4、停止捕获数据包,然后开始分析。

3.3 抓包分析

3.3.1 TCP连接建立信息

在执行上述openstack命令的同时,记录下的TCP连接信息:

root@controller:~# ss -tp | grep -E "memcached|beam\.smp|apache2|mariadbd|glance\-api|openstack"
ESTAB      0      0               10.0.20.11:mysql          10.0.20.11:43428 users:(("mariadbd",pid=966,fd=148)) 
ESTAB      0      0               10.0.20.11:11211          10.0.20.11:59030 users:(("memcached",pid=811,fd=23)) 
CLOSE-WAIT 1      0               10.0.20.11:41884          10.0.20.11:5000  users:(("openstack",pid=22082,fd=3))
ESTAB      0      0               10.0.20.11:43424          10.0.20.11:mysql users:(("apache2",pid=6451,fd=20))  
ESTAB      0      0               10.0.20.11:59030          10.0.20.11:11211 users:(("apache2",pid=6458,fd=17))  
ESTAB      0      0               10.0.20.11:43428          10.0.20.11:mysql users:(("apache2",pid=6458,fd=12))  
ESTAB      0      0               10.0.20.11:56250          10.0.20.11:5000  users:(("apache2",pid=6458,fd=21))  
ESTAB      0      0                127.0.0.1:54684           127.0.0.1:epmd  users:(("beam.smp",pid=814,fd=19))  
ESTAB      0      0               10.0.20.11:39544          10.0.20.11:8778  users:(("openstack",pid=22082,fd=4))
ESTAB      0      0               10.0.20.11:mysql          10.0.20.11:43424 users:(("mariadbd",pid=966,fd=115)) 

 3.3.2 抓包结果

需要指出的是,在本次练习中,所有相关组件都在控制节点上进行交互,因此无法通过IP地址来区分不同服务,同时目前的wireshark版本抓包信息中,没有相关的进程信息。我们只能通过分析具体的报文来进行判断。对于某些报文,我们需要根据端口号来检查特定的TCP连接,并通过这些连接找到相应的PID号,然后根据这个PID号来确定具体的服务

例如,在上图的第3943号报文中,源端口是59030,目的端口是11211,无法确定是哪个服务发出的源端口,需要检查TCP连接(参见3.3.1节)。通过这种方式,我们发现相应的进程号(pid)是6458:

 根据PID 6458进行信息查询(参见2.1章节),可以确定是由placement服务发出的:

4、Mermaid绘制时序图

 附mermaid code:

sequenceDiagram
  autonumber
  participant C as OpenStackClient
  participant P as placement
  participant M as memcached
  participant K as keystone
  participant KD as keystone DB
  participant PD as placement DB 
  C ->> K: user admin scope to project admin, 发送username:admin/password:openstack
  Note left of C: 命令行中输入: <br/> openstack <br/>--os-placement-api-version 1.2 <br/>resource class list <br/>--sort-column name
  K ->> KD: Keystone第一次login keyston DB, 查询user admin的身份
  KD ->> K: ok
  K ->> C: user admin身份验证成功,Keystone生成admin token
  C ->> P: user admin向placement service发送GET /resource_classes HTTP/1.1,请求中包含之前从Keystone 获取的admin token
  P ->> PD: placement第一次Login placement DB,(没有进行实际的查询)
  PD ->> P: Response
  P ->> M: placement服务接收到请求,去memcache检查请求中的admin token
  Note right of M: 先检查memcached是否有admin token
  M ->> P: 没有,继续去keystone检查
  P ->> K: user placement scope to project service,发送username:placement/password:openstack
  Note right of P: placement首先要认证自己的身份!
  K ->> KD: Keystone第二次login, 查询user placement的身份
  KD ->> K: ok
  K ->> P: placement的身份验证成功,Keystone 生成placement token
  P ->> K: placement服务将admin token发送回 Keystone,请求验证admin token的有效性,请求中包含之前从 Keystone 获取的placement token
  Note right of P: placement拿着自己的token,去验证admin token
  K ->> KD: Keystone第三次login, 查询admin token
  KD ->> K: ok
  K ->> P: admin token有效,Keystone 返回给placement service
  P ->> M: please store admin token
  Note right of M: 保存一份到memcache
  M ->> P: stored
  P ->> PD: placement service继续查询placement db,没有重新login
  PD ->> P: 返回查询结果
  P ->> C: 返回查询结果
  • 21
    点赞
  • 23
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值