Last active
November 26, 2020 12:18
-
-
Save kngvamxx/7f2c25f0967302a36fec4f1720e5cda5 to your computer and use it in GitHub Desktop.
Installing Redis on Ubuntu
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Start by updating the apt packages list by running the following command in your SSH terminal: | |
sudo apt update | |
#Install Redis by typing: | |
sudo apt install redis-server | |
#Once the installation is completed, the Redis service will start automatically. To check the status of the service, enter the following command: | |
sudo systemctl status redis-server | |
#Congratulations, at this point you have Redis installed and running on your Ubuntu 18.04 server. | |
#Configure Redis Remote Access | |
#By default, Redis doesn't allow remote connections. You can connect to the Redis server only from 127.0.0.1 (localhost) - the machine where Redis is running. | |
#Perform the following steps only if you want to connect to your Redis server from remote hosts. If you are using a single server setup, where the application and Redis are running on the same machine then you should not enable remote access. | |
#To configure Redis to accept remote connections open the Redis configuration file with your text editor: | |
sudo nano /etc/redis/redis.conf | |
#Locate the line that begins with bind 127.0.0.1 ::1 and replace 127.0.0.1 with 0.0.0.0. | |
# IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES | |
# JUST COMMENT THE FOLLOWING LINE. | |
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
bind 0.0.0.0 ::1 | |
#Save the file and close the editor.Restart the Redis service for changes to take effect:sudo ufw allow proto tcp from 192.168.121.0/24 to any port 6379 | |
sudo systemctl restart redis-server | |
#Use the following command to verify that redis is listening on all interfaces on port 6379: | |
ss -an | grep 6379 | |
#Next, you'll need to add a firewall rule that enables traffic from your remote machines on TCP port 6379. | |
#Assuming you are using UFW to manage your firewall and you want to allow access from the 192.168.121.0/24 subnet you would run the following command: | |
sudo ufw allow proto tcp from 192.168.121.0/24 to any port 6379 | |
#At this point, Redis server will accept remote connections on TCP port 6379. | |
#Make sure your firewall is configured to accept connections only from trusted IP ranges. | |
#To verify that everything is set up properly, you can try to ping the Redis server from your remote machine using the redis-cli utility: | |
redis-cli -h localhost ping | |
#The command should return a response of PONG: | |
#youtube link | |
https://youtu.be/r3zbnfImn4M | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment