Skip to content

Instantly share code, notes, and snippets.

@kevinbull
Last active December 28, 2018 11:22
Show Gist options
  • Save kevinbull/1005a3231bb0e9a69447 to your computer and use it in GitHub Desktop.
Save kevinbull/1005a3231bb0e9a69447 to your computer and use it in GitHub Desktop.
Vagrant - Redis Provisioning Script
#!/usr/bin/env bash
echo "updating yum"
sudo yum update
echo "installing git"
sudo yum install -y curl-devel expat-devel gettext-devel openssl-devel zlib-devel git-core
echo "adding rpm repository"
sudo rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
echo "installing redis"
cd /etc
sudo wget http://download.redis.io/releases/redis-2.8.13.tar.gz
sudo tar xzf redis-2.8.13.tar.gz
cd redis-2.8.13
sudo make
echo "configuring redis"
sudo mkdir /etc/redis
sudo mkdir -p /var/redis/6379
sudo cp /etc/redis-2.8.13/utils/redis_init_script /etc/init.d/redis_6379
# Need to insert the following lines beginning with line 2 into /etc/init.d/redis_6379 to make it work with chkconfig
# chkconfig:2345 95 20
# description: ClearC2 Redis server service
# This script starts and stops the redis server
# processname:redis_6379
sudo sed -i "2i\# chkconfig:2345 95 20\n# description: ClearC2 Redis server service\n# This script starts and stops the redis server\n# processname:redis_6379\n" /etc/init.d/redis_6379
sudo sed -i "s/daemonize .*/daemonize yes/" /etc/redis-2.8.13/redis.conf
sudo sed -i "s/pidfile .*/pidfile \/var\/run\/redis_6379.pid/" /etc/redis-2.8.13/redis.conf
sudo sed -i "s/logfile .*/logfile \/var\/log\/redis_6379.log/" /etc/redis-2.8.13/redis.conf
sudo sed -i "s/dbfilename .*/dbfilename redis_6379.rdb/" /etc/redis-2.8.13/redis.conf
sudo sed -i "s/dir .*/dir \/var\/redis/" /etc/redis-2.8.13/redis.conf
sudo sed -i "s/hash-max-ziplist-entries .*/hash-max-ziplist-entries 512/" /etc/redis-2.8.13/redis.conf
sudo sed -i "s/hash-max-ziplist-value .*/hash-max-ziplist-value 255/" /etc/redis-2.8.13/redis.conf
sudo sed -i "s/list-max-ziplist-entries .*/list-max-ziplist-entries 512/" /etc/redis-2.8.13/redis.conf
sudo sed -i "s/list-max-ziplist-value .*/list-max-ziplist-value 255/" /etc/redis-2.8.13/redis.conf
sudo cp /etc/redis-2.8.13/redis.conf /etc/redis/6379.conf
sudo sysctl vm.overcommit_memory=1
# For an explanation of swap files in Linux visit https://wiki.archlinux.org/index.php/swap
sudo sysctl vm.swappiness=10
echo "making redis commands globally available"
sudo ln -s /etc/redis-2.8.13/src/redis-server /usr/local/bin/redis-server
sudo ln -s /etc/redis-2.8.13/src/redis-cli /usr/local/bin/redis-cli
rm -f /etc/redis-2.8.13.tar.gz
echo "Adding Redis service to chkconfig"
sudo chkconfig --add redis_6379
sudo chkconfig --level 2345 redis_6379 on
# Start Redis service - this will echo message
sudo service redis_6379 start
echo "\n\n***************************\nRedis provisioning complete!!!\n***************************\n\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment