Jamers Posted July 4, 2017 Report Share Posted July 4, 2017 安装redis方式就不再多述,假设可以运行一个正常的redis的环境下。 Ports路径 :/usr/ports/databases/redis 安装ruby(建集群时需要用到): cd /usr/ports/accessibility/rubygem-atk make install clean 安装 ruby-gems cd /usr/ports/devel/rubygem-gems make install clean 安装ruby-redis gem install redis 建立集群至少要求超过3个结点,我这里配置了五个,如果集群挂掉的结点超过一半,将无法正常提供服务。 修改配置文件: cd /usr/local/etc /usr/local/etc/rc.d/redis stop cp redis.conf redis-6379.conf cp redis.conf redis-6380.conf cp redis.conf redis-6381.conf cp redis.conf redis-6382.conf cp redis.conf redis-6383.conf chown redis redis-*.conf ee redis-6379.conf 主要修改以下内容: bind 0.0.0.0 port 6379 #修改各自的端口号 6379-6383 pidfile /var/run/redis/6379.pid dbfilename dump-6379.rdb cluster-enabled yes cluster-config-file nodes-6379.conf #修改启动参数 ee /etc/rc.conf redis_profiles="6379 6380 6381 6382 6383" 然后重启服务 /usr/local/etc/rc.d/redis start 建立集群: cd /usr/ports/databases/redis/work/redis-3.2.9/src ./redis-trib.rb create --replicas 1 127.0.0.1:6379 127.0.0.1:6380 127.0.0.1:6381 127.0.0.1:6382 127.0.0.1:6383 #等提示时输入yes即可 上面的IP如果要其他机器访问,请使用内网IP 连接测试: redis-cli -h 192.168.1.86 -c -p 6379 set hello world #提示: #-> Redirected to slot [8516] located at 192.168.1.86:6381 #OK #成功 注意:建立集群前不能设置访问密码,需要身份验证的话需要在建立集群后再逐一用config命令进行设置: config set masterauth passowrd config set requirepass password config rewrite Link to comment Share on other sites More sharing options...
Jamers Posted July 4, 2017 Author Report Share Posted July 4, 2017 设置密码后predis居然没办法连接,因为集群不支持密码验证,所以如果需要放在公网上的话,必须配置好允许访问的IP,以防止被非法访问。 希望后续版本能够加上这个功能。 Link to comment Share on other sites More sharing options...
Jamers Posted July 15, 2017 Author Report Share Posted July 15, 2017 上面集群已经架设完毕,但是无法自动进行切换主从关系。还需要进一步设置: ee /usr/local/etc/sentinel.conf #修改参数:下面为参考设置,可自行调整 daemonize yes logfile "/var/log/sentinel_log.log" sentinel monitor mymaster 192.168.1.86 6379 2 sentinel down-after-milliseconds mymaster 10000 sentinel parallel-syncs mymaster 1 sentinel failover-timeout mymaster 180000 sentinel monitor my6380 192.168.1.86 6380 2 sentinel down-after-milliseconds my6380 10000 sentinel parallel-syncs my6380 1 sentinel failover-timeout my6380 180000 sentinel monitor my6381 192.168.1.86 6381 2 sentinel down-after-milliseconds my6381 10000 sentinel parallel-syncs my6381 1 sentinel failover-timeout my6381 180000 启动: redis-server /usr/local/etc/sentinel.conf --sentinel 暂时未找到做好的脚本可以自动执行,只能放在rc.local里了。 rc.local #!/bin/sh /usr/local/bin/redis-server /usr/local/etc/sentinel.conf --sentinel Link to comment Share on other sites More sharing options...
Jamers Posted July 17, 2017 Author Report Share Posted July 17, 2017 假设三台服务器组网成6个redis集群相关设置备忘: 服务器1: 192.168.1.101A 6379B 6382 服务器2:192.168.1.102B 6380C 6383服务器3:192.168.1.103C 6381A 6384192.168.1.101:6379 192.168.1.102:6380 192.168.1.103:6381 192.168.1.103:6384 192.168.1.101:6382 192.168.1.102:6383 这样如果是一台服务器停机,可以保证redis集群正常运作。 Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now