千家信息网

ubuntu16.04怎么安装redis主从集群

发表于:2025-02-05 作者:千家信息网编辑
千家信息网最后更新 2025年02月05日,这篇文章主要讲解了"ubuntu16.04怎么安装redis主从集群",文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习"ubuntu16.04怎么安装red
千家信息网最后更新 2025年02月05日ubuntu16.04怎么安装redis主从集群

这篇文章主要讲解了"ubuntu16.04怎么安装redis主从集群",文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习"ubuntu16.04怎么安装redis主从集群"吧!

安装单机版

前置环境

apt-get updateapt install makeapt install gcc gcc+ build-essential tcl

下载安装

cd /appwget http://download.redis.io/releases/redis-5.0.5.tar.gztar zxvf redis-5.0.5.tar.gzcd redis-5.0.5make MALLOC=libcmake testcd src && make install PREFIX=/usr/local/redis# 安装成功后root@redis-node1:/app/redis-5.0.5/src# make install  PREFIX=/usr/local/redisHint: 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.tclExpected 'somevalue {}' to equal or match '{} {}'Cleanup: may take some time... OKMakefile:262: recipe for target 'test' failedmake[1]: *** [test] Error 1make[1]: Leaving directory '/app/redis-5.0.5/src'Makefile:6: recipe for target 'test' failedmake: *** [test] Error 2某些操作性需要更多的时间,修改tests/unit/expire.tcltags {"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... OKmake[1]: Leaving directory '/app/redis-5.0.5/src'

配置

mkdir -p /data/redis/logmkdir -p /data/redis/dirmkdir -p /data/redis/runcd /usr/local/redismkdir confvim conf/6379

配置文件如下

bind 10.13.6.21protected-mode yesport 6379tcp-backlog 511timeout 0tcp-keepalive 300daemonize yessupervised nopidfile /data/redis/run/redis_6379.pidloglevel noticelogfile "/data/redis/log/6379.log"databases 16always-show-logo yessave 900 1save 300 10save 60 10000stop-writes-on-bgsave-error yesrdbcompression yesrdbchecksum yesdbfilename dump_6379.rdbdir /data/redis/dirreplica-serve-stale-data yesreplica-read-only yesrepl-diskless-sync norepl-diskless-sync-delay 5repl-disable-tcp-nodelay noreplica-priority 100lazyfree-lazy-eviction nolazyfree-lazy-expire nolazyfree-lazy-server-del noreplica-lazy-flush noappendonly yesappendfilename "appendonly_6379.aof"appendfsync everysecno-appendfsync-on-rewrite noauto-aof-rewrite-percentage 100auto-aof-rewrite-min-size 64mbaof-load-truncated yesaof-use-rdb-preamble yeslua-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 3000stream-node-max-bytes 4096stream-node-max-entries 100activerehashing yesclient-output-buffer-limit normal 0 0 0client-output-buffer-limit replica 256mb 64mb 60client-output-buffer-limit pubsub 32mb 8mb 60hz 10dynamic-hz yesaof-rewrite-incremental-fsync yesrdb-save-incremental-fsync yesslave-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 initialized3195: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 = 1024vm.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.servicesystemctl daemon-reloadsystemctl enable redis.servicesystemctl start redis# 内容如下root@redis-node1:/data/redis# cat /etc/systemd/system/redis.service[Unit]Description=Redis In-Memory Data StoreAfter=network.target[Service]User=rootGroup=rootExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/conf/6379 --daemonize noExecStop=/usr/local/redis/bin/redis-cli -h 10.13.6.21 -p 6379 shutdownRestart=always[Install]WantedBy=multi-user.target

客户端测试

root@redis-node1:/data/redis# redis-cli -h 10.13.6.21 -p 637910.13.6.21:6379> keys *(empty list or set)10.13.6.21:6379> info replication# Replicationrole:masterconnected_slaves:0master_replid:98832eb375d0399255e1094bf546c88efb8ccd97master_replid2:0000000000000000000000000000000000000000master_repl_offset:0second_repl_offset:-1repl_backlog_active:0repl_backlog_size:1048576repl_backlog_first_byte_offset:0repl_backlog_histlen:0

安装主从模式

主从模式 - slave安装方式同上,配置文件略有不同

slaveof 10.13.6.21 6379slave-priority 90

完整配置

bind 10.13.6.22protected-mode yesport 6379tcp-backlog 511timeout 0tcp-keepalive 300daemonize yessupervised nopidfile /data/redis/run/redis_6379.pidloglevel noticelogfile "/data/redis/log/6379.log"databases 16always-show-logo yessave 900 1save 300 10save 60 10000stop-writes-on-bgsave-error yesrdbcompression yesrdbchecksum yesdbfilename dump_6379.rdbdir /data/redis/dirreplica-serve-stale-data yesreplica-read-only yesrepl-diskless-sync norepl-diskless-sync-delay 5repl-disable-tcp-nodelay noreplica-priority 100lazyfree-lazy-eviction nolazyfree-lazy-expire nolazyfree-lazy-server-del noreplica-lazy-flush noappendonly yesappendfilename "appendonly_6379.aof"appendfsync everysecno-appendfsync-on-rewrite noauto-aof-rewrite-percentage 100auto-aof-rewrite-min-size 64mbaof-load-truncated yesaof-use-rdb-preamble yeslua-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 3000stream-node-max-bytes 4096stream-node-max-entries 100activerehashing yesclient-output-buffer-limit normal 0 0 0client-output-buffer-limit replica 256mb 64mb 60client-output-buffer-limit pubsub 32mb 8mb 60hz 10dynamic-hz yesaof-rewrite-incremental-fsync yesrdb-save-incremental-fsync yesslaveof 10.13.6.21 6379slave-priority 90

主从测试

10.13.6.21:6379> info replication# Replicationrole:masterconnected_slaves:2slave0:ip=10.13.6.22,port=7000,state=online,offset=168,lag=0slave1:ip=10.13.6.22,port=7001,state=online,offset=168,lag=1master_replid:ee4636f02a76df701b61507656c833de3cde259emaster_replid2:0000000000000000000000000000000000000000master_repl_offset:168second_repl_offset:-1repl_backlog_active:1repl_backlog_size:1048576repl_backlog_first_byte_offset:1repl_backlog_histlen:16810.13.6.21:6379> exit

可以看到connected_slaces为2

感谢各位的阅读,以上就是"ubuntu16.04怎么安装redis主从集群"的内容了,经过本文的学习后,相信大家对ubuntu16.04怎么安装redis主从集群这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是,小编将为大家推送更多相关知识点的文章,欢迎关注!

0