|

How to Install LiteSpeed Memcached (LSMCD) with OpenLiteSpeed

Although OpenLiteSpeed (OLS) can work well with Redis or Memcached for object caching, it is recommended to use LiteSpeed Memcached (LSMCD), which was developed specifically for OLS and guarantees the best performance. LSMCD is unfortunately not available as a package for Ubuntu/Debian nor for CentOS/RHEL and thus will have to be compiled and installed manually. In this case, we are going to see how to install LSMCD on Ubuntu.

Before starting the installation, check that Memcached (default package or LSCMD) is not already installed on your system and active on port 11211. We can test this using the “telnet” command.

# telnet 127.0.0.1 11211
Trying 127.0.0.1...
telnet: Unable to connect to remote host: Connection refused

Make sure all the required packages are installed to compile and install the source code.

# apt install git build-essential zlib1g-dev libexpat1-dev openssl libssl-dev libsasl2-dev libpcre3-dev -y

Although not strictly necessary, it is best to store the source code we download in the “/usr/src” directory.

# cd /usr/src

We use “git” to clone the last repository, which automatically creates a directory “lsmcd” where all the files are stored.

# git clone https://github.com/litespeedtech/lsmcd.git

Move to the directory “lsmcd” that has just been created.

# cd lsmcd

To compile and install LSMCD, you need to run a few commands.

# ./fixtimestamp.sh
# ./configure CFLAGS=" -O3" CXXFLAGS=" -O3"
# make
# make install

LSMCD should now be successfully installed and all you need to do is enable and start the daemon.

# systemctl enable lsmcd
# systemctl start lsmcd
# systemctl status lsmcd

Verify that LSMCD is running with telnet.

# telnet 127.0.0.1 11211
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.

Type “stats” and press enter to see the available stats and verify that everything is working properly.

stats
STAT pid 2235
STAT version 1.0.0
STAT pointer_size 64
STAT rusage_user 0.000289
STAT rusage_system 0.007185
STAT cmd_get 129390
STAT cmd_set 15255
STAT cmd_flush 0
STAT cmd_touch 0
STAT get_hits 116605
STAT get_misses 12785
STAT delete_misses 1863
STAT delete_hits 581
STAT incr_misses 0
STAT incr_hits 0
STAT decr_misses 0
STAT decr_hits 0
STAT cas_misses 0
STAT cas_hits 0
STAT cas_badval 0
STAT touch_hits 0
STAT touch_misses 0
STAT auth_cmds 0
STAT auth_errors 0
END

To exit, just type “quit” and press enter.

If you are running LSMCD on a single server, you can use a unix socket instead of the default TCP/IP port, which will provide a significant speed gain. To achieve this, it is necessary to adjust the value of “CACHED.ADDR” directive in the “node.conf” file.

# vi /usr/local/lsmcd/conf/node.conf

Change “CACHED.ADDR” to “UDS:///tmp/lsmcd.sock”.

#CACHED.ADDR=127.0.0.1:11211
CACHED.ADDR=UDS:///tmp/lsmcd.sock

You might also want to increase the maximum memory size as well by adding the “Cached.MemMaxSz” directive with a value of “1000000000”.

Cached.MemMaxSz=1000000000

Restart LSMCD.

# systemctl restart lsmcd

LSMCD should now be available through the unix socket “/tmp/lsmcd.sock” which we can check using the “nc” command.

# nc -U /tmp/lsmcd.sock -C

Type “stats” and press enter to see the available stats and verify that everything is working properly.

stats
STAT pid 2296
STAT version 1.0.0
STAT pointer_size 64
STAT rusage_user 0.059236
STAT rusage_system 0.123845
STAT cmd_get 131555
STAT cmd_set 15961
STAT cmd_flush 0
STAT cmd_touch 0
STAT get_hits 118240
STAT get_misses 13315
STAT delete_misses 2744
STAT delete_hits 659
STAT incr_misses 0
STAT incr_hits 0
STAT decr_misses 0
STAT decr_hits 0
STAT cas_misses 0
STAT cas_hits 0
STAT cas_badval 0
STAT touch_hits 0
STAT touch_misses 0
STAT auth_cmds 0
STAT auth_errors 0
END

To exit, just type “quit” and press enter.

Finally, the PHP memcached extension must be installed for the version used on your server, which in our case is PHP 8.0.

# apt install lsphp80-memcached

You may want to check the version of your LSMCD installation from time to time to see if an update is needed.

# /usr/local/lsmcd/bin/lsmcd -v

To install a new version of LSMCD you must first completely uninstall the old version.

# systemctl stop lsmcd
# systemctl disable lsmcd
# rm -rf /usr/local/lsmcd
# rm -rf /dev/shm/lsmcd
# rm -rf /tmp/lsmcd
# rm /tmp/lsmcd.log

Similar Posts