Redis羣集

Redis羣集

部署安裝Redis

上傳redis程序包
[root@centos01 ~]# rz

[root@centos01 ~]# ls
anaconda-ks.cfg initial-setup-ks.cfg redis-3.2.9.tar.gz

解壓縮Redis程序包到/usr/src目錄
[root@centos01 ~]# tar zxvf redis-3.2.9.tar.gz -C /usr/src/

進入/usr/src/目錄,將軟件包程序剪切到redis目錄
[root@centos01 ~]# cd /usr/src/
[root@centos01 src]# ls
debug kernels redis-3.2.9
[root@centos01 src]# mv redis-3.2.9/ redis
[root@centos01 src]# ls
debug kernels redis

編輯安裝redis
[root@centos01 redis]# make && make install

初始化redis
[root@centos01 redis]# cd utils/
[root@centos01 utils]# ./install_server.sh

修改redis自主配置文件啓動羣集功能
[root@centos01 utils]# vi /etc/redis/6379.conf
62 bind 192.168.100.10
85 port 6379
129 daemonize yes
164 logfile /var/log/redis_6379.log
722 cluster-enabled yes
730 cluster-config-file nodes-6379.conf
736 cluster-node-timeout 15000
813 cluster-require-full-coverage no

啓動redis服務,並查看6379和16379端口是否正常啓動
[root@centos01 ~]# netstat -anptu | grep redis
tcp 0 0 192.168.100.10:6379 0.0.0.0:* LISTEN 4668/redis-server 1
tcp 0 0 192.168.100.10:16379 0.0.0.0:* LISTEN 4668/redis-server 1

掛載操作光盤,
[root@centos01 ~]# mount /dev/cdrom /mnt
mount: /dev/sr0 寫保護,將以只讀方式掛載

安裝羣集所需依賴程序
[root@centos01 ~]# yum -y install ruby rubygems

上傳準備好的gem軟件包
[root@centos01 ~]# rz
[root@centos01 ~]# ls
anaconda-ks.cfg redis-3.2.0.gem
initial-setup-ks.cfg redis-3.2.9.tar.gz

安裝gem工具
[root@centos01 ~]# gem install redis --version 3.2.0

將redis程序包遠程複製到192.168.100.20、30、40、50/60服務器的根目錄
[root@centos01 ~]# scp redis-3.2.9.tar.gz [email protected]:/root
[root@centos01 ~]# scp redis-3.2.9.tar.gz [email protected]:/root
[root@centos01 ~]# scp redis-3.2.9.tar.gz [email protected]:/root
[root@centos01 ~]# scp redis-3.2.9.tar.gz [email protected]:/root
[root@centos01 ~]# scp redis-3.2.9.tar.gz [email protected]:/root

部署第二臺redis服務器
掛載系統光盤
[root@centos02 ~]# mount /dev/cdrom /mnt
mount: /dev/sr0 寫保護,將以只讀方式掛載

安裝redis羣集依賴程序
[root@centos02 ~]# yum -y install ruby rubygems

解壓縮redis程序包,剪切到/usr/src/redis/src/redis-trib.rb/目錄
[root@centos02 ~]# tar zxvf redis-3.2.9.tar.gz -C /usr/src/
[root@centos02 src]# mv redis-3.2.9/ redis
[root@centos02 src]# ls
debug kernels redis

進入redis目錄,編輯安裝redis
[root@centos02 src]# cd redis/
[root@centos02 redis]# make && make install

初始化redis
[root@centos02 redis]# cd utils/
[root@centos02 utils]# ./install_server.sh

依次部署6臺redis服務器

在第一臺redis服務器上將redis主配置文件遠程複製到剩下5臺服務器上
[root@centos01 ~]# scp /etc/redis/6379.conf [email protected]:/etc/redis/
[root@centos01 ~]# scp /etc/redis/6379.conf [email protected]:/etc/redis/
[root@centos01 ~]# scp /etc/redis/6379.conf [email protected]:/etc/redis/
[root@centos01 ~]# scp /etc/redis/6379.conf [email protected]:/etc/redis/
[root@centos01 ~]# scp /etc/redis/6379.conf [email protected]:/etc/redis/

第二臺redis服務器修改主配置文件監聽的IP地址
[root@centos02 ~]# vim /etc/redis/6379.conf
bind 192.168.100.20

依次修改6臺

啓動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 43094/redis-server
tcp 0 0 192.168.100.20:16379 0.0.0.0:* LISTEN 43094/redis-server

[root@centos03 ~]# netstat -anptu | grep redis
tcp 0 0 192.168.100.30:6379 0.0.0.0:* LISTEN 43087/redis-server
tcp 0 0 192.168.100.30:16379 0.0.0.0:* LISTEN 43087/redis-server

[root@centos04 ~]# netstat -anptu | grep redis
tcp 0 0 192.168.100.40:6379 0.0.0.0:* LISTEN 5176/redis-server 1
tcp 0 0 192.168.100.40:16379 0.0.0.0:* LISTEN 5176/redis-server 1

[root@centos05 utils]# netstat -anptu | grep redis
tcp 0 0 192.168.100.50:6379 0.0.0.0:* LISTEN 43084/redis-server
tcp 0 0 192.168.100.50:16379 0.0.0.0:* LISTEN 43084/redis-server

[root@centos06 utils]# netstat -anptu | grep redis
tcp 0 0 192.168.100.60:6379 0.0.0.0:* LISTEN 4929/redis-server 1
tcp 0 0 192.168.100.60:16379 0.0.0.0:* LISTEN 4929/redis-server 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 configuration? (type ‘yes’ to accept): yes

Nodes 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.

查看羣集狀態
[root@centos01 ~]# cd /usr/src/redis/src/
[root@centos01 src]# ./redis-trib.rb check 192.168.100.10:6379

測試羣集

[root@centos01 ~]# redis-cli -h 192.168.100.10 -p 6379 -c
192.168.100.10:6379> set centos 7
OK
192.168.100.10:6379> get centos
“7”
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”
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”
192.168.100.10:6379> quit

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章