这篇文章主要介绍“CentOS7怎么搭建Redis集群”的相关知识,小编通过实际案例向大家展示操作过程,操作方法简单快捷,实用性强,希望这篇“CentOS7怎么搭建Redis集群”文章能帮助大家解决问题。CentOS 7搭建Redis5.0.5集群(三台机器,3主3备)准备工作准备三台centos 7的机器:如下图机器的分配情况(每台机器关闭防火墙):IP master节点 salve节点192.168.0.166 redis-166:7001 redis-166:7002192.168.0.167 redis-167:7001 redis-167:7002192.168.0.168 redis-168:7001 redis-168:7002设置三台机器的/etc/hosts,每台都要添加如下三行,保存退出[root@localhost tools]# vim /etc/hosts192.168.0.166 redis-166192.168.0.167 redis-167192.168.0.168 redis-1681234官网下载redis-5.0.5版本:http://download.redis.io/releases/redis-5.0.5.tar.gz把下载的包上传到上面3台centos中开始安装我们以192.168.0.166机器安装为例,其他两台只是配置文件的IP不一样如果centos中没有gcc环境,则需要先安装gcc。如果有就直接看下一步。[root@localhost tools]# yum install -y gcc1解压redis包到当前目录下[root@localhost tools]# tar -zxvf redis-5.0.5.tar.gz1进入刚解压出来的redis目录,开始编译安装[root@localhost tools]# cd redis-5.0.5/[root@localhost redis-5.0.5]# make && make PREFIX=/usr/local/redis install12查看是否编译安装成功,执行 如下命令,如果输出0 表示redis安装成功了[root@localhost redis-5.0.5]# echo $?012配置环境变量,在/etc/profile文件最后添加如下内容:[root@localhost tools]# vim /etc/profile###### redis env ######export REDIS_HOME=/usr/local/redisexport PATH=$PATH:$REDIS_HOME/bin12345其他167和168两台机器,安装redis跟上面166机器完全一样集群配置我们还是以192.168.0.166机器安装为例,其他两台只是配置文件的IP不一样分别创建两个7001和7002的配置文件目录conf,日志目录logs,数据存储目录data,如下命令:mkdir -p /usr/local/redis/redis_cluster/7001/conf/mkdir -p /usr/local/redis/redis_cluster/7001/logs/mkdir -p /usr/local/redis/redis_cluster/7001/data/mkdir -p /usr/local/redis/redis_cluster/7002/conf/mkdir -p /usr/local/redis/redis_cluster/7002/logs/mkdir -p /usr/local/redis/redis_cluster/7002/data/1234567创建7001的配置文件,并添加如下内容:vim /usr/local/redis/redis_cluster/7001/conf/redis.conf# 绑定服务器域名或IP地址bind redis-166# 设置端口,区分集群中Redis的实例port 7001# 后台运行daemonize yes# pid进程文件名,以端口号命名pidfile /var/run/redis-7001.pid# 日志文件名称,以端口号为目录来区分logfile /usr/local/redis/redis_cluster/7001/logs/redis.log# 数据文件存放地址,以端口号为目录名来区分dir /usr/local/redis/redis_cluster/7001/data# 启用集群cluster-enabled yes# 配置每个节点的配置文件,同样以端口号为名称cluster-config-file nodes_7001.conf# 配置集群节点的超时时间cluster-node-timeout 15000# 启动AOF增量持久化策略appendonly yes# 发生改变,则记录日志appendfsync always123456789101112131415161718192021222324创建7002的配置文件,并添加如下内容:vim /usr/local/redis/redis_cluster/7002/conf/redis.conf# 绑定服务器域名或IP地址bind redis-166# 设置端口,区分集群中Redis的实例port 7002# 后台运行daemonize yes# pid进程文件名,以端口号命名pidfile /var/run/redis-7002.pid# 日志文件名称,以端口号为目录来区分logfile /usr/local/redis/redis_cluster/7002/logs/redis.log# 数据文件存放地址,以端口号为目录名来区分dir /usr/local/redis/redis_cluster/7002/data# 启用集群cluster-enabled yes# 配置每个节点的配置文件,同样以端口号为名称cluster-config-file nodes_7002.conf# 配置集群节点的超时时间cluster-node-timeout 15000# 启动AOF增量持久化策略appendonly yes# 发生改变,则记录日志appendfsync always123456789101112131415161718192021222324其他167和168两台机器,集群配置跟上面166机器配置只是域名不同,其他设置都是一样的启动集群在保证上面166,167,168都配置完成后,开始启动166,167,168各节点redis-server /usr/local/redis/redis_cluster/7001/conf/redis.confredis-server /usr/local/redis/redis_cluster/7002/conf/redis.conf12查看各机器上的各节点是否都启动成功[root@localhost redis-5.0.5]# ps -ef | grep redisroot 6460 1 0 14:14 ? 00:00:10 /usr/local/redis/bin/redis-server redis-166:7001 [cluster]root 6471 1 0 14:14 ? 00:00:10 /usr/local/redis/bin/redis-server redis-166:7002 [cluster]1234[root@localhost redis-5.0.5]# ps -ef | grep redisroot 6532 1 0 14:14 ? 00:00:10 /usr/local/redis/bin/redis-server redis-167:7001 [cluster]root 6548 1 0 14:14 ? 00:00:10 /usr/local/redis/bin/redis-server redis-167:7002 [cluster]1234[root@localhost redis-5.0.5]# ps -ef | grep redisroot 6486 1 0 14:14 ? 00:00:10 /usr/local/redis/bin/redis-server redis-168:7001 [cluster]root 6498 1 0 14:14 ? 00:00:10 /usr/local/redis/bin/redis-server redis-168:7002 [cluster]1234使用 reids-cli 创建Redis集群 (注:这里必须使用IP,如果使用像redis-166这样的域名,则会报错,具体原因我也不清楚)redis-cli –cluster create 192.168.0.166:7001 192.168.0.167:7001 192.168.0.168:7001 192.168.0.166:7002 192.168.0.167:7002 192.168.0.168:7002 –cluster-replicas 11查看我们刚创建集群的状态,如下命令:(在3台集群中的任意一台机器查看任意节点都一样,会带出所有的节点信息)[root@localhost redis-5.0.5]# redis-cli –cluster check 192.168.0.167:7001192.168.0.167:7001 (b909c05c…) -> 0 keys | 5462 slots | 1 slaves.192.168.0.166:7001 (e136a43b…) -> 0 keys | 5461 slots | 1 slaves.192.168.0.168:7001 (4bf0b7df…) -> 1 keys | 5461 slots | 1 slaves.[OK] 1 keys in 3 masters.0.00 keys per slot on average.>>> Performing Cluster Check (using node 192.168.0.167:7001)M: b909c05ca4c89695fee7b4799050312ed20c989e 192.168.0.167:7001 slots:[5461-10922] (5462 slots) master 1 additional replica(s)M: e136a43b8dbfd7612f48fe2c17e33203d5329eed 192.168.0.166:7001 slots:[0-5460] (5461 slots) master 1 additional replica(s)M: 4bf0b7df6ce34ad2d3ee87ab500b200f3ae64cee 192.168.0.168:7001 slots:[10923-16383] (5461 slots) master 1 additional replica(s)S: 84ada651baf494cbcdbfe26232b0061146260a3d 192.168.0.167:7002 slots: (0 slots) slave replicates e136a43b8dbfd7612f48fe2c17e33203d5329eedS: 4b9a181365ba49dde3def4d9d562c5a4d4ef657e 192.168.0.166:7002 slots: (0 slots) slave replicates 4bf0b7df6ce34ad2d3ee87ab500b200f3ae64ceeS: 02c3fc75bc6e6d4e070563f2b42a41f2616f66a5 192.168.0.168:7002 slots: (0 slots) slave replicates b909c05ca4c89695fee7b4799050312ed20c989e[OK] All nodes agree about slots configuration.>>> Check for open slots…>>> Check slots coverage…[OK] All 16384 slots covered.123456789101112131415161718192021222324252627282930测试集群是否正常:在集群中的任意一台测试都可以,如我们可以在166上连接167上的7002节点并添加一个数据[root@localhost redis-5.0.5]# redis-cli -c -h 192.168.0.167 -p 7002192.168.0.167:7002> set key001 helloRredis-> Redirected to slot [274] located at 192.168.0.166:7001OK192.168.0.166:7001> get key001“helloRredis”192.168.0.166:7001>12345678再去167上连接7001节点和168上连接7001或者7002看是否可以查询到数据[root@localhost redis-5.0.5]# redis-cli -c -h 192.168.0.167 -p 7001192.168.0.167:7001> get key001-> Redirected to slot [274] located at 192.168.0.166:7001“helloRredis”192.168.0.166:7001>123456[r免费云主机域名oot@localhost redis-5.0.5]# redis-cli -c -h 192.168.0.168 -p 7002192.168.0.168:7002> get key001-> Redirected to slot [274] located at 192.168.0.166:7001“helloRredis”192.168.0.166:7001>123456出现上面的结果,说明我们搭建的集群运作正常如果需要配置开机自启动,添加如下两行:(每台机器都要配置),保存退出即可。以后开机就会自动启动集群[root@localhost redis-5.0.5]# vim /etc/rc.local/usr/local/redis/bin/redis-server /usr/local/redis/redis_cluster/7001/conf/redis.conf/usr/local/redis/bin/redis-server /usr/local/redis/redis_cluster/7002/conf/redis.conf1234如果上面设置了,还是不能开机自启动,则有可能是/etc/rc.d/rc.local没有执行权限,需要给一个执行权限,如下:[root@localhost redis-5.0.5]# chmod +x /etc/rc.d/rc.local1
关于“CentOS7怎么搭建Redis集群”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识,可以关注百云主机行业资讯频道,小编每天都会为大家更新不同的知识点。
这篇文章主要介绍“如何利用Python和C语言分别实现哈夫曼编码”的相关知识,小编通过实际案例向大家展示操作过程,操作方法简单快捷,实用性强,希望这篇“如何利用Python和C语言分别实现哈夫曼编码”文章能帮助大家解决问题。a 创建双向链表:在创建哈夫曼树的过…
免责声明:本站发布的图片视频文字,以转载和分享为主,文章观点不代表本站立场,本站不承担相关法律责任;如果涉及侵权请联系邮箱:360163164@qq.com举报,并提供相关证据,经查实将立刻删除涉嫌侵权内容。