找回密码
 注册
查看: 1566|回复: 5

config drive on openstack subnet 没有开 DHCP

[复制链接]

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
发表于 2021-11-23 11:14:39 | 显示全部楼层 |阅读模式
上一节最后问了大家一个问题:如果 subnet 没有开 DHCP,会是怎样一个情况?/ S5 V( \2 K# W# ~7 z; j) C  D# O
在其他条件不变的情况下,cloud-init 依然会完成那 3 个步骤,也就是说网卡还是会被配置成 dhcp 模式,只是最后网卡没办法获得 IP 而已。  K2 v$ b  o) k; T
不开 DHCP 也是一个常见的场景,为了让 instance 的网卡在这种情况下也能够被正确配置,我们需要借助 config drive。
4 J+ }. Q# U+ T+ y; \( I+ R# Y
在计算节点 /etc/nova/nova.conf 中需要添加一个配置,然后重启 nova-compute 服务

0 ]$ Q8 W" M5 s) o

" Z5 s1 c! S" L$ i. ^, b% x0 S: q  \[DEFAULT]

$ y6 B" W! {( k. p7 uflat_injected = True
: N: F7 }. o& L

5 {2 V0 T& Y" ~, H

& T+ t  ?, z% t( J* V& [7 ~
flat_injected 的作用是让 config drive 能够在 instance 启动时将网络配置信息动态注入到操作系统中。
当前网络的 DHCP 已经关闭。

0 E5 l; N* s9 J- R; k- d& ~: x' v0 `+ F* K
instance 部署时指定使用 config drive
+ G7 B6 G, J6 t6 W( `3 @" p
3 e8 [# O  _& J
Neutron 为 instance 分配的 IP 为 18.18.18.5。
% h) ]) Q# F1 ^3 i: P+ ~0 \' V
instance 启动后登录系统,ip a 验证 IP 已经成功配置,说明 config drive 起作用了
# T' |* f9 h8 _, }2 ]- g2 s6 W" k9 S7 \! h
重要的是弄懂 18.18.18.5 这个 IP 是如何配置上去的。打开 /var/log/cloud-init.log,分析如下
2 P1 m0 M( W5 q9 f
① 扫描出 instance 中的所有网卡,这一步与不使用 config drive 的情况完全一样。
② 获取该网卡的配置信息。 日志显示配置信息是从 ds 获取。ds 是 datasource 的缩写,在这里指的就是 config drive。. P. K' a% E: o. z, Q0 H
在不使用 config drive 的情况下采用的是 fallback 配置。
+ {# }  r9 {; W6 L; U( R0 A* _网卡配置信息记录在 config drive openstack/latest/network_data.json 文件里,内容如下:
7 z% U$ w! @7 O$ [3 ~
③ 将配置信息写入 /etc/network/interfaces.d/50-cloud-init.cfg,内容为:
4 T& m( X+ N- |: H5 S
可以看到 IP 以 static 方式配置。
  总结  
1 D4 h4 g0 F- K) y
1. 在没有使用 config drive 的情况下,cloud-init 只会配置第一块网卡,且设置为 dhcp 模式,所以:
& ^* D' i" A% e% l0 {
    ① 如果 instance 只有一块网卡,且启用了 DHCP,网卡能够被正常拉起。
    ② 如果 instance 有多块网卡,第一块会尝试以 dhcp 方式拉起,其他网卡不作处理。
2. 使用 config drive 的情况下,无论是否启用 DHCP,所有网卡都能被正确配置且成功拉起(如果 dhcp 网卡 >= 2,CentOS 还是有问题,可能跟目前所用的 cloud-init 版本较低有关)。
3. 如果可能,尽量使用 config drive。
讨论完网络配置这个最重要的主题,下一节我们来看看 cloud-init 的其他典型应用:设置 hostanme,设置用户初始密码,安装软件等。
# Q8 {3 `7 I" t) X

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
 楼主| 发表于 2021-11-23 11:19:07 | 显示全部楼层
环境:
openstack版本pike
控制节点主机openstack-controller(ubuntu 16.04.5) 172.27.34.372 S' x: q9 i* q! ?, C7 b- N
计算节点主机openstack-computer(ubuntu 16.04.5) 172.27.34.38
vxlan100
& [- M2 Y, x5 g+ j! k
centos7-init(172.27.100.2)、ubuntu1604(172.27.100.20)
centos7镜像" g) H- W2 U2 g, I
CentOS-7-x86_64-GenericCloud-1809.qcow2c
ubuntu16.04镜像, a/ T, d3 U3 A
xenial-server-cloudimg-amd64-disk1.img
cloud-init
9 C) I7 _/ x8 q9 [) B
cloud-init 0.7.9

( e( |. R; H" k+ ~: G9 ^5 k
ubuntu安装详见:Ubuntu16.04.5以lvm方式安装全记录
openstack安装详见:OpenStack实践(一):Ubuntu16.04下DevStack方式搭建p版OpenStack
浮动ip搭建详见:OpenStack实践(九):Open vSwitch方式实现floating IP  h: j% U) x0 ^# W

7 q# E0 r& K) F) T( L! I1 a4 N- T$ `: G% S# ]/ F: J" _

; t1 w( A2 y/ x
8 A5 @: t/ F' B9 F; P! H
cloud-init简介
& M( }/ z! Y/ z: e; [
cloud-init是linux的一个工具,当系统启动时,cloud-init可从nova metadata服务或者config drive中获取metadata,完成包括但不限于下面的定制化工作:
% T/ p1 w* z$ w: M1.设置 default locale
' \8 D! T: V9 l) E2 A6 R2.设置 hostname, p; d4 Z& `2 U2 R( H% G9 D/ z+ b+ v
3.添加 ssh keys到 .ssh/authorized_keys
: \- F3 e  }$ T( h4.设置用户密码4 L5 U7 i- \3 m2 ]- u
5.配置网络1 v- T/ L; Z' `/ m( P; `' W0 Y7 ~

6 @9 C7 ]" j2 h8 l; ^" O
为了实现instance定制工作,cloud-init会按5个阶段执行任务:1 H9 _0 K( i2 v/ H
1.Generator    (cloud-config.target)% {7 B7 y9 L6 l5 N
2.Local    (cloud-init-local.service). J# V: [7 M2 a6 d4 I+ Q8 j
3.Network    (cloud-init.service)1 C2 U8 o" y; _0 p- q2 B- J
4.Config    (cloud-config.service)
& D, X- G% \3 d$ Y( s5.Final    (cloud-final.service)
如下服务:
[root@ltestwithoutdhcp ~]#  systemctl  list-units|grep cloud-
2 j; z! J6 [2 ?% W  cloud-config.service                                                        loaded active exited    Apply the settings specified in cloud-config1 N3 r; \1 L; ^7 h( g
  cloud-final.service                                                         loaded active exited    Execute cloud user/final scripts
' {2 y4 L6 f3 \  cloud-init-local.service                                                    loaded active exited    Initial cloud-init job (pre-networking)- u, ~8 f/ a+ Z/ I
  cloud-init.service                                                          loaded active exited    Initial cloud-init job (metadata service crawler)
' T, ]3 S" S+ O4 Y9 d  cloud-config.target                                                         loaded active active    Cloud-config availability
2 D4 r+ @$ h% N% m8 Y  cloud-init.target                                                           loaded active active    Cloud-init target
8 A  Y6 u8 h2 i, ?
: F0 p/ t, {5 s  z# d( V$ {0 A

) S$ z1 o* i9 F% A+ ]6 m
各阶段作用
Generator:读取配置文件cloud.cfg;
Local:定位“本地”数据源和配置网络;
Network:读取cloud_init_modules模块的指定配置;
Config:读取cloud_config_modules模块的指定配置
Final :分别读取cloud_final_modules模块的指定配置
, ~! @4 f+ ^/ [+ \
cloud_init_modules:" P0 }/ r0 d7 }/ z0 G9 D
- disk_setup+ z! U! b9 }& Z: e* T9 K
- migrator: b, @* H& P/ c' @* P+ l
- bootcmd
% q) g' o7 U  u8 V9 ]: [/ n+ L - write-files
- H1 a4 R/ F* ]$ W$ j0 w - growpart
$ S- F, V& V4 h, I  N - resizefs' G2 y$ z. Y( [4 L% D5 M
- set_hostname
3 F  M# R8 Z( S# - update_hostname4 c9 J5 i$ B4 r% Q$ p
- update_etc_hosts
* f. J7 V0 K+ M* T1 p  j - rsyslog
7 r9 M2 Q% @& q# ^  a5 r9 o2 w - users-groups8 l% Z% ~! o3 N& p+ V
- ssh
cloud_config_modules:
$ ]' i& y% Z+ d1 d - mounts4 P  N8 }8 `" B5 E
- locale3 S( g5 ~" n8 \  G
- set-passwords
4 k1 y% E) C" M4 D1 L - rh_subscription
! e  Q( p2 W  D6 i2 @( ^ - yum-add-repo5 x/ D6 O4 z8 g/ _6 w1 C% N% z
- package-update-upgrade-install
$ w; w6 U5 ]8 f9 @ - timezone
8 U; K0 K5 H0 y- n0 D - puppet
) f1 I, E2 A8 F, c' K - chef
6 H6 _9 t) _. T  i6 Y$ w( m - salt-minion
1 V' H' z* c& l& l$ v: Y- s  n - mcollective2 U$ ?, q/ O5 a( `
- disable-ec2-metadata2 I6 P2 Q: h1 G  ]! L
- runcmd
cloud_final_modules:
1 s9 Z3 u$ k0 ^7 _ - rightscale_userdata' b1 N: h/ _( |, t
- scripts-per-once( T. n6 c5 A3 v  t8 [- Q: O9 o! O
- scripts-per-boot" a: p1 j! S5 R/ \* G
- scripts-per-instance
6 T& K4 z" z' k  p( M- M - scripts-user6 u: @/ u  u/ i# h3 j; R
- ssh-authkey-fingerprints6 j8 z9 t9 y4 w) t' J9 Z
- keys-to-console" C9 k; l/ C# G
- phone-home
0 Y/ E3 G$ M9 d1 b) X' U- \ - final-message
  [1 T& \5 w4 C6 V - power-state-change
. U/ f2 `! o! ]5 u9 ~* w' ?

; q* y& R. n% h# c: @5 I3 I% O
cloud image) e- h* V3 V% J+ G2 J. s
ubuntu镜像:http://cloud-images.ubuntu.com/7 S( B. o) m5 L# R6 ]- V; z/ w# C
centos7镜像:http://cloud.centos.org/centos/7/images/
2 q6 q* @& x: D: v: S' _, y这些镜像已经预装cloud-init

3 @! E  j  D8 {( M0 C8 C4 n$ Y9 {0 G7 ?& N
config drive
' b) J# r8 S# l- H" G
当无dhcp服务时,可以通过config drive获得metadata
配置config driver
[root@compute01 nova-compute]# view /etc/kolla/nova-compute/nova.conf 4 G3 T  P6 t$ F5 ^7 y
[DEFAULT]
* y$ N+ l. a% V! _' K
0 o4 a7 D  g+ Z" G, U! q0 r5 C# x& h2 W4 ?! V( l2 |
flat_injected = True- b$ Q: z3 n4 }1 q1 W
" N+ _# i: k9 B& Z
该配置是为了关闭DHCP服务时实例网卡也能被正确配置,重启计算服务后配置生效。
stack@openstack-controller:~$ sudo systemctl restart openstack-nova-compute.service+ }; F2 x8 s6 r) ]6 U. w$ z$ @6 S2 P) u
+ |0 o: j7 I0 b0 h  ]$ h
关闭dhcp
为确保实例通过config driver获取的metadata,这里关闭dhcp服务' [7 W; r- i4 t  J
- h/ r+ |3 r1 [  U. y' n
企业微信截图_163763823247 ...
. `7 M  e+ X) C5 @( m! C: }
启动实例
root@openstack-controller:~# nova boot --flavor m1.small --image centos7  --availability-zone nova:openstack-controller --nic net-name=vxlan100 --key-name centos7 --security-groups centos7 --user-data /tmp/centos.config --config-drive true centos7-init
通过--config-drive true启用config-driver,通过--user-data /tmp/centos.config加载配置,ubuntu的配置文件为/tmp/ubuntu.config
打印的日志,传入的user_data

+ t, I6 r% e0 A; X6 l" z8 b: a% t
绑定浮动IP
8 Y" M0 `, M3 Q2 C
# ?$ v, i% O9 F7 Q8 ^& R: q+ f
user-data:centos.config
#cloud-config* v4 o$ r9 f$ n) @  X
chpasswd:
! y! U# T. D. |; ]- `4 Q    list: |
: d( L& ]) R& B7 a0 ^3 q. ^        root:rootroot
. _- z: O4 J' j        centos:centos6 t2 S$ j) y5 J) J) J) z
    expire: false
/ M& l4 w5 N9 m$ r1 J  wssh_pwauth: yes6 e5 d- o  F$ Q9 D6 m
hostname: loong576) J+ Z6 O, D6 X; x# |. t6 K% u/ Z
yum_repos:$ r+ h1 B' k+ B+ |
    epel-163:
- ^$ u4 X$ I" y5 M/ R0 F- [- |        baseurl: http://mirrors.163.com/centos/$releasever/os/$basearch/
) v5 h7 i7 P! ^2 {# `& h        name: Centos-7
, p6 C! n- `2 l* v; M        enabled: true3 r0 R# ~! E, w, K
resolv_conf:- u5 E1 N7 C, w# D9 u' z7 g; {6 `
    nameservers: ['218.104.1xx.1xx', '8.8.8.8']# K" P, Z- Y8 p) b, [$ K, S" P
    searchdomains:
! k( I" G: R+ \$ P1 z7 j& G6 q$ x        - localdomain
& v) ]# z' G2 C0 n    domain: localdomain
8 m. Z4 Y2 a( L/ o# i    options:
/ Y) E* V: [0 Y# P        rotate: true. V. f8 H7 Y' G
        timeout: 1
+ w, {, o- c  @% B0 z8 qmanage_resolv_conf: true
& ^! o, E4 B: P3 @
  s+ U* a9 D% z; B- ?  Wpackages:) b) Y5 f7 r9 F
    - vim0 k4 ?0 f; @% f
    - wget6 h" R  W% W! Y( {9 m1 e9 Z
    - httpd) H1 t8 t* O8 p$ w; M, o
