redis配置master/slave主从模式集群
程序员文章站
2022-03-22 21:22:53
...
redis配置master/slave主从模式集群
http://download.redis.io/releases/redis-5.0.3.tar.gz
server1(172.25.2.1) redis主服务器 /home/redis 解压reids
server2(172.25.2.1) redis从服务器1 /home/redis2 解压reids
make MALLOC=libc
make install
server1的配置:redis.conf
bind 172.25.2.1
protected-mode no
port 6379
server2的配置:redis2.conf
bind 172.25.2.1
protected-mode no
port 6389
replicaof 172.25.2.1 6379
分别启动server1、server2:
redis-cli server1:
set "a1" 999
redis-cli server2:
get "a2"
info Replication
//redis 主从模式集群
public class RedisMS {
public static void main(String[] args) {
isServerRunning();
Jedis client = getConnection(6379);
System.out.println(client.isConnected());
client.set("count", "123456"); //master 可读可写
String c1=client.get("count");
client.close();
Jedis client2 = getConnection(6389); //slave 只读
String c2=client2.get("count");
client2.close();
System.out.println("c1="+c1+",c2="+c2);
}
static Jedis getConnection(int port){
String host = "172.25.2.1";
//连接本地的 Redis 服务
Jedis client = new Jedis(host, port);
return client;
}
private static void isServerRunning(){
String host = "172.25.2.1";
Jedis jedis = new Jedis(host, 6379);
//查看服务是否运行
System.out.println("Server is running: "+jedis.ping());
}
}
http://download.redis.io/releases/redis-5.0.3.tar.gz
server1(172.25.2.1) redis主服务器 /home/redis 解压reids
server2(172.25.2.1) redis从服务器1 /home/redis2 解压reids
make MALLOC=libc
make install
server1的配置:redis.conf
bind 172.25.2.1
protected-mode no
port 6379
server2的配置:redis2.conf
bind 172.25.2.1
protected-mode no
port 6389
replicaof 172.25.2.1 6379
分别启动server1、server2:
redis-cli server1:
set "a1" 999
redis-cli server2:
get "a2"
info Replication
//redis 主从模式集群
public class RedisMS {
public static void main(String[] args) {
isServerRunning();
Jedis client = getConnection(6379);
System.out.println(client.isConnected());
client.set("count", "123456"); //master 可读可写
String c1=client.get("count");
client.close();
Jedis client2 = getConnection(6389); //slave 只读
String c2=client2.get("count");
client2.close();
System.out.println("c1="+c1+",c2="+c2);
}
static Jedis getConnection(int port){
String host = "172.25.2.1";
//连接本地的 Redis 服务
Jedis client = new Jedis(host, port);
return client;
}
private static void isServerRunning(){
String host = "172.25.2.1";
Jedis jedis = new Jedis(host, 6379);
//查看服务是否运行
System.out.println("Server is running: "+jedis.ping());
}
}
上一篇: 详解Windows7绑定其他浏览器
下一篇: session共享多节点部署之redis
推荐阅读
-
MySQL5.6 数据库主从(Master/Slave)同步安装与配置详解
-
mysql5.5 master-slave(Replication)主从配置
-
mysql5.5 master-slave(Replication)主从配置
-
解读mysql主从配置及其原理分析(Master-Slave)
-
mysql5.5 master-slave(Replication)主从配置
-
解读mysql主从配置及其原理分析(Master-Slave)
-
MySQL5.6 数据库主从同步安装与配置详解(Master/Slave)
-
MySQL5.6 数据库主从同步安装与配置详解(Master/Slave)
-
Mysql主从数据库(Master/Slave)同步配置与常见错误
-
MYSQL5.6.33数据库主从(Master/Slave)同步安装与配置详解(Master-Linux Slave-windows7)