Redis 主从复制集群部署记录
本文档依赖于 中标麒麟 centos 7 操作系统部署
redis-5.0.7.tar.gz
predixy-1.0.5-bin-amd64-linux.tar.gz
关闭防火墙
因为是多个服务器做主从复制,服务器之间必须可以链通,需要关闭所有服务器的防火墙,如果现场不允许关闭,请酌情配置端口
[root@localhost ~]
[root@localhost ~]
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
Redis实例的安装
mkdir /home/archser/soft
cd /home/archser/soft
wget http://download.redis.io/releases/redis-5.0.7.tar.gz
cd ./redis-5.0.7
make
make install
mkdir /home/archser/redis_6379
./utils/install_server.sh
[root@localhost utils]
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] /home/archser/redis_6379/6379.conf
Please select the redis log file name [/var/log/redis_6379.log] /home/archser/redis_6379/6379.log
Please select the data directory for this instance [/var/lib/redis/6379] /home/archser/redis_6379/data
Please select the redis executable path [/usr/local/bin/redis-server]
Selected config:
Port : 6379
Config file : /home/archser/redis_6379/6379.conf
Log file : /home/archser/redis_6379/6379.log
Data dir : /home/archser/redis_6379/data
Executable : /usr/local/bin/redis-server
Cli Executable : /usr/local/bin/redis-cli
Is this ok? Then 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!
[root@localhost utils]
root 17591 1 0 10:30 ? 00:00:00 /usr/local/bin/redis-server 127.0.0.1:6379
root 17656 12909 0 10:36 pts/1 00:00:00 grep --color=auto redis
cd /home/archser/redis_6379
vi 6379.conf
protected-mode no
daemonize yes
requirepass archser_redis
[root@localhost redis_6379]
127.0.0.1:6379> SHUTDOWN
not connected>
[root@localhost redis_6379]
Starting Redis server...
[root@localhost redis_6379]
root 17991 1 0 10:53 ? 00:00:00 /usr/local/bin/redis-server *:6379
root 17996 12909 0 10:53 pts/1 00:00:00 grep --color=auto redis
[root@localhost redis_6379]
127.0.0.1:6379> AUTH archser_redis
OK
127.0.0.1:6379> keys *
(empty list or set)
127.0.0.1:6379>
从节点的配置
修改从节点的配置
注意:这里说的是从节点是为了更好的理解配置的含义,如果主节点宕机,Redis哨兵则会选举新的主节点,当宕机的主节点重启后则会变成从节点,所以无论主从节点都需要配置
vi /home/archser/redis_6379/6379.conf
replicaof 192.168.31.151 6379
masterauth archser_redis
修改主节点的配置
注意:这里说的是主节点是为了更好的理解配置的含义,但是如果主节点宕机,则哨兵会选举出新的主节点,也就是之前的从节点,那么新的从节点也应该有以下的配置,所以无论主从节点都需要配置
min-replicas-to-write 2
min-replicas-max-lag 3
[root@localhost redis_6379]
127.0.0.1:6379> SHUTDOWN
(error) NOAUTH Authentication required.
127.0.0.1:6379>
[root@localhost redis_6379]
总用量 176
-rwxr-xr-x 1 root root 62000 2月 22 11:15 6379.conf
-rwxr-xr-x 1 root root 113968 2月 22 11:29 6379.log
drwxr-xr-x 2 root root 22 2月 22 11:29 data
[root@localhost redis_6379]
/var/run/redis_6379.pid exists, process is already running or crashed
[root@localhost redis_6379]
[root@localhost redis_6379]
Starting Redis server...
[root@localhost redis_6379]
root 18203 1 0 11:19 ? 00:00:00 /usr/local/bin/redis-server *:6379
root 18528 13457 0 11:32 pts/0 00:00:00 grep --color=auto redis
[root@localhost redis_6379]
127.0.0.1:6379> AUTH archser_redis
OK
/home/archser/redis_6379/6379.log
[root@localhost redis_6379]
27223:S 22 Feb 2021 11:40:57.134 * Connecting to MASTER 192.168.31.151:6379
27223:S 22 Feb 2021 11:40:57.134 * MASTER <-> REPLICA sync started
27223:S 22 Feb 2021 11:40:57.134 * Non blocking connect for SYNC fired the event.
27223:S 22 Feb 2021 11:40:57.134 * Master replied to PING, replication can continue...
27223:S 22 Feb 2021 11:40:57.135 * Partial resynchronization not possible (no cached master)
27223:S 22 Feb 2021 11:40:57.135 * Full resync from master: 38e55326217099121a346935616b52972e155074:1331
27223:S 22 Feb 2021 11:40:57.172 * MASTER <-> REPLICA sync: receiving 186 bytes from master
27223:S 22 Feb 2021 11:40:57.173 * MASTER <-> REPLICA sync: Flushing old data
27223:S 22 Feb 2021 11:40:57.173 * MASTER <-> REPLICA sync: Loading DB in memory
27223:S 22 Feb 2021 11:40:57.173 * MASTER <-> REPLICA sync: Finished with success
测试主从复制
测试思路是在主节点添加数据,看从节点中是否有相同的数据
[root@localhost ~]
127.0.0.1:6379> AUTH archser_redis
OK
127.0.0.1:6379> keys *
(empty list or set)
127.0.0.1:6379> set a a
OK
[root@localhost redis_6379]
127.0.0.1:6379> AUTH archser_redis
OK
127.0.0.1:6379> keys *
1) "a"
|