在Linux上yum安装运行Redis,只能安装2.4.10(主从)

mac2022-06-30  82

Installing Redis on CentOS 6.4

First, install the epel repo

sudo rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm

Next, install the remi repo

sudo rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm

Now, you should be able to install redis using the yum package manager.

yum install redis -y

修改/etc/redis.conf配置文件中的数据库存放路经,日志存放路经和绑定IP地址。Redis系列-配置文件小结

mkdir /data/redis --创建目录vim /etc/redis.conf

修改数据库存放路经

dir /var/lib/redis/ --修改前 dir /data/redis/ --修改后

修改日志存放路经

logfile /var/log/redis/redis.log --修改前 logfile /data/redis/redis.log --修改后

修改绑定的IP地址

bind 127.0.0.1 --修改前 bind 192.168.7.209    --修改后bind 127.0.0.1 192.168.7.209 --绑定多个IP,注意是空格不是逗号,2.8以后的版本才支持(内网地址,外网地址)

修改绑定的port号

port 6379 --修改前 port **** --修改后

设置密码,去掉行前的注释,并修改密码为所需的密码,保存文件.

requirepass 密码

设置后台运行redis

daemonize no   --修改前daemonize yes  --修改后

修改/data/redis目录权限

chown -R redis:redis /data/redis chmod -R 744 /data/redis chkconfig redis on

启动Redis服务

service redis start   --启动redis服务redis-server --version --查看redis版本号

本地测试Redis

redis-cli --连接redisredis-cli -h 127.0.0.1 -p 6379 -a 指定密码 set name 存储的值 --设置key,value get name --读取key exit --退出redis

设置防火墙

iptables -I INPUT -p tcp --dport 6379 -j ACCEPT service iptables save service iptables restart cat /etc/sysconfig/iptables

设置redis主从读写分离:

修改从库的/etc/redis.conf

slaveof <masterip> <masterport> 指定master的ip和port masterauth <master-password> master有验证的情况下 slave-read-only yes 设置slave为只读模式

 主和从分别执行查看同期情况确认:

INFO replication

同期正常时:

master_link_status:up master_repl_offset和slave_repl_offset相等,刚搭完时两边是一样的 master_last_io_seconds_ago在10秒内。

主:

从:

Slave升级为Master

Master不可用的情况下,停止Master,将Slave的设定无效化后,Slave升级为Master

> SLAVEOF NO ONE> info ...... role:master ......

 

redis基础:http://www.cnblogs.com/ee900222/p/redis_1.html

redis主从:http://www.cnblogs.com/ee900222/p/redis_2.html

http://blog.csdn.net/love__coder/article/details/8678219

 

转载于:https://www.cnblogs.com/qiyebao/p/4807785.html

最新回复(0)