环境准备
echo 512 > /proc/sys/net/core/somaxconn ;\echo vm.overcommit_memory=1 >> /etc/sysctl.conf ;\ sysctl -p ;\echo 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' >> /etc/rc.local ;\ chmod +x /etc/rc.d/rc.local ;\ useradd -s /sbin/nologin redis ;\ mkdir -p /var/lib/redis/run ;\ mkdir -p /var/lib/redis/logs ;\ mkdir -p /var/lib/redis/data/26379 ;\ mkdir -p /var/lib/redis/data/6379 ;\ touch /var/lib/redis/logs/6379.log ;\ touch /var/lib/redis/logs/6379.log ;\ firewall-cmd --add-port=26379/tcp --permanent ;\ firewall-cmd --add-port=6379/tcp --permanent ;\ firewall-cmd --reload ;\ firewall-cmd --list-all
编译安装
tar xf redis-4.0.11.tar.gz;\cd redis-4.0.11;\ yum install gcc make -y;\ make && make install;\ mkdir /etc/redis;\ cp redis.conf /etc/redis/;\ chown -R redis. /etc/redis;\ chown -R redis. /var/lib/redis
修改node配置
#修改数据目录sed -i '/dir ./c\dir /var/lib/redis/data/6379' /etc/redis/redis.conf#更改日志目录sed -i '/logfile /c\logfile "/var/lib/redis/logs/6379.log"' /etc/redis/redis.conf#访问master需要的密码sed -i '/masterauth /c\masterauth Redis_dev_2018' /etc/redis/redis.conf#自身密码sed -i '/requirepass /c\requirepass Redis_dev_2018' /etc/redis/redis.conf#注释掉bindsed -i '/bind 127.0.0.1/c\#bind 127.0.0.1' /etc/redis/redis.conf
添加node节点服务
tee /etc/systemd/system/redis.service << 'EOF' [Unit] Description=Redis Server After=network.target [Service] Type=simple PIDFile=/var/lib/redis/run/6379.pid User=redis Group=redis LimitNOFILE=100000 ExecStart=/usr/local/bin/redis-server /etc/redis/redis.conf ExecStop=/usr/local/bin/redis-cli -p 6379 shutdown Restart=on-failure [Install] WantedBy=multi-user.target EOF
启动node
systemctl daemon-reload ;\ systemctl enable redis ;\ systemctl start redis ;\ systemctl status redis
添加sentinel配置文件
tee /etc/redis/sentinel.conf << 'EOF' port 26379 dir "/var/lib/redis/data/26379" protected-mode no daemonize no logfile "/var/lib/redis/logs/26379.log" sentinel monitor dev 192.168.1.151 6379 2 sentinel down-after-milliseconds dev 20000 sentinel failover-timeout dev 60000 sentinel auth-pass dev Redis_dev_2018 EOF chown -R redis. /etc/redis
添加sentinel服务
tee /etc/systemd/system/redis-sentinel.service << 'EOF' [Unit] Description=Redis sentinel Server After=network.target [Service] Type=simple PIDFile=/var/lib/redis/run/26379.pid User=redis Group=redis LimitNOFILE=100000 ExecStart=/usr/local/bin/redis-server /etc/redis/sentinel.conf --sentinel ExecStop=/usr/local/bin/redis-cli -p 26379 shutdown Restart=on-failure [Install] WantedBy=multi-user.target EOF
启动sentinel
systemctl daemon-reload ;\ systemctl enable redis-sentinel ;\ systemctl start redis-sentinel ;\ systemctl status redis-sentinel
维护Slave关系
#添加slave-42redis-cli -h 192.168.1.152 auth Redis_dev_2018 slaveof 192.168.1.151 6379#添加slave-43redis-cli -h 192.168.1.153 auth Redis_dev_2018 slaveof 192.168.1.151 6379
常用命令
#查看slave信息redis-cli -p 26379 sentinel slaves dev
作者:Hanson1330
链接:https://www.jianshu.com/p/5d5b68b9a35c