redis5.0.4 搭建过程
1.获取文件包
wget http://download.redis.io/releases/redis-5.0.4.tar.gz
2.解压缩到指定目录 tar zxvf redis-5.0.4.tar.gz -C ../servers/
3 安装
make
1.出这个异常:make cc Command not found(没有安装gcc环境,命令:yum install gcc)
2.Error jemalloc/jemalloc.h: No such file or directory (命令: make MALLOC=libc)
3.在不行,从新解压安装。
4 启动
./src/redis-server
./src/redis-server ./redis.conf
5 登录
./src/redis-cli
6 测试
set key val
get key
7 java (配置文件启动redis)
1. Jedis jedis = new Jedis("ip", 6379);
jedis.set("key", "val");
System.out.println(jedis.get("key"));
2.外部连接访问不了,关闭防火墙,吧redis.conf 中给为: bind 0.0.0.0
8.主从复制(集群部署)
1. master 不用动 (读写)
2.在从服务器上加上 slaveof ip 6379 (ip为master的ip)
3.slave 只读
9.哨兵模式(先建立好主从复制)
1.vim sentinel.conf
2.修改 sentinel monitor mymaster 192.168.195.129 6379 2 (master名字,ip port)
3. ./src/redis-server sentinel.conf --sentinel & (启动)
10.java(哨兵)
1. Set<String> set = new HashSet() {
};
set.add("ip:26379");
JedisSentinelPool jedisSentPool = new JedisSentinelPool("mymaster", set);
Jedis jedis = jedisSentPool.getResource();
jedis.set("key", "val");
System.out.println(jedis.get("key"));
11.简单命令:
1. ./src/redis-cli -h 192.168.195.129 -p 26379 info Sentinel
2. 信息:sentinel_masters:1
sentinel_tilt:0
sentinel_running_scripts:0
sentinel_scripts_queue_length:0
sentinel_simulate_failure_flags:0
master0:name=mymaster,status=ok,address=192.168.195.128:6379,slaves=1,sentinels=3