timezone: 'Asia/Shanghai'
' @% E* {1 K, U, {: M: {5 druncmd:
. {9 T  o% Y3 q5 D    - [ sed, -i, "s/^ *SELINUX=enforcing/SELINUX=disabled/g", /etc/selinux/config ]
, [  L3 m+ m- c; O$ M9 |' K    - [ mkdir, /dropme ]- R* X+ L# c/ H/ \: J6 |( W5 H: J
    - [ touch, /root/abc.txt ]
: K9 V8 S/ x6 q4 @1 e! [    - [ sed, -i, "s/^ *nameserver.*/nameserver 114.114.1xx.1xx/g", /etc/resolv.conf ]9 Y/ {* z! I! q4 U
    - [ rpm, --import, /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 ]( }) J; k! o" V% A5 g! a
power_state:
7 K) P, _* {- Q6 s/ E    delay: now
2 O  B) L3 q. G( G+ w/ N( T    mode: reboot
: ]5 G& K( H; R6 d; }    message: reboot now
' V/ S" E1 A6 w# x* N4 k0 R- p$ _! @    timeout: 305 Z1 V7 M1 U3 r) K* p- W; N1 r
    condition: true2 G' \& m( y# E4 V& b5 u
5 W( k6 ~. l; R/ q  q  h1 Q
验证是否生效
, P2 A" k; d4 o9 Z
验证定制的配置文件centos.config是否生效
16376386143172.png
' }$ c3 h- T% q! l' _* T5 r+ ^# o
* u( P2 b) k  R; w, ]
实例可以直接root登陆(默认只能通过创建密钥对方式登陆)成功获取到ip,配置了yum源、时区,runcmd运行正常,关闭了selinux(power-state-change正常),产生了测试文件,修改了[url=]dns[/url]信息( ]3 ]0 B, k4 o' x) j9 l5 v
  C, T0 Z6 O$ h! C$ _- ]2 P
user-data:ubuntu.config
root@openstack-controller:~# more /tmp/ubuntu.config$ H/ U+ i8 E9 R6 f. Z" F/ m
#cloud-config
4 ~5 \& p4 d9 r& `$ k$ p7 U8 }chpasswd:3 @# x) V/ g8 M
    list: |
# n; C0 Z& B1 ~- X" }7 I        root:rootroot
6 E+ i# E) ^6 J+ q        ubuntu:ubuntu6 N, w" t! Q; g, V8 D, P
    expire: false  f- J- `& A3 h& O7 ^
ssh_pwauth: yes4 [, @; l) e! b+ `) G+ u
+ v9 l0 l0 O) A2 O
hostname: ubuntu1604& |/ P7 i9 t' [! u( }2 j
apt:
8 {+ d5 v: J1 Z" g1 q& X/ M! x/ J+ j    primary:" ^2 W. x; E( Q, O6 A
        - arches: [default]
1 P. y; A6 P4 {) f1 A          uri: "http://mirrors.aliyun.com/ubuntu/"5 Y. j& `% W5 G& l# b" d
          search:7 I/ W, U) s" S& M% Q2 s- h' {
            - "http://mirrors.aliyun.com/ubuntu/"5 W8 \* q6 R3 R, I' |6 D

