1.单实例部署
(1).下载安装包
Redis 官方网站 :https://redis.io/
(2).解压编译
tar -zxvf redis-5.0.4.tar.gz
cd redis-5.0.4/
make
运行结果:
(3).安装
make PREFIX=/usr/local/redis install
若redis.conf文件不存在,则从解压目录中复制过去
(4).修改配置-redis.cof
修改redis.conf文件:
- daemonize改为yes,
- 同时也将#bind 127.0.0.1注释,
- 将protected-mode设置为no。
- logfile “/usr/local/redis/logs/redis.log”
- dir “/usr/local/redis/bin”
- requirepass foobared 然后去掉注释,这个foobared改为自己的密码。
(5).启动redis
./bin/redis-server ./redis.conf
2.哨兵模式部署
(1).部署Redis一主两从
在三台机器上安装上述步骤部署redis后。
1).主
redis.conf
daemonize no => daemonize yes
protected-mode yes => protected-mode no
logfile "/usr/local/redis/logs/redis.log"
dir ./
dir "/usr/local/redis/bin"
appendonly yes
requirepass foobared
masterauth foobared
2).从
redis.conf 在上述主库基础上,增加下述配置
replicaof 192.168.31.168 9500
3).启动redis
./bin/redis-server ./redis.conf
4).查看主从关系是否配置成功
[root@centos7a src]
192.168.31.168:9500> info replication
Replication
role:master
connected_slaves:2
slave0:ip=192.168.31.181,port=9501,state=online,offset=2235966,lag=1
slave1:ip=192.168.31.129,port=9502,state=online,offset=2235966,lag=1
master_replid:1df20ecc0df92307ef811e9bd81cc09e131725c7
master_replid2:0000000000000000000000000000000000000000
masterreploffset:2236538
........
[root@mimy-centos7b src]
192.168.31.181:9501> info replication
Replication
role:slave
master_host:192.168.31.168
master_port:9500
masterlinkstatus:up
masterlastio_seconds_ago:0
mastersyncin_progress:0
slavereploffset:2317523
........
[root@localhost src]
192.168.31.129:9502> info replication
Replication
role:slave
master_host:192.168.31.168
master_port:9500
masterlinkstatus:up
masterlastio_seconds_ago:1
mastersyncin_progress:0
slavereploffset:2336225
........
(2).配置哨兵
修改每个 sentinel.conf
1).主、从
bind 10.100.0.178 127.0.0.1
daemonize yes
logfile "/usr/local/redis/logs/sentinel.log"
dir /tmp
sentinel monitor mymaster 192.168.31.168 9500 2
sentinel down-after-milliseconds mymaster 30000
sentinel parallel-syncs mymaster 1
sentinel failover-timeout mymaster 180000
sentinel deny-scripts-reconfig yes
sentinel auth-pass mymaster 密码
2).启动哨兵
./bin/redis-sentinel ./sentinel.conf
3).查看哨兵信息
/redis-cli -h 192.168.31.168 -p 26379
info sentinel
|