The best way to set up and configure memcached on Ubuntu Linux 18.04
I want to scale back the load on my MariaDB/MySQL/PostgreSQL server utilizing memcached. How do I set up and configure memcached server on Ubuntu Linux 18.04 LTS?
Introduction : Memcached is a high-performance, distributed reminiscence object caching server. It’s free and open supply software program meant to be used in dashing up dynamic internet purposes by mitigating database load. This web page reveals how one can set up, configure, confirm memcached set up on Ubuntu Linux 18.04 LTS.
The best way to set up and configure memcached on Ubuntu 18.04
The process to put in and configure memcached on Ubuntu is as follows:
Replace your Ubuntu primarily based system utilizing the apt commandInstall memcached on Ubuntu by operating sudo apt set up
Step 1 – Replace your Ubuntu server
Sort the next apt command or apt-get command to improve system to newest software program:
$ sudo apt replace
$ sudo apt improveReplace Ubuntu Linux 18.04 LTS server bundle index and set up updates if any
Step 2 – Set up memcached server on Ubuntu
Once more run apt command as follows:
$ sudo apt set up memcachedPutting in memcached server from the official Ubuntu repos
Step three – Configure memcached server on Ubuntu Linux 18.04 LTS
Subsequent you’ll want to edit config file named /and so forth/memcached.conf utilizing a textual content editor equivalent to nano command or vim command:
$ sudo nano /and so forth/memcached.conf
OR
$ sudo vi /and so forth/memcached.conf
Begin with a cap of 256 MB of reminiscence:
-m 256
Default connection port for memcached is 11211:
-p 11211
Specify which IP tackle to hear on. The default is to hear on all IP addresses. This parameter is without doubt one of the solely safety measures that memcached has, so be sure that
it’s listening on a firewalled interface. In my instance, I’m going to hear on 127.zero.zero.1 and servers non-public IP tackle 172.26.12.173 :
-l 127.zero.zero.1,172.26.12.173
Restrict the variety of simultaneous incoming connections. The daemon default is 1024 however I’m going to extend to 4096:
-c 4096
Save and shut the file when utilizing vim textual content editor by typing ESC + :x.
The best way to restart, cease, reload memcached server on Ubuntu 18.04
One can use the systemctl command as follows:
$ sudo systemctl cease memcached
$ sudo systemctl begin memcached
$ sudo systemctl restart memcached
$ sudo systemctl standing memcachedCommand to start out, cease, restart memached on Ubuntu Linux 18.04 LTS
The best way to open memcached port 11211 utilizing ufw
Allow us to say you’ve lxd primarily based containers operating on Ubuntu and utilizing 10.147.164.zero/24 sub-net vary. I’m going to restrict IP entry with the ufw primarily based firewall on Ubuntu as follows:
sudo ufw enable from container_ip1 to any port 11211
sudo ufw enable from vm2_ip2 to any port 11211
sudo ufw enable from sub/internet to any port 11211
sudo ufw enable from 10.147.164.5 to any port 11211
sudo ufw enable from 10.147.164.three to 172.26.12.173 port 11211 proto tcp
sudo ufw enable from 10.147.164.zero/24 to any port 11211
The best way to confirm that memcached is operating
Use the ss command or netstat command to confirm that TCP port # 11211 open and itemizing:
$ sudo ss -tulpn | grep :11211
$ sudo netstat -tulpn | grep :11211
The best way to set up CLI device for speaking to memcached by way of libmemcached
Allow us to set up libmemcached-tools for administration of memcached server and testing goal:
$ sudo apt set up libmemcached-tools
Confirm memcached server connectivity:
$ memcstat –servers=127.zero.zero.1Dumps the state of memcached servers with the assistance of memstat command
The best way to entry memcached from PHP/Perl/Python/Ruby lang
Set up bundle as per your wants:
ruby-dalli – Ruby clientphp-memcached – PHP modulepython-memcache – Python clientpython3-pymemcache – Python three.x clientlibcache-memcached-libmemcached-perl – Perl for Memcached::libmemcached
Conclusion
This web page confirmed how one can set up, configure, confirm memcached server on Ubuntu Linux 18.04 LTS. For more information see the official memached challenge web page right here. Alternately, you possibly can set up memcached extensions for WordPress to enhance efficiency.