1.准备6台机器
192.168.134.71
192.168.134.72
192.168.134.73
192.168.134.75
192.168.134.76
192.168.134.77
2.安装redis(6个节点都安装)
3.配置redis集群
mkdir -p /usr/local/redis-cluster
cp -r /usr/local/redis/bin /usr/local/redis-cluster
vi /usr/local/redis-cluster/redis.conf
redis.conf
##六节点除过bind属性值不同外,其它全部相同
bind 192.168.134.71 #绑定的id 192.168.134.72 192.168.134.73 192.168.134.74 192.168.134.75 192.168.134.76
port 6379 #端口
daemonize yes
cluster-enabled yes #是否启用集群模式
cluster-config-file /usr/local/redis-cluster/nodes.conf #集群节点文件
cluster-node-timeout 5000
appendonly yes
protected-mode no
pidfile /usr/local/redis-cluster/redis.pid #redis进程文件
logfile "/usr/local/redis-cluster/redis.log" #redis日志文件
dir /usr/local/redis-cluster
tcp-backlog 511
timeout 0
tcp-keepalive 0
loglevel notice
logfile ""
databases 16
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
masterauth oumiga #redis集群通信密码(6节点必须一致)
slave-serve-stale-data yes
slave-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
slave-priority 100
requirepass oumiga #客户端访问密码(6节点尽量保持一致)
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-entries 512
list-max-ziplist-value 64
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
aof-rewrite-incremental-fsync yes
4.启动所有节点
/usr/local/redis-cluster/bin/redis-server /usr/local/redis-cluster/redis.conf
5.创建集群
/usr/local/redis-cluster/bin/redis-cli --cluster create 192.168.134.71:6379 192.168.134.72:6379 192.168.134.73:6379 192.168.134.74:6379 192.168.134.75:6379 192.168.134.7176:6379 --cluster-replicas 1 -a oumaga
6.查看集群状态
##随便登录一台redis
/usr/local/redis-cluster/bin/redis-cli -c -a oumiga -h 192.168.134.71 -p 6379
cluster info #查看集群信息
cluster nodes #查看节点信息
7.关闭防火墙
systemctl stop firewalld
systemctl disable firewalld
8.创建service文件
vi /etc/systemd/system/redis.service
redis.service
[Unit]
Description=Run a Custom Script at Startup
After=network.target
[Service]
Type=forking
User=root
Group=root
ExecStart=/usr/local/redis-cluster/bin/redis-server /usr/local/redis-cluster/redis.conf
ExecStop=kill -9 -INT `/usr/local/redis-cluster/redis.pid`
[Install]
WantedBy=multi-user.target
9.加入开机自启动
systemctl daemon-reload
systemctl enable redis
10.启动、关闭、状态命令
systemctl start redis
systemctl stop redis
systemctl status redis
**注:有什么不对的地方希望大家批评指出