A Step-by-Step Guide Vagrant install Redis server

Introduction

In this tutorial, How to use Vagrant install Redis server. Vagrant, a powerful open-source tool, allows developers to create and manage lightweight, reproducible, and portable virtual machines effortlessly.

My Environment for Vagrant install Redis server

  • Host OS: Windows 11
  • Vagrant version: 2.2.18
  • Vagrant provider: VirtualBox
  • Boxes Vagrant: rockylinux/8
  • Terminal/PowerShell
  • Installed VirtualBox

The vagrant directory and files will look like as below:

C:\MYDATA\VAGRANT_VMS\PROJECTS\VAGRANT\ROCKY-REDIS
│   Vagrantfile
│
├───conf
│       redis.conf
│
└───shell
        init-redis.sh

I created an “init-redis.sh” script to install Redis Server on Rocky Linux. I use the provisioning shell of Vagrant to deploy Redis Server on Rocky Linux.

The content script is as below:

#!/bin/bash

# Install Redis
sudo dnf install -y git unzip net-tools
sudo dnf module install redis -y

sudo sysctl vm.overcommit_memory=1
echo never > sudo  /sys/kernel/mm/transparent_hugepage/enabled

#Configure Redis
sudo cp /etc/redis.conf /etc/redis.conf.orig
sudo cp /vagrant/conf/redis.conf /etc/redis.conf

sudo systemctl start redis
sudo systemctl enable redis
sudo systemctl status redis

For example, the File “redis.conf” configures Redis Server as below:

bind 0.0.0.0
protected-mode yes
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize no
supervised no
pidfile /var/run/redis_6379.pid
loglevel notice
logfile /var/log/redis/redis.log
databases 16
always-show-logo yes
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
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
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
replica-lazy-flush no
appendonly yes
appendfilename "appendonly.aof"
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
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
stream-node-max-bytes 4096
stream-node-max-entries 100
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit replica 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
dynamic-hz yes
aof-rewrite-incremental-fsync yes
rdb-save-incremental-fsync yes
requirepass devosroles.com

Create a Virtual Machine

I will navigate to my working directory. For example, the “Rocky-Redis” folder and create initialized Vagrantfile vagrant as the command below.

cd Rocky-Redis
vagrant init rockylinux/8

Configure the Virtual Machine

Edit the Vagrantfile and paste the content below

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|

  config.vm.box = "rockylinux/8"
  config.ssh.insert_key = false  

  config.vbguest.auto_update = false
  
  config.vm.define "redisserver" do |redisserver|
    redisserver.vm.hostname = "devopsroles.com"
    redisserver.vm.network "private_network", ip: "192.168.4.4"
    redisserver.vm.network "forwarded_port", guest: 6379, host: 6379
    redisserver.vm.provision "shell", 
     path: "C:\\MyData\\Vagrant_VMS\\Projects\\Vagrant\\Rocky-Redis\\shell\\init-redis.sh"

  end

end

Deploy Redis Server on Rocky Linux

Use the command below to create and configures guest machines according to your Vagrantfile.

vagrant up

Finally, we will connect to the Redis server.

vagrant ssh redisserver

The output terminal as below

Vagrant install Redis server

Conclusion

You’ve successfully installed the Redis server on a virtual machine using Vagrant. With this setup, you can now develop and test your Redis-dependent applications in an isolated and portable environment.

Vagrant’s ease of use and versatility make it an invaluable tool for any developer’s toolkit. I hope will this your helpful. Thank you for reading the DevopsRoles page!

About HuuPV

My name is Huu. I love technology, especially Devops Skill such as Docker, vagrant, git, and so forth. I like open-sources, so I created DevopsRoles.com to share the knowledge I have acquired. My Job: IT system administrator. Hobbies: summoners war game, gossip.
View all posts by HuuPV →

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.