Multiple instances of memcached from CentOS 7

Source: Internet
Author: User
Tags memcached centos

Memcached is a distributed cache system that is currently used by many Web sites. In general, after memcached is installed by default, it listens on port 11211.
In some special cases, we want to have multiple memcached instances, each of which listens on different ports. On CentOS 7, how is this supposed to be done?

The solution is to modify and add the configuration file. First, you need to figure out what the memcached configuration file is by default. As in these few:

/usr/lib/systemd/system/memcached.service
This file is not long, only 46 lines, and less comments are removed. The most important of these is the following 2 lines:

[Service]
Environmentfile=/etc/sysconfig/memcached
Execstart=/usr/bin/memcached-p ${port}-u ${user}-M ${cachesize}-C ${maxconn} $OPTIONS

The first line of Environmentfile indicates another configuration file, and this file defines the configuration entries for port, USER, CACHESIZE, Maxconn, options mentioned in the second line.

/etc/sysconfig/memcached
Already described above.

/etc/systemd/system/multi-user.target.wants/memcached.service
This is a soft link that points to the configuration file described in 1.

In order to do a long example, we have to do the following, all in code description. The brief description is: The above 1, 2, 3 of the configuration file, all again copy one copy and rename, such as named Memcached_controller.service or Memcached_controller, that is, add "_controller" This suffix (suffix can be arbitrarily up). Then modify the environmentfile and port numbers in them.

Cp/usr/lib/systemd/system/memcached.service/usr/lib/systemd/system/memcached_controller.service
sed-i ' s% environmentfile=/etc/sysconfig/memcached%environmentfile=/etc/sysconfig/memcached_controller% '/usr/lib/systemd /system/memcached_controller.service

ln-s/usr/lib/systemd/system/memcached_controller.service/etc/systemd/ System/multi-user.target.wants/memcached_controller.service 

cp/etc/sysconfig/memcached/etc/sysconfig/ Memcached_controller
sed-i ' s/port= "11211/port=" 22122 "/'/etc/sysconfig/memcached_controller

systemctl Enable Memcached_controller
systemctl Restart Memcached_controller

At this point, another memcached is up. It listens on port 22122.

Finish

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.