How to install Memcached on Ubuntu 18.04

Memcached is a free and open source high-performance memory key-value database. It is mainly used for system caching to improve the response speed of the application by caching the results in the database.

In this guide, we will describe how to install and configure the latest version of Memcached on Ubuntu 18.04. The same instructions apply to Ubuntu 16.04 and any other Ubuntu-based distributions.

1. Prerequisites##

Before continuing this guide, make sure you have logged in to the system as a user with sudo privileges.

Two, install Memcached

The Memcached package is included in the default 18.04 software source. This installation is very straightforward, just follow the steps below:

  1. Start updating the apt package list:
sudo apt update
  1. To install Memcached, enter:
sudo apt install memcached libmemcached-tools

This libmemcached-tools package contains various command line tools to manage Memcached server.

  1. Once the installation is complete, the Memcached service will be automatically started. To check the service status, enter the following command:
sudo systemctl status memcached

The output will look like this:

 memcached.service - memcached daemon
 Loaded:loaded(/lib/systemd/system/memcached.service; enabled; vendor preset: enabled)
 Active:active(running) since Tue 2019-04-3015:13:41 PDT; 37s ago
 Docs: man:memcached(1)
Main PID:10753(memcached)
 Tasks:10(limit:2319)
 CGroup:/system.slice/memcached.service
   `- 10753 /usr/bin/memcached -m 64-p 11211-u memcache -l 127.0.0.1-P /var/run/memcached/memcached.pid

That's it, at this time you have installed Memcached and it is running on your Ubuntu 18.04 server.

Three, configure Memcached

Memcached can be configured by editing the /etc/memcached.conf file. The default configuration file is sufficient for most users.

By default, Memcached is configured to only listen on the local localhost. If the client and server connecting to the server are on the same host, you do not need to modify the default configuration file.

3.1 remote access###

When Memcached is not properly configured, it can be used to perform denial of service attacks (DDos). If you want to allow remote access to Memcached service, you need to configure your firewall and only allow trusted clients to access Memcached through port 11211 UDP.

In the following example, suppose you want to connect to your Memcached server through a LAN. The server IP address is 192.168.100.20, and the client IP address is 192.168.100.30.

The firewall configuration tool that comes with Ubuntu is called UFW. By default, UFW is installed, but not enabled. Before enabling UFW, first add a rule to allow SSH connections:

sudo ufw allow 22

Allow remote client IP address access:

sudo ufw allow from192.168.100.30 to any port 11211

To enable UFW, enter:

sudo ufw status

Once the firewall is configured, the next step is to edit the Memcached configuration and set the Memcached service to listen to the server's LAN interface:

To do this, open the configuration file memcached.conf:

sudo nano /etc/memcached.conf

Locate this line, replace 127.0.0.1 with -l 127.0.0.1 and use the server's IP address 192.168.100.20.

# Specify which IP address to listen on. The default is to listen on all IP addresses
# This parameter is one of the only security measures that memcached has, so make sure
# it's listening on a firewalled interface.-l 192.168.100.20

Restart the Memcached service to make the changes take effect:

sudo systemctl restart memcached

You can connect to the Memcached server from your remote location.

Fourth, connect to Memcached

To connect to the Memcached server, you need to use a client in a specific language.

4.1 PHP

To use Memcached as your PHP application such as Wordpress, Drupal, Joomla or Magento as a cache database, you need to install php-memcached extension:

sudo apt install php-memcached

4.2 Python

There are some libraries on Python that can be used to interact with memcache, you can use pip to install your favorite libraries:

pip install pymemcache
pip install python-memcached

Five, summary##

You have learned how to install Memcached on your Ubuntu server. For more information on this topic, read Memcached Wiki.

Recommended Posts

How to install Memcached on Ubuntu 20.04
How to install Memcached on Ubuntu 18.04
How to install Ruby on Ubuntu 20.04
How to install Java on Ubuntu 20.04
How to install MySQL on Ubuntu 20.04
How to install Memcached on CentOS 8
How to install Elasticsearch on Ubuntu 20.04
How to install Protobuf 3 on Ubuntu
How to install Nginx on Ubuntu 20.04
How to install Node.js on Ubuntu 16.04
How to install MySQL on Ubuntu 20.04
How to install Bacula-Web on Ubuntu 14.04
How to install PostgreSQL on Ubuntu 16.04
How to install Git on Ubuntu 20.04
How to install Anaconda3 on Ubuntu 18.04
How to install Jenkins on Ubuntu 16.04
How to install MemSQL on Ubuntu 14.04
How to install Go on Ubuntu 20.04
How to install MongoDB on Ubuntu 16.04
How to install Mailpile on Ubuntu 14.04
How to install PrestaShop on Ubuntu 16.04
How to install Skype on Ubuntu 20.04
How to install Jenkins on Ubuntu 20.04
How to install Python 3.8 on Ubuntu 18.04
How to install KVM on Ubuntu 18.04
How to install KVM on Ubuntu 20.04
How to install opencv3.0.0 on ubuntu14.04
How to install Anaconda on Ubuntu 20.04
How to install Prometheus on Ubuntu 16.04
How to install Jenkins on Ubuntu 18.04
How to install Apache on Ubuntu 20.04
How to install R on Ubuntu 20.04
How to install Moodle on Ubuntu 16.04
How to install Solr 5.2.1 on Ubuntu 14.04
How to install Teamviewer on Ubuntu 16.04
How to install MariaDB on Ubuntu 20.04
How to install Nginx on Ubuntu 20.04
How to install Mono on Ubuntu 20.04
How to install Go on Ubuntu 20.04
How to install Zoom on Ubuntu 20.04
How to install Nginx on Ubuntu 16.04
How to install OpenCV on Ubuntu 20.04
How to install Spotify on Ubuntu 20.04
How to install Postman on Ubuntu 18.04
How to install Go 1.6 on Ubuntu 16.04
How to install Go on Ubuntu 18.04
How to install MySQL on Ubuntu 14.04
How to install PostgreSQL on Ubuntu 20.04
How to install VLC on Ubuntu 18.04
How to install TeamViewer on Ubuntu 20.04
How to install Webmin on Ubuntu 20.04
How to install Bacula Server on Ubuntu 14.04
How to install MySQL on Ubuntu 18.04 (linux)
How to install Ubuntu 19.10 on Raspberry Pi 4
How to install Apache Kafka on Ubuntu 18.04
How to install Apache Maven on Ubuntu 20.04
How to install Apache Tomcat 8 on Ubuntu 16.04
How to install Python2 on Ubuntu20.04 ubuntu/focal64
How to install GCC compiler on Ubuntu 18.04
How to install Graylog 1.x on Ubuntu 14.04.
How to install Zabbix on Ubuntu 16.04 Server