|
At the end of the previous section, I asked you a question: What would happen if DHCP was not enabled on the subnet? 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. 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. You need to add a configuration in the compute node/etc/nova/nova.conf, and then restart the nova-compute service.
* @5 Z( V+ d: O& R6 D. }
& j% [6 ]% }9 \! ^
4 f3 n$ {* @2 j7 A H
P/ e; d8 [+ w" k' N0 y
[DEFAULT]
d5 H6 p% W a5 @7 K9 \flat_injected = True
G9 i/ U/ U+ x+ F- N3 u( JThe function of flat_injected is to allow config drive to dynamically inject network configuration information into the operating system when the instance starts.
% c5 ~9 ~9 h f& I! P3 Q8 NThe DHCP of the current network is closed.
6 v& t7 ~, t7 |5 p& _) U5 y' Q) N4 S+ P b3 i
; |( }& j6 X) P* m# e( `
q/ o- E9 c6 B+ c7 k
/ |2 b" }6 g. C8 L$ ~
1 `. S/ m) y+ D* tThe config drive is specified when the instance is deployed. * [& \ M. `- t# J# h3 W! `( b( T
& ?( N1 e* g2 ~ j; S7 @2 U' e9 ^9 |. Y/ w! P
* P; w: R5 q3 F. i& Q/ a& P% l" O9 F ?# k9 E7 z3 {
The IP assigned by Neutron for the instance is 18.18.18.5! }+ ~9 j* Q5 y5 M+ d$ s
Log in to the system after the instance is started, ip a
, P% J1 c1 J$ |( ^1 S& P Verify that the IP has been successfully configured, indicating that the config drive is working.
- v; B% e; Z! `# w; W: T! u) ^The important thing is to understand 18.18.18.5, i9 U7 @, M+ d; T" t7 G
How is this IP configured? Open/var/log/cloud-init.log and analyze as follows:
/ l7 Q! z! N6 i# J3 E2 _6 t' _① Scan out all the network cards in the instance. This step is exactly the same as the case without config drive. ② Obtain the configuration information of the network card. The log shows that the configuration information is from ds
8 l$ U5 `# L0 w4 _- D8 U3 K9 B/ qObtain. ds is the abbreviation of datasource, here it refers to config drive. In the case of not using config drive, the
7 w: S |( M( b9 T3 n+ Sfallback1 t& C) N* |) ^2 ~' ~# U
Configuration. The network card configuration information is recorded in the config drive openstack/latest/network_data.json file, and the content is as follows:4 D; d7 S9 x9 A" j9 W: ?& D
③ Write the configuration information into/etc/network/interfaces.d/50-cloud-init.cfg, the content is: You can see the IP to static* \; G4 D. e @8 F6 p/ ~
Mode configuration.
+ ^+ w% [ V4 @# I0 K3 k; m5 @[Conclusion: 1. Without using config drive, cloud-init will only configure the first network card and set it to dhcp mode, so: ① If the instance has only one network card and DHCP is enabled, the network card can be pulled up normally. ② 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. 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. 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. |