ubuntu16.04怎么安装redis主从集群
这篇文章主要讲解了“ubuntu16.04怎么安装redis主从集群”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“ubuntu16.04怎么安装redis主从集群”吧!
公司主营业务:网站设计制作、做网站、移动网站开发等业务。帮助企业客户真正实现互联网宣传,提高企业的竞争能力。成都创新互联公司是一支青春激扬、勤奋敬业、活力青春激扬、勤奋敬业、活力澎湃、和谐高效的团队。公司秉承以“开放、自由、严谨、自律”为核心的企业文化,感谢他们对我们的高要求,感谢他们从不同领域给我们带来的挑战,让我们激情的团队有机会用头脑与智慧不断的给客户带来惊喜。成都创新互联公司推出禅城免费做网站回馈大家。
安装单机版
前置环境
apt-get update apt install make apt install gcc gcc+ build-essential tcl
下载安装
cd /app wget http://download.redis.io/releases/redis-5.0.5.tar.gz tar zxvf redis-5.0.5.tar.gz cd redis-5.0.5 make MALLOC=libc make test cd src && make install PREFIX=/usr/local/redis # 安装成功后 root@redis-node1:/app/redis-5.0.5/src# make install PREFIX=/usr/local/redis Hint: It's a good idea to run 'make test' ;) INSTALL install INSTALL install INSTALL install INSTALL install INSTALL install
make test出错
!!! WARNING The following tests failed: *** [err]: PEXPIRE/PSETEX/PEXPIREAT can set sub-second expires in tests/unit/expire.tcl Expected 'somevalue {}' to equal or match '{} {}' Cleanup: may take some time... OK Makefile:262: recipe for target 'test' failed make[1]: *** [test] Error 1 make[1]: Leaving directory '/app/redis-5.0.5/src' Makefile:6: recipe for target 'test' failed make: *** [test] Error 2 某些操作性需要更多的时间,修改tests/unit/expire.tcl tags {"slow"} { test {EXPIRE - After 2.1 seconds the key should no longer be here} { after 21000 # 这里加个0 list [r get x] [r exists x] } {{} 0} } test {EXPIRE - write on expire should work} { r del x r lpush x foo r expire x 10000 # 这里加个0 r lpush x bar r lrange x 0 -1 } {bar foo} # 如下输出安装成功 \o/ All tests passed without errors! Cleanup: may take some time... OK make[1]: Leaving directory '/app/redis-5.0.5/src'
配置
mkdir -p /data/redis/log mkdir -p /data/redis/dir mkdir -p /data/redis/run cd /usr/local/redis mkdir conf vim conf/6379
配置文件如下
bind 10.13.6.21 protected-mode yes port 6379 tcp-backlog 511 timeout 0 tcp-keepalive 300 daemonize yes supervised no pidfile /data/redis/run/redis_6379.pid loglevel notice logfile "/data/redis/log/6379.log" databases 16 always-show-logo yes save 900 1 save 300 10 save 60 10000 stop-writes-on-bgsave-error yes rdbcompression yes rdbchecksum yes dbfilename dump_6379.rdb dir /data/redis/dir replica-serve-stale-data yes replica-read-only yes repl-diskless-sync no repl-diskless-sync-delay 5 repl-disable-tcp-nodelay no replica-priority 100 lazyfree-lazy-eviction no lazyfree-lazy-expire no lazyfree-lazy-server-del no replica-lazy-flush no appendonly yes appendfilename "appendonly_6379.aof" appendfsync everysec no-appendfsync-on-rewrite no auto-aof-rewrite-percentage 100 auto-aof-rewrite-min-size 64mb aof-load-truncated yes aof-use-rdb-preamble 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 stream-node-max-bytes 4096 stream-node-max-entries 100 activerehashing yes client-output-buffer-limit normal 0 0 0 client-output-buffer-limit replica 256mb 64mb 60 client-output-buffer-limit pubsub 32mb 8mb 60 hz 10 dynamic-hz yes aof-rewrite-incremental-fsync yes rdb-save-incremental-fsync yes slave-priority 100
启动
/usr/local/bin/redis-server /usr/local/redis/conf/6379 --daemonize no # 启动后会报如下警告 3195:M 15 Sep 2019 22:17:50.852 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128. 3195:M 15 Sep 2019 22:17:50.852 # Server initialized 3195:M 15 Sep 2019 22:17:50.852 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect. 3195:M 15 Sep 2019 22:17:50.852 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled. 3195:M 15 Sep 2019 22:17:50.852 * Ready to accept connections #安装提示解决即可 # 解决第一个,第二个 vim /etc/sysctl.conf 添加 net.core.somaxconn = 1024 vm.overcommit_memory = 1 # 生效 sysctl -p # 解决第三个 # shell执行,重启会失效 echo never > /sys/kernel/mm/transparent_hugepage/enabled # 永久生效 vim /etc/rc.local 添加 echo never > /sys/kernel/mm/transparent_hugepage/enabled
加入systemctl
vim /etc/systemd/system/redis.service systemctl daemon-reload systemctl enable redis.service systemctl start redis # 内容如下 root@redis-node1:/data/redis# cat /etc/systemd/system/redis.service [Unit] Description=Redis In-Memory Data Store After=network.target [Service] User=root Group=root ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/conf/6379 --daemonize no ExecStop=/usr/local/redis/bin/redis-cli -h 10.13.6.21 -p 6379 shutdown Restart=always [Install] WantedBy=multi-user.target
客户端测试
root@redis-node1:/data/redis# redis-cli -h 10.13.6.21 -p 6379 10.13.6.21:6379> keys * (empty list or set) 10.13.6.21:6379> info replication # Replication role:master connected_slaves:0 master_replid:98832eb375d0399255e1094bf546c88efb8ccd97 master_replid2:0000000000000000000000000000000000000000 master_repl_offset:0 second_repl_offset:-1 repl_backlog_active:0 repl_backlog_size:1048576 repl_backlog_first_byte_offset:0 repl_backlog_histlen:0
安装主从模式
主从模式 - slave安装方式同上,配置文件略有不同
slaveof 10.13.6.21 6379 slave-priority 90
完整配置
bind 10.13.6.22 protected-mode yes port 6379 tcp-backlog 511 timeout 0 tcp-keepalive 300 daemonize yes supervised no pidfile /data/redis/run/redis_6379.pid loglevel notice logfile "/data/redis/log/6379.log" databases 16 always-show-logo yes save 900 1 save 300 10 save 60 10000 stop-writes-on-bgsave-error yes rdbcompression yes rdbchecksum yes dbfilename dump_6379.rdb dir /data/redis/dir replica-serve-stale-data yes replica-read-only yes repl-diskless-sync no repl-diskless-sync-delay 5 repl-disable-tcp-nodelay no replica-priority 100 lazyfree-lazy-eviction no lazyfree-lazy-expire no lazyfree-lazy-server-del no replica-lazy-flush no appendonly yes appendfilename "appendonly_6379.aof" appendfsync everysec no-appendfsync-on-rewrite no auto-aof-rewrite-percentage 100 auto-aof-rewrite-min-size 64mb aof-load-truncated yes aof-use-rdb-preamble 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 stream-node-max-bytes 4096 stream-node-max-entries 100 activerehashing yes client-output-buffer-limit normal 0 0 0 client-output-buffer-limit replica 256mb 64mb 60 client-output-buffer-limit pubsub 32mb 8mb 60 hz 10 dynamic-hz yes aof-rewrite-incremental-fsync yes rdb-save-incremental-fsync yes slaveof 10.13.6.21 6379 slave-priority 90
主从测试
10.13.6.21:6379> info replication # Replication role:master connected_slaves:2 slave0:ip=10.13.6.22,port=7000,state=online,offset=168,lag=0 slave1:ip=10.13.6.22,port=7001,state=online,offset=168,lag=1 master_replid:ee4636f02a76df701b61507656c833de3cde259e master_replid2:0000000000000000000000000000000000000000 master_repl_offset:168 second_repl_offset:-1 repl_backlog_active:1 repl_backlog_size:1048576 repl_backlog_first_byte_offset:1 repl_backlog_histlen:168 10.13.6.21:6379> exit
可以看到connected_slaces为2
感谢各位的阅读,以上就是“ubuntu16.04怎么安装redis主从集群”的内容了,经过本文的学习后,相信大家对ubuntu16.04怎么安装redis主从集群这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是创新互联,小编将为大家推送更多相关知识点的文章,欢迎关注!
本文标题:ubuntu16.04怎么安装redis主从集群
分享路径:http://pwwzsj.com/article/gedcoi.html