Redis_3.2.4主从部署

系统:Centos6.6x64

创新互联专注于开阳企业网站建设,响应式网站设计,成都做商城网站。开阳网站建设公司,为开阳等地区提供建站服务。全流程按需制作网站,专业设计,全程项目跟踪,创新互联专业和态度为您提供的服务

版本:redis-3.2.4

安装目录:/opt/

主:172.16.15.103

从:172.16.15.104

1,下载安装:

安装依赖:

# yum install gcc tcl ruby -y 

# wget http://download.redis.io/releases/redis-3.2.4.tar.gz

# tar xf redis-3.2.4.tar.gz

# mv redis-3.2.4 /opt/redis

# cd /opt/redis

# make 

# make test 

2,内核修改配置

echo "vm.overcommit_memory=1" >> /etc/sysctl.conf

/sbin/sysctl -p

3, iptables/selinux及内核设置:

# cat /etc/sysconfig/iptables 

-A INPUT -p tcp -m state --state NEW -m tcp --dport 6379 -j ACCEPT

4,创建数据日志目录

#mkdir -p redis/{log,data}

5,redis 主从配置

主服务:172.16.15.103

# cat redis.conf

bind 172.16.15.103

protected-mode yes

port 6379

tcp-backlog 511

timeout 0

tcp-keepalive 300

daemonize yes

supervised no

pidfile /var/run/redis_6379.pid

loglevel notice

logfile /opt/redis/log/redis.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 /opt/redis/data

requirepass 1qaz@WSX

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 no

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

从服务:172.16.15.104

# cat redis.conf

bind 172.16.15.104

protected-mode yes

port 6379

tcp-backlog 511

timeout 0

tcp-keepalive 300

daemonize yes

supervised no

pidfile /var/run/redis_6379.pid

loglevel notice

logfile /opt/redis/log/redis.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 /opt/redis/data

slaveof 172.16.15.103 6379

masterauth 1qaz@WSX

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 no

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

6,启动测试:

# /opt/redis# nohup src/redis-server redis.conf &

# ps-ef|grep redis

# /usr/local/redis/bin/redis-cli ping

7,测试:

主服务103上执行创建:

# /usr/local/redis/bin/redis-cli -h 172.16.15.103 -a 1qaz@WSX 

    >set test 123456

从服务104上执行查看:

# /usr/local/redis/bin/redis-cli -h 172.16.15.104

    >get test

性能测试

# /usr/local/redis/bin/redis-benchmark

关闭服务

# /usr/local/redis/bin/redis-cli -p 6379 shutdown

强制刷新数据到磁盘【Redis默认是异步写入磁盘的】

# /usr/local/redis/bin/redis-cli -p 6379 save

redis 资源信息数据统计查看: info

# redis-cli -h 127.0.0.1 -a passwd

    > info 

Redis 模糊搜索

 keys *

 select 2 

删除所有以user开头的key 可以这样实现:

# redis-cli keys "user*"

1) "user1"

2) "user2"

# redis-cli keys "user*" | xargs redis-cli del

(integer) 2

# 删除成功

# 批量删除匹配通配符的key用到了Linux中的管道和xargs参数:

redis-cli keys "s*" | xargs redis-cli del 

# 如果需要制定数据库,需要用到 -n 数据库编号   参数,下面是删除2数据库中s开头的键:

redis-cli -n 2 keys "s*" | xargs redis-cli -n 2 del

redis-cli keys "*" | xargs redis-cli del  

# 如果redis-cli没有设置成系统变量,需要指定redis-cli的完整路径  

# 如:/opt/redis/redis-cli keys "*" | xargs /opt/redis/redis-cli del 

# 删除当前数据库中的所有Key  

flushdb  

# 删除所有数据库中的key  

flushall 


分享标题:Redis_3.2.4主从部署
网页URL:http://myzitong.com/article/gipccc.html