Firewall Configuration
To allow Redis traffic through the firewall, add a rule for port 6379:
iptables -I INPUT -p tcp --dport 6379 -j ACCEPT
service iptables save
Installation Steps
- Navigate to the download directory:
cd /usr/local/src
- Download the Redis source package (example version 3.2.9):
wget http://download.redis.io/releases/redis-3.2.9.tar.gz
- Extract the archive:
tar xzf redis-3.2.9.tar.gz
- Enter the source directory:
cd redis-3.2.9
- Create the installation directory structure:
mkdir -p /opt/redis/etc
- Compile Redis:
make
- Install Redis to the target directory:
cd src
make install PREFIX=/opt/redis
- Copy the configuratoin file:
cp redis.conf /opt/redis/etc
- Configure Redis to run in the background:
vim /opt/redis/etc/redis.conf
Set daemonize yes in the configuration file.
- Start the Redis server:
/opt/redis/bin/redis-server /opt/redis/etc/redis.conf
- Enable startup on boot:
vim /etc/rc.local
Add the following line to the file:
/opt/redis/bin/redis-server /opt/redis/etc/redis.conf
Configuration File Parameters
- background_execution: Set to
yesto run Redis in the background. - listen_ip: Specify the IP address Redis should bind to (e.g.,
127.0.0.1for local access). - listen_port: Default port is 6379.
- connection_timeout: Time in seconds before a client connection times out.
- log_level: Log verbosity (debug, verbose, notice, warning). Use
noticein production. - log_file: Path to the log file (e.g.,
/var/log/redis.log). - database_count: Number of databases (default: 1).
- snapshot_schedule: Frequency of database snapshots (e.g.,
save 900 1saves every 15 minutes if 1 key changed). - rdb_compression: Enable compression for RDB snapshots.
- rdb_filename: Name of the RDB snapshot file (default:
dump.rdb). - snapshot_dir: Directory for RDB snapshots.
- replica_of: Configure as a replica of another Redis instance.
- master_password: Password for the master server (if required).
- client_password: Password required for client connections.
- max_clients: Maximum number of concurrent clients.
- max_memory: Maximum memory Redis can use.
- append_only: Enable AOF (Append-Only File) mode for persistence.
- aof_sync_frequency: Frequency of AOF file synchronization.
- vm_enabled: Enable virtual memory support (deprecated in recent versions).
- vm_swap_file: Path to the virtual memory swap file.
- vm_max_memory: Maximum physical memory for virtual memory.
- vm_page_size: Size of virtual memory pages.
- vm_pages: Total number of pages in the swap file.
- vm_max_threads: Number of threads for VM I/O operations.
Redis Tools
- redis-benchmark: Performance testing tool.
- redis-check-aof: AOF log integrity checker.
- redis-check-dump: RDB snapshot integrity checker.
- redis-cli: Command-line client.
- redis-server: Redis server process.
Startup Warning Fixes
Warning 1: overcommit_memory is set to 0
This warning occurs when the kernel’s memory overcommit policy is too restrictive. To fix:
- Permanently set
vm.overcommit_memory = 1:
echo "vm.overcommit_memory=1" > /etc/sysctl.conf
sysctl -p
- Temporarily apply the setting (no reboot needed):
echo 1 > /proc/sys/vm/overcommit_memory
Note: Redis forks a child process during snapshots. Setting vm.overcommit_memory = 1 allows the kernel to allocate memory evenif physical memory is low, preventing crashes.
Warning 2: TCP backlog setting cannot be enforced
This warning occurs when somaxconn is lower than the desired backlog. Fix by setting somaxconn to 511:
echo 511 > /proc/sys/net/core/somaxconn