非关系数据库——redis群集
发表于:2025-12-02 作者:千家信息网编辑
千家信息网最后更新 2025年12月02日,redis群集,实验环境两台服务器,六个节点,每台服务器三个网卡6个节点三个主,三个副本主服务器安装redis[root@localhost ~]# yum install gcc gcc-c++ m
千家信息网最后更新 2025年12月02日非关系数据库——redis群集
redis群集,实验环境两台服务器,六个节点,每台服务器三个网卡
6个节点三个主,三个副本
主服务器安装redis
[root@localhost ~]# yum install gcc gcc-c++ make -y #安装环境包[root@localhost ~]# mkdir /abc[root@localhost ~]# mount.cifs //192.168.100.25/redis /abc/ 挂载Password for root@//192.168.100.25/redis: [root@localhost ~]# cd /abc/[root@localhost abc]# lsredis-5.0.7.tar.gz[root@localhost abc]# tar zxvf redis-5.0.7.tar.gz -C /opt/ #解压到opt底下[root@localhost abc]# cd /opt/redis-5.0.7/make[root@localhost redis-5.0.7]# make PREFIX=/usr/local/redis install #安装[root@localhost redis-5.0.7]# ln -s /usr/local/redis/bin/* /usr/local/bin/ #做软连接[root@localhost redis-5.0.7]# cd /opt/redis-5.0.7/utils/[root@localhost utils]# ./install_server.sh Welcome to the redis service installerThis script will help you easily set up a running redis serverPlease select the redis port for this instance: [6379] Selecting default: 6379Please select the redis config file name [/etc/redis/6379.conf] Selected default - /etc/redis/6379.confPlease select the redis log file name [/var/log/redis_6379.log] Selected default - /var/log/redis_6379.logPlease select the data directory for this instance [/var/lib/redis/6379] Selected default - /var/lib/redis/6379Please select the redis executable path [/usr/local/bin/redis-server] /usr/local/redis/bin/redis-server从服务器(一样的操作不重复了)
主服务器配置redis
带"#"的原本配置文件的内容方便写shell脚本
[root@localhost utils]# vim /etc/redis/6379.conf #70 bind 127.0.0.1 70 #bind 127.0.0.1 #89 protected-mode yes 89 protected-mode no #关闭保护功能#833 # cluster-enabled yes833 cluster-enabled yes #开启群集功能#841 # cluster-config-file nodes-6379.conf841 cluster-config-file nodes-6379.conf #开启群集功能配置文件#847 # cluster-node-timeout 15000847 cluster-node-timeout 15000 #设置群集超时时间为15000秒 #700 appendonly no 700 appendonly yes #开启AOF支持[root@localhost redis]# /etc/init.d/redis_6379 restart #开起redisStopping ...Waiting for Redis to shutdown ...Redis stoppedStarting Redis server...[root@localhost utils]# cd /var/lib/redis/[root@localhost redis]# cd 6379/[root@localhost 6379]# lsappendonly.aof dump.rdb nodes-6379.conf#aof配置文件,rdb快照文件,节点配置文件从服务器一样的操作
主服务器安装rvm,ruby控制群集
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 #导入密钥[root@localhost 6379]# curl -sSL https://get.rvm.io | bash -s stable #寻找这个地址安装RVM[root@localhost 6379]# cd /opt/[root@localhost opt]# lsredis-5.0.7 rh[root@localhost opt]# vim abc.sh #rvm的脚本很长[root@localhost opt]# lsabc.sh redis-5.0.7 rh[root@localhost opt]# chmod +x abc.sh [root@localhost opt]# lsabc.sh redis-5.0.7 rh[root@localhost opt]# source /etc/profile.d/rvm.sh [root@localhost opt]# rvm list known #查看rvm安装的版本[root@localhost opt]# rvm install 2.4.1 #安装rvm2.4.1版本[root@localhost opt]# rvm use 2.4.1 #使用rvmUsing /usr/local/rvm/gems/ruby-2.4.1[root@localhost opt]# ruby -v #查看ruby的版本ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-linux][root@localhost opt]# gem install redis #安装redis主服务器安装三块网卡
192.168.136.229
192.168.136.232
192.168.136.231
从服务器安装三块网卡
192.168.136.185
192.168.136.233
192.168.136.234
两台服务器都重启网路服务
[root@localhost opt]# systemctl restart network
两台服务器关闭防火墙和增强功能
[root@localhost opt]# systemctl stop firewalld.service
[root@localhost opt]# setenforce 0
主服务器,重启redis,创建群集
[root@localhost 6379]# /etc/init.d/redis_6379 restart #重启redisredis-cli --cluster create 192.168.136.229:6379 192.168.136.232:6379 192.168.136.231:6379 192.168.136.185:6379 192.168.136.233:6379 192.168.136.234:6379 --cluster-replicas 1Can I set the above configuration? (type 'yes' to accept): yes #出现这行输入yes三个节点master,三个副本节点,彼此对应关系是随机的,但是是一主带一从。开始验证
[root@localhost opt]# redis-cli -h 192.168.136.229 -p 6379 #登录一台主服务器229192.168.136.229:6379> set name zhangsan #创建键值对OK192.168.136.229:6379> keys * #查看所有键1) "name"192.168.136.229:6379> get name #查看值"zhangsan"192.168.136.229:6379> quit[root@localhost opt]# redis-cli -h 192.168.136.234 -p 6379 #登录一台从服务器234192.168.136.234:6379> keys *1) "name"192.168.136.234:6379> get name #查看数据,查看不了,会提示你数据存放在231服务器中(error) MOVED 5798 192.168.136.231:6379[root@localhost opt]# redis-cli -h 192.168.136.231 -p 6379 #登录231服务器,就看到数据了192.168.136.231:6379> keys *1) "name"192.168.136.231:6379> get name"zhangsan"用hash方式建立键值对,设置键的删除时间
[root@master opt]# redis-cli -h 192.168.136.229 -p 6379 192.168.136.229:6379> hset person age 20 ##用hash方式建立键值对(integer) 1192.168.136.229:6379> hset person name lisi(integer) 1192.168.136.229:6379> keys *1) "person"192.168.136.229:6379> hget person age ##获取键的值"20"192.168.136.229.128:6379> expire person 5 ##设置键的删除时间5s(integer) 1192.168.136.229:6379> keys *1) "person"192.168.136.229:6379> keys *(empty list or set)以上就是我们全部的内容了,谢谢收看
服务
服务器
三个
文件
节点
配置
功能
数据
时间
版本
网卡
登录
内容
副本
方式
环境
脚本
原本
地址
密钥
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
市教育局网络安全制度
网络安全委员
华威大学网络安全
大学数据库应用技术
汉寿服务器
企业网络安全风险预警
上海夺畅网络技术有限公司上市了吗
安卓与sql数据库交互
联通软件开发岗待遇知乎
使用c开发sql数据库
济宁网络安全培训
数据库并发一致性
软件开发方法原型法常用吗
php程序软件开发是什么
我的世界服务器之旅第一期
下载什么歌服务器最快
数据库有时间长度么
给数据库写去字符
单一来源智慧校园软件开发
自贡多媒体软件开发
恐鬼症为啥服务器大厅进不去
网络安全教育周鸿祎
郑州手机软件开发收费多少
深圳星盾网络技术
博科网络安全黑板报
金格签章管理服务器
普法微电影 网络安全
绿色上网共建网络安全内容
北流市软件开发
河南互联网科技企业名单