Redis非关系型数据库群集
部署及安装Redis
1) 上传redis程序包
10)安装gem工具
[root@centos01 ~]# ls
anaconda-ks.cfg initial-setup-ks.cfg redis-3.2.0.gem redis-3.2.9.tar.gz
[root@centos01 ~]# gem install redis –version 3.2.0
11)将redis程序包远程复制到100.20、30、40、50、60服务器的根目录
[root@centos01 ~]# scp redis-3.2.9.tar.gz root@192.168.100.20:/root
The authenticity of host ‘192.168.100.20 (192.168.100.20)’ can’t be established.
ECDSA key fingerprint is SHA256:PUueT9fU9QbsyNB5NC5hbSXzaWxxQavBxXmfoknXl4I.
ECDSA key fingerprint is MD5:6d:f7:95:0e:51:1a:d8:9e:7b:b6:3f:58:51:51:4b:3b.
Are you sure you want to continue connecting (yes/no)es
Warning: Permanently added ‘192.168.100.20’ (ECDSA) to the list of known hosts.
root@192.168.100.20’s password:
redis-3.2.9.tar.gz 100% 1511KB 44.5MB/s 00:00
[root@centos01 ~]# scp redis-3.2.9.tar.gz root@192.168.100.30:/root
The authenticity of host ‘192.168.100.30 (192.168.100.30)’ can’t be established.
ECDSA key fingerprint is SHA256:PUueT9fU9QbsyNB5NC5hbSXzaWxxQavBxXmfoknXl4I.
ECDSA key fingerprint is MD5:6d:f7:95:0e:51:1a:d8:9e:7b:b6:3f:58:51:51:4b:3b.
Are you sure you want to continue connecting (yes/no)es
Warning: Permanently added ‘192.168.100.30’ (ECDSA) to the list of known hosts.
root@192.168.100.30’s password:
redis-3.2.9.tar.gz 100% 1511KB 48.7MB/s 00:00
[root@centos01 ~]# scp redis-3.2.9.tar.gz root@192.168.100.40:/root
The authenticity of host ‘192.168.100.40 (192.168.100.40)’ can’t be established.
ECDSA key fingerprint is SHA256:PUueT9fU9QbsyNB5NC5hbSXzaWxxQavBxXmfoknXl4I.
ECDSA key fingerprint is MD5:6d:f7:95:0e:51:1a:d8:9e:7b:b6:3f:58:51:51:4b:3b.
Are you sure you want to continue connecting (yes/no)es
Warning: Permanently added ‘192.168.100.40’ (ECDSA) to the list of known hosts.
root@192.168.100.40’s password:
redis-3.2.9.tar.gz 100% 1511KB 72.2MB/s 00:00
[root@centos01 ~]# scp redis-3.2.9.tar.gz root@192.168.100.50:/root
The authenticity of host ‘192.168.100.50 (192.168.100.50)’ can’t be established.
ECDSA key fingerprint is SHA256:PUueT9fU9QbsyNB5NC5hbSXzaWxxQavBxXmfoknXl4I.
ECDSA key fingerprint is MD5:6d:f7:95:0e:51:1a:d8:9e:7b:b6:3f:58:51:51:4b:3b.
Are you sure you want to continue connecting (yes/no)es
Warning: Permanently added ‘192.168.100.50’ (ECDSA) to the list of known hosts.
root@192.168.100.50’s password:
redis-3.2.9.tar.gz 100% 1511KB 47.3MB/s 00:00
[root@centos01 ~]# scp redis-3.2.9.tar.gz root@192.168.100.60:/root
The authenticity of host ‘192.168.100.60 (192.168.100.60)’ can’t be established.
ECDSA key fingerprint is SHA256:PUueT9fU9QbsyNB5NC5hbSXzaWxxQavBxXmfoknXl4I.
ECDSA key fingerprint is MD5:6d:f7:95:0e:51:1a:d8:9e:7b:b6:3f:58:51:51:4b:3b.
Are you sure you want to continue connecting (yes/no)es
Warning: Permanently added ‘192.168.100.60’ (ECDSA) to the list of known hosts.
root@192.168.100.60’s password:
redis-3.2.9.tar.gz 100% 1511KB 3.5MB/s 00:00
部署第二台redis服务器
1)挂载操作系统光盘,删除系统自动yum源
[root@centos02 ~]# mount /dev/cdrom /mnt/
mount: /dev/sr0 写保护,将以只读方式挂载
[root@centos02 ~]# rm -rf /etc/yum.repos.d/CentOS-*
2)安装redis群集所需依赖程序
[root@centos02 ~]# yum -y install ruby rubygems
3)解压缩redis程序包,剪切到/usr/src/redis/目录
[root@centos02 ~]# ls
anaconda-ks.cfg initial-setup-ks.cfg redis-3.2.9.tar.gz
[root@centos02 ~]# tar zxvf redis-3.2.9.tar.gz
[root@centos02 ~]# mv redis-3.2.9 /usr/src/redis/
5)初始化redis
[root@centos02 redis]# cd utils/
[root@centos02 utils]# ./install_server.sh
Welcome to the redis service installer
This script will help you easily set up a running redis server
Please select the redis port for this instance: [6379]
Selecting default: 6379
Please select the redis config file name [/etc/redis/6379.conf]
Selected default – /etc/redis/6379.conf
Please select the redis log file name [/var/log/redis_6379.log]
Selected default – /var/log/redis_6379.log
Please select the data directory for this instance [/var/lib/redis/6379]
Selected default – /var/lib/redis/6379
Please select the redis executable path [/usr/local/bin/redis-server]
Selected config:
Port : 6379
Config file : /etc/redis/6379.conf
Log file : /var/log/redis_6379.log
Data dir : /var/lib/redis/6379
Executable : /usr/local/bin/redis-server
Cli Executable : /usr/local/bin/redis-cli
Is this okhen press ENTER to go on or Ctrl-C to abort.
Copied /tmp/6379.conf => /etc/init.d/redis_6379
Installing service…
Successfully added to chkconfig!
Successfully added to runlevels 345!
Starting Redis server…
Installation successful!
6)在第一台redis服务器上将redis主配置文件远程复制到剩下五台服务器上
[root@centos01 ~]# scp /etc/redis/6379.conf root@192.168.100.20:/etc/redis/
root@192.168.100.20’s password:
6379.conf 100% 46KB 37.4MB/s 00:00
[root@centos01 ~]# scp /etc/redis/6379.conf root@192.168.100.30:/etc/redis/
root@192.168.100.30’s password:
6379.conf 100% 46KB 27.9MB/s 00:00
[root@centos01 ~]# scp /etc/redis/6379.conf root@192.168.100.40:/etc/redis/
root@192.168.100.40’s password:
6379.conf 100% 46KB 13.5MB/s 00:00
[root@centos01 ~]# scp /etc/redis/6379.conf root@192.168.100.50:/etc/redis/
root@192.168.100.50’s password:
6379.conf 100% 46KB 35.4MB/s 00:00
[root@centos01 ~]# scp /etc/redis/6379.conf root@192.168.100.60:/etc/redis/
root@192.168.100.60’s password:
6379.conf 100% 46KB 44.7MB/s 00:00
7)第二台redis服务器修改主配置文件监听的IP地址
[root@centos02 ~]# vim /etc/redis/6379.conf
bind 192.168.100.20
8)启动redis服务,监听redis服务是否正常启动
[root@centos02 ~]# redis-server /etc/redis/6379.conf
[root@centos02 ~]# netstat -anptu | grep redis
tcp 0 0 192.168.100.20:6379 0.0.0.0:* LISTEN 6224/redis-server 1
tcp 0 0 192.168.100.20:16379 0.0.0.0:* LISTEN 6224/redis-server 1
剩下四台安装第二台的操作步骤做同样的配置即可,修改主配置文件监听的IP地址设置成服务器自己的IP地址即可
使用脚本创建群集
1)在第一台redis服务器上使用脚本创建群集
[root@centos01 ~]# /usr/src/redis/src/redis-trib.rb create –replicas 1 192.168.100.10:6379 192.168.100.20:6379 192.168.100.30:6379 192.168.100.40:6379 192.168.100.50:6379 192.168.100.60:6379
Creating cluster
Performing hash slots allocation on 6 nodes…
Using 3 masters:
192.168.100.10:6379
192.168.100.20:6379
192.168.100.30:6379
Adding replica 192.168.100.40:6379 to 192.168.100.10:6379
Adding replica 192.168.100.50:6379 to 192.168.100.20:6379
Adding replica 192.168.100.60:6379 to 192.168.100.30:6379
M: 53a7082afe52d1216a447bd505f1828e8c04c7b6 192.168.100.10:6379
slots:0-5460 (5461 slots) master
M: 7023c518c9bde44e137db167abcaf3ef6302ef5c 192.168.100.20:6379
slots:5461-10922 (5462 slots) master
M: 82196443876dd7a7dba2cbda237064577e6996e5 192.168.100.30:6379
slots:10923-16383 (5461 slots) master
S: b86a7228dc45da696a9e95f6593cf28e9d350643 192.168.100.40:6379
replicates 53a7082afe52d1216a447bd505f1828e8c04c7b6
S: 2ef78b8d7e4174c7cb8ff6c9c7834e8e0e97e6fc 192.168.100.50:6379
replicates 7023c518c9bde44e137db167abcaf3ef6302ef5c
S: 161c231d36b342103ff1524d027e131e66da06ef 192.168.100.60:6379
replicates 82196443876dd7a7dba2cbda237064577e6996e5
Can I set the above configurationtype ‘yes’ to accept): yesNodes configuration updated
Assign a different config epoch to each node
Sending CLUSTER MEET messages to join the cluster
Waiting for the cluster to join…Performing Cluster Check (using node 192.168.100.10:6379)
M: 53a7082afe52d1216a447bd505f1828e8c04c7b6 192.168.100.10:6379
slots:0-5460 (5461 slots) master
1 additional replica(s)
M: 7023c518c9bde44e137db167abcaf3ef6302ef5c 192.168.100.20:6379
slots:5461-10922 (5462 slots) master
1 additional replica(s)
S: b86a7228dc45da696a9e95f6593cf28e9d350643 192.168.100.40:6379
slots: (0 slots) slave
replicates 53a7082afe52d1216a447bd505f1828e8c04c7b6
M: 82196443876dd7a7dba2cbda237064577e6996e5 192.168.100.30:6379
slots:10923-16383 (5461 slots) master
1 additional replica(s)
S: 161c231d36b342103ff1524d027e131e66da06ef 192.168.100.60:6379
slots: (0 slots) slave
replicates 82196443876dd7a7dba2cbda237064577e6996e5
S: 2ef78b8d7e4174c7cb8ff6c9c7834e8e0e97e6fc 192.168.100.50:6379
slots: (0 slots) slave
replicates 7023c518c9bde44e137db167abcaf3ef6302ef5c
[OK] All nodes agree about slots configuration.Check for open slots…
Check slots coverage…
[OK] All 16384 slots covered.
2)查看群集状态
[root@centos01 ~]# cd /usr/src/redis/src/
[root@centos01 src]# ./redis-trib.rb check 192.168.100.10:6379
Performing Cluster Check (using node 192.168.100.10:6379)
M: 53a7082afe52d1216a447bd505f1828e8c04c7b6 192.168.100.10:6379
slots:0-5460 (5461 slots) master
1 additional replica(s)
M: 7023c518c9bde44e137db167abcaf3ef6302ef5c 192.168.100.20:6379
slots:5461-10922 (5462 slots) master
1 additional replica(s)
S: b86a7228dc45da696a9e95f6593cf28e9d350643 192.168.100.40:6379
slots: (0 slots) slave
replicates 53a7082afe52d1216a447bd505f1828e8c04c7b6
M: 82196443876dd7a7dba2cbda237064577e6996e5 192.168.100.30:6379
slots:10923-16383 (5461 slots) master
1 additional replica(s)
S: 161c231d36b342103ff1524d027e131e66da06ef 192.168.100.60:6379
slots: (0 slots) slave
replicates 82196443876dd7a7dba2cbda237064577e6996e5
S: 2ef78b8d7e4174c7cb8ff6c9c7834e8e0e97e6fc 192.168.100.50:6379
slots: (0 slots) slave
replicates 7023c518c9bde44e137db167abcaf3ef6302ef5c
[OK] All nodes agree about slots configuration.Check for open slots…
Check slots coverage…
[OK] All 16384 slots covered.
3)测试群集
[root@centos01 ~]# redis-cli -h 192.168.100.10 -p 6379 -c
192.168.100.10:6379> set centos 7.4
OK
192.168.100.10:6379> get centos
“7.4”
192.168.100.10:6379> quit
[root@centos01 ~]# redis-cli -h 192.168.100.40 -p 6379 -c
192.168.100.40:6379> get centos
-> Redirected to slot [467] located at 192.168.100.10:6379
“7.4”
192.168.100.10:6379> quit
[root@centos01 ~]# redis-cli -h 192.168.100.60 -p 6379 -c
192.168.100.60:6379> get centos
-> Redirected to slot [467] located at 192.168.100.10:6379
“7.4”
192.168.100.10:6379> quit
文章知识点与官方知识档案匹配,可进一步学习相关知识CS入门技能树Linux入门初识Linux25131 人正在系统学习中
声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!