Redis master-slave configuration Linux (rpm)
1, the installation Redis
##下载redis安装包
wget http://download.redis.io/releases/redis-3.0.4.tar.gz
##解压
tar -xzvf redis-3.0.4.tar.gz
cd redis-3.0.4 #执行make命令编译 make
- 1
- 2
- 3
- 4
- 5
- 6
- 7
make install after the installation is complete, an executable file is generated in the next few / usr / local / bin directory, their role are:
Redis-Server: the Redis server initiates a process
redis-cli: Redis client operating tool. Telnet can also be used to operate according to its plain-text protocol
redis-benchmark: Redis performance testing tool
redis-check-aof: data recovery tool
redis-check-dump: checking export tool
2, modify the configuration file Redis
Here with a main library, two from the library Example:
Create a profile :( main library file location is also the best place to find convenient installation directory)
I placed /usr/local/redis-3.0 unity in the configuration file .0 / conf, as shown in the following figure:
Redis-6379.conf profile as follows:
#主表的配置文件
# Redis使用后台模式
daemonize yes
# 注释以下内容开启远程访问
# bind 127.0.0.1
# 修改启动端口为6379
port 6379 # 修改pidfile指向路径--Redis以守护进程方式运行时把pid写入文件 pidfile /usr/local/redis-3.0.0/conf/redis_6379.pid #数据库的存放位置 自己定义 dir /usr/local/redis-3.0.4/db/master/
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
redis-6380.conf profile as follows:
# Redis使用后台模式
daemonize yes
# 关闭保护模式
#protected-mode no
# 注释以下内容开启远程访问
# bind 127.0.0.1
# 修改启动端口为6379
port 6380
# 修改pidfile指向路径
pidfile /usr/local/redis-3.0.0/conf/redis_6380.pid
#数据库的存放位置
dir /usr/local/redis-3.0.4/db/slave_one
#Slaveof命令可以将当前服务器转变为指定服务器的从属服务器(slave server)。
slaveof 127.0.0.1 6379
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
redis-6381.conf profile as follows:
# Redis使用后台模式
daemonize yes
# 关闭保护模式
#protected-mode no
# 注释以下内容开启远程访问
# bind 127.0.0.1
# 修改启动端口为6379
port 6381
# 修改pidfile指向路径
pidfile /usr/local/redis-3.0.0/conf/redis_6381.pid
#数据库的存放位置
dir /usr/local/redis-3.0.4/db/slave_two/
#Slaveof命令可以将当前服务器转变为指定服务器的从属服务器(slave server)。
slaveof 127.0.0.1 6379
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
3, start the Redis service
Use the newly created configuration file to start the service redis
/usr/local/bin/redis-server /usr/local/redis-3.0.4/conf/redis-6379.conf
/usr/local/bin/redis-server /usr/local/redis-3.0.4/conf/redis-6380.conf /usr/local/bin/redis-server /usr/local/redis-3.0.4/conf/redis-6381.conf
- 1
- 2
- 3
Redis check whether a successful start, as shown below represents the start successfully.
ps -ef|grep redis
- 1
4, the master Verify
Use redis redis-cli to connect the local view. First of all clients connected redis-6379 end:
#默认连接6379端口
/usr/local/bin/redis-cli
- 1
- 2
An insert data in the main database
is switched to from the library. Check whether the data exists. And there is a master-slave configuration takes effect.
#连接6380从库
/usr/local/bin/redis-cli -p 6380
- 1
- 2
Or enter the command content directly in redis
127.0.0.1:6379> info replication
- 1
FIG effect as follows:
the master is done from this Redis configured.