How to install Memcached on Ubuntu 20.04

Article Directory

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.

This article shows how to install and configure Memcached on Ubuntu 20.04.

One, install Memcached

The Memcached package is included in the default Ubuntu 20.04 software source. To install it, run the following command as root or another sudo user:

sudo apt update
sudo apt install memcached libmemcached-tools
This one`libmemcached-tools`The package contains various command line tools to manage the Memcached server.

Once the installation is complete, memcached will start automatically. To check the server status, enter:

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 Mon 2020-07-1319:32:01 UTC; 23s ago

That's it, you have installed memcached on your Ubuntu 20.04 server, and you can start using it.

Two, configure Memcached

Memcached can be configured by editing the /etc/memcached.conf file. 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.

The default configuration file is sufficient for most users.

2.1 remote access###

If the client connecting to memcached and memcached are running on the same host, you should not allow 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 first step is to edit the memcached configuration file and set up the service to monitor the server's LAN interface:

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

sudo nano /etc/memcached.conf

Locate this line, start with -l 127.0.0.1, and replace 127.0.0.1 with 192.168.100.20

/etc/memcached.conf

- l 192.168.100.20

Restart the Memcached service to make the application take effect:

sudo systemctl restart memcached

Once the server is configured, the next step is to open the memcached port on the firewall.

sudo ufw allow from192.168.100.30 to any port 11211

Three, connect to Memcached

There are many different memcached clients, suitable for different programming languages.

3.1 PHP

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

sudo apt install php-memcached

3.2 Python

There are several Python libraries that can interact with memcache. You can use pip to install your favorite library:

pip install pymemcache
pip install python-memcached

Four, summary##

We have shown you how to install Memcached on Ubuntu 20.04. For more information on this topic, check the 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 VirtualBox on Ubuntu 20.04
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 Apache on Ubuntu 20.04
How to install Git on Ubuntu 20.04
How to install Node.js on Ubuntu 16.04
How to install MySQL on Ubuntu 20.04
How to install Vagrant 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 Docker Compose on Ubuntu 18.04
How to install Ubuntu on Raspberry Pi
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