Prerequire
? ? ? ? ? 1、操作系統版本:? CentOS7;
? ? ? ? ? 2、Redis 版本:5.0.5,cluster默認集成在redis包中;
? ? ? ? ? 3、cluster集群的部署方式為:9臺redis機器上分別以cluster模式運行9個redis服務,
? ? ? ? ? ? ? 10.8.23.107;10.8.23.108;10.8.23.109;10.8.32.104;10.8.32.105;10.8.32.106;10.8.32.107;10.8.32.109;10.8.32.111
? ? ? ? ? 4、如無特殊說明下載文件總是放在/usr/local/src、安裝目錄總是在/app/redis、日志目錄總是在/app/redis/logs、數據目錄/data/redis。?
一、初始設置:
1.1、相關內核參數
#設置內存 overcommit 總是允許分配內存
sysctl -a 2>/dev/null? |grep overcommit_memory
vm.overcommit_memory = 1
#禁用透明大頁
cat /sys/kernel/mm/transparent_hugepage/enabled
always madvise [never]
#使用命令查看時,如果輸出結果為[always]表示透明大頁啟用了。[never]表示透明大頁禁用、[madvise]表示只在MADV_HUGEPAGE標志的VMA中使用THP
#增加somaxconn 內核參數
# +該參數需要大于redis.conf配置文件中tcp-backlog 的設置
cat /proc/sys/net/core/somaxconn
65535
注:內核參數設置可以基于文件然后systctl -p,也可使用sysctl -w? key=value,這里不再詳述
1.2、賬號設置
groupadd nobody
useradd -g redis -s /sbin/nologin nobody
二、安裝配置
2.1、安裝redis
cd /usr/local/src/
wget http://download.redis.io/releases/redis-5.0.5.tar.gz
tar -zxvf redis-5.0.5.tar.gz && cd redis-5.0.5
make
make PREFIX=/app/redis install
2.2、配置redis
#設置配置目錄
mkdir -p /app/redis/conf
#設置日志目錄
mkdir -p /app/redis/logs/
#設置持久化數據目錄
mkdir -p /data/redis
#復制redis模板配置
cp /usr/local/src/redis-5.0.5/redis.conf? /app/redis/conf/
#以下僅列出部分配置信息,詳細信息請參見配置說明
port 6379
bind 0.0.0.0
supervised systemd
daemonize yes
protected-mode no
cluster-enabled yes
pidfile /var/run/redis.pid
logfile "/app/redis/logs/redis.log"
cluster-config-file /app/redis/conf/nodes.conf
dir /data/redis
cluster-node-timeout 5000
masterauth redis123456
requirepass redis123456
maxclients 50000
save ""
appendonly yes
cluster-require-full-coverage no
no-appendfsync-on-rewrite yes
##############rename command##########
rename-command KEYS? ? "NYKJKEYS"
rename-command FLUSHALL "NYKJFLUSHALL"
rename-command FLUSHDB? "NYKJFLUSHDB"
2.3、redis啟動腳本及開機啟動? /etc/systemd/system/redis.service
#redis systemd啟動腳本
[Unit]
Description=Redis 5.0.5
After=network.target
[Service]
Type=simple
PIDFile=/var/run/redis.pid
LimitNOFILE=65535
ExecStart=/app/redis/bin/redis-server /app/redis/conf/redis.conf? --daemonize no
ExecReload=/bin/kill -HUP $MAINPID
User=nobody
[Install]
WantedBy=multi-user.target
#設置文件權限
chown -R nobody.nobody /app/redis /app/redis/logs /data/redis
#設置開機啟動
systemctl enable redis
systemctl start redis
2.4、redis cluster搭建
/app/redis/bin/redis-cli -a redis123456 --cluster create 10.8.23.62:6379 10.8.23.63:6379 10.8.31.70:6379 10.8.31.71:6379 10.8.31.72:6379 10.8.31.73:6379 --cluster-replicas 1