CentOS7下Redis3.2.3Cluster配置

配置redis cluster,以两台机器,6个实例为环境。

创新互联坚持“要么做到,要么别承诺”的工作理念,服务领域包括:成都网站建设、网站建设、企业官网、英文网站、手机端网站、网站推广等服务,满足客户于互联网时代的汤原网站设计、移动媒体设计的需求,帮助企业找到有效的互联网解决方案。努力成为您成熟可靠的网络建设合作伙伴!

操作系统 CentOS Linux release 7 64位

安装依赖包:单独下载redis-3.3.1.gem这个包要对应os版本
yum -y install tcl   
yum -y install ruby ruby-devel rubygems rpm-build
gem install redis 

解压安装:

cd /usr/local/
tar zxvf redis-3.2.3.tar.gz
cd redis-3.2.3
make && make install

在172.16.25.220的/usr/local/webapp下创建bin、redis6379、redis6380、redis6381四个目录
mkdir bin
mkdir redis6379
mkdir redis6380
mkdir redis6381

在172.16.25.72的/usr/local/webapp下创建bin、redis6379、redis6380、redis6381四个目录
mkdir bin
mkdir redis6379
mkdir redis6380
mkdir redis6381

分别在两台机器上创建配置文件,并启动:
cd /usr/local/redis-3.2.3/src/
cp mkreleasehdr.sh redis-benchmark redis-sentinel redis-server redis-trib.rb redis-cli /usr/local/webapp/bin
cd /usr/local/webapp/redis6379/
touch redis-6379.conf
cp /usr/local/webapp/redis6379/redis-6379.conf /usr/local/webapp/redis6380/redis-6380.conf
cp /usr/local/webapp/redis6379/redis-6379.conf /usr/local/webapp/redis6381/redis-6381.conf
sed -i 's/6379/6380/g' /usr/local/webapp/redis6380/redis-6380.conf
sed -i 's/6379/6381/g' /usr/local/webapp/redis6381/redis-6381.conf
/usr/local/webapp/bin/redis-server /usr/local/webapp/redis6379/redis-6379.conf
/usr/local/webapp/bin/redis-server /usr/local/webapp/redis6380/redis-6380.conf
/usr/local/webapp/bin/redis-server /usr/local/webapp/redis6381/redis-6381.conf

创建集群(在其中一台服务器上执行即可)
cd /usr/local/webapp/bin/
./redis-trib.rb create --replicas 1 172.16.25.220:6379 172.16.25.72:6379 172.16.25.220:6380 172.16.25.72:6380 172.16.25.220:6381 172.16.25.72:6381

集群状态查看:
./redis-cli -c -h 172.16.25.220 -p 6380
172.16.25.220:6380> cluster nodes
3b64702727c2e047f255ebb6eb111359990fba85 172.16.25.72:6379 master - 0 1478249255421 2 connected 5461-10922
a0ac9b45dd7bfabeb7036278c13efb744794adc8 172.16.25.72:6380 master - 0 1478249256423 7 connected 0-5460
f612b1d6e362c52ac606a627bcc27a95224ce2b3 172.16.25.220:6381 slave 3b64702727c2e047f255ebb6eb111359990fba85 0 1478249254919 5 connected
954200fe3b22806af5afc035cdf0a25899c14ecd 172.16.25.220:6380 myself,slave ca66b71a3e2b7bf75885720b4c7bd3015dd732a1 0 0 3 connected
ca66b71a3e2b7bf75885720b4c7bd3015dd732a1 172.16.25.72:6381 master - 0 1478249254419 8 connected 10923-16383
2b2b3a1885a9a2b64060b20322d3c425b64ca063 172.16.25.220:6379 slave a0ac9b45dd7bfabeb7036278c13efb744794adc8 0 1478249255921 7 connected

给redis cluster集群加上认证功能:
登陆集群后配置密码(我这里测试不生效)
./redis-cli -c -h 172.16.25.72 -p 6379
config set masterauth mypasswd
config set requirepass mypasswd
config rewrite
 
修改配置文件:加入下面两行
requirepass "mypasswd"
masterauth "mypasswd"
 
