redis-master:192.168.199.223
redis-slave: 192.168.199.224
cd /optwget http://download.redis.io/releases/redis-4.0.11.tar.gztar zxvf redis-4.0.11.tar.gzmv redis-4.0.11 rediscd redismake&&make install
redis-master配置文件[root@test ~]# cat /opt/redis/redis.conf |grep -Ev '^$|^#'bind 192.168.199.223protected-mode yesport 6379tcp-backlog 511timeout 0tcp-keepalive 300daemonize yessupervised nopidfile /var/run/redis_6379.pidloglevel noticelogfile "/usr/local/log/redis-6379.log"databases 16always-show-logo yessave 900 1save 300 10save 60 10000stop-writes-on-bgsave-error yesrdbcompression yesrdbchecksum yesdbfilename dump.rdbdir ./slave-serve-stale-data yesslave-read-only yesrepl-diskless-sync norepl-diskless-sync-delay 5repl-disable-tcp-nodelay noslave-priority 100requirepass jason_zhanglazyfree-lazy-eviction nolazyfree-lazy-expire nolazyfree-lazy-server-del noslave-lazy-flush noappendonly noappendfilename "appendonly.aof"appendfsync everysecno-appendfsync-on-rewrite noauto-aof-rewrite-percentage 100auto-aof-rewrite-min-size 64mbaof-load-truncated yesaof-use-rdb-preamble nolua-time-limit 5000slowlog-log-slower-than 10000slowlog-max-len 128latency-monitor-threshold 0notify-keyspace-events ""hash-max-ziplist-entries 512hash-max-ziplist-value 64list-max-ziplist-size -2list-compress-depth 0set-max-intset-entries 512zset-max-ziplist-entries 128zset-max-ziplist-value 64hll-sparse-max-bytes 3000activerehashing yesclient-output-buffer-limit normal 0 0 0client-output-buffer-limit slave 256mb 64mb 60client-output-buffer-limit pubsub 32mb 8mb 60hz 10aof-rewrite-incremental-fsync yes
redis-slave配置文件[root@jason opt]# cat /opt/redis/redis.conf|grep -Ev '^$|^#'bind 127.0.0.1protected-mode yesport 6379tcp-backlog 511timeout 0tcp-keepalive 300daemonize yessupervised nopidfile /var/run/redis_6379.pidloglevel noticelogfile "/usr/local/log/redis-6379.log"databases 16always-show-logo yessave 900 1save 300 10save 60 10000stop-writes-on-bgsave-error yesrdbcompression yesrdbchecksum yesdbfilename dump.rdbdir ./slaveof 192.168.199.223 6379masterauth jason_zhangslave-serve-stale-data yesslave-read-only yesrepl-diskless-sync norepl-diskless-sync-delay 5repl-disable-tcp-nodelay noslave-priority 100requirepass jason_zhanglazyfree-lazy-eviction nolazyfree-lazy-expire nolazyfree-lazy-server-del noslave-lazy-flush noappendonly noappendfilename "appendonly.aof"appendfsync everysecno-appendfsync-on-rewrite noauto-aof-rewrite-percentage 100auto-aof-rewrite-min-size 64mbaof-load-truncated yesaof-use-rdb-preamble nolua-time-limit 5000slowlog-log-slower-than 10000slowlog-max-len 128latency-monitor-threshold 0notify-keyspace-events ""hash-max-ziplist-entries 512hash-max-ziplist-value 64list-max-ziplist-size -2list-compress-depth 0set-max-intset-entries 512zset-max-ziplist-entries 128zset-max-ziplist-value 64hll-sparse-max-bytes 3000activerehashing yesclient-output-buffer-limit normal 0 0 0client-output-buffer-limit slave 256mb 64mb 60client-output-buffer-limit pubsub 32mb 8mb 60hz 10aof-rewrite-incremental-fsync yes
启动master和slave的redis服务(如果不能同步请重启redis服务或者重启主机)
cd /usr/local/bin./redis-server /opt/redis/redis.conf
master
添加两个键值jason 、monday 键值为jason_test monday_test
语法 set jason jason_test
命令 INFO 查看redis信息
redis-slave
连上redis
测试写入
测试删除
配置启动脚本
vim redis
#!/bin/bash#chkconfig: 2345 80 90# Simple Redis init.d script conceived to work on Linux systems# as it does use of the /proc filesystem.PATH=/usr/local/bin:/sbin:/usr/bin:/binREDISPORT=6379EXEC=/usr/local/bin/redis-serverREDIS_CLI=/usr/local/bin/redis-cli PIDFILE=/var/run/redis.pidCONF="/opt/redis/redis.conf" case "$1" in start) if [ -f $PIDFILE ] then echo "$PIDFILE exists, process is already running or crashed" else echo "Starting Redis server..." $EXEC $CONF fi if [ "$?"="0" ] then echo "Redis is running..." fi ;; stop) if [ ! -f $PIDFILE ] then echo "$PIDFILE does not exist, process is not running" else PID=$(cat $PIDFILE) echo "Stopping ..." $REDIS_CLI -p $REDISPORT SHUTDOWN while [ -x ${PIDFILE} ] do echo "Waiting for Redis to shutdown ..." sleep 1 done echo "Redis stopped" fi ;; restart|force-reload) ${ 0} stop ${ 0} start ;; *) echo "Usage: /etc/init.d/redis {start|stop|restart|force-reload}" >&2 exit 1esac
# 复制脚本文件到init.d目录下cp redis /etc/init.d/# 给脚本增加运行权限chmod +x /etc/init.d/redis# 添加服务chkconfig --add redis# 配置启动级别chkconfig --level 2345 redis on
重启redis,kill掉进程,重新启动
或者连上客户端之后,执行shutdown命令,再启动服务
设置最大内存
CONFIG SET maxmemory 100MB
CONFIG GET maxmemory参考:http://happyqing.iteye.com/blog/2348255
https://www.cnblogs.com/stulzq/p/9288401.html
https://www.ilanni.com/?p=11838#%E4%B8%80%E3%80%81redis%E6%BA%90%E7%A0%81%E5%AE%89%E8%A3%85