一,安装
https://www.cnblogs.com/lauhp/p/8487029.html
1.获取redis资源
wget http://download.redis.io/releases/redis-4.0.8.tar.gz
2.解压
tar xzvf redis-4.0.8.tar.gz
3.安装
cd redis-4.0.8
make
cd src
make install PREFIX=/usr/local/redis
4.移动配置文件到安装目录下
cd ../
mkdir /usr/local/redis/etc
mv redis.conf /usr/local/redis/etc
5.配置redis为守护进程后台启动
# By default Redis does not run as a daemon. Use 'yes' if you need it.
# Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
daemonize yes
6.将redis加入到开机启动
vi /etc/rc.local //在里面添加内容:/usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf (意思就是开机调用这段开启redis的命令)
7.开启redis
/usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf
常用命令
redis-server /usr/local/redis/etc/redis.conf //启动redis
pkill redis //停止redis
卸载redis:
rm -rf /usr/local/redis //删除安装目录
rm -rf /usr/bin/redis-* //删除所有redis相关命令脚本
rm -rf /root/download/redis-4.0.4 //删除redis解压文件夹
二.配置linux redis集群
注:该集群中有三个节点,每个节点有一主一备。需要6台虚拟机。在此搭建一个伪分布式的集群,使用6个redis实例来模拟。
1、需要gcc环境,如果没有执行命令安装gcc
yum install gcc-c++
2、安装ruby环境
yum install ruby yum install rubygems
3. 安装ruby的包
gem install redis-3.0.0.gem
4.新建文件目录 cluster-redis
修改redis.conmfig 配置文件
#
# Normal Redis instances can't be part of a Redis Cluster; only nodes that are
# started as cluster nodes can. In order to start a Redis instance as a
# cluster node enable the cluster support uncommenting the following:
#
cluster-enabled yes
5.复制这个文件 到 cluster-redis 文件夹 复制6份,然后每一份独立配置,port 端口号
6.开启服务
7.复制redis安装文件下的src目录下的,redis-trib.rb 复制到cluster-redis 文件夹
8.创建集群
./redis-trib.rb create --replicas 1
192.168.242.134:7001
192.168.242.134:7002
192.168.242.134:7003
192.168.242.134:7004
192.168.242.134:7005
192.168.242.134:7006
中途点yes
注意:
1.make Install要到src目录下才能指定目录安装;
2.要设置守护线程
3.关闭失败后,要删除一次东西,重启redis服务
参考文档:
https://www.cnblogs.com/guxiong/p/6270140.html