A kind of host stores network IP dynamic conversions into static method
Technical field
The present invention relates to field of cloud computer technology, it is dynamic that particularly a kind of cloud computing automatic deployment host stores network IP
The method for changing into static state.
Background technology
After field of cloud calculation host automatic deployment, dynamic IP changes into static network method to set up, most of at present
It is the network information that dynamic network interface card is obtained using ifconfig orders, then obtains ip addresses, mask digit is covered calculating subnet
The numerical value of code, finally by the edit commands of vim, is added manually in the middle of configuration file, then restarts network and come into force.For this
The method of kind especially drawback, needs acquisition IP address information manually simultaneously to change corresponding network profile, compares in deployment node
In the case of many, it may appear that a large amount of to repeat the manual confirmation network information and change the situation of configuration file, it is easy to configuration occur
Mistake, causes network communication problem, so as to affect the speed of cloud computing automatic deployment host installation and deployment.And this method makes
With effectively reducing configuration error appearance, or even occur without, while reducing the working time of configuration.
The content of the invention
Present invention solves the technical problem that being that a kind of cloud computing automatic deployment host storage network dynamic ip conversion is quiet
The method of state ip, it is unstable to solve cloud computing automatic deployment host storage network dynamic IP, and manual modification is into fixed IP
Easily there is configuration error, expend the problem of a large amount of configuration works.
The present invention solves the technical scheme of above-mentioned technical problem,
Described method comprises the steps:
Step 1:Host storage network interface card obtains DHCP dynamic IP addressings;
Step 2:Identification host storage network interface card title;
Step 3:Obtain storage network interface card dynamic IP addressing information;
Step 4:Create static ip address configuration file;
Step 5:Static storage network ip address is set;
Step 6:Network configuration information is persisted in network profile, most at last the network of host from DHCP from
Dynamic acquisition modes become static network configuration.
Remote deployment host of the described method using PXE, and the specified network interface card acquisition storage network of host is set.
Described host storage network interface card obtains dynamic IP, is passed through in the middle of cloud computing host automatic deployment process
DHCP modes are distributed the mode of IP address and obtain dynamic IP addressing information;
Described IP address information includes IP address, gateway address, the network segment, domain name resolution server.
Described establishment static ip address file, refers to according to network type, creates new by touch orders
Ifcfg-* files.
Described static network configuration, after referring to acquisition network configuration information, by network configurator by network configuration
Information is persisted in network profile;Network interface card is reloaded, static configuration is come into force.
The method that the method for the present invention combines the self-defined transmission of parameter and the identification of system network interface card, by the concrete network information
Transmission, and the automatic decision of relevant network conditions carries out automatically conversion of the networking from dynamic IP to static network, effectively solves
Certainly by the artificial acquisition network information and configuration file is set to it is easily configured mistake encountered in, it is in a large number numerous and diverse to match somebody with somebody
Work is put, operating efficiency is realized that principle is simple, reliable, is easily integrated in cloud computing platform than relatively low problem.
Description of the drawings
The present invention is further described below in conjunction with the accompanying drawings:
Fig. 1 is the flow chart of the present invention.
Specific embodiment
According to flow process Fig. 1, the step of the present invention is:
(1) host storage network interface card obtains dhcp dynamic IP addressings
(2) recognize host storage network interface card title
Implement and can be found under/sys/class/net using all of network interface of linux lower networks, no matter
Interface type.
The network interface card title recognized by following interception of commands operating system:
Ls/sys/class/net/ | grep e | awk ' NR==3 { print $ 1 } '
And pass to call by value parameter DHCP_CARD
(3) obtain storage network interface card dynamic IP addressing information
Implement the information that network interface card is obtained using linux lower network order ip addr:
ip addr|grep″dynamic$DHCP_CARD″
For example:
3:enpls0f1:<BROADCAST, MULTICAST, UP, LOWER_UP>mtu 1500
qdisc mq state UP qlen 1000
link/ether 00:a0:d1:eb:5e:65brd ff:ff:ff:ff:ff:ff
inet 192.168.2.43/24brd 192.168.2.255scope global enpls0f1
valid_lft forever preferred_lft forever
inet6fe80::2a0:dlff:feeb:5e65/64scope link
valid_lft forever preferred_lft forever
Then the IP address of current network node is:192.168.2.43/24
The IP address of network is obtained by the intercepting order of script again:
Ip addr | grep " dynamic $ DHCP_CARD " | awk ' { print $ 2 } ' | 1 subnet masks of cut-d "/"-f:
Ip addr | grep " dynamic $ DHCP_CARD " | awk ' { print $ 2 } ' | cut-d "/"-f2 gateways:
`echo$DHCP_IP|awk-F.′{print$1″f.″$2″.″$3}′`.254
(4) create static IP configuration file
Related file is created by touch orders
touch/etc/sysconfig/network-scripts/ifcfg-$DHCP_CARD
(5) static storage network ip address is set
The network schemer of conversion current configuration file:
sed-i′s/dhcp/static/g′$ETHCONF
Remove IPV6 settings, remove UUID
sed-i-e′s/∧UUID/#UUID/g′-e″s/∧IPV6INIT/#IPV6INIT/g″-e
″s/∧NETBOOT/#NETBOOT/g″$ETHCONF
Setting IP relevant informations are in the middle of current network configuration file:
echo-e
" IPADDR=$ DHCP_IP nNETMASK=255.255.255.0 nGATEWAY=`echo
$ DHCP_IP | awk-F. ' { 2 ". " 3 of print 1 ". " } ' ` .254 " > > ETHCONF.