amazon-web-services - 在 red hat ami-7.5 上自动化网络接口相关配置
问题描述
我创建了一个 ENI,我需要使用云形成将它作为辅助 ENI 动态附加到我的 EC2 实例。当我使用红帽 AMI 时,我必须继续手动配置 RHEL,其中包括下面帖子中提到的步骤。
在 Red hat ami- 7.5 上手动配置辅助 Elastic 网络接口
有人可以告诉我如何使用云形成自动化所有这些。有没有办法使用云形成模板中的用户数据来完成所有这些工作?此外,即使我重新启动我的 ec2 实例,我也需要确保配置仍然存在(当前配置在重新启动后被删除。)
解决方案
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
推荐阅读
- javascript - 使用 Flask 表单发送额外数据?
- android - Kotlin 如何从 android.app.Application 启动异步处理
- python-3.x - pyparse 发现的奇怪的早期文本结尾
- .net - 在不了解文化的情况下将月份名称从一种语言转换为另一种语言?
- javascript - 运行时 Lambda 层未加载节点模块
- python - 如何在时间序列数据框中索引出每一天的第一行和最后一行?
- python - Recusive fxn 没有返回预期的结果
- javascript - 以数字开头的 JSON 标识符导致错误
- python - 在 NumPy 中转置存储在一维数组中的矩阵的最快方法?
- angular - 为什么这个变量来自未定义的本地存储?角 10