您的位置:首页 > 数据库 > Redis

redis安装和主从配置

2017-09-18 20:39 423 查看
环境条件:

主:192.168.5.35

备:192.168.5.38

1、解压

tar -zxvf redis-2.3.9.tar.gz

2、编译安装

make

make test     //检查一下 看有没有问题

make install

安装完之后,会在src目录下生成几个可执行文件,分别是mkreleasehdr.sh redis-benchmark redis-check-aof redis-check-dump redis-cli redis-sentinel redis-server。其中redis-server是启动Redis服务的,redis-cli是进入Redis客户端的。

3、初始化

# cd /usr/local/redis/utils/

[root@xt-redis-2 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.

4、配置

vim /etc/redis/6379.conf

daemonize
yes

bind
0.0.0.0

5、启动

/usr/local/redis/src/redis-server /etc/redis/6379.conf

6、主从配置:

备redis配置:vim /etc/redis/6379.conf

slaveof
192.168.8.35 6379

重启redis生效

6、测试、查询

在master和slave分别执行info命令,查看结果如下:

[root@xt-redis-2 utils]# /usr/local/redis/src/redis-cli 

127.0.0.1:6379> info

主上查询显示:

然后在master执行set age 18

在slave执行get age,看是否能得到18,如果能够得到值则说明配置成功

主:

从:
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: