mb-admin/scripts/relay/install_relay_ocp.sh

69 lines
2.6 KiB
Bash

#!/bin/bash
set -e
# Commands that require root permissions
sudo su <<'ROOT_BLOCK'
yum install -y openssl11
yum install -y lsphp-pecl-msgpack
# Other root commands here...
ROOT_BLOCK
# Determine PHP version and directories
LSPHP=$(php-config --version | cut -c -3)
LSPHP="${LSPHP//./}"
RELAY_PHP=$(php-config --version | cut -c -3)
RELAY_INI_DIR=$(php-config --ini-dir)
RELAY_EXT_DIR=$(php-config --extension-dir)
RELAY_VERSION=$(curl -fs https://builds.r2.relay.so/meta/latest)
RELAY_ARCH=$(arch | sed -e 's/arm64/aarch64/;s/amd64\|x86_64/x86-64/')
# Install Relay (requires root)
sudo curl -L "https://builds.r2.relay.so/$RELAY_VERSION/relay-$RELAY_VERSION-php$RELAY_PHP-centos7-$RELAY_ARCH.tar.gz" | tar xz -C /tmp
sudo cp "/tmp/relay-$RELAY_VERSION-php$RELAY_PHP-centos7-$RELAY_ARCH/relay.ini" "$RELAY_INI_DIR/60-relay.ini"
sudo cp "/tmp/relay-$RELAY_VERSION-php$RELAY_PHP-centos7-$RELAY_ARCH/relay-pkg.so" "$RELAY_EXT_DIR/relay.so"
echo "extension = msgpack.so" | sudo tee "$RELAY_INI_DIR/50-msgpack.ini" > /dev/null
# Configure Relay (requires root)
sudo sed -i 's/^;\? \?relay.maxmemory =.*/relay.maxmemory = 128M/' $RELAY_INI_DIR/60-relay.ini
sudo sed -i 's/^;\? \?relay.eviction_policy =.*/relay.eviction_policy = lru/' $RELAY_INI_DIR/60-relay.ini
sudo sed -i 's/^;\? \?relay.environment =.*/relay.environment = production/' $RELAY_INI_DIR/60-relay.ini
sudo sed -i "s/^;\? \?relay.key =.*/relay.key = SJR3-5IHD-CKMYLH-YJRQSY2-8443KZZ-V2LAS6/" $RELAY_INI_DIR/60-relay.ini
sudo sed -i "s/00000000-0000-0000-0000-000000000000/$(cat /proc/sys/kernel/random/uuid)/" "$RELAY_EXT_DIR/relay.so"
# Install Object Cache Pro in WordPress (do not run as root)
cd /var/www/webroot/ROOT
wp plugin install 'https://objectcache.pro/plugin/object-cache-pro.zip?token=091801712a649241ca11668fdf19552c2d13dad4d9b1d28848c276cd5111' --force --activate
# Configure Object Cache Pro
ocp_config="[
'token' => '091801712a649241ca11668fdf19552c2d13dad4d9b1d28848c276cd5111',
'host' => '127.0.0.1',
'port' => 6379,
'client' => 'relay',
'database' => 0,
'prefix' => 'db0',
'shared' => false,
'compression' => 'zstd',
'serializer' => 'igbinary',
'prefetch' => false,
'split_alloptions' => false,
'timeout' => 0.5,
'read_timeout' => 0.5,
'retries' => 3,
'backoff' => 'smart',
'debug' => false,
'save_commands' => false,
]"
wp config set WP_REDIS_CONFIG "$ocp_config" --raw
wp config set WP_REDIS_DISABLED false --raw
wp redis enable --force
wp redis flush
# Restart LiteSpeed server (requires root)
sudo service lsws restart
echo "Relay and Object Cache Pro installation and configuration are complete."