{"id":2205,"date":"2016-07-13T17:34:36","date_gmt":"2016-07-13T21:34:36","guid":{"rendered":"https:\/\/www.globo.tech\/learning-center\/?p=2205"},"modified":"2018-01-12T13:56:43","modified_gmt":"2018-01-12T18:56:43","slug":"memcached-repcached-patch-high-availability-ubuntu-14","status":"publish","type":"post","link":"https:\/\/www.globo.tech\/learning-center\/memcached-repcached-patch-high-availability-ubuntu-14\/","title":{"rendered":"Memcached with the Repcached patch to achieve High Availability &#8211; Ubuntu 14"},"content":{"rendered":"<h1>Memcached with the Repcached patch to achieve High Availability &#8211; Ubuntu 14<\/h1>\n<p>Memcached is an open source program under the BSD license that performs distributed memory caching. It is ideal for web applications using databases, as it will cache data into the server&#8217;s RAM to reduce how often the database must be accessed. This cache can be distributed amongst multiple servers.<\/p>\n<p>But if a server fails, then all data associated with its cache is lost. That&#8217;s where Repcached comes in. It&#8217;s a free patch for Memcached that uses redundancy to allow normal operation even in the event of node failure.<\/p>\n<h2>Getting Started<\/h2>\n<p>To complete this guide, you will need the following:<br \/>\n\u2022 1 Node (<a href=\"https:\/\/www.globo.tech\/cloud-server-pricing\" target=\"_blank\">Cloud Server<\/a> or <a href=\"http:\/\/www.globo.tech\/dedicated-server-hosting\" target=\"_blank\">Dedicated Server<\/a>) running Ubuntu 14.<br \/>\n\u2022 All commands should be run as the root user<\/p>\n<p>For the purposes of this guide, both nodes will have IP addresses that are on the same local network. The first server has 10.0.0.77 and the second server has 10.0.0.78. Keep in mind that repcached is not a broadly used patch. Ensure that you have thoroughly tested it in your environment before adding it into production.<\/p>\n<h2>Step-by-step guide<\/h2>\n<p>Start off with two identical servers running Ubuntu 14. Make sure both are fully up to date before beginning.<\/p>\n<p><code>apt-get update && apt-get -y upgrade<\/code><\/p>\n<p>Get the patched memcached package from our repositories and install it onto both servers.<\/p>\n<p><code>cd \/root<br \/>\nwget https:\/\/launchpad.net\/~niedbalski\/+archive\/ubuntu\/memcached-repcached\/+files\/memcached_1.4.14-0ubuntu10repcache3_amd64.deb<br \/>\ndpkg -i\u2002\u2002memcached_1.4.14-0ubuntu10repcache3_amd64.deb<\/code><\/p>\n<p>After Memcached has been installed, it may start automatically. On both servers, look for and kill any active memcached instances.<\/p>\n<p><code>killall -9 memcached<\/code><\/p>\n<p>Prepare the configuration file for the server at 10.0.0.77 first.<\/p>\n<p><code>cp \/etc\/memcached.conf \/etc\/memcached_server1.conf<\/code><\/p>\n<p>Don&#8217;t alter memcached.conf, but instead modify the new file:<\/p>\n<p><code>nano \/etc\/memcached_server1.conf<\/code><\/p>\n<p>The new file&#8217;s contents are not needed, so delete the entirety. Add the following into the file, making sure to set IP addresses appropriately for your setup (-l is for the local node IP and -x is for the remote node IP):<\/p>\n<p><code class=\"gris\"># Run as daemon<br \/>\n-d<br \/>\n# Logfile location<br \/>\nlogfile \/var\/log\/memcached.log<br \/>\n# Memory Amount<br \/>\n-m 64<br \/>\n# Connection Port TCP<br \/>\n-p 11211<br \/>\n# User under which the daemon will run<br \/>\n-u memcache<br \/>\n# Bind on IP<br \/>\n-l 10.0.0.77<br \/>\n# Connections Limit<br \/>\n-c 4096<br \/>\n# Return error when memory is exhausted (rather than removing items)<br \/>\n-M<br \/>\n# Slave Memcached Server<br \/>\n-x 10.0.0.78<\/code><\/p>\n<p>Start Memcached on the server at 10.0.0.77.<\/p>\n<p><code>service memcached start<\/code><\/p>\n<p>Next, prepare the configuration file for the other server at 10.0.0.78.<\/p>\n<p><code>cp \/etc\/memcached.conf \/etc\/memcached_server2.conf<\/code><\/p>\n<p>Again, leave the original memcached.conf intact and just modify the new file:<\/p>\n<p><code>nano \/etc\/memcached_server2.conf<\/code><\/p>\n<p>Delete the new file&#8217;s contents and add in the following, taking care to set the correct IP addresses:<\/p>\n<p><code class=\"gris\"># Run as daemon<br \/>\n-d<br \/>\n# Logfile location<br \/>\nlogfile \/var\/log\/memcached.log<br \/>\n# Memory Amount<br \/>\n-m 64<br \/>\n# Connection Port TCP<br \/>\n-p 11211<br \/>\n# User under which the daemon will run<br \/>\n-u memcache<br \/>\n# Bind on IP<br \/>\n-l 10.0.0.78<br \/>\n# Connections Limit<br \/>\n-c 4096<br \/>\n# Return error when memory is exhausted (rather than removing items)<br \/>\n-M<br \/>\n# Slave Memcached Server<br \/>\n-x 10.0.0.77<\/code><\/p>\n<p>Start Memcached on the server at 10.0.0.78.<\/p>\n<p><code>service memcached start<\/code><\/p>\n<p>Now it&#8217;s time to test replication using the two nodes.<\/p>\n<p>First, telnet to the Memcached server on the first node at 10.0.0.77 and add some keys to Memcached.<\/p>\n<p><code class=\"gris\">telnet 10.0.0.77 11211<br \/>\nset besthost 0 0 10<br \/>\nglobo.tech<br \/>\nget besthost<br \/>\nVALUE besthost 0 10<br \/>\nglobo.tech<br \/>\nquit<\/code><\/p>\n<p>On the second node at 10.0.0.78, verify that same key.<\/p>\n<p><code class=\"gris\">telnet 10.0.0.78 11211<br \/>\nget besthost<br \/>\nVALUE besthost 0 10<br \/>\nglobo.tech<br \/>\nquit<\/code><\/p>\n<p>If the keys for besthost return the same value, your two replicated Memcached instances are now fully functional and replicate data between them. Taking either server (but not both) offline will have no affect on the availability of data from the cache.<\/p>\n<h2>Conclusion<\/h2>\n<p>Memcached with the Repcached patch is a powerful tool in use by sites such as Reddit, Twitter, Facebook, and many more. Consider adding it to your tool suite if you have a dynamic database-driven web application to improve data reliability and reduce errors resulting from node failure. If this guide was helpful to you, kindly share it with others who may also be interested. <\/p>\n<!-- AddThis Advanced Settings generic via filter on the_content --><!-- AddThis Share Buttons generic via filter on the_content -->","protected":false},"excerpt":{"rendered":"<p>Memcached with the Repcached patch to achieve High Availability &#8211; Ubuntu 14 Memcached is an open source program under the BSD license that performs distributed memory caching. It is ideal for web applications using databases, as it will cache data into the server&#8217;s RAM to reduce how often the database must be accessed. This cache<!-- AddThis Advanced Settings generic via filter on get_the_excerpt --><!-- AddThis Share Buttons generic via filter on get_the_excerpt --><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[75],"tags":[],"class_list":["post-2205","post","type-post","status-publish","format-standard","hentry","category-ha-clustering"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.0 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Memcached with the Repcached patch to achieve High Availability - Ubuntu 14 - Globo.Tech<\/title>\n<meta name=\"description\" content=\"This tutorial will show you how to use Memcached with the Repcached Patch to achieve High Availability for your servers. Read now!\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.globo.tech\/learning-center\/memcached-repcached-patch-high-availability-ubuntu-14\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Memcached with the Repcached patch to achieve High Availability - Ubuntu 14 - Globo.Tech\" \/>\n<meta property=\"og:description\" content=\"This tutorial will show you how to use Memcached with the Repcached Patch to achieve High Availability for your servers. Read now!\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.globo.tech\/learning-center\/memcached-repcached-patch-high-availability-ubuntu-14\/\" \/>\n<meta property=\"og:site_name\" content=\"Globo.Tech\" \/>\n<meta property=\"article:published_time\" content=\"2016-07-13T21:34:36+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2018-01-12T18:56:43+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.globo.tech\/learning-center\/wp-content\/uploads\/2016\/09\/GloboTech-Logo.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1920\" \/>\n\t<meta property=\"og:image:height\" content=\"963\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"GloboTech Communications\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"GloboTech Communications\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.globo.tech\/learning-center\/memcached-repcached-patch-high-availability-ubuntu-14\/\",\"url\":\"https:\/\/www.globo.tech\/learning-center\/memcached-repcached-patch-high-availability-ubuntu-14\/\",\"name\":\"Memcached with the Repcached patch to achieve High Availability - Ubuntu 14 - Globo.Tech\",\"isPartOf\":{\"@id\":\"https:\/\/www.globo.tech\/learning-center\/#website\"},\"datePublished\":\"2016-07-13T21:34:36+00:00\",\"dateModified\":\"2018-01-12T18:56:43+00:00\",\"author\":{\"@id\":\"https:\/\/www.globo.tech\/learning-center\/#\/schema\/person\/e17784b37f4a4f49b7bc611847912e87\"},\"description\":\"This tutorial will show you how to use Memcached with the Repcached Patch to achieve High Availability for your servers. Read now!\",\"breadcrumb\":{\"@id\":\"https:\/\/www.globo.tech\/learning-center\/memcached-repcached-patch-high-availability-ubuntu-14\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.globo.tech\/learning-center\/memcached-repcached-patch-high-availability-ubuntu-14\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.globo.tech\/learning-center\/memcached-repcached-patch-high-availability-ubuntu-14\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.globo.tech\/learning-center\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Memcached with the Repcached patch to achieve High Availability &#8211; Ubuntu 14\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.globo.tech\/learning-center\/#website\",\"url\":\"https:\/\/www.globo.tech\/learning-center\/\",\"name\":\"Globo.Tech\",\"description\":\"Welcome to the Official Globo.Tech Learning Center\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.globo.tech\/learning-center\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.globo.tech\/learning-center\/#\/schema\/person\/e17784b37f4a4f49b7bc611847912e87\",\"name\":\"GloboTech Communications\",\"sameAs\":[\"http:\/\/www.gtcomm.net\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Memcached with the Repcached patch to achieve High Availability - Ubuntu 14 - Globo.Tech","description":"This tutorial will show you how to use Memcached with the Repcached Patch to achieve High Availability for your servers. Read now!","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.globo.tech\/learning-center\/memcached-repcached-patch-high-availability-ubuntu-14\/","og_locale":"en_US","og_type":"article","og_title":"Memcached with the Repcached patch to achieve High Availability - Ubuntu 14 - Globo.Tech","og_description":"This tutorial will show you how to use Memcached with the Repcached Patch to achieve High Availability for your servers. Read now!","og_url":"https:\/\/www.globo.tech\/learning-center\/memcached-repcached-patch-high-availability-ubuntu-14\/","og_site_name":"Globo.Tech","article_published_time":"2016-07-13T21:34:36+00:00","article_modified_time":"2018-01-12T18:56:43+00:00","og_image":[{"width":1920,"height":963,"url":"https:\/\/www.globo.tech\/learning-center\/wp-content\/uploads\/2016\/09\/GloboTech-Logo.png","type":"image\/png"}],"author":"GloboTech Communications","twitter_misc":{"Written by":"GloboTech Communications","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.globo.tech\/learning-center\/memcached-repcached-patch-high-availability-ubuntu-14\/","url":"https:\/\/www.globo.tech\/learning-center\/memcached-repcached-patch-high-availability-ubuntu-14\/","name":"Memcached with the Repcached patch to achieve High Availability - Ubuntu 14 - Globo.Tech","isPartOf":{"@id":"https:\/\/www.globo.tech\/learning-center\/#website"},"datePublished":"2016-07-13T21:34:36+00:00","dateModified":"2018-01-12T18:56:43+00:00","author":{"@id":"https:\/\/www.globo.tech\/learning-center\/#\/schema\/person\/e17784b37f4a4f49b7bc611847912e87"},"description":"This tutorial will show you how to use Memcached with the Repcached Patch to achieve High Availability for your servers. Read now!","breadcrumb":{"@id":"https:\/\/www.globo.tech\/learning-center\/memcached-repcached-patch-high-availability-ubuntu-14\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.globo.tech\/learning-center\/memcached-repcached-patch-high-availability-ubuntu-14\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.globo.tech\/learning-center\/memcached-repcached-patch-high-availability-ubuntu-14\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.globo.tech\/learning-center\/"},{"@type":"ListItem","position":2,"name":"Memcached with the Repcached patch to achieve High Availability &#8211; Ubuntu 14"}]},{"@type":"WebSite","@id":"https:\/\/www.globo.tech\/learning-center\/#website","url":"https:\/\/www.globo.tech\/learning-center\/","name":"Globo.Tech","description":"Welcome to the Official Globo.Tech Learning Center","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.globo.tech\/learning-center\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.globo.tech\/learning-center\/#\/schema\/person\/e17784b37f4a4f49b7bc611847912e87","name":"GloboTech Communications","sameAs":["http:\/\/www.gtcomm.net"]}]}},"_links":{"self":[{"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/posts\/2205","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/comments?post=2205"}],"version-history":[{"count":6,"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/posts\/2205\/revisions"}],"predecessor-version":[{"id":4072,"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/posts\/2205\/revisions\/4072"}],"wp:attachment":[{"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/media?parent=2205"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/categories?post=2205"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/tags?post=2205"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}