EC2에서 / mnt에 / tmp를 마운트하는 방법은 무엇입니까? /mnt/tmp /tmp 그러나 그것은 나를

EC2 인스턴스 /tmp의 임시 스토리지 /mnt에 엔드 포인트 를 마운트 하고 ubuntu사용자 에게 기본 쓰기 권한을 부여하는 가장 좋은 방법이 무엇인지 궁금했습니다 .

다음과 같은 방법으로 /etc/rc.local을 편집하십시오.

mkdir -p /mnt/tmp && mount --bind -o nobootwait /mnt/tmp /tmp

그러나 그것은 나를 위해 작동하지 않습니다 (파일이 다릅니다).

기본 fstab 항목을 편집하려고했습니다.

/dev/xvdb /mnt auto defaults,nobootwait,comment=cloudconfig 0 2

/ mnt를 / tmp로 바꾸고 umask = 0777을 주지만 cloudconfig 때문에 작동하지 않습니다.

우분투 12.04를 사용하고 있습니다. 감사.



답변

처음 제안 할 때는 몇 가지 문제가 있지만 좋은 방향으로 가고있는 것 같습니다.

  1. 보안을 위해 mkdir명령은 모드에서 고정 비트가 설정된 디렉토리를 작성해야합니다.

    mkdir -m 1777 /mnt/tmp
    
  2. -o nobootwait이 저장되지 않는 필요하지 않는 것 같습니다 /mnt/fstab.

따라서 다음을 시도하는 것이 좋습니다 /etc/rc.local.

test -d /mnt/tmp || mkdir -m 1777 /mnt/tmp
mount --bind /mnt/tmp /tmp

/etc/fstab/ mnt가 임시 스토리지이고 /mnt/tmp디렉토리를 포함한 모든 내용 이 사라질 때 인스턴스를 중지 / 시작하거나 AMI를 생성하고 새 인스턴스를 실행할 때 바인드 마운트를 넣으 려고하면 문제가 발생합니다. .


답변

우분투를 실행하고 있기 때문에 더 강력한 접근법은 Eric Hammond의 제안을 Upstart 스크립트 안에 넣고 마운트 직후에 바인딩을 수행하는 것입니다 /mnt.

# File /etc/init/mounted-mnt.conf

# mounted-mnt - Binds /tmp to /mnt/tmp

description     "Binds /tmp to /mnt/tmp"

start on mounted MOUNTPOINT=/mnt

task

script
    test -d /mnt/tmp || mkdir -m 1777 /mnt/tmp
    mount --bind /mnt/tmp /tmp
end script

Apache / Passenger와 같은 일부 서버는에 중요한 임시 파일을 생성 할 수 있습니다 /tmp. 일단 rc.local– 부팅 순서에서 마지막으로 – 그들이 숨겨진 서버를 혼동 얻을 것이다 달렸다.


답변

Romulo Ceccon제안한 Upstart 스크립트 사용 아이디어 는 훌륭합니다. 그러나, 불분명 한 스크립트 안에 마법을 숨기고 싶지 않을 수도 있습니다. fstab 안에 마운트를 추가해도됩니다. 예 :

LABEL=cloudimg-rootfs   /    ext4   defaults    0 0

# auto mount ephemeral storage (if any)
# init contents in /etc/init/mounted-local*.conf
/dev/xvdb  /mnt/local1  auto  defaults,nofail,nobootwait,comment=cloudconfig  0 2
/dev/xvdc  /mnt/local2  auto  defaults,nofail,nobootwait,comment=cloudconfig  0 2
/dev/xvdd  /mnt/local3  auto  defaults,nofail,nobootwait,comment=cloudconfig  0 2
/dev/xvde  /mnt/local4  auto  defaults,nofail,nobootwait,comment=cloudconfig  0 2

# bind /tmp to /mnt/local1, might still be on / if no ephemeral storage
/mnt/local1  /tmp  none  bind

그리고 이것은 Upstart 스크립트입니다 :

# File /etc/init/mounted-local1.conf

# mounted-local1 - init ephemeral storage in /mnt/local1

description     "Initializes ephemeral storage in /mnt/local1"

start on mounted MOUNTPOINT=/mnt/local1

# provide defult, see /etc/init/mounted-tmp.conf for details
env MOUNTPOINT=/mnt/local1

task

script
    # fix permissions if needed
    test -d $MOUNTPOINT && chmod 1777 $MOUNTPOINT

    # log to /var/log/upstart/mounted-local1.log
    #echo "initialized $MOUNTPOINT"

end script

이런 식으로 모든 디렉토리 구조와 임시 스토리지에없는 디렉토리 구조를 작성할 수 있습니다.

남아있는 것은 mkdir -p /mnt/local{1..4}다시 시작하고 다시 시작합니다 (현재 파일을 숨기지 않고는 / tmp를 마운트하지 않습니다).


답변