Distributed memcached on 2 Webserver [CentOS7]

Install memcached

yum install memcached libmemcached -y
vi /etc/sysconfig/memcached

Change options to listen to the private IP on both web's:

OPTIONS="-l 10.1.1.X -U 0"

Restart memcached

systemctl restart memcached
systemctl enable memcached

Edit php ini

vi /etc/php.ini
session.save_handler = memcache
session.save_path = "tcp://, tcp://"

Install php-pecl-memcache

yum -y install php-pecl-memcache
echo "extension=memcache.so" >> /etc/php.d/memcache.ini
systemctl restart httpd

Allow in FW

firewall-cmd --zone=public --permanent --add-port=11211/tcp
firewall-cmd --reload

Check if memcached is running

watch memcached-tool X.X.X.X stats

Create test page:

vim /home/www/domain.com/session.php

Test Page:

header('Content-Type: text/plain');
echo "Page to test memcache.\n";
$_SESSION['visit'] = 0;
echo "You have visited this server ".$_SESSION['visit'] . " times. \n";
echo "Server IP: ".$_SERVER['SERVER_ADDR'] . "\n";
echo "Client IP: ".$_SERVER['REMOTE_ADDR'] . "\n";