一、安装Redis
1) 本实验采用一主一从,后面文章会持续讲解redis主从,哨兵,cluster
2) 主库 192.168.12.131:7001
3) 从库 192.168.12.131:7002
4) wget http://download.redis.io/releases/redis-3.2.6.tar.gz
5) tar zxf redis-3.2.6.tar.gz;mv redis-3.2.6 redis
6) 进入redis目录执行make;make install 完成编译安装二、配置Redis
1) 打开redis.conf修改以下参数
2) bind 127.0.0.1 修改为 bind 192.168.12.131
3) protected-mode yes 修改为no
4) port 6379 修改为7001
5) daemonize no 修改为 yes
6) pidfile /var/run/redis_6379.pid 6379修改为7001
7) logfile "" 修改为 logfile "/usr/local/software/redis/logs/redis_7001.log"
8) dir ./ 修改为 dir /usr/local/software/redis/data/7001
9) 需要创建data 、logs目录,其他配置目前保持默认
10) mv redis.conf redis_7001.conf; cp redis_7001.conf redis_7002.conf
11) 编辑redis_7002.conf把7001全部修改为7002
12) slaveof <masterip> <masterport> 修改为slaveof 192.168.12.131 7001 高版本此参数 为replicaof
13) ln -s /usr/local/software/redis/src/redis-* /usr/bin/三、启动Redis并查看主从状态
1) 启动redis 命令如下
/usr/bin/redis-server /usr/local/software/redis/redis_7001.conf
/usr/bin/redis-server /usr/local/software/redis/redis_7002.conf
2) 查看端口及进程状态
3) 登录7001及7002查看主从状态
4) 在主库上写入数据查看从库是否同步
7001主库
7002从库
5)把Redis服务添加到开机启动项
1) 进入/usr/local/software/redis/utils 目录执行cp redis_init_script /etc/init.d/redis
2) 修改/etc/init.d/redis配置文件如下,并添加服务chkconfig --add redis
6)Redis启动项描述信息
#!/bin/sh
# chkconfig: 2345 10 90
# description: Start and Stop redis
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.
### BEGIN INIT INFO
# Provides: redis_6379
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Redis data structure server
# Description: Redis data structure server. See https://redis.io
### END INIT INFO