redis配置筆記

weixin_34259232發表於2018-01-10

#cd /opt
#tar -zxvf redis-4.0.6.tar.gz
#cd redis-4.0.6
#make
#cd src
#make install PREFIX=/usr/local/redis
#mkdir –p /usr/local/redis/etc放配置檔案
#mv /opt/redis-4.0.6/redis.conf /usr/local/redis/etc/
修改配置檔案:
預設情況,Redis不是在後臺執行,我們需要把redis放在後臺執行
vi /usr/local/redis/etc/redis.conf
將daemonize的值改為yes
bind 192.168.100.101
save <seconds> <changes>:儲存快照的頻率
將其註釋掉:
# save 900 1
# save 300 10
# save 60 10000

啟動:

# /usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf 
10422:C 09 Jan 16:41:21.005 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
10422:C 09 Jan 16:41:21.005 # Redis version=4.0.6, bits=64, commit=00000000, modified=0, pid=10422, just started
10422:C 09 Jan 16:41:21.005 # Configuration loaded

測試:

[root@redis-master bin]# ./redis-cli -h 10.174.66.201 -p 6379 或
[root@redis-master bin]# ./redis-cli 
192.168.100.101:6379> info
# Server
redis_version:4.0.6
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:e17e63b9178f2308
redis_mode:standalone
os:Linux 3.10.0-693.el7.x86_64 x86_64
arch_bits:64
……

192.168.100.101:6379> set key hello
OK
192.168.100.101:6379> get key
"hello"
192.168.100.101:6379> keys *
1) "key"
192.168.100.101:6379> FLUSHALL
OK
192.168.100.101:6379>

停止redis例項

# ./redis-cli -h 192.168.100.101 -p 6379
192.168.100.101:6379> SHUTDOWN

redis主從配置,修改slave從伺服器的配置檔案。
slaveof 192.168.100.101 6379 (對映到主伺服器上)

檢視master伺服器

[root@redis-master bin]# ./redis-cli -h 192.168.100.101 -p 6379
192.168.100.101:6379> info
……
# Replication
role:master
connected_slaves:1
slave0:ip=192.168.100.102,port=6379,state=online,offset=42,lag=0
master_replid:a0d0bdb21443e69c99a32bc3859be833d61d09cc
master_replid2:0000000000000000000000000000000000000000
……

檢視slave伺服器:

[root@redis-slave bin]# ./redis-cli -h 10.174.66.202 -p 6379
192.168.100.102:6379> info
# Replication
role:slave
master_host:10.174.66.201
master_port:6379
master_link_status:up

新增開機自啟動:

#crontab -e

@reboot  /usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf 

 

相關文章