Skip to content

Instantly share code, notes, and snippets.

@FlorianPfisterer
Created November 14, 2020 17:42
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FlorianPfisterer/7b171e3701dced4105405b78c7e7998d to your computer and use it in GitHub Desktop.
Save FlorianPfisterer/7b171e3701dced4105405b78c7e7998d to your computer and use it in GitHub Desktop.
An user data script (AWS EC2 Launch Template) that sets up a Redis instance loading the RedisGraph module with restart on boot and persistence.
#!/bin/bash
# 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 https://github.com/RedisGraph/RedisGraph.git
# result will be in /home/ubuntu/RedisGraph/src/redisgraph.so
cd RedisGraph
make
# move to /var/redis
sudo mkdir -p /var/redis
sudo cp /home/ubuntu/RedisGraph/src/redisgraph.so /var/redis/redisgraph.so
# 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/redisgraph.so
# security
requirepass your-secret-password
protected-mode yes
bind 127.0.0.1 ::1
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300
# running env (important)
daemonize yes
supervised systemd
# general
pidfile /var/run/redis/redis-server.pid
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