Redis安装

环境

  • CentOS版本:CentOS 7.4
  • IP:118.190.144.33,47.104.79.18,47.104.171.222

注意事项

  • 安裝 GCC 编译工具 不然会有编译不过的问题
yum install -y gcc g++ gcc-c++ make
# 升级所有的包,防止出现版本过久不兼容问题
yum -y update
  • 安装telnet

    ==需要通过telnet验证端口是否可以访问==

$ rpm -qa | grep telnet #检查是否安装了telnet
$ yum install xinetd telnet telnet-server -y

关闭防火墙 节点之前需要开放指定端口,为了方便,生产不要禁用

$ firewall-cmd --state #查看防火墙是否运行  or  systemctl list-unit-files|grep firewalld.service
$ service iptables stop  # 关闭命令:centos 6.x
$ systemctl stop firewalld.service # 停止firewall centos 7.x

安装 Redis

下载,解压,编译安装

$ cd /opt
$ wget http://download.redis.io/releases/redis-4.0.7.tar.gz
$ tar xzf redis-4.0.7.tar.gz
$ cd redis-4.0.7
$ make
$ make test #测试编译是否成功
$ make install [prefix=/path] #完成安装

如果因为上次编译失败,有残留的文件

make distclean

安装遇到的异常

  • ==You need tcl 8.5 or newer in order to run the Redis test==异常解决方法

    make test 发生该异常

$ wget http://downloads.sourceforge.net/tcl/tcl8.6.1-src.tar.gz  
$ sudo tar xzvf tcl8.6.1-src.tar.gz  -C /usr/local/  
$ cd  /usr/local/tcl8.6.1/unix/  
$ sudo ./configure  
$ sudo make  
$ sudo make install 

redis.conf

#bind 127.0.0.1  注释掉bind

#设置成后台进程运行redis
daemonize yes 

#保护模式修改为:no
protected-mode no 

# Specify the log file name. Also the empty string can be used to force
# Redis to log on the standard output. Note that if you use standard
# output for logging but daemonize, logs will be sent to /dev/null
# 修改日志生成路径
logfile /opt/redis-masterslave/log/redis.log

Master-slave

角色主机
Master118.190.144.33
Slave47.104.79.18
Slave47.104.171.222

redis.conf

################################# REPLICATION #################################

# Master-Slave replication. Use slaveof to make a Redis instance a copy of
# another Redis server. A few things to understand ASAP about Redis replication.
#
# 1) Redis replication is asynchronous, but you can configure a master to
#    stop accepting writes if it appears to be not connected with at least
#    a given number of slaves.
# 2) Redis slaves are able to perform a partial resynchronization with the
#    master if the replication link is lost for a relatively small amount of
#    time. You may want to configure the replication backlog size (see the next
#    sections of this file) with a sensible value depending on your needs.
# 3) Replication is automatic and does not need user intervention. After a
#    network partition slaves automatically try to reconnect to masters
#    and resynchronize with them.
#
# 只需要配置slave机器
slaveof 118.190.144.33 6379

验证是否成功 info replication

127.0.0.1:6379> info replication
# Replication
role:slave
master_host:118.190.144.33
master_port:6379
master_link_status:up  # up:表示成功
master_last_io_seconds_ago:6
master_sync_in_progress:0
slave_repl_offset:299
slave_priority:100
slave_read_only:1
connected_slaves:0
master_replid:0143f8f51faa2abbd3130e5b6e607063c8cf26b3
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:299
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1
repl_backlog_histlen:299

哨兵(sentinel)

    原文作者:rexwong
    原文地址: https://segmentfault.com/a/1190000013022591
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