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驗證端口是否能夠訪問==c++

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

關閉防火牆 節點以前須要開放指定端口,爲了方便,生產不要禁用redis

$ 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

下載,解壓,編譯安裝shell

$ 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] #完成安裝

若是由於上次編譯失敗,有殘留的文件centos

make distclean

安裝遇到的異常

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

    make test 發生該異常app

$ 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

角色 主機
Master 118.190.144.33
Slave 47.104.79.18
Slave 47.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 replicationasync

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)

相關文章
相關標籤/搜索