Redis for linux安装配置之—-源码安装

时间:2021-12-12 23:23:02

一‘redis单实例安装配置
1.下载redis源码压缩包,并将其上传至服务器/usr/local
2.解压redis源码压缩包
  # tar -xzvf redis-3.2.12.tar.gz
3.进入redis解压缩后的目录进行编译
  # cd redis-3.2.12
  # make
4.编译成功后,再对redis进行安装
  # cd src
  # make install
5.对安装后的redis进行部署
  # mkdir -p /usr/local/redis/
  # mkdir -p /usr/local/redis/etc/
  # mkdir -p /usr/local/redis/bin
  # cd ..
  # cd ..
  # mv redis-3.2.12 redis
  # cd redis
  # cp redis.conf /usr/local/redis/etc/
  # cp mkreleasdhdr.sh redis-benchmark redis-check-aof redis-check-dump redis-cli redis-server /usr/local/redis/bin/
  # groupadd redis
  # useradd -r -g redis
  # mkdir -p /home/redis
  # chown -R redis.redis /home/redis
  # chmod -R 755 /home/redis
  # passwd redis
  # chown -R redis.redis /usr/local/redis/
  # chmod -R 755 /usr/local/redis/  
  # vi /home/redis/.bash_profile
6.启动redis
  # su - redis
  $ cd /usr/local/redis/bin/
  $ redis-server ../etc/redis.conf
7.连接redis
  $ redis-cli -p 6379
8.关闭redis
  $ redis-cli -p 6379
  或
  $ pkill redis

二、redis集群安装配置
1.创建配置文件
  $ mdkir -p /usr/local/redis/cluster
  $ cd /usr/local/redis/etc/
  $ cp redis.conf ../cluster/redis-6379.conf
  $ cp redis.conf ../cluster/redis-6380.conf
  $ cp redis.conf ../cluster/redis-6381.conf
2.修改配置文件
  $ vi redis-6379.conf
  daemonize yes
  pidfile /var/run/redis6301.pid
  port 6379
  logfile "/usr/local/redis/cluster/6379.log"
  dbfilename dump6379.rdb
  
  $ vi redis-6380.conf
  daemonize yes
  pidfile /var/run/redis6380.pid
  port 6380
  logfile "/usr/local/redis/cluster/6380.log"
  dbfilename dump6380.rdb
  
  $ vi redis-6381.conf
  daemonize yes
  pidfile /var/run/redis6381.pid
  port 6381
  logfile "/usr/local/redis/cluster/6381.log"
  dbfilename dump6381.rdb
3.启动redis cluster
  $ cd /usr/local/redis/bin
  redis-server /usr/local/redis/cluster/redis-6379.conf
  redis-server /usr/local/redis/cluster/redis-6380.conf
  redis-server /usr/local/redis/cluster/redis-6381.conf
4.主从同步
  1)方法一
  $ redis-cli -p 6380
  auth "passwd"
  info replication
  slaveof 127.0.0.1 6379
  
  $ redis-cli -p 6381
  auth "passwd"
  info replication
  slaveof 127.0.0.1 6379
  2)方法二
  将如下行分别加入redis-6380.conf和redis-6381.conf中
  slaveof 127.0.0.1 6379
  
5.验证redis cluster
  $ redis-cli -p 6379
  auth "passwd"
  info replication
  
  $ redis-cli -p 6380
  auth "passwd"
  info replication
  
  $ redis-cli -p 6381
  auth "passwd"
  info replication
  
三、redis集群哨兵模式
1.创建配置文件
  $ mkdir -p /usr/local/redis/sentinel/
  $ cd /usr/local/redis/sentinel/
  
  $ touch sentinel-26379.conf
  $ touch sentinel-26380.conf 
  $ touch sentinel-26381.conf
2.修改配置文件
  $ vi sentinel-26379.conf
  # 后台启动
  daemonize yes
  # 启动目录
  dir "/usr/local/redis/bin"
  # 日志文件
  logfile "/usr/local/redis/sentinel/sentinel-26379.log"
  # 监听Redis主库IP地址及端口
  sentinel monitor host6379 127.0.0.1 6379 2
  
  $ vi sentinel-26380.conf
  # 后台启动
  daemonize yes
  # 启动目录
  dir "/usr/local/redis/bin"
  # 日志文件
  logfile "/usr/local/redis/sentinel/sentinel-26380.log"
  # 监听Redis主库IP地址及端口
  sentinel monitor host6379 127.0.0.1 6379 2
  
  $ vi sentinel-26381.conf
  # 后台启动
  daemonize yes
  # 启动目录
  dir "/usr/local/redis/bin"
  # 日志文件
  logfile "/usr/local/redis/sentinel/sentinel-26381.log"
  # 监听Redis主库IP地址及端口
  sentinel monitor host6379 127.0.0.1 6379 2
 
3.启动哨兵
  $ redis-sentinel /usr/local/redis/sentinel/sentinel-26301.conf
  $ redis-sentinel /usr/local/redis/sentinel/sentinel-26302.conf
  $ redis-sentinel /usr/local/redis/sentinel/sentinel-26303.conf
  
4.查看哨兵
  $ tail -f /usr/local/redis/sentinel/sentinel-26379.log
  $ tail -f /usr/local/redis/sentinel/sentinel-26380.log
  $ tail -f /usr/local/redis/sentinel/sentinel-26381.log