linux redis-4.0.11安装记录

 

 

一,下载及安装

   redis 官网下载地址 https://redis.io/download

我的redis安装目录是/data/program/redis-4.0.11
$ wget http://download.redis.io/releases/redis-2.8.3.tar.gz
$ tar xzf redis-2.8.3.tar.gz
$ cd redis-2.8.3
$ make
安装过程可能出现的问题:
  1. linux 中没有安装gcc包,通过下面命令安装: 
  $ yum -y install gcc
  
  2.make时报如下错误:
[root@localhost redis-4.0.11]# make
cd src && make all
make[1]: Entering directory `/data/program/redis-4.0.11/src'
    CC Makefile.dep
make[1]: Leaving directory `/data/program/redis-4.0.11/src'
make[1]: Entering directory `/data/program/redis-4.0.11/src'
    CC adlist.o
In file included from adlist.c:34:0:
zmalloc.h:50:31: fatal error: jemalloc/jemalloc.h: No such file or directory
 #include <jemalloc/jemalloc.h>
                               ^
compilation terminated.
make[1]: *** [adlist.o] Error 1
make[1]: Leaving directory `/data/program/redis-4.0.11/src'
make: *** [all] Error 2
    原因是jemalloc重载了Linux下的ANSI C的malloc和free函数。解决办法:make时添加参数。
  $ make MALLOC=libc

启动服务

[root@localhost src]# ./redis-server 
10558:C 15 Oct 14:10:40.927 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
10558:C 15 Oct 14:10:40.927 # Redis version=4.0.11, bits=64, commit=00000000, modified=0, pid=10558, just started
10558:C 15 Oct 14:10:40.927 # Warning: no config file specified, using the default config. In order to specify a config file use ./redis-server /path/to/redis.conf
10558:M 15 Oct 14:10:40.931 * Increased maximum number of open files to 10032 (it was originally set to 1024).
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 4.0.11 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                   
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 10558
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           http://redis.io        
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               

10558:M 15 Oct 14:10:40.935 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
10558:M 15 Oct 14:10:40.935 # Server initialized
10558:M 15 Oct 14:10:40.935 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
10558:M 15 Oct 14:10:40.936 * Ready to accept connections
 

二,修改配置

表示安装成功. redis 的进程id为 10558,端口为 6379.
但是这样启动不是很方便,启动服务端的窗口不能关闭,一旦关闭服务自动停止...
修改 reids.conf 文件
将daemonize参数的值由no改为yes,系统默认是no.保存退出,指定配置文件启动

$  ./redis-server redis.conf

三,配置全局命令

创建redis的命令目录
$ mkdir /data/program/redis-4.0.11/bin
将脚本目录复制到命令目录中
$ cp redis-cli redis-server redis-sentinel redis-check-aof redis-benchmark /data/program/redis-4.0.11/bin/

配置环境变量
$ vim /etc/profile (在文件末尾加入)
export PATH=$PATH:/data/program/redis-4.0.11/bin
$ source /etc/profile 

四,redis 的主从集群配置

我配置了三台节点分别是

192.168.1.129(主),192.168.1.130(从),192.168.1.131(从)

把两台从节点服务器的 redis.conf配置文件中配置  slaveof

redis.conf
.......
# slaveof <masterip> <masterport>
# 如果加入哨兵机制 192.168.1.129 这个ip每次选举会被修改,修改成master节点的ip,
# 如果本节点被选为, master节点,则会删除该配置信息
slaveof 192.168.1.129 6379 
.......

三台重启后可以看到主从节点信息:

通过 info replication可以查看主/从复制信息
[root@localhost redis-4.0.11]# redis-cli 
127.0.0.1:6379> info replication
# Replication
role:master
connected_slaves:2
slave0:ip=192.168.1.131,port=6379,state=online,offset=280,lag=1
slave1:ip=192.168.1.130,port=6379,state=online,offset=280,lag=1
master_replid:f6569297affb0f168fa2fbc5097aa32cb4b30d83
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:280
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1
repl_backlog_histlen:280
127.0.0.1:6379> 

 

   五,加入哨兵机制,
1,我在同一台机上配置三个哨兵节点 sentinel1.conf,sentinel2.conf,sentinel3.conf,端口分别是5000,5001,5002

port 5000
#192.168.1.129 默认的主节点
#2代表最少要有两台哨兵节点同意选票才能通过,我只配了3台哨兵节点
sentinel monitor mymaster 192.168.1.129 6379 2 
sentinel down-after-milliseconds mymaster 5000
sentinel failover-timeout mymaster 60000
bind 0.0.0.0

   注:redis.conf文件的配置,protected-mode no 要设置为no,不然master挂掉后,不能自动选主

.................
# By default protected mode is enabled. You should disable it only if
# you are sure you want clients from other hosts to connect to Redis
# even if no authentication is configured, nor a specific set of interfaces
# are explicitly listed using the "bind" directive.
protected-mode no  //这个地方要设置为no

2,启动哨兵

redis-sentinel sentinel1.conf
redis-sentinel sentinel2.conf
redis-sentinel sentinel3.conf

3,连接一台哨兵,查看状态

$ redis-cli -p 5000

获取当前主服务器的地址

127.0.0.1:5000> SENTINEL get-master-addr-by-name mymaster
1) "192.168.1.130"
2) "6379"

参考https://redis.io/topics/sentinel 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值