{"id":398,"date":"2016-04-26T12:03:11","date_gmt":"2016-04-26T17:03:11","guid":{"rendered":"http:\/\/www.popmartian.com\/tipsntricks\/?p=398"},"modified":"2021-04-06T09:34:43","modified_gmt":"2021-04-06T14:34:43","slug":"howto-build-mcrouter-for-rhel-ol-centos-7-x","status":"publish","type":"post","link":"https:\/\/www.popmartian.com\/tipsntricks\/2016\/04\/26\/howto-build-mcrouter-for-rhel-ol-centos-7-x\/","title":{"rendered":"HOWTO Build and Install Mcrouter for RHEL, OL, CENTOS 7.x"},"content":{"rendered":"<p><strong>UPDATE: Unless you have a very specific environment, Facebook likely now has packages or updated compile instructions that will work better than this: <a href=\"https:\/\/github.com\/facebook\/mcrouter\">https:\/\/github.com\/facebook\/mcrouter<\/a><\/strong><\/p>\n<p><strong>The instructions below are likely out of date and may no longer work.<\/strong><\/p>\n<p>This post will show you how to build and install Mcrouter. Once complete, you will have a portable Mcrouter installation that you can apply to multiple machines via RPM.<\/p>\n<p>Building Mcrouter is not easy, but this step-by-step process should get you to a collection of RPMs which make up a functional and upgrade-able Mcrouter environment.<\/p>\n<p><strong>About Mcrouter<\/strong><\/p>\n<blockquote><p><em>Mcrouter is a memcached protocol router for scaling memcached (http:\/\/memcached.org\/) deployments. It&#8217;s a core component of cache infrastructure at Facebook and Instagram where mcrouter handles almost 5 billion requests per second at peak.<\/em><\/p>\n<p><em>Mcrouter is developed and maintained by Facebook.<\/em><\/p><\/blockquote>\n<p>You can get the source and more information here: <a href=\"https:\/\/github.com\/facebook\/mcrouter\">https:\/\/github.com\/facebook\/mcrouter<\/a><\/p>\n<p>You are going to do a lot of compiling and packaging.\u00c2\u00a0 Once you have this perfected, it is not a big stretch to hand it off to Jenkins or some other build tool for automation.<\/p>\n<h2><strong>Getting Started<\/strong><\/h2>\n<p>You need to build two environments.<\/p>\n<p>Environment 1: Build Environment for compiling and packaging Mcrouter<\/p>\n<ul>\n<li>An EL7 Server (RedHat, Oracle Linux, CentOS)<\/li>\n<li>Yum updates to the latest stable everything (yum -y update, then reboot)<\/li>\n<li>At LEAST 4GB RAM<\/li>\n<li>At LEAST 4GB available disk space<\/li>\n<li>A decent internet connection<\/li>\n<li>Root access<\/li>\n<\/ul>\n<p>Environment 2: Operating Environment for actually running Mcrouter<\/p>\n<ul>\n<li>An EL7 Server (RedHat, Oracle Linux, CentOS)<\/li>\n<li>Yum updates to the latest stable everything (yum -y update, then reboot)<\/li>\n<li>Sufficient privilege to install RPMs (sudo, root, etc)<\/li>\n<\/ul>\n<h2><strong>(Env 1) Setting up The Build Environment<\/strong><\/h2>\n<p>NOTE 1: All of the following assumes you are root.\u00c2\u00a0 Insert your sudo where required if you aren&#8217;t just living and breathing as root.<\/p>\n<p>NOTE 2: You are going to install a lot of crap on this system.\u00c2\u00a0 I assume you are OK with that.<\/p>\n<p>Before we begin to build Mcrouter, we need to build a lot of the dependencies and install packages required for both running and building the software.<\/p>\n<h3>Install a bunch of packages<\/h3>\n<p>NOTE 1: Some of these will not exist. We will compile our own RPMs and grab some from Fedora.\u00c2\u00a0 All of it is outlined below.<\/p>\n<p><code>yum -y install gcc-c++ ruby ruby-devel ragel cyrus-sasl cyrus-sasl-devel cmake bison python-libs python-devel numactl-libs numactl-devel scons snappy snappy-devel gflags gflags-devel glog-devel glog boost-devel automake autoconf libtool libevent libevent-devel openssl-devel libatomic flex rpm-build<br \/>\n<\/code><\/p>\n<p>Most likely the following packages are missing: ragel, scons, glfags, gflags-devel, glog, glog-devel.\u00c2\u00a0 Let&#8217;s get building and packaging for those.\u00c2\u00a0 If you are missing others, you&#8217;ll have to build and package them too.<\/p>\n<h3>Create a build location<\/h3>\n<p>This is where you need the disk space and where you will download, compile and package everything.<\/p>\n<p><code>mkdir \/build<\/code><\/p>\n<h3>Install fpm<\/h3>\n<p>(<span class=\"repository-meta-content\">Effing package management! <\/span><a href=\"https:\/\/github.com\/jordansissel\/fpm\">https:\/\/github.com\/jordansissel\/fpm<\/a>)<\/p>\n<p>We are going to use FPM to create RPMs as we go.<\/p>\n<p><code>gem install fpm<\/code><\/p>\n<p>If you see some errors at the end similar to this:<br \/>\n<code>Parsing documentation for fpm-1.5.0<br \/>\nunable to convert \"\\xF3\" from ASCII-8BIT to UTF-8 for lib\/fpm\/package\/pyfpm\/__init__.pyc, skipping<br \/>\nunable to convert \"\\xF3\" from ASCII-8BIT to UTF-8 for lib\/fpm\/package\/pyfpm\/get_metadata.pyc, skipping<\/code><\/p>\n<p>You can ignore them.<\/p>\n<h3>Build and package ragel<\/h3>\n<p>NOTE: Get the latest version of ragel here: <a href=\"http:\/\/www.colm.net\/open-source\/ragel\/\">http:\/\/www.colm.net\/open-source\/ragel\/<\/a><\/p>\n<h4>Download<\/h4>\n<p><code>cd \/build<br \/>\ncurl -O http:\/\/www.colm.net\/files\/ragel\/ragel-6.9.tar.gz<\/code><\/p>\n<h4>Build<\/h4>\n<p><code>cd \/build<br \/>\ntar zxf ragel-6.9.tar.gz<br \/>\ncd ragel-6.9<br \/>\n.\/configure<br \/>\nmake<br \/>\nmake install<\/code><\/p>\n<h4>Package<\/h4>\n<p><code>mkdir \/build\/ragelpkg<br \/>\nmake install DESTDIR=\/build\/ragelpkg<br \/>\ncd \/build<br \/>\nfpm --verbose -f -s dir -t rpm -n ragel -v 6.9 -C \/build\/ragelpkg \\<br \/>\nusr\/local\/bin \\<br \/>\nusr\/local\/share\/doc\/ragel \\<br \/>\nusr\/local\/share\/man\/man1<\/code><\/p>\n<p>You should have an RPM that will install ragel.<\/p>\n<h3>Download and install scons, glfags, gflags-devel, glog, glog-devel<\/h3>\n<h4>Download<\/h4>\n<p><code>cd \/build<br \/>\ncurl -O http:\/\/tenet.dl.sourceforge.net\/project\/scons\/scons\/2.5.0\/scons-2.5.0-1.noarch.rpm<br \/>\ncurl -O https:\/\/kojipkgs.fedoraproject.org\/\/packages\/gflags\/2.1.1\/6.el7\/x86_64\/gflags-2.1.1-6.el7.x86_64.rpm<br \/>\ncurl -O https:\/\/kojipkgs.fedoraproject.org\/\/packages\/gflags\/2.1.1\/6.el7\/x86_64\/gflags-devel-2.1.1-6.el7.x86_64.rpm<br \/>\ncurl -O https:\/\/kojipkgs.fedoraproject.org\/\/packages\/glog\/0.3.3\/8.el7\/x86_64\/glog-0.3.3-8.el7.x86_64.rpm<br \/>\ncurl -O https:\/\/kojipkgs.fedoraproject.org\/\/packages\/glog\/0.3.3\/8.el7\/x86_64\/glog-devel-0.3.3-8.el7.x86_64.rpm<\/code><\/p>\n<h4>Install<\/h4>\n<p><code>rpm -ivh .\/scons-2.5.0-1.noarch.rpm .\/gflags-2.1.1-6.el7.x86_64.rpm .\/glog-0.3.3-8.el7.x86_64.rpm .\/gflags-devel-2.1.1-6.el7.x86_64.rpm .\/glog-devel-0.3.3-8.el7.x86_64.rpm<\/code><\/p>\n<h3>Build and Package Double-Conversion<\/h3>\n<p>NOTE: Double-Conversion is a library from Google which provides binary-decimal and decimal-binary routines for IEEE doubles.\u00c2\u00a0 Details and source code here: <a href=\"https:\/\/github.com\/google\/double-conversion\">https:\/\/github.com\/google\/double-conversion<\/a><\/p>\n<h4>Download<\/h4>\n<p><code>cd \/build<br \/>\ngit clone https:\/\/github.com\/google\/double-conversion.git<\/code><\/p>\n<h4>Build<\/h4>\n<p><code>cd \/build\/double-conversion<br \/>\nmake<br \/>\nmake test<br \/>\nscons install<br \/>\nchmod 0644 \/usr\/local\/lib\/libdouble-conversion*<br \/>\nmkdir \/usr\/local\/include\/double-conversion<br \/>\ncp double-conversion\/*.h \/usr\/local\/include\/double-conversion\/<br \/>\nchmod 0755 \/usr\/local\/include\/double-conversion\/<br \/>\nchmod 0644 \/usr\/local\/include\/double-conversion\/*<\/code><\/p>\n<h4>Package<\/h4>\n<p><code>cd \/build<br \/>\nmkdir -p \/build\/dcpkg\/usr\/local\/lib\/<br \/>\nmkdir -p \/build\/dcpkg\/usr\/local\/include\/double-conversion\/<\/code><\/p>\n<p><code>cp -rp \/usr\/local\/lib\/libdouble-conversion* \/build\/dcpkg\/usr\/local\/lib\/<br \/>\ncp -rp \/usr\/local\/include\/double-conversion\/* \/build\/dcpkg\/usr\/local\/include\/double-conversion\/<\/code><\/p>\n<p><code>cd \/build\/double-conversion<br \/>\nVER=$(git tag|tail -1)<br \/>\ncd \/build<\/code><\/p>\n<p><code>fpm --verbose -f -s dir -t rpm -n double-conversion -v $VER -C \/build\/dcpkg \\<br \/>\nusr\/local\/lib\/ \\<br \/>\nusr\/local\/include\/double-conversion\/<\/code><\/p>\n<p>You should have an RPM that will install double-conversion.<\/p>\n<h3>Build and Package Folly<\/h3>\n<p>Lots of information on Folly: <a href=\"https:\/\/github.com\/facebook\/folly\">https:\/\/github.com\/facebook\/folly<\/a><\/p>\n<blockquote><p>Folly (acronymed loosely after Facebook Open Source Library) is a library of C++11 components designed with practicality and efficiency in mind. Folly contains a variety of core library components used extensively at Facebook. In particular, it&#8217;s often a dependency of Facebook&#8217;s other open source C++ efforts and place where those projects can share code.<\/p><\/blockquote>\n<h4>Download<\/h4>\n<p><code>cd \/build<br \/>\ngit clone https:\/\/github.com\/facebook\/folly<\/code><\/p>\n<h4>Build<\/h4>\n<p><code>cd \/build\/folly\/folly<br \/>\nexport LD_LIBRARY_PATH=$LD_LIBRARY_PATH:\/usr\/local\/lib<br \/>\nVER=$(git tag|tail -1)<br \/>\nautoreconf -ivf<br \/>\nLDFLAGS=-L\/usr\/local\/lib CPPFLAGS=-I\/usr\/local\/include .\/configure<br \/>\nmake -j2<br \/>\nmake install<\/code><\/p>\n<h4>Package<\/h4>\n<p><code>cd \/build\/folly\/folly<br \/>\nmkdir \/build\/follypkg<br \/>\nmake install DESTDIR=\/build\/follypkg<br \/>\ncd \/build<br \/>\nfpm --verbose -f -s dir -t rpm -n folly -v $VER -C \/build\/follypkg \\<br \/>\nusr\/local\/include \\<br \/>\nusr\/local\/lib<\/code><\/p>\n<p>You should have an RPM that will install Folly.<\/p>\n<h3>Upgrade your Automake<\/h3>\n<p>NOTE: This is only required if you have a version of Automake lower than 1.15<\/p>\n<p><code>curl -O https:\/\/kojipkgs.fedoraproject.org\/packages\/automake\/1.15\/1.fc22\/noarch\/automake-1.15-1.fc22.noarch.rpm<br \/>\n<code>rpm -Uvh automake-1.15-1.fc22.noarch.rpm<\/code><\/code><\/p>\n<h3>Download and Install jemalloc<\/h3>\n<p><code>curl -O https:\/\/kojipkgs.fedoraproject.org\/packages\/jemalloc\/3.6.0\/1.el7\/x86_64\/jemalloc-3.6.0-1.el7.x86_64.rpm<br \/>\ncurl -O https:\/\/kojipkgs.fedoraproject.org\/\/packages\/jemalloc\/3.6.0\/1.el7\/x86_64\/jemalloc-devel-3.6.0-1.el7.x86_64.rpm<\/code><\/p>\n<p><code>rpm -ivh jemalloc-devel-3.6.0-1.el7.x86_64.rpm jemalloc-3.6.0-1.el7.x86_64.rpm<\/code><\/p>\n<h3>Build and Package Wangle<\/h3>\n<p>More on Wangle: https:\/\/github.com\/facebook\/wangle<\/p>\n<blockquote><p>Wangle provides a full featured, high performance C++ futures implementation.<\/p><\/blockquote>\n<h4>Download<\/h4>\n<p><code>cd \/build<br \/>\ngit clone https:\/\/github.com\/facebook\/wangle<\/code><\/p>\n<h4>Build<\/h4>\n<p><code>cd \/build\/wangle\/wangle<br \/>\nVER=$(git tag|tail -1)<br \/>\nsed -i -r -e \"s@\\ \\ -lpthread@\\ \\ -lgflags\\n\\ \\ -lgflags@\" CMakeLists.txt<br \/>\ncmake .<br \/>\nmake<br \/>\nmake test<br \/>\nmake install<\/code><\/p>\n<h4>Package<\/h4>\n<p><code>cd \/build\/wangle\/wangle<br \/>\nmkdir \/build\/wanglepkg<br \/>\nmake install DESTDIR=\/build\/wanglepkg<br \/>\ncd \/build<br \/>\nfpm --verbose -f -s dir -t rpm -n wangle -v $VER -C \/build\/wanglepkg \\<br \/>\nusr\/local\/include \\<br \/>\nusr\/local\/lib<\/code><\/p>\n<p>You should have an RPM that will install Wangle.<\/p>\n<h3>Build and Package FBThrift<\/h3>\n<p>Read lots about fbthrift here: <a href=\"https:\/\/github.com\/facebook\/fbthrift\">https:\/\/github.com\/facebook\/fbthrift<\/a><\/p>\n<blockquote><p>FBThrift: Facebook&#8217;s branch of apache thrift<\/p><\/blockquote>\n<h4>Download<\/h4>\n<p><code>cd \/build<br \/>\ngit clone https:\/\/github.com\/facebook\/fbthrift<\/code><\/p>\n<h4>Build<\/h4>\n<p><code>cd \/build\/fbthrift\/thrift<br \/>\nVER=$(git tag|tail -1)<br \/>\nautoreconf -ifv<br \/>\nLDFLAGS=-L\/usr\/local\/lib CPPFLAGS=-I\/usr\/local\/include .\/configure<br \/>\nmake -j2<br \/>\nmake install<br \/>\n<\/code><\/p>\n<h4>Package<\/h4>\n<p><code>cd \/build\/fbthrift\/thrift<br \/>\nmkdir \/build\/fbthriftpkg<br \/>\nmake install DESTDIR=\/build\/fbthriftpkg<br \/>\ncd \/build<br \/>\nfpm --verbose -f -s dir -t rpm -n fbthrift -v $VER -C \/build\/fbthriftpkg \\<br \/>\nusr\/local\/bin \\<br \/>\nusr\/local\/include \\<br \/>\nusr\/local\/lib<\/code><\/p>\n<p>You should have an RPM that will install Thrift.<\/p>\n<h3>FINALLY!!! Build and Package McRouter!<\/h3>\n<h4>Download<\/h4>\n<p><code>cd \/build<br \/>\ngit clone https:\/\/github.com\/facebook\/mcrouter<\/code><\/p>\n<h4>Build<\/h4>\n<p><code>cd \/build\/mcrouter\/mcrouter<br \/>\nVER=$(git tag|tail -1)<br \/>\nautoreconf -ifv<br \/>\nexport THRIFT2_COMP_DIR=\/usr\/lib\/python2.7\/site-packages\/thrift_py-0.9.0-py2.7.egg\/thrift_compiler<br \/>\nLDFLAGS=-L\/usr\/local\/lib CPPFLAGS=-I\/usr\/local\/include .\/configure --prefix=\/usr\/local\/mcrouter<br \/>\nmake -j2<br \/>\nmake install<\/code><\/p>\n<h4>Package<\/h4>\n<p><code>cd \/build\/mcrouter\/mcrouter<br \/>\nmkdir \/build\/mcrouterpkg<br \/>\nmake install DESTDIR=\/build\/mcrouterpkg<br \/>\ncd \/build<br \/>\nfpm --verbose -f -s dir -t rpm -n mcrouter -v $VER -C \/build\/mcrouterpkg \\<br \/>\nusr\/local\/mcrouter<\/code><\/p>\n<p>You should have an RPM that will install mcrouter<\/p>\n<h3>Defining Your Portable Installation<\/h3>\n<p>The following RPMs from this tutorial are required to operate a mcrouter environment. Set them aside.<\/p>\n<p>As of this writing, my specific RPMs and versions are:<\/p>\n<ul>\n<li>gflags-2.1.1-6.el7.x86_64.rpm<\/li>\n<li>glog-0.3.3-8.el7.x86_64.rpm<\/li>\n<li>jemalloc-3.6.0-1.el7.x86_64.rpm<\/li>\n<li>ragel-6.9-1.x86_64.rpm<\/li>\n<li>double-conversion-v2.0.1-1.x86_64.rpm<\/li>\n<li>folly-v0.57.0-1.x86_64.rpm<\/li>\n<li>wangle-v0.9.0-1.x86_64.rpm<\/li>\n<li>fbthrift-v0.31.0-1.x86_64.rpm<\/li>\n<li>mcrouter-v0.9.0-1.x86_64.rpm<\/li>\n<\/ul>\n<h2><strong>(Env 2) Setting up The Operating Environment<\/strong><\/h2>\n<p>In order to run mcrouter on another node, you will need to install a the following system packages and packages you downloaded and created:<\/p>\n<h3>Install Packages<\/h3>\n<h4>System Packages<\/h4>\n<p><code>yum -y install cyrus-sasl python-libs numactl-libs snappy boost libtool libevent openssl libatomic<\/code><\/p>\n<h4>Downloaded Packages<\/h4>\n<p><code>rpm -ivh gflags-2.1.1-6.el7.x86_64.rpm glog-0.3.3-8.el7.x86_64.rpm jemalloc-3.6.0-1.el7.x86_64.rpm<\/code><\/p>\n<h4>Built Packages<\/h4>\n<p><code>rpm -ivh ragel-6.9-1.x86_64.rpm double-conversion-v2.0.1-1.x86_64.rpm folly-v0.57.0-1.x86_64.rpm wangle-v0.9.0-1.x86_64.rpm fbthrift-v0.31.0-1.x86_64.rpm mcrouter-v0.9.0-1.x86_64.rpm<\/code><\/p>\n<h3>Test Mcrouter<\/h3>\n<p><code>\/usr\/local\/mcrouter\/bin\/mcrouter --version<\/code><\/p>\n<h3>Done!<\/h3>\n<blockquote><p>Did you find this post useful or have questions or comments? Please let me know!<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>How to build, package, and install mcrouter on Linux <a href=\"https:\/\/www.popmartian.com\/tipsntricks\/2016\/04\/26\/howto-build-mcrouter-for-rhel-ol-centos-7-x\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[75,77,80,58,3,27,76,65,42,64,8,79,78],"tags":[],"class_list":["post-398","post","type-post","status-publish","format-standard","hentry","category-facebook","category-folly","category-fpm","category-google","category-how-to-do-stuff","category-linux","category-mcrouter","category-oracle-linux","category-redhat","category-rpm","category-software","category-thrift","category-wangle"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.popmartian.com\/tipsntricks\/wp-json\/wp\/v2\/posts\/398","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.popmartian.com\/tipsntricks\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.popmartian.com\/tipsntricks\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.popmartian.com\/tipsntricks\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.popmartian.com\/tipsntricks\/wp-json\/wp\/v2\/comments?post=398"}],"version-history":[{"count":40,"href":"https:\/\/www.popmartian.com\/tipsntricks\/wp-json\/wp\/v2\/posts\/398\/revisions"}],"predecessor-version":[{"id":483,"href":"https:\/\/www.popmartian.com\/tipsntricks\/wp-json\/wp\/v2\/posts\/398\/revisions\/483"}],"wp:attachment":[{"href":"https:\/\/www.popmartian.com\/tipsntricks\/wp-json\/wp\/v2\/media?parent=398"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.popmartian.com\/tipsntricks\/wp-json\/wp\/v2\/categories?post=398"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.popmartian.com\/tipsntricks\/wp-json\/wp\/v2\/tags?post=398"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}