美文网首页
CentOS 7下安装Redis及主从模式配置

CentOS 7下安装Redis及主从模式配置

作者: 阿鲁最靠谱 | 来源:发表于2017-08-13 18:34 被阅读0次

    创建用户组和用户

    
    $ groupadd redis
    
    $ useradd redis -g redis
    
    

    下载并编译安装(主从服务器操作相同)

    从官网下载并执行编译

    
    $ su - redis
    
    $ wget http://download.redis.io/releases/redis-4.0.1.tar.gz
    
    $ tar xzf redis-4.0.1.tar.gz
    
    $ cd redis-4.0.1
    
    $ make
    
    

    第一次编译报错

    
    make[3]: 进入目录“/home/redis/redis-4.0.1/deps/hiredis”
    
    gcc -std=c99 -pedantic -c -O3 -fPIC  -Wall -W -Wstrict-prototypes -Wwrite-strings -g -ggdb  net.c
    
    make[3]: gcc:命令未找到
    
    make[3]: *** [net.o] 错误 127
    
    make[3]: 离开目录“/home/redis/redis-4.0.1/deps/hiredis”
    
    make[2]: *** [hiredis] 错误 2
    
    make[2]: 离开目录“/home/redis/redis-4.0.1/deps”
    
    make[1]: [persist-settings] 错误 2 (忽略)
    
    CC adlist.o
    
    /bin/sh: cc: 未找到命令
    
    make[1]: *** [adlist.o] 错误 127
    
    make[1]: 离开目录“/home/redis/redis-4.0.1/src”
    
    make: *** [all] 错误 2
    
    

    缺少gcc-c++,使用yum进行安装

    
    $ yum install gcc-c++
    
    

    再次编译又报错

    
    make[1]: 进入目录“/home/redis/redis-4.0.1/src”    CC adlist.oIn file included from adlist.c:34:0:zmalloc.h:50:31: 致命错误:jemalloc/jemalloc.h:没有那个文件或目录 #include^
    
    编译中断。
    
    make[1]: *** [adlist.o] 错误 1
    
    make[1]: 离开目录“/home/redis/redis-4.0.1/src”
    
    make: *** [all] 错误 2
    
    

    需要再次执行

    
    $ make MALLOC=libc
    
    

    再次编译,成功

    配置主节点

    $ cd /home/redis/redis-4.0.1/
    $ vi redis.conf
    

    bind修改

    默认配置为127.0.0.1,那么跨服务器IP的访问就会失败,最直接的表现就是启动从节点redis时无法连接主节点,报错

    14203:S 13 Aug 17:57:26.433 * Connecting to MASTER 192.168.95.131:6379
    14203:S 13 Aug 17:57:26.433 * MASTER <-> SLAVE sync started
    14203:S 13 Aug 17:57:26.434 # Error condition on socket for SYNC: Connection refused
    

    修改为主节点实际的IP地址或

    bind 0.0.0.0
    

    设置密码

    设置密码为redis123

    requirepass redis123
    

    配置从节点

    $ cd /home/redis/redis-4.0.1/
    $ vi redis.conf
    

    主节点地址配置

    slaveof 192.168.95.131 6379
    

    主节点密码配置

    masterauth redis123
    

    数据同步验证

    主节点

    $ src/redis-cli
    127.0.0.1:6379> auth redis123
    OK
    127.0.0.1:6379> set newkey "hello redis"
    OK
    

    从节点

    $ src/redis-cli
    127.0.0.1:6379> get newkey
    "hello redis"
    

    相关文章

      网友评论

          本文标题:CentOS 7下安装Redis及主从模式配置

          本文链接:https://www.haomeiwen.com/subject/qwqerxtx.html