没有服务器的话,虚拟机也一样
2、每台服务器安装上redis相关网址:
CentOS7安装Redis完整教程_长头发的程序猿的博客-博客_centos7 redis安装
3、修改“139.196.105.140(主机)”的配置文件vim /etc/redis.conf
重启redis:
systemctl restart redis
4、修改“47.100.40.145(从机)”的配置文件vim /etc/redis.conf
快捷键“Esc+/”,粘贴“If the master is password”,按下回车:
If the master is password
重启redis:
systemctl restart redis
与主机建立主从关系(上图是永久建立主从关系,这是使用命令行暂时建立主从关系,两种都走一遍也没有坏处,反而更保险):
redis-cli -h 47.100.40.145 -p 6380 -a 123456
slaveof 139.196.105.140 6379
info replication
[root@iZuf6g6z1mqqnn0w9q3avqZ ~]# redis-cli -h 47.100.40.145 -p 6380 -a 123456
47.100.40.145:6380>slaveof 139.196.105.140 6379
OK Already connected to specified master
47.100.40.145:6380>info replication
# Replication
role:slave
master_host:139.196.105.140
master_port:6379
master_link_status:up
master_last_io_seconds_ago:8
master_sync_in_progress:0
slave_repl_offset:3949
slave_priority:100
slave_read_only:1
connected_slaves:0
master_repl_offset:0
repl_backlog_active:0
repl_backlog_size:1048576
repl_backlog_first_byte_offset:0
repl_backlog_histlen:0
47.100.40.145:6380>
5、修改“47.101.36.71(从机)”的配置文件快捷键“Esc+/”,粘贴“If the master is password”,按下回车:
If the master is password
重启redis:
systemctl restart redis
与主机建立主从关系(上图是永久建立主从关系,这是使用命令行暂时建立主从关系,两种都走一遍也没有坏处,反而更保险):
redis-cli -h 47.101.36.71 -p 6381 -a 123456
slaveof 139.196.105.140 6379
info replication
[root@iZuf69xyfhpy4n6pn0v8m5Z ~]# redis-cli -h 47.101.36.71 -p 6381 -a 123456
47.101.36.71:6381>info replication
# Replication
role:slave
master_host:139.196.105.140
master_port:6379
master_link_status:up
master_last_io_seconds_ago:9
master_sync_in_progress:0
slave_repl_offset:2115
slave_priority:100
slave_read_only:1
connected_slaves:0
master_repl_offset:0
repl_backlog_active:0
repl_backlog_size:1048576
repl_backlog_first_byte_offset:0
repl_backlog_histlen:0
47.101.36.71:6381>
6、登录“139.196.105.140(主机)”,查看主从关系是否建立成功redis-cli -h 139.196.105.140 -p 6379 -a 123456
info replication
[root@iZuf69zqdfvgs0z196tpocZ ~]# redis-cli -h 139.196.105.140 -p 6379 -a 123456
139.196.105.140:6379>info replication
# Replication
role:master
connected_slaves:2
slave0:ip=47.100.40.145,port=6380,state=online,offset=4397,lag=1
slave1:ip=47.101.36.71,port=6381,state=online,offset=4397,lag=1
master_repl_offset:4397
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:2
repl_backlog_histlen:4396
139.196.105.140:6379>
7、最后,开放端口相关网址:
Linux 防火墙常用命令_长头发的程序猿的博客-博客
别忘了服务器的控制台的安全组也要开放“6379”,“6380”,“6381”三个端口
你是否还在寻找稳定的海外服务器提供商?创新互联www.cdcxhl.cn海外机房具备T级流量清洗系统配攻击溯源,准确流量调度确保服务器高可用性,企业级服务器适合批量采购,新人活动首月15元起,快前往官网查看详情吧