Free & open source, high-performance, distributed memory object caching system, generic in nature, but intended for use in speeding up dynamic web applications by alleviating database load.Memcached is an in-memory key-value store for small chunks of arbitrary data (strings, objects) from results of database calls, API calls, or page rendering.
Memcached is simple yet powerful. Its simple design promotes quick deployment, ease of development, and solves many problems facing large data caches. Its APIis available for most popular languages.
Here is the simple steps to install Memcached on CentOS 7.
Open Terminal and then switch to root user.
[raj@itzgeek~/]$ su -l |
Install Memcached:
Install Memcached using the following command.
[root@itzgeek~/]# yum install memcached |
Edit Memcached configuration file to change / enable the features.
[root@itzgeek~/]# vi /etc/sysconfig/memcached |
There are some default settings available in the configuration file, change it (if necessary). The following is example settings for 256MB caching.
PORT="11211" USER="memcached" MAXCONN="1024" CACHESIZE="256" OPTIONS="" |
Start Memcached.
[root@itzgeek~/]# systemctl start memcached.service |
To auto-start Memcached on booting.
[root@itzgeek~/]# systemctl enable memcached.service |
Confirm the Memcached running status.
[root@itzgeek~/]# memcached-tool 127.0.0.1:11211 stats #127.0.0.1:11211 Field Value accepting_conns 1 auth_cmds 0 auth_errors 0 bytes 0 bytes_read 7 bytes_written 0 cas_badval 0 cas_hits 0 cas_misses 0 cmd_flush 0 cmd_get 0 cmd_set 0 cmd_touch 0 conn_yields 0 connection_structures 11 curr_connections 10 curr_items 0 decr_hits 0 decr_misses 0 delete_hits 0 delete_misses 0 evicted_unfetched 0 evictions 0 expired_unfetched 0 get_hits 0 get_misses 0 hash_bytes 524288 hash_is_expanding 0 hash_power_level 16 incr_hits 0 incr_misses 0 libevent 2.0.21-stable limit_maxbytes 268435456 listen_disabled_num 0 pid 12545 pointer_size 64 reclaimed 0 reserved_fds 20 rusage_system 0.014289 rusage_user 0.000000 threads 4 time 1406441667 total_connections 11 total_items 0 touch_hits 0 touch_misses 0 uptime 48 version 1.4.15 |
Iptables entry:
Add the following entry to allow the incoming connection on port no 11211.
firewall-cmd --permanent --zone=public --add-port=11211/tcp |
Check the remote connectivity.
[root@itzgeek~/]# echo stats | nc memcache_host_name_or_ip 11211 |
Install PHP Module:
Install Memcached PHP module to work with PHP5.
[root@itzgeek~/]# yum install php php-pecl-memcache |
Now restart the Memcached and Apache server to take effect.
[root@itzgeek~/]# systemctl restart memcached.service [root@itzgeek~/]# systemctl restart httpd.service |
That’s all!