1.配置3台redis服务器
1.1配置C:\Windows\System32\drivers\etchosts文件,启用ip
1.2克隆主机-配置xsync
配置xsync
[cevent@hadoop213 bin]$ ll
总用量 15464
-rwxr
-xr
-x
. 1 cevent cevent 4589179 7月
1 17:56 redis
-benchmark
-rwxr
-xr
-x
. 1 cevent cevent 22225 7月 1 17:56 redis
-check
-aof
-rwxr
-xr
-x
. 1 cevent cevent 45443 7月 1 17:56 redis
-check
-dump
-rwxr
-xr
-x
. 1 cevent cevent 4693138 7月
1 17:56 redis
-cli
lrwxrwxrwx
. 1 cevent cevent 12 7月
1 17:56 redis
-sentinel
-> redis
-server
-rwxr
-xr
-x
. 1 cevent cevent 6466413 7月
1 17:56 redis
-server
-rwxrwxrwx
. 1 cevent cevent 316 7月 1 13:36 xcall
-rwxrwxrwx
. 1 cevent cevent 842 7月 1 13:33 xsync
[cevent@hadoop213 bin]$ vim xsync
pcount=$
if((pcount==0
)); then
echo no args
;
exit;
fi
p1=
$1
fname=`basename
$p1`
echo fname=
$fname
pdir=`cd
-P $
(dirname
$p1); pwd`
echo pdir=
$pdir
user=`whoami`
for((host=213
; host<216
; host+
+)); do
echo ---
---
---
---
--- hadoop
$host.cevent
.com
---
---
---
---
---
-
rsync
-rvl
$pdir/$fname $user@hadoop
$host.cevent
.com:
$pdir
done
1.3配置xcall
[cevent@hadoop213 bin]$ vim xcall
pcount=$
if((pcount==0
));then
echo no args
;
exit;
fi
echo ---
---
---
---
-localhost
.cevent
.com-
---
---
---
$@
for((host=213
; host<216
; host+
+)); do
echo ---
---
---
-hadoop
$host.cevent
.com-
---
---
--
ssh hadoop
$host.cevent
.com $@
done
1.4拷贝多个redis.conf文件
[cevent@hadoop213 redis-3.0.4]$
cp redis
.conf redis6379
.conf
[cevent@hadoop213 redis-3.0.4]$
cp redis
.conf redis6380
.conf
[cevent@hadoop213 redis-3.0.4]$
cp redis
.conf redis6381
.conf
[cevent@hadoop213 redis-3.0.4]$ ll
总用量 288
-rw
-rw
-r-
-. 1 cevent cevent 31391 9月 8 2015 00
-RELEASENOTES
-rw
-r-
-r-
-. 1 cevent cevent 1079 7月 3 22:36 appendonly
.aof
-rw
-rw
-r-
-. 1 cevent cevent 53 9月 8 2015 BUGS
-rw
-rw
-r-
-. 1 cevent cevent 1439 9月 8 2015 CONTRIBUTING
-rw
-rw
-r-
-. 1 cevent cevent 1487 9月 8 2015 COPYING
drwxrwxr
-x
. 6 cevent cevent 4096 7月 1 17:51 deps
-rw
-rw
-r-
-. 1 cevent cevent 41 7月 3 22:36 dump
.rdb
-rw
-rw
-r-
-. 1 cevent cevent 11 9月 8 2015 INSTALL
-rw
-rw
-r-
-. 1 cevent cevent 151 9月 8 2015 Makefile
-rw
-rw
-r-
-. 1 cevent cevent 4223 9月 8 2015 MANIFESTO
-rw
-rw
-r-
-. 1 cevent cevent 5201 9月 8 2015 README
-rw
-rw
-r-
-. 1 cevent cevent 41405 7月 4
09:37 redis6379
.conf
-rw
-rw
-r-
-. 1 cevent cevent 41405 7月 4 09:37 redis6380
.conf
-rw
-rw
-r-
-. 1 cevent cevent 41405 7月 4 09:38 redis6381
.conf
-rw
-rw
-r-
-. 1 cevent cevent 41405 7月 3 15:03 redis
.conf
-rwxrwxr
-x
. 1 cevent cevent 271 9月 8 2015 runtest
-rwxrwxr
-x
. 1 cevent cevent 280 9月 8 2015 runtest
-cluster
-rwxrwxr
-x
. 1 cevent cevent 281 9月 8 2015 runtest
-sentinel
-rw
-rw
-r-
-. 1 cevent cevent 7109 9月 8 2015 sentinel
.conf
drwxrwxr
-x
. 2 cevent cevent 4096 7月 1 17:52 src
drwxrwxr
-x
. 10 cevent cevent 4096 9月 8 2015 tests
drwxrwxr
-x
. 5 cevent cevent 4096 9月 8 2015 utils
1.5redis.conf(general配置)
redis
.conf(general配置)
Use
'yes' if you need it
.
/var/run
/redis
.pid when daemonized
.
daemonize yes
pid file in
/var/run
/redis
.pid by
file location here
.
pidfile
/var/run
/redis6379
.pid
default is 6379
.
listen on a TCP socket
.
port 6379
you need an high backlog in order
Note that the Linux kernel
/proc
/sys
/net
/core
/somaxconn so
somaxconn and tcp_max_syn_backlog
tcp
-backlog 511
from all the network interfaces
to listen to just one or multiple
configuration directive
, followed by one or
will be used to listen
for
so Redis will not listen
idle
for N seconds
(0 to disable
)
timeout 0
ACKs to clients in absence
reasons:
point of view of network
equipment in the middle
.
is the period used to send ACKs
.
double of the time is needed
.
the kernel configuration
.
seconds
.
tcp
-keepalive 0
development
/testing
)
a mess like the debug level
)
in production probably
)
messages are logged
)
loglevel notice
string can be used to force
that
if you use standard
will be sent to
/dev
/null
logfile
"6379.log"
just
set 'syslog-enabled' to yes
,
parameters to suit your needs
.
or between LOCAL0
-LOCAL7
.
database is DB 0
, you can
select
using SELECT <dbid> where
'databases'-1
databases 16
1.6redis.conf(snapshotting配置)
save <seconds> <changes>
Will save the DB
if both the given number of seconds and the given
number of
write operations against the DB occurred
.
In the example below the behaviour will be to save:
after 900 sec
(15 min
) if at least 1 key changed
after 300 sec
(5 min
) if at least 10 keys changed
after 60 sec
if at least 10000 keys changed
Note: you can disable saving completely by commenting out all
"save" lines
.
It is also possible to remove all the previously configured save
points by adding a save directive with a single empty string argument
like in the following example:
save
""
save 900 1
save 120 10
save 60 10000
writes
if RDB snapshots are enabled
latest background save failed
.
hard way
) that
data is not persisting
that no one will notice and some
start working again Redis will
monitoring of the Redis server
disable this feature so that Redis will
are problems with disk
,
stop
-writes
-on
-bgsave
-error
yes
dump
.rdb databases?
almost always a win
.
saving child
set it to
'no' but
you have compressible values or keys
.
rdbcompression yes
is placed at the
end of the file
.
corruption but there is a performance
loading RDB files
, so you can disable it
disabled have a checksum of zero that will
check
.
rdbchecksum yes
dbfilename dump6379
.rdb
1.7修改hadoop214
GENERAL
pid file in
/var/run
/redis
.pid by
file location here
.
pidfile
/var/run
/redis6380
.pid
port
, default is 6379
.
listen on a TCP socket
.
port 6380
empty string can be used to force
Note that
if you use standard
will be sent to
/dev
/null
logfile
"6380.log"
SNAPSHOTTING
dbfilename dump6380
.rdb
1.8修改hadoop215
GENERAL
pid file in
/var/run
/redis
.pid by
location here
.
pidfile
/var/run
/redis6381
.pid
port
, default is 6379
.
listen on a TCP socket
.
port 6381
empty string can be used to force
Note that
if you use standard
will be sent to
/dev
/null
logfile
"6381.log"
SNAPSHOTTING
dbfilename dump6381
.rdb
1.9执行同步
[cevent@hadoop213 module]$ xsync redis-3.0.4/
2.安装yum准备配置
[cevent@hadoop215 ~]$ sudo vim
/etc
/yum
.repos
.d
/CentOS
-Base
.repo
[sudo] password
for cevent:
IP address of the client and the
mirrors that are updated to and
client
. You should use this
for CentOS
updates
mirrors
.
you
, as a fall back you can
try the
[base]
name=CentOS
-$releasever - Base
- 163
.com
baseurl=http:
//mirrors
.163
.com
/centos
/$releasever/os
/$basearch/
gpgcheck=1
enable=1
gpgkey=http:
//mirror
.centos
.org
/centos
/RPM
-GPG
-KEY
-CentOS
-6
[updates]
name=CentOS
-$releasever - Updates
- 163
.com
baseurl=http:
//mirrors
.163
.com
/centos
/$releasever/updates
/$basearch/
gpgcheck=1
gpgkey=http:
//mirror
.centos
.org
/centos
/RPM
-GPG
-KEY
-CentOS
-6
[extras]
name=CentOS
-$releasever - Extras
- 163
.com
baseurl=http:
//mirrors
.163
.com
/centos
/$releasever/extras
/$basearch/
gpgcheck=1
gpgkey=http:
//mirror
.centos
.org
/centos
/RPM
-GPG
-KEY
-CentOS
-6
[centosplus]
name=CentOS
-$releasever - Plus
- 163
.com
baseurl=http:
//mirrors
.163
.com
/centos
/$releasever/centosplus
/$basearch/
gpgcheck=1
enabled=0
gpgkey=http:
//mirror
.centos
.org
/centos
/RPM
-GPG
-KEY
-CentOS
-6
[contrib]
name=CentOS
-$releasever - Contrib
- 163
.com
baseurl=http:
//mirrors
.163
.com
/centos
/$releasever/contrib
/$basearch/
gpgcheck=1
enabled=0
gpgkey=http:
//mirror
.centos
.org
/centos
/RPM
-GPG
-KEY
-CentOS
-6
3.yum安装过程中取消,再次安装报错
[cevent@hadoop215 ~]$ sudo yum
-y install
gcc
已加载插件:fastestmirror
, refresh
-packagekit
, security
设置安装进程
Loading mirror speeds
from cached hostfile
错误:database disk image is malformed
[cevent@hadoop215 ~]$ yum clean all
已加载插件:fastestmirror
, refresh
-packagekit
, security
Cleaning repos: base extras updates
清理一切
无法删除 rpmdb 文件
/var/lib
/yum
/rpmdb
-indexes
/version
[cevent@hadoop215 ~]$ sudo yum
-y install
gcc
已加载插件:fastestmirror
, refresh
-packagekit
, security
设置安装进程
Loading mirror speeds
from cached
hostfile
错误:database disk image is malformed
[cevent@hadoop215 ~]$ sudo vim
/etc
/yum
/pluginconf
.d
/fastestmirror
.conf 修改yum设置
[main]
enabled=0 改为0不启用
verbose=0
always_print_best_host = true
socket_timeout=3
Relative paths are relative to the cachedir
(and so works
for users as
well
hostfilepath=timedhosts
.txt
maxhostfileage=10
maxthreads=15
[cevent@hadoop215 ~]$ sudo vim
/etc
/yum
.conf 修改etc的yum配置
[main]
cachedir=
/var/cache
/yum
/$basearch/$releasever
keepcache=0
debuglevel=2
logfile=
/var/log
/yum
.log
exactarch=1
obsoletes=1
gpgcheck=1
plugins=0 改为0不使用插件
installonly_limit=5
bugtracker_url=http:
//bugs
.centos
.org
/set_project
.php?project_id=19&ref=http:
//bugs
.centos
.org
/bug_report_page
.php?category=yum
distroverpkg=centos
-release
[cevent@hadoop215 ~]$ yum clean all 清洗yum
Cleaning repos: base extras updates
清理一切
无法删除 rpmdb 文件
/var/lib
/yum
/rpmdb
-indexes
/version
[cevent@hadoop215 ~]$ yum makecache 建立缓存
base
| 3
.7 kB 00:00
base
/group_gz
|
242 kB 00:00
base
/filelists_db
| 6
.4
MB 00:01
base
/other_db
|
2
.8 MB 00:00
extras
| 3
.4 kB 00:00
extras
/prestodelta
| 2
.2 kB 00:00
extras
/other_db
| 14 kB 00:00
updates
| 3
.4 kB 00:00
updates
/filelists_db
| 7
.1 MB 00:02
updates
/prestodelta
| 333
kB 00:00
updates
/other_db
|
435 kB 00:00
元数据缓存已建立
[cevent@hadoop215 ~]$ sudo yum
-y install gcc
设置安装进程
base
| 3
.7 kB 00:00
extras
| 3
.4 kB 00:00
updates
| 3
.4 kB 00:00
解决依赖关系
--> 执行事务检查
---> Package gcc
.x86_64 0:4
.4
.7
-23
.el6
will be 安装
[cevent@hadoop215 ~]$ sudo yum
-y install gcc
-c+
+
设置安装进程
解决依赖关系
--> 执行事务检查
---> Package gcc
-c+
+.x86_64
0:4
.4
.7
-23
.el6 will be 安装
--> 处理依赖关系 libstdc+
+-devel = 4
.4
.7
-23
.el6,它被软件包 gcc
-c+
+-4
.4
.7
-23
.el6
.x86_64 需要
--> 处理依赖关系 libstdc+
+ = 4
.4
.7
-23
.el6,它被软件包 gcc
-c+
+-4
.4
.7
-23
.el6
.x86_64 需要
--> 执行事务检查
---> Package libstdc+
+.x86_64
0:4
.4
.7
-17
.el6 will be 升级
---> Package libstdc+
+.x86_64
0:4
.4
.7
-23
.el6 will be an update
---> Package libstdc+
+-devel
.x86_64 0:4
.4
.7
-23
.el6
will be 安装
--> 完成依赖关系计算
4.启动redis报错权限不够/ make[1]: Leavingdirectory `/opt/module/redis-3.0.4/src’解决
[cevent@hadoop214 redis-3.0.4]$ gcc
-v
[cevent@hadoop214 redis-3.0.4]$ make distclean 清洗
[cevent@hadoop214 redis-3.0.4]$ make install
cd src && make install
make
[1
]: Entering directory
`
/opt
/module
/redis
-3
.0
.4
/src
'
Hint: It's a good idea to run
'make test'
;)
INSTALL install
install: 无法创建普通文件
"/usr/local/bin/redis-server": 权限不够
make
[1
]:
**
* [install] 错误 1
make
[1
]: Leaving
directory `
/opt
/module
/redis
-3
.0
.4
/src
'
make: *** [install] 错误 2
[cevent@hadoop214 redis-3.0.4]$ sudo chown -R cevent:cevent /opt/
[cevent@hadoop214 redis-3.0.4]$ sudo chown -R cevent:cevent /usr/local/bin/
[sudo] password for cevent:
[cevent@hadoop214 redis-3.0.4]$ make
install
cd src && make install
make[1]: Entering directory
`/opt/module/redis-3.0.4/src'
Hint: It
's a good idea to run 'make test
'
;)
INSTALL install
INSTALL install
INSTALL install
INSTALL install
INSTALL install
make[1]: Leaving directory
`/opt/module/redis-3.0.4/src'
5.Hadoop215安装
[cevent@hadoop215 ~]$ sudo yum
-y install gcc
设置安装进程
base
| 3
.7 kB 00:00
extras
| 3
.4 kB 00:00
updates
| 3
.4 kB 00:00
包 gcc
-4
.4
.7
-23
.el6
.x86_64 已安装并且是最新版本
无须任何处理
[cevent@hadoop215 ~]$ sudo yum
-y install gcc
-c+
+
设置安装进程
包 gcc
-c+
+-4
.4
.7
-23
.el6
.x86_64 已安装并且是最新版本
无须任何处理
[cevent@hadoop215 ~]$ sudo chown
-R cevent:cevent
/opt
/
[cevent@hadoop215 ~]$ sudo chown
-R cevent:cevent
/usr
/local
/bin
/
[cevent@hadoop215 redis-3.0.4]$ gcc
-v
[cevent@hadoop215 redis-3.0.4]$ make distclean
[cevent@hadoop215 redis-3.0.4]$ make install
6.主从复制:1master2slave
6.1开启redis-master
[cevent@hadoop213 module]$ cd redis
-3
.0
.4
/
[cevent@hadoop213 redis-3.0.4]$ ll
总用量 288
-rw
-rw
-r-
-. 1 cevent cevent 31391 9月 8 2015 00
-RELEASENOTES
-rw
-r-
-r-
-. 1 cevent cevent 1079 7月 3 22:36 appendonly
.aof
-rw
-rw
-r-
-. 1 cevent cevent 53 9月 8 2015 BUGS
-rw
-rw
-r-
-. 1 cevent cevent 1439 9月 8 2015 CONTRIBUTING
-rw
-rw
-r-
-. 1 cevent cevent 1487 9月 8 2015 COPYING
drwxrwxr
-x
. 6 cevent cevent 4096 7月 1 17:51 deps
-rw
-rw
-r-
-. 1 cevent cevent 41 7月 3 22:36 dump
.rdb
-rw
-rw
-r-
-. 1 cevent cevent 11 9月 8 2015 INSTALL
-rw
-rw
-r-
-. 1 cevent cevent 151 9月 8 2015 Makefile
-rw
-rw
-r-
-. 1 cevent cevent 4223 9月 8 2015 MANIFESTO
-rw
-rw
-r-
-. 1 cevent cevent 5201 9月 8 2015 README
-rw
-rw
-r-
-. 1 cevent cevent 41421 7月 4 09:47 redis6379
.conf
-rw
-rw
-r-
-. 1 cevent cevent 41421 7月 4 09:54 redis6380
.conf
-rw
-rw
-r-
-. 1 cevent cevent 41421 7月 4 09:55 redis6381
.conf
-rw
-rw
-r-
-. 1 cevent cevent 41405 7月 3 15:03 redis
.conf
-rwxrwxr
-x
. 1 cevent cevent 271 9月 8 2015 runtest
-rwxrwxr
-x
. 1 cevent cevent 280 9月 8 2015 runtest
-cluster
-rwxrwxr
-x
. 1 cevent cevent 281 9月 8 2015 runtest
-sentinel
-rw
-rw
-r-
-. 1 cevent cevent 7109 9月 8 2015 sentinel
.conf
drwxrwxr
-x
. 2 cevent cevent 4096 7月 1 17:52 src
drwxrwxr
-x
. 10 cevent cevent 4096 9月 8 2015 tests
drwxrwxr
-x
. 5 cevent cevent 4096 9月 8 2015 utils
[cevent@hadoop213 redis-3.0.4]$ redis
-server redis6379
.conf
[cevent@hadoop213 redis-3.0.4]$ redis
-cli -p 6379
127
.0
.0
.1:6379> ping
PONG
127
.0
.0
.1:6379> keys
*
1
) "debt"
2
) "balance"
6.2生成redis-rdb-conf配置文件
cevent@hadoop213 bin
]$ cd
/opt
/module
/redis
-3
.0
.4
/
[cevent@hadoop213 redis-3.0.4]$ ll
总用量 296
-rw
-rw
-r-
-. 1 cevent cevent 31391 9月 8 2015 00
-RELEASENOTES
-rw
-rw
-r-
-. 1 cevent
cevent 2997 7月 4 10:05 6379
.log
-rw
-r-
-r-
-. 1 cevent cevent 1079 7月 3 22:36 appendonly
.aof
-rw
-rw
-r-
-. 1 cevent cevent 53 9月 8 2015 BUGS
-rw
-rw
-r-
-. 1 cevent cevent 1439 9月 8 2015 CONTRIBUTING
-rw
-rw
-r-
-. 1 cevent cevent 1487 9月 8 2015 COPYING
drwxrwxr
-x
. 6 cevent cevent 4096 7月 1 17:51 deps
-rw
-rw
-r-
-. 1 cevent
cevent 41 7月 4 10:05 dump6379
.rdb
-rw
-rw
-r-
-. 1 cevent cevent 41 7月 3 22:36 dump
.rdb
-rw
-rw
-r-
-. 1 cevent cevent 11 9月 8 2015 INSTALL
-rw
-rw
-r-
-. 1 cevent cevent 151 9月 8 2015 Makefile
-rw
-rw
-r-
-. 1 cevent cevent 4223 9月 8 2015 MANIFESTO
-rw
-rw
-r-
-. 1 cevent cevent 5201 9月 8 2015 README
-rw
-rw
-r-
-. 1 cevent cevent
41421 7月 4 09:47
redis6379
.conf
-rw
-rw
-r-
-. 1 cevent cevent
41421 7月 4 09:54
redis6380
.conf
-rw
-rw
-r-
-. 1 cevent cevent
41421 7月 4 09:55
redis6381
.conf
-rw
-rw
-r-
-. 1 cevent cevent 41405 7月 3 15:03 redis
.conf
-rwxrwxr
-x
. 1 cevent cevent 271 9月 8 2015 runtest
-rwxrwxr
-x
. 1 cevent cevent 280 9月 8 2015 runtest
-cluster
-rwxrwxr
-x
. 1 cevent cevent 281 9月 8 2015 runtest
-sentinel
-rw
-rw
-r-
-. 1 cevent cevent 7109 9月 8 2015 sentinel
.conf
drwxrwxr
-x
. 2 cevent cevent 4096 7月 1 17:52 src
drwxrwxr
-x
. 10 cevent cevent 4096 9月 8 2015 tests
drwxrwxr
-x
. 5 cevent cevent 4096 9月 8 2015 utils
[cevent@hadoop213 redis-3.0.4]$
cat 6379
.log 查看redis日志
3537:M 04 Jul 10:03:06
.309
requested maxclients of 10000 requiring at least 10032 max file descriptors
.
3537:M 04 Jul 10:03:06
.309
set maximum open files to 10032 because of OS error: Operation not permitted
.
3537:M 04 Jul 10:03:06
.309
open files is 4096
. maxclients has been reduced to 4064 to compensate
for low
ulimit
. If you need higher maxclients increase
'ulimit -n'.
_
._
_
.-``__
''-._
_
.-`` `
. `_
.
''-._ Redis 3
.0
.4
(00000000
/0
) 64 bit
.-``
.-```
. ```\
/ _
.,_
''-._
(
' , .-`
| `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _
.-'| Port: 6379
|
`-._ `._ /
_.-' | PID: 3537
`
-._ `
-._ `
-./
_
.-' _.-'
|`
-._`
-._
`
-.__
.-' _.-'_
.-'|
|
`-._`-._ _.-'_
.-' | http://redis.io
`-._ `-._`-.__.-'_
.-' _.-'
|`
-._`
-._
`
-.__
.-' _.-'_
.-'|
|
`-._`-._ _.-'_
.-' |
`-._ `-._`-.__.-'_
.-' _.-'
`
-._ `
-.__
.-' _.-'
`
-._ _
.-'
`-.__.-'
3537:M 04 Jul 10:03:06
.317
TCP backlog setting of 511 cannot be enforced because
/proc
/sys
/net
/core
/somaxconn is
set to the lower value of 128
.
3537:M 04 Jul 10:03:06
.317
started
, Redis version 3
.0
.4
3537:M 04 Jul 10:03:06
.318
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
.
3537:M 04 Jul 10:03:06
.318
have Transparent Huge Pages
(THP
) support enabled in your kernel
. This will
create latency and memory usage issues with Redis
. To fix this issue run the
command
'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as
root
, and add it to your
/etc
/rc
.local in order to retain the setting after a
reboot
. Redis must be restarted after THP is disabled
.
3537:M 04 Jul 10:03:06
.336
* DB saved on
disk
3537:M 04 Jul 10:03:06
.336
* DB loaded
from append only file: 0
.018 seconds
3537:M 04 Jul 10:03:06
.336
* The server
is now ready to accept connections on port 6379
3537:M 04 Jul 10:05:07
.086
* 10 changes
in 120 seconds
. Saving
...
3537:M 04 Jul 10:05:07
.096
* Background
saving started by pid 3551
3551:C 04 Jul 10:05:07
.107
* DB saved on
disk
3551:C 04 Jul 10:05:07
.108
* RDB: 4 MB of
memory used by
copy-on
-write
3537:M 04 Jul 10:05:07
.198
* Background
saving terminated with success
6.3单机开启3个redis
[cevent@hadoop213 redis-3.0.4]$ redis
-server redis6379
.conf
[cevent@hadoop213 redis-3.0.4]$ redis
-cli -p 6379
127
.0
.0
.1:6379> ping
PONG
127
.0
.0
.1:6379> keys
*
1
) "debt"
2
) "balance"
127
.0
.0
.1:6379> ping
PONG
[cevent@hadoop213 redis-3.0.4]$ redis
-server redis6380
.conf
[cevent@hadoop213 redis-3.0.4]$ redis
-cli -p 6380
127
.0
.0
.1:6380> ping
PONG
127
.0
.0
.1:6380> keys
*
1
) "debt"
2
) "balance"
[cevent@hadoop213 redis-3.0.4]$ redis
-server redis6381
.conf
[cevent@hadoop213 redis-3.0.4]$ redis
-cli -p 6381
127
.0
.0
.1:6381> ping
PONG
127
.0
.0
.1:6381> keys
*
1
) "debt"
2
) "balance"
[cevent@hadoop213 ~]$ cd
/opt
/module
/redis
-3
.0
.4
/
[cevent@hadoop213 redis-3.0.4]$
ps -ef
| grep redis 查询redis进程
cevent
3537 1 0 10:03 ? 00:00:17 redis
-server
*:6379
cevent
3540 3409
0 10:03 pts
/1 00:00:00
redis
-cli -p 6379
cevent
4568 1 0 11:59 ? 00:00:12 redis
-server
*:6380
cevent
4572 4539 0 11:59 pts
/2 00:00:00 redis
-cli -p 6380
cevent
4611 1 0 12:00 ? 00:00:12 redis
-server
*:6381
cevent
4615 4579 0 12:00 pts
/3 00:00:00 redis
-cli -p 6381
cevent
6842 6814 0 17:50 pts
/4 00:00:00 grep redis
6.4实现主从关系
6379
127
.0
.0
.1:6379>
set k1 v1
OK
127
.0
.0
.1:6379>
set k2 v2
OK
127
.0
.0
.1:6379>
set k3 v3
OK
127
.0
.0
.1:6379> keys
*
1
) "debt"
2
) "k1"
3
) "balance"
4
) "k3"
5
) "k2"
127
.0
.0
.1:6379>
set k4 k4
OK
127
.0
.0
.1:6379> info replication (获取主从信息,在
set k4之前,其他端口开启slaveof 127
.0
.0
.1 6379 跟踪)
role:master
为主设备
connected_slaves:2 两个从设备
slave0:ip=127
.0
.0
.1
,port=6380
,state=online
,offset=263
,lag=1
slave1:ip=127
.0
.0
.1
,port=6381
,state=online
,offset=263
,lag=1
master_repl_offset:263
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:2
repl_backlog_histlen:262
6380
127
.0
.0
.1:6380> slaveof 127
.0
.0
.1 6379
开启slave主从跟踪
OK
127
.0
.0
.1:6380> get k4
"k4"
127
.0
.0
.1:6380> get k1
"v1"
127
.0
.0
.1:6380> info replication 获取主从信息
role:slave 角色为从设备
master_host:127
.0
.0
.1 主设备ip
master_port:6379 主设备端口
master_link_status:up 主设备连接状态
master_last_io_seconds_ago:1
master_sync_in_progress:0
slave_repl_offset:333
slave_priority:100
slave_read_only:1
connected_slaves:0
master_repl_offset:0
repl_backlog_active:0
repl_backlog_size:1048576
repl_backlog_first_byte_offset:0
repl_backlog_histlen:0
6381
127
.0
.0
.1:6381> slaveof 127
.0
.0
.1 6379
开启主从跟踪
OK
127
.0
.0
.1:6381> get k4
"k4"
127
.0
.0
.1:6381> get k2
"v2"
127
.0
.0
.1:6381> info replication 主从信息
role:slave
master_host:127
.0
.0
.1
master_port:6379
master_link_status:up
master_last_io_seconds_ago:8
master_sync_in_progress:0
slave_repl_offset:333
slave_priority:100
slave_read_only:1
connected_slaves:0
master_repl_offset:0
repl_backlog_active:0
repl_backlog_size:1048576
repl_backlog_first_byte_offset:0
repl_backlog_histlen:0
7.主从问题演示
7.1主从复制,只有主机可以写,其他从机只能读,主机创建了库k1,从机无法创建k1
127
.0
.0
.1:6379>
set k6 v6
OK
127
.0
.0
.1:6380>
set k6 v99 从机创建失败
(error
) READONLY You can't
write against
a read only slave
.
7.2主机未配置主从上位关系,主机死掉,从机依旧为slave
127
.0
.0
.1:6379> shutdown 关闭主机
not connected>
exit
127
.0
.0
.1:6380> info replication 查看从机主从关系
role:slave
master_host:127
.0
.0
.1
master_port:6379
master_link_status:down
master_last_io_seconds_ago:
-1
master_sync_in_progress:0
slave_repl_offset:1226
master_link_down_since_seconds:8
slave_priority:100
slave_read_only:1
connected_slaves:0
master_repl_offset:0
repl_backlog_active:0
repl_backlog_size:1048576
repl_backlog_first_byte_offset:0
repl_backlog_histlen:0
127
.0
.0
.1:6381> info replication
role:slave
master_host:127
.0
.0
.1
master_port:6379
master_link_status:down
master_last_io_seconds_ago:
-1
master_sync_in_progress:0
slave_repl_offset:1226
master_link_down_since_seconds:19
slave_priority:100
slave_read_only:1
connected_slaves:0
master_repl_offset:0
repl_backlog_active:0
repl_backlog_size:1048576
repl_backlog_first_byte_offset:0
repl_backlog_histlen:0
7.3主机再次开启,主机依旧为master,从机依旧为slave
[cevent@hadoop213 redis-3.0.4]$ redis
-server redis6379
.conf
[cevent@hadoop213 redis-3.0.4]$ redis
-cli -p 6379
127
.0
.0
.1:6379> keys
*
1
) "balance"
2
) "k1"
3
) "k2"
4
) "k5"
5
) "k3"
6
) "k4"
7
) "debt"
8
) "k6"
127
.0
.0
.1:6379>
set k6 v6
OK
127
.0
.0
.1:6379> info replication
role:master
connected_slaves:2
slave0:ip=127
.0
.0
.1
,port=6380
,state=online
,offset=109
,lag=1
slave1:ip=127
.0
.0
.1
,port=6381
,state=online
,offset=109
,lag=0
master_repl_offset:109
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:2
repl_backlog_histlen:108
127
.0
.0
.1:6380> get k6 从机获取主机k6
"v6"
127
.0
.0
.1:6380> info replication
role:slave
master_host:127
.0
.0
.1
master_port:6379
master_link_status:up
master_last_io_seconds_ago:1
master_sync_in_progress:0
slave_repl_offset:123
slave_priority:100
slave_read_only:1
connected_slaves:0
master_repl_offset:0
repl_backlog_active:0
repl_backlog_size:1048576
repl_backlog_first_byte_offset:0
repl_backlog_histlen:0
7.4从机死掉,不在于主机建立主从关系(除非将主从关系写入配置文件,则可以继续获取主机数据)
127
.0
.0
.1:6380> shutdown 从机停止
not connected>
exit
127
.0
.0
.1:6379>
set k7 v7 主机创建k7
OK
[cevent@hadoop213 redis-3.0.4]$ redis
-server redis6380
.conf 从机连接
[cevent@hadoop213 redis-3.0.4]$ redis
-cli -p 6380
127
.0
.0
.1:6380> keys
* 主机刚才创建的收到
1
) "k6"
2
) "k7"
3
) "k4"
4
) "k2"
5
) "debt"
6
) "k1"
7
) "k3"
8
) "balance"
9
) "k5"
127
.0
.0
.1:6380> get k7
"v7"
127
.0
.0
.1:6380> info replication 查看主从状态
role:master
已经和主机没有关系
connected_slaves:0
master_repl_offset:0
repl_backlog_active:0
repl_backlog_size:1048576
repl_backlog_first_byte_offset:0
repl_backlog_histlen:0
127
.0
.0
.1:6379> info replication 查看主机状态
role:master
connected_slaves:1 已经和6380脱离关系
slave0:ip=127
.0
.0
.1
,port=6381
,state=online
,offset=586
,lag=0
master_repl_offset:586
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:2
repl_backlog_histlen:585
127
.0
.0
.1:6379>
set k8 v8 再次创建k
OK
127
.0
.0
.1:6380> get k8 从机无法接收k
(nil
)
7.5从机脱机后,再次进入主机,需要进行slaveof 127.0.0.1 6379
127
.0
.0
.1:6380> slaveof 127
.0
.0
.1 6379
OK
127
.0
.0
.1:6380> get k8
"v8"
127
.0
.0
.1:6380> info replication
role:slave
master_host:127
.0
.0
.1
master_port:6379
master_link_status:up
master_last_io_seconds_ago:8
master_sync_in_progress:0
slave_repl_offset:1077
slave_priority:100
slave_read_only:1
connected_slaves:0
master_repl_offset:0
repl_backlog_active:0
repl_backlog_size:1048576
repl_backlog_first_byte_offset:0
repl_backlog_histlen:0
127
.0
.0
.1:6379> info replication 主机查看从机
role:master
connected_slaves:2
slave0:ip=127
.0
.0
.1
,port=6381
,state=online
,offset=1133
,lag=1
slave1:ip=127
.0
.0
.1
,port=6380
,state=online
,offset=1133
,lag=1
master_repl_offset:1133
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:2
repl_backlog_histlen:1132
8.master传递slave成为master,递归,薪火相传
8.1Master6379不变
[cevent@hadoop213 redis-3.0.4]$ redis
-server redis6379
.conf
[cevent@hadoop213 redis-3.0.4]$ redis
-cli -p 6379
127
.0
.0
.1:6379> info replication
role:master
connected_slaves:1
slave0:ip=127
.0
.0
.1
,port=6380
,state=online
,offset=477
,lag=0
master_repl_offset:477
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:2
repl_backlog_histlen:476
127
.0
.0
.1:6379> keys
*
1
)
"k3"
2
)
"k2"
3
)
"k5"
4
)
"k6"
5
)
"k1"
6
)
"balance"
7
)
"k4"
8
)
"k7"
9
)
"k8"
10
) "debt"
127
.0
.0
.1:6379>
set k9 v9 创建库
OK
8.2slave6380继承6379
[cevent@hadoop213 redis-3.0.4]$ redis
-server redis6380
.conf
[cevent@hadoop213 redis-3.0.4]$ redis
-cli -p 6380
127
.0
.0
.1:6380> slaveof 127
.0
.0
.1 6379
OK
127
.0
.0
.1:6380> get k9
"v9"
127
.0
.0
.1:6380> info replication
role:slave
为从设备
master_host:127
.0
.0
.1
master_port:6379
master_link_status:up
master_last_io_seconds_ago:1
master_sync_in_progress:0
slave_repl_offset:1481
slave_priority:100 slave代理中
slave_read_only:1
connected_slaves:1 链接了一个slave
slave0:ip=127
.0
.0
.1
,port=6381
,state=online
,offset=1019
,lag=0 代理从设备
master_repl_offset:1019
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:2
repl_backlog_histlen:1018
8.3slave6381继承6380
[cevent@hadoop213 redis-3.0.4]$ redis
-server redis6381
.conf
[cevent@hadoop213 redis-3.0.4]$ redis
-cli -p 6381
127
.0
.0
.1:6381> slaveof 127
.0
.0
.1 6380
OK
127
.0
.0
.1:6381> info replication
role:slave
master_host:127
.0
.0
.1
master_port:6380 这里的master为slaveof所继承的slave6380
master_link_status:up
master_last_io_seconds_ago:4
master_sync_in_progress:0
slave_repl_offset:15
slave_priority:100
slave_read_only:1 只读
connected_slaves:0
master_repl_offset:0
repl_backlog_active:0
repl_backlog_size:1048576
repl_backlog_first_byte_offset:0
repl_backlog_histlen:0
127
.0
.0
.1:6381> get k9
"v9"
8.4反客为主
Master挂掉
127
.0
.0
.1:6379> shutdown
not connected>
exit
Slave1反客为主,成为master
127
.0
.0
.1:6380> slaveof no one 取消slave跟从
OK
127
.0
.0
.1:6380> info replication 自动升级为master
role:master
connected_slaves:0
master_repl_offset:2307
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:2
repl_backlog_histlen:2306
127
.0
.0
.1:6380>
set key10 value10
OK
127
.0
.0
.1:6380> get key10
"value10"
Slave2跟从slave,继续服役
127
.0
.0
.1:6381> slaveof 127
.0
.0
.1 6380 更改主从关系
OK
127
.0
.0
.1:6381> get key10
"value10"
127
.0
.0
.1:6381> info replication
role:slave
master_host:127
.0
.0
.1
master_port:6380
master_link_status:up
master_last_io_seconds_ago:1
master_sync_in_progress:0
slave_repl_offset:2535
slave_priority:100
slave_read_only:1
connected_slaves:0
master_repl_offset:0
repl_backlog_active:0
repl_backlog_size:1048576
repl_backlog_first_byte_offset:0
repl_backlog_histlen:0