How To Install Repcached (Memcached Replication) For High-Availability Over 2 Nodes On Ubuntu 11.04
|
Submitted by michael.cmech (Contact Author) (Forums) on Wed, 2011-09-28 17:57. :: Ubuntu | Web Server | High-Availability | Lighttpd
How To Install Repcached (Memcached Replication) For High-Availability Over 2 Nodes On Ubuntu 11.04This is a short tutorial based on MarcusSpiegel's howto found here. This how to will cover the missing parts for installing Repcached on Ubuntu server 11.04. This is a copy/paste friendly tutorial so using putty will make this a lot easier. This how to will show you how to install and build memcached with replication, create a startup script and configure PHP to use memcache for sessions rather than storing them as files. This tutorial assumes you have set up 2 servers to replicate the information over.
1. My SetupIn this demo I will be setting up repcache on 2 hosts, they will have both lighttpd and repcache installed on them.
2. Installing repcacheFirst you need to visit http://repcached.lab.klab.org/ and download the lastest version (latest at time of writing: 2.2-1.2.8). After downloading the tar file, we will need to install some extra packages. Do this on both nodes. apt-get install libevent-dev g++ make From here we can continue the installation. tar xvf memcached-1.2.8-repcached-2.2.tar
3. Configuring repcacheRepcache is now installed, binary location is /usr/local/bin/memcached. From here we will create the config file and startup script. Config file and init script are the ones found on MarcusSpiegel's howto. Do this on both nodes. First open the file with vi: vi /etc/memcachedrep Then enter the following, remember to change the IP address at the end. This IP will be the other server you wish to replicate to. ## extra commandline options to start memcached in replicated mode # -x < ip_addr > hostname or IP address of the master replication server # -X < num > TCP port number of the master (default: 11212) DAEMON_ARGS="-m 64 -p 11211 -u root -P /var/run/memcachedrep.pid -d -x 10.10.20.11" Once the file is saved we need to create the init script. Once again this is the script found on MarcusSpiegel's howto with some minor changes for config location only. vi /etc/init.d/memcachedrep #! /bin/sh ### BEGIN INIT INFO # Provides: memcached # Required-Start: $syslog # Required-Stop: $syslog # Should-Start: $local_fs # Should-Stop: $local_fs # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: memcached - Memory caching daemon replicated # Description: memcached - Memory caching daemon replicated ### END INIT INFO # Author: Michael Save this then type in the following. chmod +x /etc/init.d/memcacherep This will make sure repcache is started everytime the server is restarted.
4. TestingBefore we move on we will test that the 2 nodes are replicating. server1: telnet 127.0.0.1 11211 Then type in set foo 0 0 3 You should see the word STORED appear under it. Type in quit and it will return to the console. Go to your other server and type in the following. server2: telnet 127.0.0.1 11211 Then type in get foo and it should return the value you entered on the first server. If it has then the replication is working.
5. Setting up PHPHere I will show you how to setup PHP to use memcache. Because I am using lighttpd the directories may be different to those using apache2 or nginx. Type the following into the console and repeat for the secondary server. vi /etc/php5/cgi/php.ini Search down the file till you find the following: [Session] ; Handler used to store/retrieve data. ; http://php.net/session.save-handler session.save_handler = files You will need to change these to look like this: [Session] ; Handler used to store/retrieve data. ; http://php.net/session.save-handler extension = memcache.so session.save_handler = memcache session.save_path = "tcp://127.0.0.1:11211" Once these have been saved simply type in (remember to change this to the software you are using for the hosting): /etc/init.d/lighttpd force-reload Or simply reboot both servers. You can now test out that php is using them correctly by creating a session on one and reading that session from the other.
|

![Creative Commons Attribution License [Creative Commons Attribution License]](http://creativecommons.org/images/public/somerights20.gif)


Recent comments
12 hours 53 min ago
19 hours 34 min ago
23 hours 25 min ago
1 day 1 hour ago
1 day 9 hours ago
1 day 18 hours ago
1 day 19 hours ago
1 day 23 hours ago
2 days 3 hours ago
2 days 4 hours ago