Skip to content

Instantly share code, notes, and snippets.

@tmyers273
Last active March 5, 2018 00:58
Show Gist options
  • Save tmyers273/95c47ec7887c7e791bdb3462f26ee1a6 to your computer and use it in GitHub Desktop.
Save tmyers273/95c47ec7887c7e791bdb3462f26ee1a6 to your computer and use it in GitHub Desktop.
#!/bin/bash
# DEPRECATED. Use github.com/tmyers273/friac instead
LOGFILE='redis-setup.log'
touch $LOGFILE
# Setup
echo -ne "Starting redis setup..."
add-apt-repository ppa:chris-lea/redis-server
apt-get update > $LOGFILE
apt-get install redis-server -y > $LOGFILE
echo " done"
# Config
echo -ne "Setting up configuration file..."
sed -i '/exit 0/d' /etc/rc.local
echo "vm.overcommit_memory = 1" >> /etc/sysctl.conf
sysctl vm.overcommit_memory=1 > $LOGFILE
echo "sysctl -w net.core.somaxconn=65535" >> /etc/rc.local
sysctl -w net.core.somaxconn=65535 > $LOGFILE
echo "echo never > /sys/kernel/mm/transparent_hugepage/enabled" >> /etc/rc.local
echo never > /sys/kernel/mm/transparent_hugepage/enabled > $LOGFILE
echo "exit 0" >> /etc/rc.local
echo " done"
# Bind to private ip
private_ip=$(curl -sS http://169.254.169.254/metadata/v1/interfaces/private/0/ipv4/address)
public_ip=$(curl -sS http://169.254.169.254/metadata/v1/interfaces/public/0/ipv4/address)
read -p "Do you want to expose this instance's private ip address? ($private_ip) (Y/n):" -n 1 -r
echo # Move to a new line
if [[ $REPLY =~ ^[Yy]$ ]]
then
echo -ne "Binding private ip..."
sed -i "s/bind 127\.0\.0\.1/bind 127\.0\.0\.1 $private_ip/g" /etc/redis/redis.conf
echo " done"
fi
# Bind to public ip
read -p "Do you want to expose this instance's PUBLIC ip address? ($public_ip) (Y/n):" -n 1 -r
echo # Move to a new line
if [[ $REPLY =~ ^[Yy]$ ]]
then
echo -ne "Binding public ip..."
sed -i "s/bind 127\.0\.0\.1/bind 127\.0\.0\.1 $public_ip/g" /etc/redis/redis.conf
echo " done"
fi
# Restart Redis
echo -ne "Restarting redis..."
service redis restart
echo " done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment