Skip to content

Instantly share code, notes, and snippets.

@garystafford

garystafford/consul_01.sh

Last active Apr 11, 2017
Embed
What would you like to do?
# Advertised Consul IP
export ec2_server1_private_ip=$(aws ec2 describe-instances \
--filters Name='tag:Name,Values=tf-instance-consul-server-1' \
--output text --query 'Reservations[*].Instances[*].PrivateIpAddress')
echo "consul-server-1 private ip: ${ec2_server1_private_ip}"
# Deploy Consul Server 1
ec2_public_ip=$(aws ec2 describe-instances \
--filters Name='tag:Name,Values=tf-instance-consul-server-1' \
--output text --query 'Reservations[*].Instances[*].PublicIpAddress')
consul_server="consul-server-1"
ssh -oStrictHostKeyChecking=no -T \
-i ~/.ssh/consul_aws_rsa \
ubuntu@${ec2_public_ip} << EOSSH
docker run -d \
--net=host \
--hostname ${consul_server} \
--name ${consul_server} \
--env "SERVICE_IGNORE=true" \
--env "CONSUL_CLIENT_INTERFACE=eth0" \
--env "CONSUL_BIND_INTERFACE=eth0" \
--volume /home/ubuntu/consul/data:/consul/data \
--publish 8500:8500 \
consul:latest \
consul agent -server -ui -client=0.0.0.0 \
-bootstrap-expect=3 \
-advertise='{{ GetInterfaceIP "eth0" }}' \
-data-dir="/consul/data"
sleep 5
docker logs consul-server-1
docker exec -i consul-server-1 consul members
EOSSH
# Deploy Consul Server 2
ec2_public_ip=$(aws ec2 describe-instances \
--filters Name='tag:Name,Values=tf-instance-consul-server-2' \
--output text --query 'Reservations[*].Instances[*].PublicIpAddress')
consul_server="consul-server-2"
ssh -oStrictHostKeyChecking=no -T \
-i ~/.ssh/consul_aws_rsa \
ubuntu@${ec2_public_ip} << EOSSH
docker run -d \
--net=host \
--hostname ${consul_server} \
--name ${consul_server} \
--env "SERVICE_IGNORE=true" \
--env "CONSUL_CLIENT_INTERFACE=eth0" \
--env "CONSUL_BIND_INTERFACE=eth0" \
--volume /home/ubuntu/consul/data:/consul/data \
--publish 8500:8500 \
consul:latest \
consul agent -server -ui -client=0.0.0.0 \
-advertise='{{ GetInterfaceIP "eth0" }}' \
-retry-join="${ec2_server1_private_ip}" \
-data-dir="/consul/data"
sleep 5
docker logs consul-server-2
docker exec -i consul-server-2 consul members
EOSSH
# Deploy Consul Server 3
ec2_public_ip=$(aws ec2 describe-instances \
--filters Name='tag:Name,Values=tf-instance-consul-server-3' \
--output text --query 'Reservations[*].Instances[*].PublicIpAddress')
consul_server="consul-server-3"
ssh -oStrictHostKeyChecking=no -T \
-i ~/.ssh/consul_aws_rsa \
ubuntu@${ec2_public_ip} << EOSSH
docker run -d \
--net=host \
--hostname ${consul_server} \
--name ${consul_server} \
--env "SERVICE_IGNORE=true" \
--env "CONSUL_CLIENT_INTERFACE=eth0" \
--env "CONSUL_BIND_INTERFACE=eth0" \
--volume /home/ubuntu/consul/data:/consul/data \
--publish 8500:8500 \
consul:latest \
consul agent -server -ui -client=0.0.0.0 \
-advertise='{{ GetInterfaceIP "eth0" }}' \
-retry-join="${ec2_server1_private_ip}" \
-data-dir="/consul/data"
sleep 5
docker logs consul-server-3
docker exec -i consul-server-3 consul members
EOSSH
# Output Consul Web UI URL
ec2_public_ip=$(aws ec2 describe-instances \
--filters Name='tag:Name,Values=tf-instance-consul-server-1' \
--output text --query 'Reservations[*].Instances[*].PublicIpAddress')
echo " "
echo "*** Consul UI: http://${ec2_public_ip}:8500/ui/ ***"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment