实验环境:
系统:CentOS7
软件:redis-5.0.2
一、解压redis-5.0.2
三个节点
[root@red1 software]# cd /usr/local/
[root@red1 local]# ll
total 1912
drwxr-xr-x. 2 root root 134 Apr 10 21:45 bin
drwxr-xr-x. 2 root root 6 Apr 11 2018 etc
drwxr-xr-x. 2 root root 6 Apr 11 2018 games
drwxr-xr-x. 2 root root 6 Apr 11 2018 include
drwxr-xr-x. 2 root root 6 Apr 11 2018 lib
drwxr-xr-x. 2 root root 6 Apr 11 2018 lib64
drwxr-xr-x. 2 root root 6 Apr 11 2018 libexec
drwxrwxr-x. 6 root root 4096 Apr 11 11:49 redis
-rw-r--r--. 1 root root 1952989 Apr 10 21:42 redis-5.0.2.tar.gz
drwxr-xr-x. 2 root root 6 Apr 11 2018 sbin
drwxr-xr-x. 5 root root 49 Oct 22 10:25 share
drwxr-xr-x. 2 root root 6 Apr 11 2018 src
二、安装 Redis
三个节点
make
make install
三、修改环境变量
三个节点
安装完 Redis之后,在/usr/local/bin会生成一些脚本
[root@red1 local]# cd /usr/local/bin/
[root@red1 bin]# ll
total 32628
-rwxr-xr-x. 1 root root 4365456 Apr 10 21:45 redis-benchmark
-rwxr-xr-x. 1 root root 8084864 Apr 10 21:45 redis-check-aof
-rwxr-xr-x. 1 root root 8084864 Apr 10 21:45 redis-check-rdb
-rwxr-xr-x. 1 root root 4786592 Apr 10 21:45 redis-cli
lrwxrwxrwx. 1 root root 12 Apr 10 21:45 redis-sentinel -> redis-server
-rwxr-xr-x. 1 root root 8084864 Apr 10 21:45 redis-server
修改环境变量
PATH=\$PATH:/mysql/app/mysql/bin:/mysql/app/xtrabackup/bin:$HOME/bin:/usr/bin:/sbin:/bin:/usr/local/bin
source .bash_profile
四、配置 Redis配置文件
主节点192.168.8.11
port 6000 #端口号
requirepass 123456 #登录口令
bind 192.168.8.11 #绑定IP
daemonize yes #后台运行redis
从节点一
port 6001 #端口号
bind 192.168.8.12 #绑定IP
slaveof 192.168.8.11 6000 #设置主节点信息
masterauth 123456 #主节点口令
requirepass 123456 #登录口令
slave-read-only yes #只读模式
daemonize yes #后台运行redis
从节点二
port 6002 #端口号
bind 192.168.8.13 #绑定IP
slaveof 192.168.8.11 6000 #设置主节点信息
masterauth 123456 #主节点口令
requirepass 123456 #登录口令
slave-read-only yes #只读模式
daemonize yes #后台运行redis
五、启动Redis
先启动主节点,在启动从节点
主节点
[root@red1 redis]# redis-server /usr/local/redis/redis.conf
[root@red1 redis]#
[root@red1 redis]#
[root@red1 redis]# ps -ef|grep redis
root 2012 1 0 21:35 ? 00:00:00 redis-server 192.168.8.11:6000
root 2017 1384 0 21:35 pts/0 00:00:00 grep --color=auto redis
可以看到端口号为6000的redis服务已经启动
从节点一
root@red2 ~]# redis-server /usr/local/redis/redis.conf
[root@red2 ~]# ps -ef|grep redis
root 1968 1 0 21:36 ? 00:00:00 redis-server 192.168.8.12:6001
root 1973 1386 0 21:36 pts/0 00:00:00 grep --color=auto redis
可以看到端口号为6001的 redis服务已经启动
从节点二
[root@red3 ~]# ps -ef|grep redis
root 1943 1 0 21:36 ? 00:00:00 redis-server 192.168.8.13:6002
root 1956 1034 0 21:36 pts/0 00:00:00 grep --color=auto redis
可以看到端口号为6002的 redis服务已经启动
六、可用性验证
主节点
[root@red1 redis]# redis-cli -p 6000 -a 123456 -h 192.168.8.11
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
192.168.8.11:6000> get 1
"hello"
192.168.8.11:6000> get 3
(nil)
192.168.8.11:6000> set 3 world
OK
192.168.8.11:6000> get 3
"world"
从节点一
[root@red2 ~]# redis-cli -p 6001 -a 123456 -h 192.168.8.12
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
192.168.8.12:6001> get 3
"world"
从节点二
[root@red3 ~]# redis-cli -p 6002 -h 192.168.8.13 -a 123456
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
192.168.8.13:6002> get 3
"world"
本文档详细记录了在CentOS7环境下,使用redis-5.0.2版本搭建Redis主从集群的步骤,包括解压安装、修改环境变量、配置主从节点、启动服务以及验证主从复制的正确性。每个节点都成功启动了Redis服务,并且从节点能正确地从主节点读取数据。
3140

被折叠的 条评论
为什么被折叠?



