一、redis6 集群部署(新特性了解)

Redis 6.0 introduces SSL, the new RESP3 protocol, ACLs, client side caching, diskless replicas, I/O threads, faster RDB loading, new modules APIs and many more improvements.

【Redis 6.0引入了SSL,新的RESP3协议,acl,客户端缓存,无磁盘副本,I/O线程,更快的RDB加载,新的模块api和更多的改进。】

一、redis6.2.6伪集群部署

环境:

2台虚拟机:192.168.109.137、192.168.109.138
系统:CentOS Linux release 7.6.1810 (Core)
官网下载:redis-6.2.6.tar

安装过程:

1.创建普通用户,设置
[root@localhost ~]# useradd -d /home/apprun apprun

sudo vi /etc/sudoers
%apprun ALL=NOPASSWD: /apprun/*,/bin/systemctl *,/sbin/service *,/bin/mv /tmp/* /apprun/*,/usr/bin/vi *,/usr/bin/yum install *,/usr/bin/rpm *,/usr/bin/find *,/usr/sbin/lsof *,/usr/sbin/tcpdump *,/usr/bin/chown * /apprun/*,/usr/bin/chmod * /apprun/*,/usr/bin/kill

locale -a 列出所有已安装的语言包
vim /etc/locale.conf 修改成如下字符集
LANG=en_US.UTF-8
source /etc/locale.conf 使配置生效
mkdir -p /apprun && chown -R apprun:apprun /apprun

2.安装支持的库文件:

[root@localhost ~]# su - apprun
[apprun@localhost ~]$ cd /apprun/
[apprun@localhost ~]$ sudo yum install -y gcc automake autoconf libtool make

3.上传解压文件:

[apprun@localhost apprun]$ mkdir -p /apprun/soft
[apprun@localhost apprun]$ cd /apprun/soft/
[apprun@localhost soft]$ tar -zxf redis-6.2.6.tar.gz
[apprun@localhost soft]$ mkdir -pv /apprun/redis

4.编译与安装:

[apprun@localhost soft]$ cd /apprun/soft/redis-6.2.6
[apprun@localhost redis-6.2.6]$ make PREFIX=/apprun/redis install
将 redis-trib.rb 复制到 /apprun/redis/bin 目录下:
[apprun@localhost redis-6.2.6]$ cd src/
[apprun@localhost src]$ cp redis-trib.rb /apprun/redis/bin/

5.创建 Redis 节点:

[apprun@localhost apprun]$ mkdir -pv /apprun/redis_cluster
在 redis_cluster 目录下,创建名为7000、7001、7002的目录,并将 redis.conf 拷贝到这三个目录中
[apprun@localhost apprun]$ mkdir -pv /apprun/redis_cluster/logs/
[apprun@localhost apprun]$ mkdir -pv /apprun/redis_cluster/data/{redis_7000,redis_7001,redis_7002}
[apprun@localhost apprun]$ cd /apprun/redis_cluster/
[apprun@localhost redis_cluster]$ mkdir 7000 7001 7002
[apprun@localhost redis_cluster]$ cp /apprun/soft/redis-6.2.6/redis.conf /apprun/redis_cluster/

[apprun@localhost redis_cluster]$ vim /apprun/redis_cluster/redis.conf

port 6379 //端口7000,7002,7003 
bind 192.168.109.137
requirepass wang!321
masterauth wang!321
timeout 60 //在客户端空闲N秒后关闭连接
daemonize yes //redis后台运行
pidfile /var/run/redis_6379.pid //pidfile文件对应7000,7001,7002
logfile "/apprun/redis_cluster/logs/redis_6379.log"
always-show-logo yes
cluster-enabled yes //开启集群 把注释#去掉
cluster-config-file nodes_7000.conf //集群的配置 配置文件首次启动自动生成 7000,7001,7002 把注释#去掉
cluster-node-timeout 15000 //请求超时 默认15秒,可自行设置  把注释#去掉
save 3600 1
save 300 100
save 60 10000
appendonly yes //aof日志开启 有需要就开启,它会每次写操作都记录一条日志
dir /apprun/redis_cluster/data/redis_6379
配置参考

[apprun@localhost redis_cluster]$ cp /apprun/redis_cluster/redis.conf /apprun/redis_cluster/7000/
[apprun@localhost redis_cluster]$ cp /apprun/redis_cluster/redis.conf /apprun/redis_cluster/7001/
[apprun@localhost redis_cluster]$ cp /apprun/redis_cluster/redis.conf /apprun/redis_cluster/7002/
[apprun@localhost redis_cluster]$ sed -i 's#6379#7000#g' /apprun/redis_cluster/7000/redis.conf
[apprun@localhost redis_cluster]$ sed -i 's#6379#7001#g' /apprun/redis_cluster/7001/redis.conf
[apprun@localhost redis_cluster]$ sed -i 's#6379#7002#g' /apprun/redis_cluster/7002/redis.conf

接着在另外一台机器上(192.168.109.138),的操作重复以上步骤

6.启动各个节点:

[apprun@localhost apprun]$ /apprun/redis/bin/redis-server /apprun/redis_cluster/7000/redis.conf
[apprun@localhost apprun]$ /apprun/redis/bin/redis-server /apprun/redis_cluster/7001/redis.conf
[apprun@localhost apprun]$ /apprun/redis/bin/redis-server /apprun/redis_cluster/7002/redis.conf

检查 redis 启动情况:
[apprun@localhost apprun]$ ps aux | grep redis

开启两台机器的防火墙:(实验关闭了防火墙)
firewall-cmd --zone=public --add-port=7000-7002/tcp --permanent
firewall-cmd --zone=public --add-port=17000-17002/tcp --permanent
firewall-cmd --reload
firewall-cmd --zone=public --list-ports

7.创建集群:

[apprun@localhost apprun]$ /apprun/redis/bin/redis-cli --cluster create \
192.168.109.137:7000 192.168.109.137:7001 192.168.109.137:7002 192.168.109.138:7000 192.168.109.138:7001 192.168.109.138:7002 \
--cluster-replicas 1 -a 'wang!321'

 

 

 

 

8.集群客户端命令(redis-cli -c -p port)[redis-cli --cluster]:

列:

[apprun@localhost apprun]$ /apprun/redis/bin/redis-cli -c -h 192.168.109.137 -p 7000 -a 'wang!321' cluster info

集群

cluster info :打印集群的信息

cluster nodes :列出集群当前已知的所有节点( node),以及这些节点的相关信息。

节点
cluster meet <ip> <port> :将 ip 和 port 所指定的节点添加到集群当中,让它成为集群的一份子。
cluster forget <node_id> :从集群中移除 node_id 指定的节点。
cluster replicate <node_id> :将当前节点设置为 node_id 指定的节点的从节点。
cluster saveconfig :将节点的配置文件保存到硬盘里面

槽(slot)
cluster addslots <slot> [slot ...] :将一个或多个槽( slot)指派( assign)给当前节点。
cluster delslots <slot> [slot ...] :移除一个或多个槽对当前节点的指派。
cluster flushslots :移除指派给当前节点的所有槽,让当前节点变成一个没有指派任何槽的节点。
cluster setslot <slot> node <node_id> :将槽 slot 指派给 node_id 指定的节点,如果槽已经指派给

 

另一个节点,那么先让另一个节点删除该槽>,然后再进行指派。
cluster setslot <slot> migrating <node_id> :将本节点的槽 slot 迁移到 node_id 指定的节点中。
cluster setslot <slot> importing <node_id> :从 node_id 指定的节点中导入槽 slot 到本节点。
cluster setslot <slot> stable :取消对槽 slot 的导入( import)或者迁移( migrate)。

键
cluster keyslot <key> :计算键 key 应该被放置在哪个槽上。
cluster countkeysinslot <slot> :返回槽 slot 目前包含的键值对数量。
cluster getkeysinslot <slot> <count> :返回 count 个 slot 槽中的键 
常用命令

 

posted on 2022-03-03 22:58  NG-承  阅读(400)  评论(0编辑  收藏  举报

导航