Redis安装及一主两从三sentinel配置 一.安装Redis
(1)cd /usr/src进入下载目录
(2) yum install -y wgetgcc make tcl安装依赖 (3)tar -zxvf redis-3.2.7.tar.gz 解压 (4)cd redis-3.2.7 进入redis目录 (5)make 编辑
(6)make test 测试 对编译不理解的同学可以看看这个 http://blog.csdn.net/secondjanuary/article/details/8985795 测试过程报错
[exception]: Executing test client: NOREPLICAS Not enough good slaves to write.. NOREPLICAS Not enough good slaves to write. while executing
这种情况下,可以修改当前目录文件tests/integration/replication-2.tcl,将after 1000改为after 10000以延长等待时间重新测试
(7)make install PREFIX=/usr/local/redis PREFIX安装指定目录否则安装到/usr/local/bin里面了
(8)启动redis服务 ./redis-server ./redis-conf
发现很多错误:
1.WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128
echo 511 > /proc/sys/net/core/somaxconn 写到/etc/rc.local里面 rc.local是开机启动程序是一个软连接 (确定两者都有执行权限)
lrwxrwxrwx. 1 root root 13 Aug 2 07:50 /etc/rc.local ->rc.d/rc.local
2.WARNINGovercommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctlvm.overcommit_memory=1' for this to take effect. 往/etc/sysctl.conf中添加vm.overcommit_memory = 1 /sbin/sysctl –p使文件立即生效
3.WARNING you have Transparent Huge Pages (THP) support enabled in your
kernel. This will create latency and memory usage issues with Redis. To fix this issue
run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
echo never > /sys/kernel/mm/transparent_hugepage/enabled写到/etc/rc.local里面 在后台运行的话修改配置redis.conf daemonizeyes 就可以了 (9)运行./redis-cli
二.Redis配置文件说明(/usr/local/redis/bin)
1. Redis默认不是以守护进程的方式运行,可以通过该配置项修改,使用yes启用守护进程 daemonizeyes 2. 绑定的主机地址
修改主机172.16.0.52配置文件去掉bind注释符#,bind设置成主机ip bind172.16.0.52 127.0.0.1
修改主机172.16.0.53配置文件去掉bind注释符#,bind设置成主机ip bind172.16.0.53127.0.0.1
3修改172.16.0.53机器的配置文件,使53变成52从机器 slaveof 172.16.0.52 6379 (172.16.0.52机器不需要操作)
4. 指定Redis最大内存限制,Redis在启动时会把数据加载到内存中,达到最大内存后,Redis会先尝试清除已到期或即将到期的Key,当此方法处理后,仍然到达最大内存设置,将无法再进行写入操作,但仍然可以进行读取操作。Redis新的vm机制,会把Key存放内存,Value会存放在swap区 maxmemory
/usr/local/redis/bin/redis-server /usr/local/redis/bin/redis.conf
三.一主两从三sentinel(监测主redis服务器是否异常,如果主redis服务器down掉,则从从redis服务器中选择一个作为主redis服务器)的配置
两从的配置
172.16.0.53机器上/usr/local目录下新建文件夹slave1(mkdir slave1),将/usr/local目录下的redis文件夹拷贝到slave1文件夹下(cp -R /usr/local/redis/
/usr/local/slave1/)。修改/usr/local/slave1/中的配置文件redis.conf端口号,port改为6380。 启动redis
/usr/local/slave1/redis/bin/redis-server /usr/local/slave1/redis/bin/redis.conf 三个sentinel配置
172.16.0.53机器上/usr/local目录下新建三个文件夹sentinel1 sentinel2 sentinel3 将目录/home/user05/redis-3.2.7中的sentinel.conf拷贝到三个新建的文件夹中( cp /home/user05/redis-3.2.7/sentinel.conf /usr/local/sentinel1/ cp/home/user05/redis-3.2.7/sentinel.conf /usr/local/sentinel2/ cp/home/user05/redis-3.2.7/sentinel.conf /usr/local/sentinel3/)。
将目录/home/user05/redis-3.2.7/src中的redis-sentinel拷贝到三个新建的文件夹中( cp /home/user05/redis-3.2.7/src/redis-sentinel /usr/local/sentinel1/ cp /home/user05/redis-3.2.7/src/redis-sentinel /usr/local/sentinel3/ cp /home/user05/redis-3.2.7/src/redis-sentinel /usr/local/sentinel3/)。 修改三个新建文件夹中的sentinel.conf配置文件,将三个配置文件的端口号依次
修改为 port 26379 port 26380 port 26381 其余的修改为
《1》你要监视的主服务器的ip地址,以及sentinel标记客观下线的阀值。 sentinel monitor mymaster172.16.0.52 6379 2 《2》sentinel认为“主线下线”的一个阀值。 sentinel down-after-milliseconds mymaster 3000(3秒) 《3》故障恢复期间可以同时slave的个数。 sentinel parallel-syncs mymaster1 《4》故障恢复允许的最大时长 sentinel failover-timeout mymaster 180000 《5》bind设置
bind 172.16.0.53 127.0.0.1 《6》设置成后台运行方式
daemonize yes
logfile \
启动sentinel
/usr/local/sentinel1/redis-sentinel /usr/local/sentinel1/sentinel.conf /usr/local/sentinel2/redis-sentinel /usr/local/sentinel2/sentinel.conf /usr/local/sentinel3/redis-sentinel /usr/local/sentinel3/sentinel.conf
四.安装位置
安装在/usr/local/redis/bin目录下
1、启动redis服务器./redis-server ./redis.conf(已启动) 2、启动redis客户端./redis-cli
主redis服务器在172.16.0.52上(/usr/local/redis/bin) ps -ef|grepredis