This guide is for installing redis as a replacement for the memcached php session store when using php71u IUS packages on a CentOS-6 environment.
- https://github.com/phpredis/phpredis#php-session-handler
- https://redis.io/topics/lru-cache
- https://redis.io/topics/latency
- https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Performance_Tuning_Guide/s-memory-transhuge.html
- https://access.redhat.com/solutions/46111
# rpm -q ius-release \
&> /dev/null \
|| yum -y install \
https://centos6.iuscommunity.org/ius-release.rpm \
&& rpm -q redis \
&> /dev/null \
&& rpm -q php71u-pecl-redis \
&> /dev/null \
|| yum -y install \
redis \
php71u-pecl-redis
# if ! grep -qP \
'^[0-9\.:]+\t+redis-cache' /etc/hosts; then \
printf -- \
'127.0.0.1\t%s\n::1\t\t%s\n' \
redis-cache \
redis-cache \
>> /etc/hosts; \
fi
# if ! grep -qP '^net.core.somaxconn ?=' /etc/sysctl.conf; then \
{ \
echo 'net.core.somaxconn = 1024'; \
} >> /etc/sysctl.conf; \
else \
sed -i -r \
-e 's~(^net.core.somaxconn ?= ?)[0-9]+$~\11024~' \
/etc/sysctl.conf; \
fi \
&& if ! grep -qP '^vm.overcommit_memory ?=' /etc/sysctl.conf; then \
{ \
echo 'vm.overcommit_memory = 1'; \
} >> /etc/sysctl.conf; \
else \
sed -i -r \
-e 's~(^vm.overcommit_memory ?= ?)[0-1]+$~\11~' \
/etc/sysctl.conf; \
fi \
&& sysctl -p \
&& printf -- \
'never' \
| tee \
/sys/kernel/mm/transparent_hugepage/enabled \
/sys/kernel/mm/transparent_hugepage/defrag \
&> /dev/null \
&& grubby \
--args="transparent_hugepage=never" \
--update-kernel "$(
grubby --default-kernel
)"
To use redis as a replacement for memcached it can be configured with a memory limit and eviction policy.
The settings below set a limit of 64M and increase the sample size used to predict the lru (less recently used) values from 5 to 10.
# sed -i -r \
-e 's~^(save [0-9]+ [0-9]+)~#\1~' \
-e 's~^(# )?(maxmemory ).+$~\264mb~' \
-e 's~^(# )?(maxmemory-policy ).+$~\2allkeys-lru~' \
-e 's~^(# )?(maxmemory-samples ).+$~\210~' \
/etc/redis.conf
# chkconfig redis on \
&& service redis condrestart \
&& service redis start
# sed -i -r \
-e 's~^;(session\.save_handler ?= ?redis)$~\1~' \
-e 's~^;(session\.save_path ?= ?).*$~\1"tcp://redis-cache:6379"~' \
/etc/php.d/50-redis.ini
Configuration file locations for mod_php, fcgid and php-fpm vary. The session.save_handler
and session.save_path
values need to be updated in the appropriate configuration files for your Apache MPM.
Apache needs to be reloaded for the configuration settings to be applied.
# apachectl graceful