Monday, November 9, 2015

Install Memcached (Caching Server) on RHEL/CentOS 6.3/5.8 and Fedora 17-12

What is Memcached?

Memcached is an open source distributed memory object caching program that allows us to improve and speeding up performance of dynamic web applications by caching data and objects in Memory. Memcached is also used to cache entire database tables and queries to improve performance of database. It is the only one caching system available freely and used by many big sites like YouTube, Facebook, Twitter, Reddit, Drupal, Zynga etc.

Enable EPEL repository under RHEL/CentOS 6.3/5.8

The fastest and easiest way to install and enable EPEL repository using YUM. First, select the RPM that matches your Linux OS architecture from the provided links and install it using method shown in below. The EPEL repo will install all the required dependency packages for memcached. (Note : Fedora doesn’t required EPEL repo, because it is part of fedora project).

For RHEL/CentOS 6 ( 32-Bit )

# wget http://mirrors.kernel.org/fedora-epel/6/i386/epel-release-6-7.noarch.rpm
# rpm -Uvh epel-release-6-7.noarch.rpm

For RHEL/CentOS 6 ( 64-Bit )

# wget http://mirrors.kernel.org/fedora-epel/6/x86_64/epel-release-6-7.noarch.rpm
# rpm -Uvh epel-release-6-7.noarch.rpm

For RHEL/CentOS 5 ( 32-Bit )

# wget http://mirrors.kernel.org/fedora-epel/5/i386/epel-release-5-4.noarch.rpm
# rpm -Uvh epel-release-5-4.noarch.rpm

For RHEL/CentOS 5 ( 64-Bit )

# wget http://mirrors.kernel.org/fedora-epel/5/x86_64/epel-release-5-4.noarch.rpm
# rpm -Uvh epel-release-5-4.noarch.rpm

Install Memcached

Install Memcached program by using following command with YUM tool.
# yum install memcached
Sample Output
Loaded plugins: fastestmirror
Determining fastest mirrors
epel: kartolo.sby.datautama.net.id
Dependencies Resolved

=====================================================================================================
 Package   Arch    Version     Repository     Size
=====================================================================================================
Installing:   
memcached   i386    1.4.5-1.el5    epel      71 k

Transaction Summary
=====================================================================================================
Install       1 Package(s)
Upgrade       0 Package(s)

Total download size: 71 k
Is this ok [y/N]: y
Downloading Packages:
memcached-1.4.5-1.el5.i386.rpm             |  71 kB     00:00
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing     : memcached                        1/1

Installed:
  memcached.i386 0:1.4.5-1.el5

Complete!

Configure Memcached

Open the file called /etc/sysconfig/memcached with VI editor.
# vi /etc/sysconfig/memcached
Set or update parameters as follows, save the file and exit.
# Running on Port 11211
PORT="11211"

# Start as memcached daemon
USER="memcached"

# Set max simultaneous connections to 1024
MAXCONN="1024"

# Set Memory size to 2048 - 4GB(4096)
CACHESIZE="2048"

#Set server IP address
OPTIONS="-l 127.0.0.1"
Let’s discuss each of the above parameters in details.
  1. PORT : The port used by memcached to run.
  2. USER : The start-up daemon for memcached service.
  3. MAXCONN : The value used to set max simultaneous connections to 1024. For busy web servers you can increase to any number based on your requirements.
  4. CACHESIZE : Set cache size memory to 2048. For busy servers you can increase upto 4GB.
  5. OPTIONS : Set IP address of server, so that Apache or Nginx web servers can connect to it.

Start Memcached

Type the following commands to start and restart the Memcached daemon.
# chkconfig --levels 235 memcached on
# /etc/init.d/memcached start
# /etc/init.d/memcached restart
To stop and check status, use the following commands.
# /etc/init.d/memcached stop
# /etc/init.d/memcached status

Verify Memcached

Use netstat command to verify Memcached is running.
# netstat -tulpn | grep :11211

tcp        0      0 127.0.0.1:11211             0.0.0.0:*                   LISTEN      20775/memcached
udp        0      0 127.0.0.1:11211             0.0.0.0:*                               20775/memcached
Check the stats of the server using memcached-tool.
# memcached-tool 127.0.0.1 stats

Install Memcached PHP extension

