博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
centos 7 redis-4.0.11 主从
阅读量:5102 次
发布时间:2019-06-13

本文共 5046 字,大约阅读时间需要 16 分钟。

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

转载于:https://www.cnblogs.com/xiaoyou2018/p/9597964.html

你可能感兴趣的文章
那些黑刘翔的人,你们的良心被狗吃了
查看>>
图片延迟加载(lazyload)的实现原理
查看>>
TreeMap和TreeSet在排序时如何比较元素?Collections工具类中的sort()方法如何比较元素?...
查看>>
Redis系列--内存淘汰机制(含单机版内存优化建议)
查看>>
最小二乘法
查看>>
iptables端口转发
查看>>
金融三问
查看>>
HTML5新API记录
查看>>
Android 8 AudioPolicy 分析
查看>>
map.entry<k,v>小用法(转)
查看>>
mysql自增字段重排 或 归零
查看>>
eclipse svn设置忽略文件
查看>>
centos7更改默认的python版本,安装python3.6.4
查看>>
大数据应用期末总评
查看>>
Java Web开发后端常用技术汇总
查看>>
How to use jQuery countdown plugin
查看>>
富文本常用封装(NSAttributedString浅析)
查看>>
c++ STL
查看>>
json数据在前端(javascript)和后端(php)转换
查看>>
[Serializable]的应用--注册码的生成,加密和验证
查看>>