启动: cd /usr/local/redis-cluster ./start-cluster.sh
cd /usr/locar/reds/src
redis-cli -p 7001 #连接
./redis-cli --cluster help #查看帮助
cluster nodes #节点查看
cluster info # 查看
yum -y install gcc
yum -y install tcl
wget http://download.redis.io/releases/redis-5.0.7.tar.gz
解压到/usr/local -> redis-5.0.7
cd redis-5.0.7
make
报错:
zmalloc.h:50:31: fatal error: jemalloc/jemalloc.h: No such file or directory
#include <jemalloc/jemalloc.h>
使用:make MALLOC=libc
# 启动并指定配置文件 src/redis‐server redis.conf(注意要使用后台启动,所以修改redis.conf里的daemonize改为yes)
验证启动是否成功 ps ‐ef | grep redis
进入redis客户端 /usr/local/redis/src/redis‐cli
退出客户端 quit
退出redis服务: (1)pkill redis‐server 28 (2)kill 进程号 (3)src/redis‐cli shutdown
集群安装
mkdir -p /usr/local/redis-cluster
mkdir 7001 7002 7003 7004 7005 7006
cd 7001 ,创建redis.conf
port 7001
#yes 设置后台运行
daemonize yes
#设置pidfile存放在 run目录下的文件名
pidfile /var/run/redis_7001.pid
#指定数据文件存放位置,必须要指定不同的目录位置,不然会丢失数据
dir /usr/local/redis-cluster/7001/
#设置开启AOF模式
appendonly yes
#启动集群
cluster-enabled yes
#关联集群节点信息文件,这里700x好和port对应上
cluster-config-file "nodes-7001.conf"
#设置超时
cluster-node-timeout 5000
#关闭保护模式
protected-mode no
#日志信息,可有可无
logfile "redis.log"
#指定ip访问的地址,设置0.0.0.0 默认是全部地址,不设置,后面会连接不上的
bind 0.0.0.0
requirepass 123456
masterauth 123456
复制 修改端口->其他5个 。 这里万一修改错了,批量修改: sed -i "s/#bind/bind/g" 700*/redis.conf
sed -i "s/old/new/g" the path of the files
eg: sed -i "s/linux/Unix/g" text2.txt text3.txt
挨着启动6个redis
/usr/local/redis-5.0.7/src/redis-server /usr/local/redis-cluster/7001/redis.conf
ps -ef | grep redis 检查
关闭防火墙:systemctl stop firewalld
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall开机启动
创建集群:
/usr/local/redis-5.0.7/src/redis-cli -a 123456 --cluster create --cluster-replicas 1 192.168.20.8:7001 192.168.20.8:7002 192.168.20.8:7003 192.168.20.8:7004 192.168.20.8:7005 192.168.20.8:7006
/usr/local/redis-5.0.7/src/redis-cli --cluster create --cluster-replicas 1 192.168.20.8:7001 192.168.20.8:7002 192.168.20.8:7003 192.168.20.8:7004 192.168.20.8:7005 192.168.20.8:7006
还是参考之前的安装 ok