Now, install PHP extension to work with Memcached daemon.
# yum install php-pecl-memcache

Install Memcached Perl Library

Install perl library for Memcached.
# yum install perl-Cache-Memcached

Install Memcached Python Library

Install python library for Memcached.
# yum install python-memcached

Restart Apache

Restart the Apache service to reflect changes.
# /etc/init.d/httpd restart
OR
# service httpd restart

Configure Firewall to Secure Memcached Server

Make sure you only have access to memcached server, to enable access to your own servers open file called /etc/sysconfig/iptables.
# vi /etc/sysconfig/iptables
Append the following iptables rules to allow access to your own servers.
## Enable access on IP ranges from 172.16.1.1 to 172.16.1.10 for Port 11211 ##
# iptables -A INPUT -p tcp --destination-port 11211 -m state --state NEW  -m iprange --src-range 172.16.1.1-172.16.1.10 -j ACCEPT
# iptables -A INPUT -p udp --destination-port 11211 -m state --state NEW  -m iprange --src-range 172.16.1.1-172.16.1.10 -j ACCEPT
Restart the iptables service to reflect changes.
# service iptables restart
OR
# /etc/init.d/iptables restart

Cache MySQL Queries with Memcached

It isn’t an easy task for all, you need to use API’s to modify your PHP codes to enable MySQL caching. You can find the examples codes at Memcache with MySQL and PHP.

Enable Memcached on WordPress Sites

For WordPress based sites, there is a plugin called Memcached Object Cache that you need to install it on your WordPress CMS.

34 comments:

dev said...

Hi, I check your blog on a regular basis. Latest Admit card
Your story-telling style is awesome, keep it up for your good work! Latest Admit card

tejaswini said...

I have bookmarked your site since this site contains significant data in it. You rock for keeping incredible stuff. I am a lot of appreciative of this site.https://360digitmg.com/course/certification-program-in-data-science

360digitmgdelhi said...

I've been looking at a portion of your posts on this site, and I think this site is really enlightening! Keep setting it up.
artificial intelligence course in delhi

360DigiTMG said...

I was looking at a portion of your posts on this site and I consider this site is really enlightening! Keep setting up..
hrdf contribution

pmp certification said...


Nice work... Much obliged for sharing this stunning and educative blog entry!

https://360digitmg.com/course/project-management-professional-pmp

dataanalyticscourse said...

I think I have never watched such online diaries ever that has absolute things with all nuances which I need. So thoughtfully update this ever for us.
big data course in malaysia

360digitmg said...

Wow! Such an amazing and helpful post this is. I really really love it. It's so good and so awesome. I am just amazed. I hope that you continue to do your work like this in the future also.
best data science courses in hyderabad

Anonymous said...

What an extremely wonderful post this is. Genuinely, perhaps the best post I've at any point seen to find in as long as I can remember. Goodness, simply keep it up.
HRDF Claimable

360digitmgtrainings said...

I really like your writing style, great date, thank you for posting.
https://360digitmg.com/course/project-management-professional-pmp

Bhavana said...

Astounding information and I like to impart this sort of data to my companions and expectation they like it they why I do
360DigiTMG PMP Certification

EXCELR said...

"Very good article with very useful information. Visit our websitedata science training in Hyderabad
"

Maneesha said...

Maybe you had an extraordinary handle on the topic, yet you neglected to incorporate your perusers. Maybe you should consider this from more than one point. data scientist training

artifcial intelligence malaysia said...


You should talk it's shocking. Your blog survey would extend your visitors. I was fulfilled to find this site.I expected to thank you for this phenomenal read!! artifcial intelligence malaysia

Anonymous said...

I truly like your composing style, incredible date, thank you for posting...
angrygran

360digiTMG Training said...


Impressive. Your story always brings hope and new energy. Keep up the good work.
Best Institute for Data Science in Hyderabad

Isaiah Coleman said...

Will you make a video how to install it? I would post such video on youtube on your place cause I know where to get youtube views and subscribers. I buy it on this site https://viplikes.net

Nolan Alvarez said...

I think if you make video about it I would understand all of this easier. You could post your video on tiktok and create tiktok profile. From here https://n4gm.com/tiktok-promotion-the-main-whys-and-hows-explained-to-you-by-professionals/ you can read about followers and get it for your profile

