[pgpool-hackers: 4048] Re: Patch for how to up/down virtual IP on AWS for pgpool2 (Ubuntu 20.04.3 LTS)
Bo Peng
pengbo at sraoss.co.jp
Mon Oct 25 18:52:43 JST 2021
Hello,
Thank you for sharing the scripts used to set VIP on AWS.
I am going to test your scripts and enhance the documentation.
Regards,
On Sat, 23 Oct 2021 17:14:30 +0300
Nirav Bhatt <niravbhatt.cpp at gmail.com> wrote:
> In pgpool2 configuration, there are 3 commands that attach / detach network
> interface to/from newly active/now inactive servers to enable failover.
> In AWS setup, this setup might be different than the one described in
> standard watchdog example.
>
> Here are the things one must consider to enable this functionality in AWS
> instances:
>
> 1 - Edit /etc/pgpool2/pgpool.conf file:
>
> if_cmd_path = '/sbin' #Will be ignored
> if_up_cmd = '/usr/bin/sudo /etc/pgpool2/up.sh $_IP_$'
> if_down_cmd = '/usr/bin/sudo /etc/pgpool2/down.sh $_IP_$'
> arping_path = '/usr/sbin' # Will be ignored
> arping_cmd = '' #Empty string - not required for AWS
>
> 2 - Following is the up.sh described above (note the last line, this is
> different compared to other setups. Also, you must replace ens5 & ens5:1
> with your respective interface name):
>
> #!/bin/sh
> VIRTUAL_IP=$1
> instanceId="$(wget -q -O -
> http://169.254.169.254/latest/meta-data/instance-id/)"
> currentRegion="$(wget -q -O -
> http://169.254.169.254/latest/meta-data/placement/region)"
> #finds the subnetId that the instance belongs to
> subnetId=$(aws ec2 describe-instances \
> --instance-id $instanceId \
> --query "Reservations[*].Instances[].SubnetId" \
> --output text \
> --region $currentRegion)
>
> routingTableId=$(aws ec2 describe-route-tables \
> --query
> "RouteTables[*].Associations[?SubnetId=='$subnetId'].RouteTableId" \
> --output text \
> --region $currentRegion)
>
> #Add network interface for virtual IP
> /usr/bin/sudo /sbin/ip addr add ${VIRTUAL_IP}/32 dev ens5 label ens5:1
>
> #Create AWS route. If it fails, replace it.
> aws ec2 create-route --route-table-id $routingTableId
> --destination-cidr-block ${VIRTUAL_IP}/32 --instance-id $instanceId
> --region $currentRegion
> if [ $? != 0 ];then
> aws ec2 replace-route --route-table-id $routingTableId
> --destination-cidr-block ${VIRTUAL_IP}/32 --instance-id $instanceId
> --region $currentRegion
> fi
>
> #Disable source-destination check
> mac="$(wget -q -O -
> http://169.254.169.254/latest/meta-data/network/interfaces/macs/)"
> interface="$(wget -q -O -
> http://169.254.169.254/latest/meta-data/network/interfaces/macs/${mac}/interface-id
> )"
>
> #Disable source-destination check
> aws ec2 modify-network-interface-attribute --network-interface-id
> $interface --no-source-dest-check --region $currentRegion
>
> 3 - Following is the down.sh described above: (note the last line, this is
> different compared to other setups. Also, you must replace ens5 with your
> respective interface name)
>
> #!/bin/sh
> VIRTUAL_IP=$1
> instanceId="$(wget -q -O -
> http://169.254.169.254/latest/meta-data/instance-id/)"
> currentRegion="$(wget -q -O -
> http://169.254.169.254/latest/meta-data/placement/region)"
> #finds the subnetId that the instance belongs to
> subnetId=$(aws ec2 describe-instances \
> --instance-id $instanceId \
> --query "Reservations[*].Instances[].SubnetId" \
> --output text \
> --region $currentRegion)
>
> routingTableId=$(aws ec2 describe-route-tables \
> --query
> "RouteTables[*].Associations[?SubnetId=='$subnetId'].RouteTableId" \
> --output text \
> --region $currentRegion)
>
> mac="$(wget -q -O -
> http://169.254.169.254/latest/meta-data/network/interfaces/macs/)"
> interface="$(wget -q -O -
> http://169.254.169.254/latest/meta-data/network/interfaces/macs/${mac}/interface-id
> )"
>
> #Remove network interface for virtual IP
> /usr/bin/sudo /sbin/ip addr del $VIRTUAL_IP/32 dev ens5
>
> #Delete AWS route.
> aws ec2 delete-route --route-table-id $routingTableId
> --destination-cidr-block $VIRTUAL_IP/32 --region $currentRegion
>
> #Enable source-destination check
> aws ec2 modify-network-interface-attribute --network-interface-id
> $interface --source-dest-check --region $currentRegion
>
> -Nirav Bhatt
--
Bo Peng <pengbo at sraoss.co.jp>
SRA OSS, Inc. Japan
http://www.sraoss.co.jp/
More information about the pgpool-hackers
mailing list