Redis Server Installation and Operations

 


Redis is an in-memory key-value store known for its flexibility, performance, and wide language support.

Redis (for REmote DIctionary Server)is an open source, in-memory, NoSQL key/value store that is used primarily as an application cache or quick-response database. 

Because it stores data in memory, rather than on a disk or solid-state drive (SSD), Redis delivers unparalleled speed, reliability, and performance.


Installation steps:


1) Update the repository.

root@docker:~# apt-get update


2) Install redis server.

root@docker:~# apt-get install redis-server


3) Update /etc/redis/redis.conf - supervised to enable redis service to start on boot.


#   supervised no      - no supervision interaction

#   supervised upstart - signal upstart by putting Redis into SIGSTOP mode

#   supervised systemd - signal systemd by writing READY=1 to $NOTIFY_SOCKET

#   supervised auto    - detect upstart or systemd method based on

#                        UPSTART_JOB or NOTIFY_SOCKET environment variables


root@docker:~# cat /etc/redis/redis.conf | grep -v "^#" | grep -i super

supervised systemd

root@docker:~#


4) Start the redis service and enable the service.


root@docker:~# systemctl status redis.service

root@docker:/# systemctl enable redis-server.service

Synchronizing state of redis-server.service with SysV service script with /lib/systemd/systemd-sysv-install.

Executing: /lib/systemd/systemd-sysv-install enable redis-server

Created symlink /etc/systemd/system/redis.service → /lib/systemd/system/redis-server.service.

root@docker:/#


root@docker:/# systemctl status redis-server.service

● redis-server.service - Advanced key-value store

     Loaded: loaded (/lib/systemd/system/redis-server.service; linked; vendor preset: enabled)

     Active: active (running) since Thu 2022-02-10 20:28:23 MST; 2min 10s ago

       Docs: http://redis.io/documentation,

             man:redis-server(1)

   Main PID: 3874 (redis-server)

      Tasks: 4 (limit: 2178)

     Memory: 2.1M

     CGroup: /system.slice/redis-server.service

             └─3874 /usr/bin/redis-server 127.0.0.1:6379


Feb 10 20:28:23 docker systemd[1]: Starting Advanced key-value store...

Feb 10 20:28:23 docker systemd[1]: redis-server.service: Can't open PID file /run/redis/redis-server.pid (yet?) after start: Operation not permitted

Feb 10 20:28:23 docker systemd[1]: Started Advanced key-value store.

root@docker:/# 


5) To test that Redis is functioning correctly, connect to the server using the command-line client:


root@docker:/# redis-cli

127.0.0.1:6379> ping

PONG

127.0.0.1:6379>


This output confirms that the server connection is still alive. 


6) Next, check that you’re able to set keys by running:


127.0.0.1:6379> set name "John"

OK

127.0.0.1:6379> get name

"John"

127.0.0.1:6379>


By default, Redis is only accessible from localhost. Bind redis service to primary IP.

root@docker:/# cat /etc/redis/redis.conf | grep -v "^#" | grep -i bind

bind 192.168.45.128

root@docker:/#


root@docker:/# systemctl restart  redis-server.service


root@docker:/# netstat -antp | grep -i 6379

tcp        0      0 192.168.45.128:6379     0.0.0.0:*               LISTEN      4012/redis-server 1

root@docker:/#


7) This is an additional step of configuring redis password.

Configuring a Redis password enables one of its two built-in security features — the auth command, which requires clients to authenticate to access the database.


Update "requirepass" with the password in /etc/redis/redis.conf


root@docker:/# cat /etc/redis/redis.conf | grep -v "^#" | grep -i requirepass

requirepass Password12345

root@docker:/#


Restart redis.


root@docker:/# systemctl restart redis.service


root@docker:/# redis-cli -h  192.168.45.128

192.168.45.128:6379> set a 10

(error) NOAUTH Authentication required.

192.168.45.128:6379> auth Password12345

OK

192.168.45.128:6379> set a 10

OK

192.168.45.128:6379>







Comments

Popular posts from this blog

SRE/DevOps Syllabus

AWS Code Commit - CI/CD Series Part 1

Docker - Preventing IP overlapping