traininginstitute said...

Really nice and interesting post. I was looking for this kind of information and enjoyed reading this one. Keep posting. Thanks for sharing.
digital marketing courses in hyderabad with placement

Jose Ramos said...

I think more people will understand it if you make a video. You could post your video on youtube and get some likes on this site https://soclikes.com/

business analytics course in chennai with placement said...

Impressive. Your story always bring hope and new energy. Keep up the good work.Data Scientist Course in Vadodara

Data Analytics Course in Dehradun said...

Impressive. Your story always bring hope and new energy. Keep up the good work. Data Analytics Course in Vadodara

traininginstitute said...

I have been searching to find a comfort or effective procedure to complete this process and I think this is the most suitable way to do it effectively.
data science course in malaysia

Ramesh Sampangi said...

Really an awesome blog and informative content. Keep sharing more bogs with us. If you want to become a data science course training, follow the given below link.
Data Science Certification Course in Hyderabad

Bali Digital Enthusiast said...

Known as the Island of the Gods, Bali’s culture is dominated by a unique form of Hinduism evident in every aspect of Balinese life, from the temples that ornament every corner of the island to the daily offerings found in every home.

Mounika Digital Blogs said...

Digital marketing institute in KPHBDigital marketing institute in KPHB, we address all major and minor aspects required for any student’s advancement in digital marketing. Clutch USA named our Digital Marketing Institute the best SEO firm.
The future of digital marketing is promising and full of possibilities.
As a result, skilled digital marketers who can keep up with the rising demand are in high order.
In the Emblix Academy Digital marketing institute in KPHB, you will learn about all the major and minor modules of digital marketing, from Search engine marketing to Social Media Marketing and almost all Tools used for Digital Marketing.
One stop place for all Digital Marketing courses! Emblix Academy is a Team of dedicated Professionals with 12years of experience in various Digital Platforms. We assure to provide the best Digital Marketing courses to enhance your Career.
Certifications
• Search Advertising
• Display Advertising
• Analytics Certification
• Hubspot Certification
• Bing Certification
• Twitter Certification
• Facebook Certification

Alina jonas said...

The market growth can be attributed to the robust growth of the maritime industry globally. The rising demand for sonobuoy can be attributed to the increasing consumer requirements. Several technological innovations have led to the development of the Sonobuoy Market
market, including the use of sophisticated sensing, range, and directional capability. Rising security expenditure and the growing use of underground vehicles are anticipated to further boost the demand.

Also read: sandwich panel market, hub motor market, europe biodiesel market

Anonymous said...

Regards for this particular clarifying and also fabulous blog page. I am extremely jubilant to experience this type of details on your web page.
UWatchFree
PlayTubes

traininginstitute said...

I can say this has been one of the most interesting blog posts I have ever read on this topic. I have added a bookmark to this post, so that I can refer to it whenever I have any queries on this subject. Thanks for providing us with many inputs from many angles on this subject.
power bi course malaysia

Admin said...

See also various Indonesian information: here get new experiences

seriale le turcesti said...


Urmăriți Pe All Serialele Turcesti 2023 Netflix Online. Urmărește Serialul Românesc Gratis Online Streaming Video HD. You Can Enjoy It TV Shows And Seriale Turcesti Comedii Romantic And Filme De Dragoste Streaming For Free

terasacucartii said...

Urmariti Online Serial Drama, Actiune, Drama, Si Comedie, Seriale Turcesti Vechi sau Nou in situatii foarte odihnitoare. Asta înseamnă că inima ta se simte confortabil seriale turcești comedie romantică, atât de mult încât te simți confortabil. Vă puteți bucura și, de asemenea, să împărtășiți cu prietenii și cu Faimly.

pencurimovie said...

Pencuri Movie 123 Dalam era digital yang serba canggih ini, akses kepada pelbagai jenis hiburan dalam talian semakin mudah diperoleh. Salah satu fenomena yang telah menjadi perbualan hangat dalam kalangan peminat filem dan pengguna internet adalah laman web seperti “Pencuri Movie” dan “123 Movies

La Casa de los Famosos Colombia said...

La Casa de los Famosos Colombia

Anonymous said...

clicksud is best website
https://klicksud.online/