Kickstart 期间的网络配置

Kickstart 期间的网络配置

我们最近遇到了一个问题,在我们的 anaconda kickstart 文件的安装后部分,ipconfig 不再能够拾取网络。

这导致我们的机器无法安装 Puppet,启动机器时必须手动调整。这非常麻烦,让我们无法在基础设施中完全实现自动化。我们是一家小公司,无法承担手动完成这些任务的费用。

我尝试使用新的ip packagenmcli来获取网络信息。

ip实际上在安装后过程中获取信息,但此时没有 IP 地址。nmcli根本没有获取任何信息。下面是ip address安装后过程中获取的信息的屏幕截图(因为此时您看不到 IP)。

ip 地址命令输出

下面是我想要实现的目标的一步步演示。

  1. 设置网络以寻找 DHCP 租约(只有一个可能)
  2. 使用某种形式的网络包来列出 IP 地址、网关等。
  3. 在 bash 中解析数据,然后将其移动到我的 eth0 接口文件中。
  4. 在 kickstart 完成之前安装 puppet,以便它可以在重启后自行启动。

下面是我的 kickstart 文件,其中包含我尝试过的各种方法(抱歉,有点混乱,但我确实来回尝试过让不同的东西发挥作用)。

install
url --url http://repo1.example.com/centos/7/os/x86_64
lang en_US.UTF-8
keyboard us
timezone --utc America/Vancouver
network --noipv6 --onboot=yes --bootproto=dhcp --activate --device=eth0
authconfig --enableshadow --passalgo=sha512
rootpw --iscrypted ************************************
firewall --enabled --port 22:tcp
selinux --permissive
bootloader --location=mbr --driveorder=vda --append="crashkernel=auth rhgb"

# Disk Partitioning
  zerombr
  clearpart --all --drives=vda
  part / --fstype=ext4 --grow --asprimary --size=200
  part swap --size=4096
# END of Disk Partitioning

# Make sure we reboot into the new system when we are finished
reboot

repo --name=base --baseurl=http://repo1.example.com/centos/7/os/x86_64/

# Package Selection
%packages --nobase 
@core
wget
NetworkManager
-rsyslog
%end

%pre
echo "------------------------- IP COMMANDS ---------------------"
ip address
ip route
echo "------------------------- IP COMMANDS ---------------------"
%end

%post --log=/root/install-post.log (

PATH=/bin:/sbin:/usr/bin:/usr/sbin
export PATH

# PLACE YOUR POST DIRECTIVES HERE

echo "**************************************************"
echo "Converting DHCP scope to static IP address on eth0"
echo "**************************************************"

### NMCLI DOES NOT WORK IN KICKSTART
# IPADDR=`nmcli con show eth0 | grep IP4.ADDRESS | awk '{sub(/IP4.ADDRESS[1]:/,""); print $2}'`
# GATEWAY=`nmcli con show eth0 | grep IP4.GATEWAY | awk '{sub(/IP4.GATEWAY[1]:/,""); print $2}'`
# DNS1=`nmcli con show eth0 | grep "IP4.DNS\[1\]" | awk '{sub(/IP4.DNS[1]:/,""); print $2}'` 
# DNS2=`nmcli con show eth0 | grep "IP4.DNS\[2\]" | awk '{sub(/IP4.DNS[2]:/,""); print $2}'`

## LETS TRY IP as IPCONFIG is EOL
IPADDR=`ip address | grep global | awk '{print $2}' | cut -d / -f1`
GATEWAY=`ip route | grep default | awk '{print $2}'`

echo "------------------------- IP COMMANDS ---------------------"
ip address
ip route
echo "------------------------- IP COMMANDS ---------------------"


echo "##### TEST NMCLI"
echo "IP ADDRES: " $IPADDR
echo "GATEWAY: " $GATEWAY
echo "DNS1: " $DNS1
echo "DNS2: " $DNS2


#nmcli con mod eth0 ipv4.dns $DNS1 
#nmcli con mod eth0 +ipv4.dns $DNS2
#nmcli con mod eth0 ipv4.addresses $IPADDR
#nmcli con mod eth0 ipv4.dns-search example.com
#nmcli con mod eth0 ipv4.gateway $GATEWAY
#nmcli con mod eth0 ipv4.method manual


echo "************************************"
echo "Network test and to clear ARP caches"
echo "************************************"

ping -c 4 repo1.example.com

echo "************"
echo "Setup Puppet"
echo "************"
/usr/bin/wget "https://yum.puppetlabs.com/el/7/products/x86_64/puppetlabs-release-7-12.noarch.rpm"
/usr/bin/rpm -Uvh "puppetlabs-release-7-12.noarch.rpm"
/usr/bin/sed -i "s/yum.puppetlabs.com/repo1.example.com\/puppetlabs/g" /etc/yum.repos.d/puppetlabs.repo
/usr/bin/yum -y --nogpgcheck install puppet
/usr/bin/sed -i 's/\[main\]/\[main\]\nenvironment=infrastructure/g' /etc/puppet/puppet.conf
/usr/bin/echo "server = puppet1.example.com" >> /etc/puppet/puppet.conf
/usr/bin/echo "configtimeout = 30m" >> /etc/puppet/puppet.conf
puppet agent --test # this shouldn't fail
puppet agent --test # this shouldn't fail
puppet agent --test # this shouldn't fail
service puppet start
/usr/sbin/chkconfig puppet on


echo "START NETWORK *********************************"

DEVICE=`route -n | grep '^0.0.0.0' | awk '{print $8}'`
IPADDR=`ifconfig $DEVICE  | grep 'inet ' | awk '{print $2}'`
NETMASK=`ifconfig $DEVICE | grep 'inet ' | awk '{print $4}'`
# NETWORK=`ipcalc $IPADDR -n $NETMASK| cut -d = -f2`
GATEWAY=`route -n|grep '^0.0.0.0'| awk '{print $2}'`
HWADDR=`ifconfig $DEVICE|grep 'ether'| awk '{print $2}'`
# UUID=`uuidgen $DEVICE`

cat <<EOF >/etc/sysconfig/network
NETWORKING=yes
HOSTNAME=$HOSTNAME
GATEWAY=$GATEWAY
EOF

cat <<EOF >/etc/sysconfig/network-scripts/ifcfg-$DEVICE
# NAME=$DEVICE
DEVICE=$DEVICE
BOOTPROTO=static
IPADDR=$IPADDR
NETMASK=$NETMASK
ONBOOT=yes
GATEWAY=$GATEWAY
HWADDR=$HWADDR
DNS1=10.1.1.23
DNS2=10.1.1.24
# UUID=$UUID
EOF
echo "END NETWORK *********************************"

)
%end

相关内容