At this point, you can make use of a delivered, interactive utility to configure Redis as a service (it generates an init.d script) and to generate a Redis configuration file. This step can be bypassed if the installation is done solely for local development. To run the setup utility, execute the following command (with sudo):
sudo utils/install_server.sh
The install_server.sh utility will prompt for a few specific settings. Leaving the defaults and providing the path to the server executable returns a summary similar to this:
Selected config:
Port : 6379
Config file : /etc/redis/6379.conf
Log file : /var/log/redis_6379.log
Data dir : /var/lib/redis/6379
Executable : /local/redis/src/redis-server
Cli Executable : /local/redis/src/redis-cli
Is this ok? Then press ENTER to go on or Ctrl-C to abort.
Copied /tmp/6379.conf => /etc/init.d/redis_6379
Installing service...
Success!
Starting Redis server...
Installation successful!
To start/stop/restart the service, provide the entire service name. Example:
sudo service redis_6379 stop
Like many other NoSQL databases, Redis treats security as a bit of an afterthought. While it does not provide robust user or role-based security features, you can enable authentication by setting a password in the config file. By default, this feature is disabled. To enable it, simply uncomment the requirepass line, and provide a good, long password:
requirepass currentHorseBatteryStaple
It is important to remember that this password will be stored in clear text in your configuration file. While it will be owned by the root user, it is recommended to make this password long and difficult to remember (the preceding example notwithstanding).
Additionally, Redis defaults to protected mode as of version 3.2. This setting is also present in the config file:
protected-mode yes
What this setting does is it forces Redis to only accept client requests from the following loopback addresses:
- IPv4: 127.0.0.1
- IPv6: ::1
You should also bind Redis to a specific (preferably internal) IP address. By default, it binds to the IPv4 loopback IP:
bind 127.0.0.1
If you are intending your Redis node to serve remote clients, you will need to alter that line to an IP address that is accessible by the client application(s). It is not advisable to comment out that line, which would cause Redis to listen for connections on all network interfaces.
As mentioned earlier, it is also recommended to disable THP to avoid latency issues as a privileged user:
sudo echo never > /sys/kernel/mm/transparent_hugepage/enabled
Additionally, add that line to the end of your /etc/rc.local file to persist that change after a reboot of the server.
If you have skipped the install_server step, you can run Redis with this command (specifying your redis.conf file):
src/redis-server redis.conf
To ensure that Redis is running, try to connect and authenticate with the redis-cli:
src/redis-cli 127.0.0.1:6379> ping (error) NOAUTH Authentication required. 127.0.0.1:6379>auth currentHorseBatteryStaple OK 127.0.0.1:6379> ping PONG 127.0.0.1:6379> exit
Of course, you can always verify that Redis is running by checking the process scheduler for redis:
ps -ef | grep redis