How to setup Redis on Ubuntu Server
Recently I was messing around with some projects and decided to give a shot at Redis, for those who don't know it yet, Redis is a key/value data store that can be used as cache with persistence.
While following the quick start guide I ran into some issues so I decided write about my experience and how I succeeded.
Before we get to go goods, there is some preparations that we have to do, since we will install redis from source, we need to install
sudo apt-get install build-essential
On Redis quick start guide suggests that we compile it from the sources, so thats what we will do, for that we'll need to download the latest sources, extract and then compile.
wget http://download.redis.io/redis-stable.tar.gz tar xvzf redis-stable.tar.gz cd redis-stable make
After that you should run the recommended make test
And then install
sudo make install
If for some reason you get an error similar to the one below, what can you do??
zmalloc.h:50:31: error: jemalloc/jemalloc.h: No such file or directory zmalloc.h:55:2: error: #error "Newer version of jemalloc required"
Google knows the answer:
cd deps make hiredis jemalloc linenoise lua geohash-int cd .. sudo make install
OK, it's compiled... now what?
You could manually copy the binaries and setup all by yourself, buy why do all that work if you have a script that does exactly that, the file that you downloaded comes with a built-in script that sets up Redis to run as a background daemon.
cd utils sudo ./install_server.sh
Then, the setup will start and you'll need to enter the following details:
- Now you have to choose the port that'll be used for this instance, default is
- Select the location of the Redis configuration file, default is
- Select the location of the log file, default is
- Select the data directory for this instance, default is
- Select the redis executable location, should be
/usr/local/bin/redis-server, if you didn't execute
sudo make isntallpreviously you'll be warned
After the confirmation it'll be good to go.
Assuming you used the port
6379 you can start and stop the process with these commands:
sudo service redis_6379 start sudo service redis_6379 stop
If you want Redis to start automatically on boot run:
sudo update-rc.d redis_6379 defaults
If you made it so far you are on point, let's waste no more time. We have have two commands,
redis-server that is responsible for [you know what] the server, and
redis-cli that you can use to interact with the server.
Once you enter
redis-cli you can start sending commands
127.0.0.1:6379> ping PONG 127.0.0.1:6379> set foo bar OK 127.0.0.1:6379> get foo "bar" 127.0.0.1:6379> exit
By default the connections are limited to localhost, but you can change the allowed IPs of set a authentication password on the configuration file just open the file
sudo nano /etc/redis/6379.conf and look for
requirepass, uncomment and change the value to your password, if you want to change the pass, or you can
bind some other IPs
And that concluded this tutorial, let me know how was your experience on the comments below.