Files
nextcloud-vmm/addons/redis-server-ubuntu.sh
2020-08-10 17:57:42 +02:00

101 lines
2.5 KiB
Bash

#!/bin/bash
# shellcheck disable=2034,2059
true
# shellcheck source=lib.sh
. <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/master/lib.sh)
# T&M Hansson IT AB © - 2020, https://www.hanssonit.se/
# Check for errors + debug code and abort if something isn't right
# 1 = ON
# 0 = OFF
DEBUG=0
debug_mode
# Must be root
root_check
# Check Ubuntu version
check_distro_version
# Check if dir exists
if [ ! -d $SCRIPTS ]
then
mkdir -p $SCRIPTS
fi
# Check the current PHPVER
check_php
# Install Redis
install_if_not php"$PHPVER"-dev
pecl channel-update pecl.php.net
if ! yes no | pecl install -Z redis
then
msg_box "PHP module installation failed"
exit 1
else
printf "${IGreen}\nPHP module installation OK!${Color_Off}\n"
fi
install_if_not redis-server
# Setting direct to PHP-FPM as it's installed with PECL (globally doesn't work)
print_text_in_color "$ICyan" "Adding extension=redis.so to $PHP_INI..."
echo 'extension=redis.so' >> "$PHP_INI"
# Prepare for adding redis configuration
sed -i "s|);||g" $NCPATH/config/config.php
# Add the needed config to Nextclouds config.php
cat <<ADD_TO_CONFIG >> $NCPATH/config/config.php
'memcache.local' => '\\OC\\Memcache\\APCu',
'filelocking.enabled' => true,
'memcache.distributed' => '\\OC\\Memcache\\Redis',
'memcache.locking' => '\\OC\\Memcache\\Redis',
'redis' =>
array (
'host' => '$REDIS_SOCK',
'port' => 0,
'timeout' => 0.5,
'dbindex' => 0,
'password' => '$REDIS_PASS',
),
);
ADD_TO_CONFIG
## Redis performance tweaks ##
if ! grep -Fxq "vm.overcommit_memory = 1" /etc/sysctl.conf
then
echo 'vm.overcommit_memory = 1' >> /etc/sysctl.conf
fi
# Disable THP
if ! grep -Fxq "never" /sys/kernel/mm/transparent_hugepage/enabled
then
echo "never" > /sys/kernel/mm/transparent_hugepage/enabled
fi
# Raise TCP backlog
#if ! grep -Fxq "net.core.somaxconn" /proc/sys/net/core/somaxconn
#then
# sed -i "s|net.core.somaxconn.*||g" /etc/sysctl.conf
# sysctl -w net.core.somaxconn=512
# echo "net.core.somaxconn = 512" >> /etc/sysctl.conf
#fi
sed -i "s|# unixsocket .*|unixsocket $REDIS_SOCK|g" $REDIS_CONF
sed -i "s|# unixsocketperm .*|unixsocketperm 777|g" $REDIS_CONF
sed -i "s|^port.*|port 0|" $REDIS_CONF
sed -i "s|# requirepass .*|requirepass $REDIS_PASS|g" $REDIS_CONF
sed -i 's|# rename-command CONFIG ""|rename-command CONFIG ""|' $REDIS_CONF
redis-cli SHUTDOWN
# Secure Redis
chown redis:root /etc/redis/redis.conf
chmod 600 /etc/redis/redis.conf
apt update -q4 & spinner_loading
apt autoremove -y
apt autoclean
exit