一.redis部署
第一步 编译redis源码
[root@itheima ~]# cd redis-3.0.0
[root@itheima redis-3.0.0]# make
第二步 安装redis
[root@itheima redis-3.0.0]# make install PREFIX=/usr/local/redis19
第三步 前端启动的命令
[root@itheima bin]# ./redis-server
正常关闭:[root@itheima bin]# ./redis-cli shutdown
启动界面:(一旦客户端关闭,则redis服务也停掉)
第四步 后端启动
需要将redis解压之后的源码包中的redis.conf文件拷贝到bin目录下,
[root@itheima bin]# cp /root/redis-3.0.0/redis.conf ./
第五步:修改redis.conf文件,将daemonize改为yes
第六步:使用命令后端启动redis
[root@itheima bin]# ./redis-server redis.conf
第七步:查看是否启动成功
关闭后端启动的方式:
正常关闭:[root@itheima bin]# ./redis-cli shutdown
第八步:防火墙设置
[root@itheima redis-3.0.0]# vim /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 6379 -j ACCEPT
重启防火墙设置[root@itheima redis-3.0.0]# service iptables restart
二.
1 Redis持久化方案
在redis.conf中可以指定持久化文件存储的目录
1.1.1 Rdb问题
一旦redis非法关闭,那么会丢失最后一次持久化之后的数据。
如果数据不能允许丢失,那么要使用aof方式。
1.1 Aof方式
Redis默认是不使用该方式持久化的。Aof方式的持久化,是操作一次redis数据库,
则将操作的记录存储到aof持久化文件中。
第一步:开启aof方式的持久化方案
将redis.conf中的appendonly改为yes,即开启aof方式的持久化方案。
Aof文件存储的目录和rdb方式的一样。
Aof文件存储的名称.
在使用aof和rdb方式时,如果redis重启,则数据从aof文件加载。
三.redis 主从配置(6台)
第一步:复制出六个从机
第二步:1.修改从机的port地址为7001-7006。2.bind ip地址
第三步:清除从机中的持久化文件
[root@itheima bin2]# rm -rf appendonly.aof dump.rdb
第四步:安装ruby第五步:将redis-3.0.0包下src目录中的以下文件拷贝到redis19/redis-cluster/
第六步 启动7001-7006这六台机器
第七步:修改start-all.sh文件的权限
[root@itheima redis-cluster]# chmod u+x start-all.sh
[root@itheima redis-cluster]# ./start-all.sh
[root@itheima redis-cluster]# ./redis-trib.rb create --replicas 1 192.168.242.137:7001 192.168.242.137:7002 192.168.242.137:7003 192.168.242.137:7004 192.168.242.137:7005 192.168.242.137:7006
第八步 设置防火墙
-A INPUT -m state --state NEW -m tcp -p tcp --dport 7001 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 7002 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 7003 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 7004 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 7005 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 7006 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 7007 -j ACCEPT