停redis
./redis-cli -c -h 172.16.25.220 -p 6379 shutdown
./redis-cli -c -h 172.16.25.220 -p 6380 shutdown
./redis-cli -c -h 172.16.25.220 -p 6381 shutdown
./redis-cli -c -h 172.16.25.72 -p 6381 shutdown 
./redis-cli -c -h 172.16.25.72 -p 6380 shutdown
./redis-cli -c -h 172.16.25.72 -p 6379 shutdown
 
修改
修改gem的redis工具下的一个文件,我这里是默认安装,路径如下:/usr/local/share/gems/gems/redis-3.3.1/lib/redis/client.rb
vim /usr/local/share/gems/gems/redis-3.3.1/lib/redis/client.rb
 
启动redis
service redis6379 start
service redis6380 start
service redis6381 start
 
登陆
./redis-cli -c -h 172.16.25.220 -p 6380
172.16.25.220:6380> cluster nodes
NOAUTH Authentication required.
172.16.25.220:6380> auth mypasswd
OK
172.16.25.220:6380> cluster nodes
3b64702727c2e047f255ebb6eb111359990fba85 172.16.25.72:6379 master - 0 1478249211338 2 connected 5461-10922
a0ac9b45dd7bfabeb7036278c13efb744794adc8 172.16.25.72:6380 master - 0 1478249211839 7 connected 0-5460
f612b1d6e362c52ac606a627bcc27a95224ce2b3 172.16.25.220:6381 slave 3b64702727c2e047f255ebb6eb111359990fba85 0 1478249210836 5 connected
954200fe3b22806af5afc035cdf0a25899c14ecd 172.16.25.220:6380 myself,slave ca66b71a3e2b7bf75885720b4c7bd3015dd732a1 0 0 3 connected
ca66b71a3e2b7bf75885720b4c7bd3015dd732a1 172.16.25.72:6381 master - 0 1478249212341 8 connected 10923-16383
2b2b3a1885a9a2b64060b20322d3c425b64ca063 172.16.25.220:6379 slave a0ac9b45dd7bfabeb7036278c13efb744794adc8 0 1478249210334 7 connected
172.16.25.220:6380> 
 
./redis-cli -c -h 172.16.25.220 -p 6380 -a mypasswd
172.16.25.220:6380> cluster nodes
3b64702727c2e047f255ebb6eb111359990fba85 172.16.25.72:6379 master - 0 1478249255421 2 connected 5461-10922
a0ac9b45dd7bfabeb7036278c13efb744794adc8 172.16.25.72:6380 master - 0 1478249256423 7 connected 0-5460
f612b1d6e362c52ac606a627bcc27a95224ce2b3 172.16.25.220:6381 slave 3b64702727c2e047f255ebb6eb111359990fba85 0 1478249254919 5 connected
954200fe3b22806af5afc035cdf0a25899c14ecd 172.16.25.220:6380 myself,slave ca66b71a3e2b7bf75885720b4c7bd3015dd732a1 0 0 3 connected
ca66b71a3e2b7bf75885720b4c7bd3015dd732a1 172.16.25.72:6381 master - 0 1478249254419 8 connected 10923-16383
2b2b3a1885a9a2b64060b20322d3c425b64ca063 172.16.25.220:6379 slave a0ac9b45dd7bfabeb7036278c13efb744794adc8 0 1478249255921 7 connected
172.16.25.220:6380> 
 
停止有密码认证的集群
./redis-cli -c -a "mypasswd" -h 172.16.25.220 -p 6379 shutdown

redis的配置文件如下:
bind 172.16.25.220
protected-mode yes
port 6379
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 5000
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize yes
supervised no
pidfile /usr/local/webapp/redis6379/redis_6379.pid
loglevel notice
logfile /usr/local/webapp/redis6379/redis_6379.log
databases 16
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir /usr/local/webapp/redis6379
slave-serve-stale-data yes
slave-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
slave-priority 100
appendonly yes
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
aof-rewrite-incremental-fsync yes
requirepass "mypasswd"
masterauth "mypasswd"

当前名称:CentOS7下Redis3.2.3Cluster配置
当前链接:http://www.mswzjz.com/qtweb/news20/203270.html

网站建设、网络推广公司-创新互联,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联