A Complete Guide to Installing Memcached on Amazon Linux 2023
May 10, 2024 | by biplob.ice
How to Install Memcached on Amazon Linux 2023
Memcached is a popular in-memory caching system that can greatly improve the performance of your web applications. In this guide, we will walk you through the steps to install Memcached on Amazon Linux 2023.
Step 1: Update System Packages
Before we begin the installation process, let’s make sure our system packages are up to date. Open your terminal and run the following command:
sudo yum update -y
This command will update all the installed packages on your Amazon Linux system.
Step 2: Install Memcached
Now that our system is up to date, we can proceed with the installation of Memcached. Run the following command in your terminal:
sudo yum install memcached -y
This command will download and install Memcached on your system.
Step 3: Start and Enable Memcached Service
After the installation is complete, we need to start the Memcached service and enable it to start automatically on system boot. Run the following commands:
sudo systemctl start memcachedsudo systemctl enable memcached
These commands will start the Memcached service and configure it to start on system boot.
Step 4: Configure Memcached
By default, Memcached listens on the loopback interface (127.0.0.1) and uses the default port 11211. If you want to change these settings, you can edit the Memcached configuration file located at /etc/sysconfig/memcached. Open the file using a text editor:
sudo vi /etc/sysconfig/memcached
Inside the file, you can modify the OPTIONS variable to specify the listening IP address and port. For example, to make Memcached listen on all interfaces and use port 12345, you can set the following:
OPTIONS="-l 0.0.0.0 -p 12345"
Save the file and exit the text editor.
Step 5: Test Memcached
Now that Memcached is installed and configured, let’s test if it’s working correctly. Run the following command in your terminal:
echo "stats" | nc 127.0.0.1 11211
If Memcached is running properly, you should see a list of statistics related to the Memcached server.
How to Install in Docker Container Image
# Install memcached
dnf install -q -y php-devel php-pear gcc
pear update-channels
pecl update-channels
/usr/bin/yes 'no' | pecl install igbinary
echo 'extension=igbinary.so' > /etc/php.d/30-igbinary.ini
/usr/bin/yes 'no' | pecl install msgpack
echo 'extension=msgpack.so' > /etc/php.d/30-msgpack.ini
dnf install -q -y memcached-devel libmemcached-awesome-devel zlib-devel cyrus-sasl-devel libevent-devel
/usr/bin/yes 'no' | pecl install --configureoptions 'enable-memcached-igbinary="yes" enable-memcached-msgpack="yes" enable-memcached-json="yes" enable-memcached-protocol="yes" enable-memcached-sasl="yes" enable-memcached-session="yes"' memcached
echo 'extension=memcached.so' > /etc/php.d/41-memcached.ini
# Test memcached
dnf install telnet
telnet dev-memcached 11211
How to Install using DockerFile
# Install Memcached
RUN dnf install -y php8.2-devel php-pear gcc \
&& pear update-channels \
&& pecl update-channels
RUN pecl install igbinary \
&& echo 'extension=igbinary.so' > /etc/php.d/30-igbinary.ini
RUN pecl install msgpack \
&& echo 'extension=msgpack.so' > /etc/php.d/30-msgpack.ini
RUN dnf install -y memcached-devel libmemcached-awesome-devel zlib-devel cyrus-sasl-devel libevent-devel \
&& echo 'no' | pecl install --configureoptions 'enable-memcached-igbinary="yes" enable-memcached-msgpack="yes" enable-memcached-json="yes" enable-memcached-protocol="yes" enable-memcached-sasl="yes" enable-memcached-session="yes"' memcached \
&& echo 'extension=memcached.so' > /etc/php.d/41-memcached.ini
EXPOSE 11211
Conclusion
Congratulations! You have successfully installed Memcached on Amazon Linux 2023. You can now start using Memcached to improve the performance of your web applications by caching frequently accessed data in memory.
Remember to regularly monitor and tune your Memcached configuration to ensure optimal performance. Happy caching!
RELATED POSTS
View all