1.安装好Redis
第一步:下载或者手动上传redis安装包
192.168.137.110服务器执行以下命令下载redis安装包
wget https://github.com/redis/redis/archive/7.2.3.tar.gz
第二步:解压redis压缩包到指定目录
tar -zxvf redis-7.2.3.tar.gz -C /usr/local/
第三步:安装C程序运行环境
yum install -y autoconf make automake imake cmake gcc gcc-c++ libaio libaio-devel bzr bison expat-devel libtool ncurses5-devel gd-devel libjpeg-devel libpng-devel libxml2-devel bzip2-devel libcurl-devel vim openssh* ntp wget screen bash-completion tcl
第四步:进行编译redis
执行以下命令进行编译:
cd /usr/local/
chmod -R 755 redis-7.2.3
cd redis-7.2.3/src
make 进行编译
注意:需要使用sudo权限执行命令。
sudo make test
sudo make install
2.创建相关文件夹
mkdir -p /usr/local/redis-7.2.3/cluster/6379
mkdir -p /usr/local/redis-7.2.3/cluster/6380
mkdir -p /usr/local/redis-7.2.3/cluster/6381
mkdir -p /usr/local/redis-7.2.3/cluster/6382
mkdir -p /usr/local/redis-7.2.3/cluster/6383
mkdir -p /usr/local/redis-7.2.3/cluster/6384
cd /usr/local/redis-7.2.3/
chmod -R 755 cluster
cp ./redis.conf /usr/local/redis-7.2.3/cluster/6379
cp ./redis.conf /usr/local/redis-7.2.3/cluster/6380
cp ./redis.conf /usr/local/redis-7.2.3/cluster/6381
cp ./redis.conf /usr/local/redis-7.2.3/cluster/6382
cp ./redis.conf /usr/local/redis-7.2.3/cluster/6383
cp ./redis.conf /usr/local/redis-7.2.3/cluster/6384
chmod -R 755 cluster
redis.conf配置
# 绑定服务器IP地址---wusunan
bind 192.168.137.110
# 绑定端口号,必须修改,以此来区分Redis实例
port 6379
# 后台运行
daemonize yes
# 修改pid进程文件名,以端口号命名
pidfile /usr/local/redis-7.2.3/redis-6379.pid
# 修改日志文件名称,以端口号为目录来区分
logfile /usr/local/redis-7.2.3/cluster/6379/redis.log
# 修改数据文件存放地址,以端口号为目录名来区分
dir /usr/local/redis-7.2.3/cluster/6379/
# 启用集群
cluster-enabled yes
# 配置每个节点的配置文件,同样以端口号为名称
cluster-config-file nodes-6379.conf
# 配置集群节点的超时时间,可改可不改
cluster-node-timeout 15000
# 关闭记录日志
# appendfsync always
# appendfsync everysec
appendfsync no
protected-mode yes
# 关闭持久化
自动持久化规则配置
# save 900 1
# save 300 10
# save 60 10000
# redis也可以关闭自动持久化,注释掉这些save配置,或者save “”
requirepass 密码
masterauth 密码
注意:另外几个同样配置,修改端口号
方便于全局直接使用Redis命令
export REDIS_HOME=/usr/local/redis-7.2.3
export PATH=$REDIS_HOME/bin:$PATH
source /etc/profile
4.单独启动6个Redis
单独启动各个Redis
cd /usr/local/redis-7.2.3/src
./redis-server /usr/local/redis-7.2.3/cluster/6379/redis.conf
./redis-server /usr/local/redis-7.2.3/cluster/6380/redis.conf
./redis-server /usr/local/redis-7.2.3/cluster/6381/redis.conf
./redis-server /usr/local/redis-7.2.3/cluster/6382/redis.conf
./redis-server /usr/local/redis-7.2.3/cluster/6383/redis.conf
./redis-server /usr/local/redis-7.2.3/cluster/6384/redis.conf
5.创建集群
注意:加入了密码之后,进入到集群时,需要加 -a 选项 ,后面跟上你设置的密码
./redis-cli --cluster create 192.168.137.110:6379 192.168.137.110:6380 192.168.137.110:6381 192.168.137.110:6382 192.168.137.110:6383 192.168.137.110:6384 --cluster-replicas 1 -a 密码
6.检查集群状态
./redis-cli --cluster check 192.168.137.110:6379 -a 密码
#查看节点信息命令
> cluster info
No Comments