1、下载redis安装包
http://download.redis.io/releases/redis-5.0.0.tar.gz
2、解压压缩包
tar zxvf redis-5.0.0.tar.gz
3、配置编译环境:
yum install gcc-c++
4、编译
cd redis-5.0.0
make MALLOC=libc
注意:make命令执行完成编译后,会在src目录下生成6个可执行文件,分别是redis-server、redis-cli、redis-benchmark、redis-check-aof、redis-check-rdb、redis-sentinel
编译报错:
cc: error: ../deps/hiredis/libhiredis.a: No such file or directory
cc: error: ../deps/lua/src/liblua.a: No such file or directory
make[1]: *** [redis-server] Error 1
make[1]: Leaving directory `/root/soft/redis-5.0.0/src'
make: *** [all] Error 2
解决办法:
cd deps
make geohash-int hiredis jemalloc linenoise lua
或者
make hiredis jemalloc linenoise lua
5、安装Redis
make install
6、配置Redis能随系统启动
[root@instance-4fqr1u35-5 redis-5.0.0]# ./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!
7、重命名
mv /etc/init.d/redis_6379 /etc/init.d/redis
8、启动、关闭redis
ps -ef|grep redis命令查看Redis进程
/etc/init.d/redis start/stop
或者
service redis start/stop
9、redis的配置信息
cat /etc/redis/6379.conf
master库 6379.conf:
bind 192.168.1.1 ##主库地址
protected-mode no ##一般均为内网,可以关闭保护模式
port 6379 ##端口
timeout 30 ##超时时间限制
daemonize yes ##后台运行
pidfile "/usr/local/redis/redis_6379.pid" ## 执行PID文件的路径
logfile "/usr/local/redis/redis.log" ## 指定log日志的路径
dir "/usr/local/redis/data" ## 指定数据文件的目录
masterauth "123456" ## 指定认证密码
slave-serve-stale-data yes ## 设置成 NO 如果slave 无法与master 同步,设
置成slave不可读,方便监控脚本发现问题;此处设置为yes 继续提供查询服务
slave-read-only yes ## 指定从库只读
requirepass "123456" ## 指定登录密码
appendonly yes ## 指定aof增量持久化
appendfsync always ## 指定增量同步
slave库 6379.conf:
bind 192.168.1.2 ##主库地址
protected-mode no ##一般均为内网,可以关闭保护模式
port 6379 ##端口
timeout 30 ##超时时间限制
daemonize yes ##后台运行
pidfile "/usr/local/redis/redis_6379.pid" ## 执行PID文件的路径
logfile "/usr/local/redis/redis.log" ## 指定log日志的路径
dir "/usr/local/redis/data" ## 指定数据文件的目录
masterauth "123456" ## 指定认证密码
slave-serve-stale-data yes ##
slave-read-only yes ## 指定从库只读
requirepass "123456" ## 指定登录密码
appendonly yes ## 指定aof增量持久化
appendfsync always ## 指定增量同步
slaveof 192.168.1.1 6379 ## 指定主库的IP 端口
登录主库查看信息
redis-cli -h 192.168.1.1 -p 6379 -a 123456
>info replication
登录从库查看信息
redis-cli -h 192.168.1.2 -p 6379 -a 123456
>info replication
10、哨兵模式配置
# 保护模式 no
protected-mode no
port 16379
dir "/tmp"
sentinel deny-scripts-reconfig yes
# Sentinel去监视一个名为mymaster的主redis实例,
# 这个主实例的IP地址为本机地址127.0.0.1,端口号为6379,
# 而将这个主实例判断为失效至少需要2个Sentinel进程的同意,只要同意Sentinel的数量不达标,自动failover就不会执行
# 如果提供外网访问,实例的IP地址为服务器地址127.0.0.1。
sentinel monitor mymaster 192.168.1.2 6379 1
sentinel down-after-milliseconds mymaster 5000
sentinel auth-pass mymaster 123456
sentinel notification-script /data/scripts/sendMail.sh ##当sentinel触发时,切换主从状态时,需要执行的脚本。当主down的时候可以通知
11、启动哨兵模式
redis-sentinel sentinel.conf