{"id":622,"date":"2016-06-20T15:37:09","date_gmt":"2016-06-20T10:07:09","guid":{"rendered":"https:\/\/pheonixsolutions.com\/blog\/?p=622"},"modified":"2026-09-07T17:14:32","modified_gmt":"2026-09-07T11:44:32","slug":"redismaster-and-slave-setup","status":"publish","type":"post","link":"https:\/\/pheonixsolutions.com\/blog\/redismaster-and-slave-setup\/","title":{"rendered":"RedisMaster and Slave Setup"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Introduction<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Redis supports replication by allowing one Redis server to act as the <strong>master<\/strong> and another Redis server to act as the <strong>slave<\/strong>. The slave maintains a copy of the data from the master and can be used for read operations and redundancy.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This guide explains how to install Redis, configure the Redis master server, configure a Redis slave server, and enable Redis to start automatically after a reboot.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\"><strong>Note:<\/strong> This article uses Redis 3.0-era configuration and commands. In newer Redis versions, the term <strong>replica<\/strong> is preferred over <strong>slave<\/strong>, and some configuration directives may have changed.<\/p>\n<\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\">Prerequisites<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Before starting the Redis master-slave setup, make sure you have:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Two Linux\/CentOS servers.<\/li>\n\n\n\n<li>Root or <code>sudo<\/code> access.<\/li>\n\n\n\n<li>Network connectivity between the Redis master and slave.<\/li>\n\n\n\n<li>Port <code>6379<\/code> available between the servers.<\/li>\n\n\n\n<li>GCC and Make installed for compiling Redis.<\/li>\n\n\n\n<li>The hostname or IP address of the Redis master server.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Implementation<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Step 1: Install Linux Dependencies on the Redis Server<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Install GCC and Make using <code>yum<\/code>:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo yum -y install gcc make<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 2: Download and Compile Redis 3.0<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Download the Redis source package, extract it, and compile Redis:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">wget http:\/\/&lt;Download the latest file from the redis official site>\ntar xzf redis-3.3.0-rc3.tar.gz\ncd redis-3.0.0-rc3\nmake<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 3: Create Redis Directories and Copy Files<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Create the required directories:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo mkdir \/etc\/redis \/var\/lib\/redis<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Copy the Redis server and CLI binaries:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo cp src\/redis-server src\/redis-cli \/usr\/local\/bin\nsudo cp redis.conf \/etc\/redis<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 4: Configure redis.conf on the Master<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Open the Redis configuration file:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo vim \/etc\/redis\/redis.conf<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Configure the following settings:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">daemonize yes\nbind 0.0.0.0\ndir \/var\/lib\/redis\npidfile \/var\/run\/redis.pid\nport 6379\ndir \/var\/lib\/redis\nlogfile \"\/var\/log\/redis.log\"<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>bind<\/code> setting determines which network interfaces Redis listens on. If Redis needs to communicate with a remote slave, make sure the network and firewall configuration allow the required traffic.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 5: Download the Redis Init Script<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Download the Redis service init script:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">wget https:\/\/raw.github.com\/saxenap\/install-redis-amazon-linux-centos\/master\/redis-server<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 6: Move and Configure redis-server<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Move the downloaded init script to <code>\/etc\/init.d<\/code>:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo mv redis-server \/etc\/init.d\nsudo chmod 755 \/etc\/init.d\/redis-server\nsudo nano \/etc\/init.d\/redis-server<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Make sure the Redis binary path is configured as:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">redis=\"\/usr\/local\/bin\/redis-server\"<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 7: Enable Redis at System Startup<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Add Redis to the system services:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo chkconfig --add redis-server\nsudo chkconfig --level 345 redis-server on<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 8: Start the Redis Master Server<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Start Redis:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo service redis-server start<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The Redis master server is now ready to accept connections from the slave server.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Configure the Redis Slave Server<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Step 9: Install and Configure Redis on the Slave<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">On the Redis slave server, follow <strong>Steps 1 through 6<\/strong>, except for the master-specific configuration in Step 4.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Open the Redis configuration file:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">vim \/etc\/redis\/redis.conf<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Specify the following settings:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">daemonize yes\nslaveof &lt;hostname or IPaddress> 6379\npidfile \/var\/run\/redis.pid\nport 6379<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Replace <code>&lt;hostname or IPaddress&gt;<\/code> with the hostname or IP address of the Redis master server.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">slaveof 192.168.1.10 6379<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This configures the Redis server to replicate data from the specified master.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 10: Enable Redis on the Slave<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Add Redis to the system startup configuration:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo chkconfig --add redi-server &amp;&amp; sudo chkconfig --level 345 redis-server on<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 11: Start Redis on the Slave<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Start the Redis service:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo service redis-server start<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Once the slave connects successfully to the master, Redis will begin replicating the master&#8217;s data.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Verify Redis Replication<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">After starting both servers, connect to Redis:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">redis-cli<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Run:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">INFO<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Check the <code>role<\/code> field.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">On the master, you should see:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">role:master<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">On the slave, you should see:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">role:slave<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You can also check the replication information on the master to verify that the slave is connected.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Redis master-slave replication provides a simple way to maintain a copy of Redis data on another server. This setup involves installing Redis on both servers, configuring one server as the master, configuring the second server as the slave, and enabling Redis to start automatically.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For newer Redis deployments, use current Redis documentation and configuration syntax because this guide is based on an older Redis release.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">FAQs<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1. What is Redis master-slave replication?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Redis master-slave replication allows a Redis master to replicate its data to one or more slave servers. In newer Redis terminology, these are generally called <strong>primary<\/strong> and <strong>replica<\/strong> servers.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2. Which port does Redis use by default?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Redis uses port <strong>6379<\/strong> by default. The master and slave servers must be able to communicate over the configured Redis port.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3. How can I check whether Redis is running as a master or slave?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Connect using <code>redis-cli<\/code> and run:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">INFO<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Then check the <code>role<\/code> field.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">4. What does the <code>slaveof<\/code> configuration do?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>slaveof<\/code> directive tells a Redis server to replicate data from the specified master server.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">5. Can Redis replication be used for high availability?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Replication provides a copy of the data on another Redis server, but replication by itself is not the same as automatic failover. For high availability, Redis Sentinel or Redis Cluster may be more appropriate depending on the architecture.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Related Articles<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Redis Common Commands<\/strong> \u2013 Learn commonly used Redis commands for managing keys, databases, replication, backups, connections, monitoring, and server statistics.<br><a href=\"https:\/\/pheonixsolutions.com\/blog\/redis-common-commands\/?utm_source=chatgpt.com\" target=\"_blank\" rel=\"noreferrer noopener\">Read the article<\/a><\/li>\n\n\n\n<li><strong>Enable Redis Module for PHP with Nginx Web Server<\/strong> \u2013 Learn how to enable Redis support in PHP and use Redis with applications running on an Nginx web server.<br><a href=\"https:\/\/pheonixsolutions.com\/blog\/enable-redis-module-php-nginx-webserver\/?utm_source=chatgpt.com\" target=\"_blank\" rel=\"noreferrer noopener\">Read the article<\/a><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Talk to our experts<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Looking for the right technology solution for your business? Our team of experts can help you with development, cloud, DevOps, design, and a wide range of other technology needs. Get in touch with our team&nbsp;<a href=\"https:\/\/pheonixsolutions.com\/contact\" target=\"_blank\" rel=\"noreferrer noopener\">here<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction Redis supports replication by allowing one Redis server to act as the master and another Redis server to act [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[1019,1040,1041,1024],"tags":[],"class_list":["post-622","post","type-post","status-publish","format-standard","hentry","category-cloud-aws","category-linux","category-network","category-security","psol-cat-cloud-aws"],"jetpack_publicize_connections":[],"jetpack_shortlink":"https:\/\/wp.me\/phn2x7-a2","jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/622","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/comments?post=622"}],"version-history":[{"count":1,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/622\/revisions"}],"predecessor-version":[{"id":11472,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/622\/revisions\/11472"}],"wp:attachment":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=622"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=622"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=622"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}