& m% ]9 j# |5 \8 C, sresolv_conf:
& u0 @4 o& @* e. @9 a  @9 T    nameservers: ['218.104.1xx.1xx', '8.8.8.8']( B9 a1 n; v' @6 s% v: e0 n
    searchdomains:
: z8 Y# s( I( h( P& L        - localdomain  B! h9 }6 s1 @- ~8 x# R4 s
    domain: localdomain
4 }# E5 U6 @2 ?- f    options:
9 ]' D$ I8 Z/ W1 g; `4 M, W        rotate: true
- m9 B) l+ {, J( K; a7 A        timeout: 1
3 {" u3 x$ l; B5 X1 \manage_resolv_conf: true
/ @# k& t" k4 z% J! wpackages:
- e3 \  I% ]& j3 k9 U5 |' P7 K - apache2: }9 @1 d! U+ w( ?; `  A) d
timezone: 'Asia/Shanghai'
; |# N6 ?$ b/ X4 ]runcmd:. ~* f* d  E! n: ]& V1 u: Z
    - [ mkdir, /dropme ]
5 o6 Q5 ~7 \: c* N3 ?    - [ sed, -i, "$a nameserver 114.114.1xx.xxx", /etc/resolv.conf ]
7 ^* i) S1 \( M7 m, T; K( |! y5 x  z4 i! _  R2 x7 H0 i6 [

0 k; {# d+ ]8 n
验证是否生效( I2 R8 O; w& d' l9 }
验证定制的配置文件ubuntu.config是否生效
16376386143172.png5 f2 N  e& t5 T+ b6 D, T
实例可以直接ubuntu登陆(默认只能通过创建密钥对方式登陆)成功获取到ip,配置了hostname、apt源、时区,runcmd运行正常,产生了测试文件,修改了dns信息

4 t  F, Y4 |$ h% \+ C6 e
查看config drive
sr0就是config driver,挂载并查看
0 x7 e& p/ ?; v
[root@centos7-init ~]# lsblk
6 g% Q3 c4 z) l& b/ j7 X/ [0 g+ P$ G' A, c, _5 k' ~' l, f+ W, n
[root@centos7-init ~]# mount /dev/sr0 /mnt! ?/ m" x$ r8 k2 s
[root@centos7-init ~]# cd /mnt/openstack/latest/ && ll6 {1 }: U  H5 o

9 [( q) E% {- T9 ^9 \- F' A5 Q[root@centos7-init latest]# more meta_data.json 1 p3 h* {$ V$ ]1 d# v7 [
[root@centos7-init latest]# more user_data
8 @" H6 `$ k8 I" x$ I7 j. N: a( e; c+ F2 ]0 o7 B9 E" X- E

- N! |8 F4 _8 h" ~/ G& @6 }# B! J- q! n+ S3 P! A/ B9 k6 g$ U2 O! h
meta_data.json中存放了public_keys,hostname等信息,user_data对应centos.config。
  U: G" x  P( i" x
cloud-init.log日志分析
[root@centos7-init ~]# view /var/log/cloud-init.log
第一阶段服务' T7 D- S3 E# d% }! O- D' h; e; D4 k

" c" c& I" \) q, B3 A- x5 ?; x
第二阶段服务. I$ J% P0 Y7 e8 C
5 m. E9 b% U) g
第三阶段服务8 z: D' a6 r8 j2 Y% c
在第三阶段init-network服务会依次读取cloud_init_modules模块中以下配置:check-cache、consume-user-data、consume-vendor-data、config-migrator、config-bootcmd、config-write-files、config-growpart、config-resizefs、config-set_hostname、config-update_etc_hosts、config-rsyslog、config-users-groups、config-ssh

4 q# {- `( Q; v& w% _4 o, K  _
第四阶段服务
在第四阶段modules-config服务会依次读取cloud_config_modules模块中以下配置:check-cache、consume-user-data、consume-vendor-data、config-migrator、config-bootcmd、config-write-files、config-growpart、config-resizefs、config-set_hostname、config-update_etc_hosts、config-disable-ec2-metadata、config-runcmd

. l& I9 O! Z) t% R8 [8 P" q
第五阶段服务
5 C; G) e, E: a5 i  L6 {
在第五阶段modules-final服务会依次读取cloud_final_modules模块中以下配置:config-rightscale_userdata、config-scripts-per-boot、config-scripts-per-instance、config-scripts-user、config-ssh-authkey-fingerprints、config-keys-to-console、config-phone-home、config-final-message、config-power-state-chang
cloud init的modules里面提供了丰富的定制信息,详情可以参考Cloud-Init官网:https://cloudinit.readthedocs.io/en/latest/index.html#

3 R( h' L! ]# E, v: Z
cloud-init调试
各服务单独调试3 a+ J5 L7 G$ Y" N: |/ ]8 h' n
init-local:cloud-init init --localcloud_init_modules:cloud-init initcloud_config_modules:cloud-init modules --mode=configcloud_final_modules:cloud-init modules --mode=final
[root@centos7-init ~]# cloud-init init --local
% k, O; S; o0 D! W$ a& d2 M; F
调试某模块的某个配置
[root@centos7-init ~]# cloud-init single --name timezone
调试cloud_config_modules模块的timezone配置

5 W" T+ M" O8 [# I7 C$ f
实践总结:
1.各模块的各配置项依次读取生效; q0 b, k/ L& z. v
在定制实例时,会依次读取配置文件cloud.cfg配置项。
实验环境的主机需配DNS才能访问外网,通过cloud_config_modules模块的runcmd配置项配置DNS,由于配置项package-update-upgrade-install在runcmd之前,cloud-init会先安装软件,这时外网是不通的,所以报错。
8 Y6 B  m* _4 Q, b2 U  }
2.centos的hostname设置不生效
尝试了很多参数组合,都没有到hostname,原因待查
尝试过的参数
hostname: loong576manage_etc_hosts: truepreserve_hostname: truefqdn: loong576
ubuntu没有这个问题,只需设置hostname即可,重启系统也任然生效。
7 e8 E5 \8 M0 m- b2 U+ h
3.DNS配置不生效
配置项resolv_conf不生效。centos和ubuntu都不生效,centos貌似是个bug,参考:https://bugzilla.redhat.com/show_bug.cgi?id=1489270,ubuntu建议将dns信息写入网卡/etc文件/network/interfaces。

; R6 Y) Q. f- q( K! @$ H& e
4.runcmd执行命令是应该是双引号
这个有点坑,在用sed命令执行关闭selinux和配置DNS时,正常的单引号''需替换为"",否则执行报错。

+ e& o! X3 \2 z* e* K
5.某个配置项不合法则整个配置不生效. g* p) U( Z6 l) P- g* b) E, Q) F
runmcd有个配置非法
报错日志
此时整个centos.config配置文件不生效

) I; l+ ]. L" D9 y; p

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
 楼主| 发表于 2021-11-23 12:56:32 | 显示全部楼层
At the end of the previous section, I asked you a question: What would happen if DHCP was not enabled on the subnet?/ I3 b" Y" I6 q" J1 E$ C) \
If other conditions remain unchanged, cloud-init will still complete the 3 steps, which means that the network card will still be configured in dhcp mode, but the network card will not be able to obtain an IP in the end.2 E1 _4 a# E8 B: D
It is also a common scenario not to enable DHCP. In order to allow the instance's network card to be correctly configured in this case, we need to use config drive. Let's start to practice.6 V5 V/ e6 D$ x
You need to add a configuration in the compute node/etc/nova/nova.conf, and then restart the nova-compute service.8 x* S) x- o# b( @* E" b
[DEFAULT]' y5 T/ x. g, v" G3 \7 ^
flat_injected = True, Q% ~: K" @5 n6 V0 N& H) s
The function of flat_injected is to allow config drive to dynamically inject network configuration information into the operating system when the instance starts.; r# ?4 l4 S! d0 N
The DHCP of the current network is closed.
# x) h# M( y7 s2 `8 H# d
9 [7 o% j* y1 g4 SThe config drive is specified when the instance is deployed.
+ R" s2 [) y5 G: f1 P2 D  J' m7 G# b6 j
The IP assigned by Neutron for the instance is
8 _) H" ?& p+ [% Q  o3 d4 ~18.18.18.5, n7 e$ }2 R& {
.* f0 c, K! |( {* b( n# Q
Log in to the system after the instance is started,/ W( I' Y% x( h  g9 ~
ip a8 o0 Q: U! ^9 l) Y/ Q2 p
Verify that the IP has been successfully configured, indicating that the config drive is working.
3 P! w: D$ ?( K% p( H* ^; t& I* mThe important thing is to understand
! g. U% {7 U/ ^5 s18.18.18.5
( s, K; e; @0 T/ u4 h+ W& S How is this IP configured? Open/var/log/cloud-init.log and analyze as follows:
3 J5 o; Z( l, u① Scan out all the network cards in the instance. This step is exactly the same as the case without config drive.
: _! G/ M# B3 n& f9 a② Obtain the configuration information of the network card. The log shows that the configuration information is from
/ S1 c0 r1 y5 d" y  ^* S# x+ F/ L: fds# x; u# t1 @& O; s
Obtain. ds is the abbreviation of datasource, here it refers to config drive. In the case of not using config drive, the 7 |0 O7 j, J' ~' M( y# o# p( G7 W
fallback
3 O- y- W+ M& e& T Configuration. The network card configuration information is recorded in the config drive openstack/latest/network_data.json file, and the content is as follows:9 S  M% u4 K5 ?5 i: ]$ y
③ Write the configuration information into/etc/network/interfaces.d/50-cloud-init.cfg, the content is:
4 }" {3 E: W0 ?9 D& e% Z/ r) e9 O
9 V  l$ t1 Y# ~7 J  g5 M- K8 QYou can see the IP to ' F, s, t0 \2 L  T% A; r
static3 f) ]2 T5 ?7 M' v! ]
Mode configuration.
' U: D$ g6 D: ], xConclusion:( V5 l8 w: d. {$ [/ {8 Z3 @
1. Without using config drive, cloud-init will only configure the first network card and set it to dhcp mode, so:- z( ^) @( }% i* R% r) Y, w. y4 c; l
① If the instance has only one network card and DHCP is enabled, the network card can be pulled up normally.8 G& \% d8 U& t) M- d4 O% F
② If the instance has multiple network cards, the first one will try to be pulled up in dhcp mode, and other network cards will not be processed.1 i6 T* A% S. g! }
2. In the case of using config drive, no matter whether DHCP is enabled, all network cards can be correctly configured and successfully pulled up (if dhcp network card>= 2, CentOS still has problems, which may be related to the lower version of cloud-init currently used ).3 r: j& [# o8 ]5 i* k6 o
3. If possible, try to use config drive. After discussing the most important topic of network configuration, in the next section we will look at other typical applications of cloud-init: setting hostanme, setting user initial password, installing software, etc.
0 D  H. j3 t. Q4 {4 `

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
 楼主| 发表于 2021-11-23 16:47:01 | 显示全部楼层
配置nova.conf文件:$ q- [$ D: r6 z# Z6 D
         flat_injected = True  #使能network信息注入功能
: U8 T6 |+ g2 _5 s         injected_network_template = ********  #配置产生网络metadata数据的模板位置。$ C& g( Z- \& {* b% L2 [
         默认在nova安装目录下,存在interfaces.template模板;
- n/ d' _% n; s0 O% M$ C         nova/virt/interfaces.template
% `* ^1 b! @# O# o+ ^, }3 x+ l) z: e# Y
         实验时,copy上述文件到/etc/nova目录下。设置injected_network_template为:
6 |. @0 G- A' x7 P  C          injected_network_template = /etc/nova/interfaces.template
* u& i% P( |' y/ [* p. E 启动虚机时,nova-compute服务会按照interfaces.template的格式,生成content/0000文件。% s5 U' q9 N0 k4 G1 n% G" `' ^
) b. z' V/ |+ l% G$ d5 q6 H

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
 楼主| 发表于 2021-11-23 16:59:47 | 显示全部楼层
cd /usr/share/nova/8 V2 \% K* }6 j  A* F2 d
cat interfaces.template - f5 s% g2 ?' s$ w2 K
DEVICE="{{ name }}"
# O+ s; j  C/ aNM_CONTROLLED="no"" @8 b6 b7 W; U& A+ S* u, f
ONBOOT=yes
3 r4 l8 m6 z" d, b9 }" VTYPE=Ethernet0 j) P3 @- G- W7 l2 J2 G/ D3 O
BOOTPROTO=static
. I+ Y6 m5 q, V% dIPADDR={{ address }}
8 S2 X9 o3 _. ^7 I: mNETMASK={{ netmask }}
$ u- x/ g* y7 E( [5 h3 kBROADCAST={{ broadcast }}
7 c! Q. G% C" g, pGATEWAY={{ gateway }}2 A2 \  q& |  P& l
DNS1={{ dns }}
) ^7 o  V  P6 Z4 C: J9 U; {+ S. M- `
#if $use_ipv6
5 C+ p" m: T' I& oIPV6INIT=yes
1 J& e) u* e/ z' \4 C* z% m" m: qIPV6ADDR={{ address_v6 }}
! E* |; C- w/ j6 k% a#end if

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
 楼主| 发表于 2021-11-23 17:03:03 | 显示全部楼层
接下来修改/etc/nova/nova.conf配置文件。由于要修改的太多我直接附上我的配置文件。并加上注释; _: ]0 m/ y2 Z. w) i/ C) X9 m
[DEFAULT]$ m# F5 R! l0 K
#debug=True, l0 h; I4 S: M1 a
#基本设置- e" y& l; w7 C9 m% D- b" ^
logdir = /var/log/nova
; k6 `' D5 A9 mstate_path = /var/lib/nova( a# x* H  l$ Q# ^
lock_path = /var/lib/nova/tmp
6 d% o+ R* u4 t. b& Lverbose=True
- [8 L2 B+ L5 U. `6 C3 q* _; Nlibvirt_type = kvm
$ R7 V# F7 m- A! Y( z! Z#volumes_dir = /etc/nova/volumes
" H5 r  x8 V2 e  L" t) D#iscsi_helper = tgtadm
* B: x6 J. l# Q) W/ p* k1 R#connect to mysql
' m3 Q) ]" b. v1 B4 b- F#设置数据库连接可以访问数据库
/ _, Y+ e( E: f! n( V1 h5 r1 [sql_connection = mysql://novaUser:novaPass@192.168.1.102:3306/nova: N# a7 ?8 p! N- @2 l' y
#rpc_backend = nova.openstack.common.rpc.impl_qpid5 |  v7 A' K* c3 L0 Q
rootwrap_config = /etc/nova/rootwrap.conf
; K0 P3 U. y: T- ?8 d; _#my_ip=192.168.137.104
0 g2 @0 Z" k6 y0 a  T#instances_path=/state/partition1/openstack/instance+ b# ^  j$ Q: X0 a
#Image Service
2 c2 ^. l0 U! P+ t0 e0 O# ~  }4 {  ]1 T#用来管理镜像服务器1 A8 h& M2 g9 F6 ^& X1 H' x
glance_api_servers=192.168.1.105:9292
. l. f% O4 c8 ~. @/ [0 Pimage_server=nova.image.glance.GlanceImageService2 W0 g$ L! `/ `2 f( Q* B2 k& F
( A2 Z# L8 O0 O6 [, |& i
#RabbitMQ3 q- a5 [& G( x/ j+ S; a
#通讯节点; J: t& u/ q; D; w( s7 N2 n
compute_scheduler_driver=nova.scheduler.filter_scheduler.FilterScheduler  ~# M5 [4 i) |# p
rabbit_host=192.168.1.103% ^- f' m- @- X1 U% G; L/ `. E4 n: F
rabbit_port=5672( P/ ]2 O( q9 k1 N
rabbit_userid=guest
5 _, H, B( O( w* l$ h  o! c4 G+ s1 Irabbit_password=myrabbitmqpassword3 \; L% g* U7 I% i* ]
api_paste_config=/etc/nova/api-paste.ini, Q- k$ L3 E0 d6 _% J
#NETWORK7 h. K# e/ W( F8 }" M
#网络节点
3 b! S1 J0 E7 k: Z. D% ldhcpbridge = /usr/bin/nova-dhcpbridge
% a! @- v$ @* N  zdhcpbridge_flagfile = /etc/nova/nova.conf
, e9 M. p6 G9 d* y1 t+ s' |force_dhcp_release = True
& k. \1 z: o/ ^" q) n#libvirt_inject_partition = -18 ^9 |+ ]5 G2 g0 {0 H
#injected_network_template = /usr/share/nova/interfaces.template8 x/ }) l8 X4 H! d' F
#libvirt_nonblocking = True8 n+ \( {0 H4 k4 T
#防火墙组件
4 R2 J6 L$ U  T* X0 C  }0 C/ ?! N! hfirewall_driver = nova.virt.libvirt.firewall.IptablesFirewallDriver+ g. w  x& F3 f+ @+ ?& B( s
#网络管理组件
; T/ N. z" ~: i2 t( I/ `5 Vnetwork_manager = nova.network.manager.FlatDHCPManager
( B8 _+ f8 T! [! R2 O" [#网段设置
+ `- V: p9 ]' u8 U; c) Ffixed_range=192.168.100.0/24
3 h2 t. b4 g; \2 S& \0 r, w#计算节点的网桥
8 r8 t# y. O5 n+ T. w+ Z! kflat_network_bridge = br100/ g+ u3 ~! @6 u; z
public_interface=eth3, l# }- ~' o6 Q' r  V5 J6 \; H
#计算节点的内部网络接口
' I, M' e( W) N0 Z6 j1 H) q! yflat_interface=eth2& [* H0 }9 o3 J  P
#网段启始ip7 r* q3 m& f2 f; d" {0 \' m
flat_network_dhcp_start=192.168.100.2( o9 h# b/ Y% ^# D: T+ k% G( D9 a( Q& {
#; Z8 c7 _3 T" f
floating_range=60.12.206.32/27$ c8 R! V' F/ S8 i" L, _! D. F! n
network_size = 1( Q& g8 M/ x/ L/ b
multi_host = true
, F8 r+ b) [' X4 B" ?1 h: W#enabled_apis=metadata
, W; C/ c9 U# G% M( R2 D; ^' s/ e; @% M( Z# z4 u! i. n
#VNC
" {3 \: N9 q* Z#设置vnc服务
9 L+ Y2 I6 ?* e. Y- \novnc_enabled=true
7 s1 l3 N8 X+ ]6 M8 h  Q1 F3 xnovncproxy_base_url=http://192.168.1.106:6080/vnc_auto.html5 q* q* O8 u/ R- w, T" ]( _
novncproxy_port = 6080
. n( ]6 R. w, E7 J0 U9 nvncserver_proxyclient_address = 192.168.137.106
4 v- ^( D% j; B, ?vncserver_listen = 0.0.0.0
% Z3 _  O6 U7 s/ |#AUTH
- o, x" M( c& J( n- Q4 ]. Wauth_strategy = keystone" K1 x9 _+ H/ f. k6 A
#Must Have
7 Q1 b& e" A( E, R- g' _; s#这个我试过用来认证如果没有将没法认证Keystone服务也无法启动
, L( ?' w3 P1 _! x[keystone_authtoken]1 g5 \( Z. o: a6 l$ D
admin_tenant_name = serviceTenant+ P) a/ g8 T" `0 l' a, b& f
admin_user = nova
  s& Q# g* ~2 z. J# L/ U$ \1 A# P# Cadmin_password = Nova_Pass6 h( P8 Q1 L3 ?: z$ c7 F6 U
auth_host = 192.168.1.104
* y: m/ w9 f$ `3 \: @1 X. i# x; Lauth_port = 35357
; _0 Q7 T- k9 e0 E* |: S8 [% fauth_protocol = http& u8 r$ F; l: t& @& b: C- n4 M: f
signing_dir = /tmp/keystone-signing-nova/ @, ]! C. e. ?. ?

; I4 _2 i$ N5 H  u& r2 |; n& e#Compute
9 Z- _4 \3 s9 [" x0 t0 k  a9 ccompute_driver = libvirt.LibvirtDriver" \- M6 e. f5 A
接下来进行数据库同步
% K3 j; q' r* t1 g( `) nnova-manage db sync
' {0 R* u) o( c& n% e: X确保nova用户对/etc/nova /var/lib/nova有完全的权限
  Y6 J, E2 b$ Z+ f( ^- b+ \5 _chown -R nova:nova /etc/nova6 u, S5 X6 m1 @
chown -R nova:nova /var/lib/nova
/ P8 A% ~* i1 C! u' o————————————————
& N6 s! r$ p% E3 i6 ?: \版权声明:本文为CSDN博主「hengrjgc」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
$ @; u0 ^) R2 Q: K9 o; G0 l. E原文链接:https://blog.csdn.net/hengrjgc/article/details/42063623( r: A6 X, w. S& E9 P+ i" R
您需要登录后才可以回帖 登录 | 注册

本版积分规则

返回首页|Archiver|手机版|小黑屋|易陆发现技术论坛 ( 蜀ICP备2026014127号-1 )

GMT+8, 2026-6-12 00:56 , Processed in 0.030604 second(s), 29 queries .

Powered by Discuz! X5.0

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表