Last active
September 7, 2017 12:30
-
-
Save apsega/4288fbceb4f5958ef0e40349e8b9934b to your computer and use it in GitHub Desktop.
aws_keepalive_eip.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# parameter | |
INSTANCE_ID=$1 | |
# variables | |
export AWS_ACCESS_KEY_ID=XXXXXXXXXXX | |
export AWS_SECRET_ACCESS_KEY=XXXXXXXXXXX | |
EIP1=eipalloc-XXXXXXXXXXX # EIP1 xx.xx.xx.xx | |
EIP2=eipalloc-XXXXXXXXXXX # EIP2 xx.xx.xx.xx | |
N1ETHID=eni-XXXXXXXXXXX # xx.xx.xx.xx / ec2-instance-1 eth1 | |
N2ETHID=eni-XXXXXXXXXXX # xx.xx.xx.xx / ec2-instance-2 eth1 | |
N1IP1=xx.xx.xx.xx # ec2-instance-1 | |
N1IP2=xx.xx.xx.xx # ec2-instance-1 | |
N2IP1=xx.xx.xx.xx # ec2-instance-2 | |
N2IP2=xx.xx.xx.xx # ec2-instance-2 | |
HOSTNAME=`hostname -s` | |
# if INSTANCE_ID=1 instance is master then set $N1ETHID and N1IP on ec2-instance-1; | |
# if INSTANCE_ID=2 instance is master then set $N2ETHID nad N2IP on ec2-instance-2; | |
if [[ ${HOSTNAME} == "ec2-instance-1" ]]; then | |
if [[ ${INSTANCE_ID} == "1" ]]; then | |
IF=${N1ETHID} | |
IP=${N1IP1} | |
EIP=${EIP1} | |
elif [[ ${INSTANCE_ID} == "2" ]]; then | |
IF=${N1ETHID} | |
IP=${N1IP2} | |
EIP=${EIP2} | |
fi | |
# AWS CLI to Assign EIP to Master (self) host | |
aws ec2 associate-address --region $region --allocation-id ${EIP} --private-ip-address ${IP} --network-interface-id ${IF} --allow-reassociation | |
fi | |
# if INSTANCE_ID=1 instance is master then set $N1ETHID and N1IP on ec2-instance-1; | |
# if INSTANCE_ID=2 instance is master then set $N2ETHID nad N2IP on ec2-instance-2; | |
if [[ ${HOSTNAME} == "ec2-instance-2" ]]; then | |
if [[ ${INSTANCE_ID} == "1" ]]; then | |
IF=${N2ETHID} | |
IP=${N2IP2} | |
EIP=${EIP1} | |
elif [[ ${INSTANCE_ID} == "2" ]]; then | |
IF=${N2ETHID} | |
IP=${N2IP1} | |
EIP=${EIP2} | |
fi | |
# AWS CLI to Assign EIP to Master (self) host | |
aws ec2 associate-address --region $region --allocation-id ${EIP} --private-ip-address ${IP} --network-interface-id ${IF} --allow-reassociation | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment