首页 > 解决方案 > 在 red hat ami-7.5 上自动化网络接口相关配置

问题描述

我创建了一个 ENI,我需要使用云形成将它作为辅助 ENI 动态附加到我的 EC2 实例。当我使用红帽 AMI 时,我必须继续手动配置 RHEL,其中包括下面帖子中提到的步骤。

在 Red hat ami- 7.5 上手动配置辅助 Elastic 网络接口

有人可以告诉我如何使用云形成自动化所有这些。有没有办法使用云形成模板中的用户数据来完成所有这些工作?此外,即使我重新启动我的 ec2 实例,我也需要确保配置仍然存在(当前配置在重新启动后被删除。)

标签: amazon-web-servicesamazon-ec2redhatamazon-cloudformation

解决方案


Though it's not complete automation but you can do below to make sure that the ENI comes up after every reboot of your ec2 instance (only for RHEL instances). If anyone has any better suggestion, kindly share.

vi /etc/systemd/system/create.service

Add below content

[Unit]
Description=XYZ
After=network.target

[Service]
ExecStart=/usr/local/bin/my.sh

[Install]
WantedBy=multi-user.target

Change permissions and enable the service

chmod a+x /etc/systemd/system/create.service
systemctl enable /etc/systemd/system/create.service

Below shell script does the configuration on rhel for ENI

vi /usr/local/bin/my.sh

add below content

#!/bin/bash
my_eth1=`curl http://169.254.169.254/latest/meta-data/network/interfaces/macs/0e:3f:96:77:bb:f8/local-ipv4s/`
echo "this is the value--" $my_eth1 "hoo"
GATEWAY=`ip route | awk '/default/ { print $3 }'`
printf "NETWORKING=yes\nNOZEROCONF=yes\nGATEWAYDEV=eth0\n" >/etc/sysconfig/network
printf "\nBOOTPROTO=dhcp\nDEVICE=eth1\nONBOOT=yes\nTYPE=Ethernet\nUSERCTL=no\n" >/etc/sysconfig/network-scripts/ifcfg-eth1
ifup eth1

ip route add default via $GATEWAY dev eth1 tab 2

ip rule add from $my_eth1/32 tab 2 priority 600 

Start the service

systemctl start create.service

You can check if the script ran fine or not by --

journalctl -u create.service -b

推荐阅读