2

OpenStack虚拟机管理及元数据meta-date配置 | CHEGVA

 3 years ago
source link: https://chegva.com/2114.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

OpenStack实战十一——虚拟机管理及元数据meta-date配置

1. 计算节点虚拟机管理

1.1 使用kvm进程管理虚拟机

[root@linux-node2 ~]# ps aux|grep kvm

1.2 本地监听vnc

[root@linux-node2 ~]# netstat -tunpl | egrep -w '5900|5901'
tcp        0      0 0.0.0.0:5900            0.0.0.0:*               LISTEN      5565/qemu-kvm       
tcp        0      0 0.0.0.0:5901            0.0.0.0:*               LISTEN      8598/qemu-kvm

1.3 虚拟机启动会连接桥接网卡

[root@linux-node2 ~]# ifconfig
brqf3006de4-de: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.56.12  netmask 255.255.255.0  broadcast 192.168.56.255
        inet6 fe80::fc16:3eff:fe97:2fb6  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:ed:46:77  txqueuelen 0  (Ethernet)
        RX packets 36320  bytes 17056880 (16.2 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 39065  bytes 12613880 (12.0 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet6 fe80::20c:29ff:feed:4677  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:ed:46:77  txqueuelen 1000  (Ethernet)
        RX packets 142825  bytes 84900717 (80.9 MiB)
        RX errors 0  dropped 14  overruns 0  frame 0
        TX packets 86701  bytes 38826030 (37.0 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

1.4 虚拟机默认存储路径

[root@linux-node2 instances]# pwd
/var/lib/nova/instances

[root@linux-node2 instances]# tree .
.
├── 937e0a08-23eb-4741-877b-077c941033fe        #虚拟机ID
│   ├── console.log     #控制台日志
│   ├── disk            #虚拟磁盘
│   ├── disk.info   
│   └── libvirt.xml     #kvm配置文件
├── _base       
│   └── 9b3b4ecb713d1ef7fed0241219c882435acbc727    #镜像
├── c87f90af-f7c0-4715-b35c-b58567a296c7
│   ├── console.log
│   ├── disk
│   ├── disk.info
│   └── libvirt.xml
├── compute_nodes
└── locks
    ├── nova-9b3b4ecb713d1ef7fed0241219c882435acbc727
    └── nova-storage-registry-lock

[root@linux-node1 ~]# source demo-openstack.sh 
[root@linux-node1 ~]# openstack server list
+--------------------------------------+-------------------+--------+---------------------------+
| ID                                   | Name              | Status | Networks                  |
+--------------------------------------+-------------------+--------+---------------------------+
| c87f90af-f7c0-4715-b35c-b58567a296c7 | demo              | ACTIVE | public-net=192.168.56.102 |
| 937e0a08-23eb-4741-877b-077c941033fe | provider-instance | ACTIVE | public-net=192.168.56.101 |
+--------------------------------------+-------------------+--------+---------------------------+

[root@linux-node2 937e0a08-23eb-4741-877b-077c941033fe]# file disk
disk: QEMU QCOW Image (v3), has backing file (path /var/lib/nova/instances/_base/9b3b4ecb713d1ef7fed0241219c882435), 1073741824 bytes

#查看磁盘信息
[root@linux-node2 937e0a08-23eb-4741-877b-077c941033fe]# qemu-img info disk
image: disk
file format: qcow2
virtual size: 1.0G (1073741824 bytes)
disk size: 2.3M
cluster_size: 65536
backing file: /var/lib/nova/instances/_base/9b3b4ecb713d1ef7fed0241219c882435acbc727
Format specific information:
    compat: 1.1
    lazy refcounts: false
    refcount bits: 16
    corrupt: false

2. 元数据meta-date配置

2.1 登陆到虚机,查看meta-date

[root@linux-node1 ~]# ssh [email protected]
$ curl http://169.254.169.254/2009-04-04/meta-data
ami-id
ami-launch-index
ami-manifest-path
block-device-mapping/
hostname
instance-action
instance-id
instance-type
local-hostname
local-ipv4
placement/
public-hostname
public-ipv4
public-keys/
reservation-id


#查看路由信息,有一条192.168.56.100
$ ip ro li
default via 192.168.56.2 dev eth0 
169.254.169.254 via 192.168.56.100 dev eth0 
192.168.56.0/24 dev eth0  src 192.168.56.102

2.2 查看namespace里的信息

[root@linux-node1 ~]# ip netns li 
qdhcp-f3006de4-de03-4bec-af7f-40d3791b645e (id: 0)

[root@linux-node1 ~]# ip netns exec qdhcp-f3006de4-de03-4bec-af7f-40d3791b645e ip ad li
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ns-dc3f9e42-af@if3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether fa:16:3e:f8:ed:79 brd ff:ff:ff:ff:ff:ff link-netnsid 0
    inet 192.168.56.100/24 brd 192.168.56.255 scope global ns-dc3f9e42-af
       valid_lft forever preferred_lft forever
    inet 169.254.169.254/16 brd 169.254.255.255 scope global ns-dc3f9e42-af
       valid_lft forever preferred_lft forever
    inet6 fe80::f816:3eff:fef8:ed79/64 scope link 
       valid_lft forever preferred_lft forever

#开启了80端口
[root@linux-node1 ~]# ip netns exec qdhcp-f3006de4-de03-4bec-af7f-40d3791b645e netstat -ntpl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      2770/python2        
tcp        0      0 192.168.56.100:53       0.0.0.0:*               LISTEN      2858/dnsmasq        
tcp        0      0 169.254.169.254:53      0.0.0.0:*               LISTEN      2858/dnsmasq        
tcp6       0      0 fe80::f816:3eff:fef8:53 :::*                    LISTEN      2858/dnsmasq

2.3 查看neutron中dhcp配置

[root@linux-node1 ~]# vim /etc/neutron/dhcp_agent.ini
# The DHCP server can assist with providing metadata support on isolated
# networks. Setting this value to True will cause the DHCP server to append
# specific host routes to the DHCP request. The metadata service will only be
# activated when the subnet does not contain any router port. The guest
# instance must be configured to request host routes via DHCP (Option 121).
# This option doesn't have any effect when force_metadata is set to True.
# (boolean value)
enable_isolated_metadata = true

192.168.56.100在namespace里面,虚拟机里的那条路由是dhcp推送给它的

2.4 虚机在启动时通过curl把密钥加进去

[root@linux-node1 ~]# ssh [email protected]
$ curl http://169.254.169.254/2009-04-04/meta-data/public-keys/0/openssh-key
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDGObNx1EbxT5tGjjPCZPEnWrnQfjvXSt7rN/kfXXJeXyPhZLpJ+vHypotBuUQpF7Vq3N2pO1j2DxKCyMJpJHeWu65wCI60EaY81oMy+BfQQ7cjLIq/S7X2Q0XAUUFZ7c+JKxISn2tnNIJpR0NM7ifXbUs4cKKKiW6Y7nQxNVZ0Mth/pzgHRJ6sr+9dBKsd/nuGkGuPW6MJos5PSnv3rlQSfCjtuUOwpQ5Le7Xr08Ef9QdYBrSW2glnkiOMTvHImbM8gMPtmOH1AkJqwT2NFKms1ocVYnSlmyZQFGUIwi/JF5k4Ren3NrQ/lY4vs3oz5MJVF3wHwFGaYjLmOYZEbnJP [email protected]

#或者hostname
$ curl http://169.254.169.254/2009-04-04/meta-data/hostname
demo.novalocal

如何配置meta-data?

  1. cloud-init:虚机启动配置meta-data

anzhihe安志合个人博客,版权所有丨 如未注明,均为原创 丨转载请注明转自:https://chegva.com/2114.html | ☆★★每天进步一点点,加油!★★☆

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK