redis配置笔记
#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
*******VICTORY LOVES PREPARATION*******