====== Настройка кластера redis на трех серверах ====== Требуется на виртуальных машинах, работающих на ОС debian 11 c IP адресами: 192.168.255.131 192.168.255.132 192.168.255.133, создать кластер redis-server ===== Подготовка к установке кластера ===== Создаем первую машину и на ней выполняем настройку сервера. # Обновляем ОСь apt update && apt upgrade -y # Установка сервера redis apt install redis-server -y systemctl disable redis-server.service systemctl stop redis-server.service ===== Создаем конфиг демона сервера redis ===== cat << EOF > /etc/systemd/system/redis-cluster-node@.service [Unit] Description=redis cluster instance at port %i After=network.target Documentation=http://redis.io/documentation, man:redis-server(1) [Service] Type=forking ExecStart=/usr/bin/redis-server /etc/redis/redis.conf \ --cluster-enabled yes \ --dbfilename dump_%i.rdb \ --port %i --cluster-config-file nodes_%i.conf \ --pidfile /var/run/redis/redis-server_%i.pid \ --logfile /var/log/redis/redis-server_%i.log PIDFile=/var/run/redis/redis-server_%i.pid TimeoutStopSec=0 Restart=always User=redis Group=redis RunTimeDirectory=redis ExecStartPre=-/bin/run-parts --verbose /etc/redis/redis-server.pre-up.d ExecStartPost=-/bin/run-parts --verbose /etc/redis/redis-server.post-up.d ExecStop=-/bin/run-parts --verbose /etc/redis/redis-server.pre-down.d ExecStop=/bin/kill -s TERM $MAINPID ExecStopPost=-/bin/run-parts --verbose /etc/redis/redis-server.post-down.d UMask=007 PrivateTmp=yes LimitNOFILE=65535 PrivateDevices=yes ProtectHome=yes ReadOnlyDirectories=/ ReadWriteDirectories=-/var/lib/redis ReadWriteDirectories=-/var/log/redis ReadWriteDirectories=-/var/run/redis CapabilityBoundingSet=~CAP_SYS_PTRACE # redis-server writes its own config file when in cluster mode so we allow # writing there (NB. ProtectSystem=true over ProtectSystem=full) ProtectSystem=true ReadWriteDirectories=-/etc/redis [Install] WantedBy=multi-user.target EOF ===== Конфигурируем сервер redis ===== mkdir -p /etc/redis/redis-server.pre-up.d mkdir -p /etc/redis/redis-server.post-up.d mkdir -p /etc/redis/redis-server.pre-down.d mkdir -p /etc/redis/redis-server.post-down.d mkdir -p /run/redis chown -R redis:redis /etc/redis/ chown redis:redis /run/redis/ systemctl daemon-reload sed -i '/^appendonly/s/no/yes/' /etc/redis/redis.conf sed -i '/^bind/s/127.0.0.1/0.0.0.0/' /etc/redis/redis.conf systemctl enable redis-cluster-node@7000 systemctl enable redis-cluster-node@7001 systemctl enable redis-cluster-node@7002 systemctl start redis-cluster-node@7000.service systemctl start redis-cluster-node@7001.service systemctl start redis-cluster-node@7002.service