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