系統(tǒng):Centos6.6x64
創(chuàng)新互聯(lián)專注于開陽企業(yè)網(wǎng)站建設,響應式網(wǎng)站設計,成都做商城網(wǎng)站。開陽網(wǎng)站建設公司,為開陽等地區(qū)提供建站服務。全流程按需制作網(wǎng)站,專業(yè)設計,全程項目跟蹤,創(chuàng)新互聯(lián)專業(yè)和態(tài)度為您提供的服務
版本: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,內(nèi)核修改配置
echo "vm.overcommit_memory=1" >> /etc/sysctl.conf
/sbin/sysctl -p
3, iptables/selinux及內(nèi)核設置:
# cat /etc/sysconfig/iptables
-A INPUT -p tcp -m state --state NEW -m tcp --dport 6379 -j ACCEPT
4,創(chuàng)建數(shù)據(jù)日志目錄
#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上執(zhí)行創(chuàng)建:
# /usr/local/redis/bin/redis-cli -h 172.16.15.103 -a 1qaz@WSX
>set test 123456
從服務104上執(zhí)行查看:
# /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
強制刷新數(shù)據(jù)到磁盤【Redis默認是異步寫入磁盤的】
# /usr/local/redis/bin/redis-cli -p 6379 save
redis 資源信息數(shù)據(jù)統(tǒng)計查看: info
# redis-cli -h 127.0.0.1 -a passwd
> info
Redis 模糊搜索
keys *
select 2
刪除所有以user開頭的key 可以這樣實現(xiàn):
# redis-cli keys "user*"
1) "user1"
2) "user2"
# redis-cli keys "user*" | xargs redis-cli del
(integer) 2
# 刪除成功
# 批量刪除匹配通配符的key用到了Linux中的管道和xargs參數(shù):
redis-cli keys "s*" | xargs redis-cli del
# 如果需要制定數(shù)據(jù)庫,需要用到 -n 數(shù)據(jù)庫編號 參數(shù),下面是刪除2數(shù)據(jù)庫中s開頭的鍵:
redis-cli -n 2 keys "s*" | xargs redis-cli -n 2 del
redis-cli keys "*" | xargs redis-cli del
# 如果redis-cli沒有設置成系統(tǒng)變量,需要指定redis-cli的完整路徑
# 如:/opt/redis/redis-cli keys "*" | xargs /opt/redis/redis-cli del
# 刪除當前數(shù)據(jù)庫中的所有Key
flushdb
# 刪除所有數(shù)據(jù)庫中的key
flushall