溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

ubuntu16.04怎么安裝redis主從集群

發(fā)布時(shí)間:2021-06-23 10:55:02 來源:億速云 閱讀:257 作者:chen 欄目:大數(shù)據(jù)

這篇文章主要講解了“ubuntu16.04怎么安裝redis主從集群”,文中的講解內(nèi)容簡(jiǎn)單清晰,易于學(xué)習(xí)與理解,下面請(qǐng)大家跟著小編的思路慢慢深入,一起來研究和學(xué)習(xí)“ubuntu16.04怎么安裝redis主從集群”吧!

安裝單機(jī)版

前置環(huán)境

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出錯(cuò)

!!! 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

某些操作性需要更多的時(shí)間,修改tests/unit/expire.tcl
tags {"slow"} {
        test {EXPIRE - After 2.1 seconds the key should no longer be here} {
            after 21000  # 這里加個(gè)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  # 這里加個(gè)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

啟動(dòng)

/usr/local/bin/redis-server /usr/local/redis/conf/6379 --daemonize no

# 啟動(dòng)后會(huì)報(bào)如下警告
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


#安裝提示解決即可

# 解決第一個(gè),第二個(gè)
vim /etc/sysctl.conf
添加
net.core.somaxconn = 1024
vm.overcommit_memory = 1

# 生效
sysctl -p

# 解決第三個(gè)
# shell執(zhí)行,重啟會(huì)失效
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

# 內(nèi)容如下
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

客戶端測(cè)試

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

主從測(cè)試

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主從集群”的內(nèi)容了,經(jīng)過本文的學(xué)習(xí)后,相信大家對(duì)ubuntu16.04怎么安裝redis主從集群這一問題有了更深刻的體會(huì),具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是億速云,小編將為大家推送更多相關(guān)知識(shí)點(diǎn)的文章,歡迎關(guān)注!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI