Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
An user data script (AWS EC2 Launch Template) that sets up a Redis instance loading the RedisGraph module with restart on boot and persistence.
# 1. install redis-server
sudo apt update -y
sudo apt install redis-server -y
# 2. clone and build the latest RedisGraph release (see the instructions on GitHub)
sudo apt-get install build-essential cmake m4 automake peg libtool autoconf -y
cd /home/ubuntu
git clone --recurse-submodules -j8
# result will be in /home/ubuntu/RedisGraph/src/
cd RedisGraph
# move to /var/redis
sudo mkdir -p /var/redis
sudo cp /home/ubuntu/RedisGraph/src/ /var/redis/
# cleanup
sudo rm -rf /home/ubuntu/RedisGraph
# 3. configure redis-server in /etc/redis/redis.conf file
# adjust the settings to your needs here
echo "# modules
loadmodule /var/redis/
# security
requirepass your-secret-password
protected-mode yes
bind ::1
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300
# running env (important)
daemonize yes
supervised systemd
# general
pidfile /var/run/redis/
loglevel notice
logfile /var/log/redis/redis-server.log
databases 16
# snapshots
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir /var/lib/redis
appendonly no
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
aof-use-rdb-preamble yes
# replication
replica-serve-stale-data yes
replica-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
replica-priority 100
# memory (adjust to your needs / instance)
maxmemory 1G
maxmemory-policy noeviction
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
replica-lazy-flush no
# other
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
" > /etc/redis/redis.conf
# 4. start daemonized redis-server
sudo service redis-server restart
sudo systemctl redis-server enable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.