# 源码下载地址:http://10.60.14.19:81/2Q2W150913379F9670F5F89739D36E2810DD4AB2AFB1_unknown_806833F0FD9E2BA71F7D33D228D0412FCC8AD15D_8/download.redis.io/releases/redis-5.0.8.tar.gz
# 因为已经有Makefile了,直接可以make
[root@server1 redis-5.0.8]# make & make install
[root@server1 redis-5.0.8]# which redis-server
/usr/local/bin/redis-server
启动server
# 脚本启动redis server
[root@server1 redis-5.0.8]# ./utils/install_server.sh
Welcome to the redis service installer
This script will help you easily set up a running redis server
Please select the redis port for this instance: [6379]
Selecting default: 6379
Please select the redis config file name [/etc/redis/6379.conf]
Selected default - /etc/redis/6379.conf
Please select the redis log file name [/var/log/redis_6379.log]
Selected default - /var/log/redis_6379.log
Please select the data directory for this instance [/var/lib/redis/6379]
Selected default - /var/lib/redis/6379
Please select the redis executable path [/usr/local/bin/redis-server]
Selected config:
Port : 6379
Config file : /etc/redis/6379.conf
Log file : /var/log/redis_6379.log
Data dir : /var/lib/redis/6379
Executable : /usr/local/bin/redis-server
Cli Executable : /usr/local/bin/redis-cli
Is this ok? Then press ENTER to go on or Ctrl-C to abort.
Copied /tmp/6379.conf => /etc/init.d/redis_6379
Installing service...
Successfully added to chkconfig!
Successfully added to runlevels 345!
Starting Redis server...
Installation successful!
修改配置
# By default, if no "bind" configuration directive is specified, Redis listens
# for connections from all the network interfaces available on the server.
# It is possible to listen to just one or multiple selected interfaces using
# the "bind" configuration directive, followed by one or more IP addresses.
#
# Examples:
#
# bind 192.168.1.100 10.0.0.1
# bind 127.0.0.1 ::1
#
# ~~~ WARNING ~~~ If the computer running Redis is directly exposed to the
# internet, binding to all the interfaces is dangerous and will expose the
# instance to everybody on the internet. So by default we uncomment the
# following bind directive, that will force Redis to listen only into
# the IPv4 loopback interface address (this means Redis will be able to
# accept connections only from clients running into the same computer it
# is running).
#
# IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES
# JUST COMMENT THE FOLLOWING LINE.
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bind 0.0.0.0 ######### 这里修改为监听任意ip
[root@server1 redis-5.0.8]# /etc/init.d/redis_6379 restart # 重启redis server
Stopping ...
Redis stopped
Starting Redis server...
# 将server1上编译完成的redis及源码包拷贝到server2和server3上
[root@server1 ~]# scp /usr/local/bin/redis-* 192.168.147.138:/usr/local/bin/ # 拷贝二进制文件
[root@server1 ~]# scp -r /root/redis-5.0.8 192.168.147.138:/root/ # 拷贝源码
# server2上
[root@localhost bin]# rm -f redis-sentinel
[root@localhost bin]# ln -s redis-server redis-sentinel # 创建软连接
# 安装redis server
[root@localhost redis-5.0.8]# ./utils/install_server.sh
Welcome to the redis service installer
This script will help you easily set up a running redis server
Please select the redis port for this instance: [6379]
Selecting default: 6379
Please select the redis config file name [/etc/redis/6379.conf]
Selected default - /etc/redis/6379.conf
Please select the redis log file name [/var/log/redis_6379.log]
Selected default - /var/log/redis_6379.log
Please select the data directory for this instance [/var/lib/redis/6379]
Selected default - /var/lib/redis/6379
Please select the redis executable path [/usr/local/bin/redis-server]
Selected config:
Port : 6379
Config file : /etc/redis/6379.conf
Log file : /var/log/redis_6379.log
Data dir : /var/lib/redis/6379
Executable : /usr/local/bin/redis-server
Cli Executable : /usr/local/bin/redis-cli
Is this ok? Then press ENTER to go on or Ctrl-C to abort.
Copied /tmp/6379.conf => /etc/init.d/redis_6379
Installing service...
Successfully added to chkconfig!
Successfully added to runlevels 345!
Starting Redis server...
Installation successful!
# 修改配置
[root@localhost redis-5.0.8]# vim /etc/redis/6379.conf
bind 0.0.0.0
################################# REPLICATION #################################
# Master-Replica replication. Use replicaof to make a Redis instance a copy of
# another Redis server. A few things to understand ASAP about Redis replication.
#
# +------------------+ +---------------+
# | Master | ---> | Replica |
# | (receive writes) | | (exact copy) |
# +------------------+ +---------------+
#
# 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 replicas.
# 2) Redis replicas 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 replicas automatically try to reconnect to masters
# and resynchronize with them.
#
# replicaof <masterip> <masterport>
replicaof 192.168.147.139 6379
# 重启redis server
[root@localhost redis-5.0.8]# /etc/init.d/redis_6379 restart
Stopping ...
Redis stopped
Starting Redis server...
# 可以看到主从复制状态
127.0.0.1:6379> info
# Replication
role:master
connected_slaves:2
slave0:ip=192.168.147.138,port=6379,state=online,offset=602,lag=0 # 可以看到有两个slave
slave1:ip=192.168.147.140,port=6379,state=online,offset=602,lag=1
master_replid:a703223a554f5f5345b3479aa99cabe041af1165
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:602
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1
repl_backlog_histlen:602