/etc/fstab中的动态IP [英] Dynamic IP in /etc/fstab

查看:55
本文介绍了/etc/fstab中的动态IP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在AWS中使用弹性文件系统(EFS)...我的目标是使用/etc/fstab

I am trying to use elastic file system (EFS) in AWS... My goal is to auto-mount it using /etc/fstab

由于EC2实例会在可用区域之间自动缩放,因此EFS挂载IP的更改取决于实例的区域.目前,AWS提供了此命令以将其安装到正确的区域...

Since EC2 instances are auto scaled across available zones, EFS mount IP's change depending on the instance's zone. At the moment AWS provides this command to mount it to the correct zone...

sudo mount -t nfs4 -o nfsvers=4.1 $(curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone).fs-xxxx.efs.us-east-1.amazonaws.com:/ efs

但是,EFS DNS网址存在一些问题,我只能通过提供的EFS IP进行连接.因此,我创建了一个bash脚本来获取与区域有关的正确IP ...

However, there is some issues with EFS DNS url's, I was only able to connect via provided EFS IP's. So I created a bash script to obtain the correct IP pertaining to zone...

nano/efsmount.sh

nano /efsmount.sh

#!/bin/sh

CURR_ZONE=$(/usr/bin/curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone)

if [ "$CURR_ZONE" == "us-east-1e" ];then
    echo "172.xx.xx.xx"
fi
... more if statements to cover all zones

我可以使用此脚本进行挂载

I can mount using this script

sudo mount -t nfs4 -o nfsvers=4.1 $(/efsmount.sh):/ /efs

现在我的问题是...如何使用fstab自动挂载?

Now my question is... how do I auto mount using fstab?

类似的事情不起作用

$(/efsmount.sh):/  /efs   nfs      auto,noatime,nolock,bg,nfsvers=4.1,intr,tcp,actimeo=1800 0 0

谢谢

推荐答案

在启动过程中,我能够使用init.d脚本自动挂载EFS.这是我遵循的说明: http://www.archisoft.ca/ami/lemp/#setting-up-efs-with-auto-mounting

I was able to auto mount EFS during boot with a init.d script. Here is the instructions I followed: http://www.archisoft.ca/ami/lemp/#setting-up-efs-with-auto-mounting

此init.d脚本在启动时启动,并循环执行一个函数,直到网络可用为止,然后尽快安装EFS.

This init.d script starts at boot time and loops through a function until network becomes available and then mounts the EFS asap.

EFS在Web服务器启动之前就已经挂载,因此NGINX Web服务器可以识别EFS中的站点目录.

EFS is getting mounted before web server starts, therefore site directories residing in the EFS are recognized by NGINX web server without issues.

我认为这可能会对某人有所帮助!

I thought this might help someone!

这篇关于/etc/fstab中的动态IP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