首页 > 数据库 >编译安装redis6.2.13集群-哨兵模式

编译安装redis6.2.13集群-哨兵模式

时间:2023-07-19 14:22:38浏览次数:33  
标签:redis6.2 13 no max redis 编译 sentinel yes true

下载并编译Redis

虽然使用SLES15进行编译,但是理论上在其它系统上也是可行的,我们把编译所需要的依赖包安装即可。

Redis我们选择6.2.13这个版本, 我们先随便找个节点进行编译产生二进制文件

#首先安装依赖包
zypper ref && zypper install gcc make systemd-devel    #SLES/SUSE
yum install gcc make systemd-devel                     #CentOS
apt install gcc make libsystemd-dev                    #Debian
#下载解压编译
curl -LO https://download.redis.io/releases/redis-6.2.13.tar.gz
tar -zcf redis-6.2.13.tar.gz
cd redis-6.2.13
make BUILD_WITH_SYSTEMD=yes USE_SYSTEMD=yes MALLOC=libc
#重新tar下包,在其它机器上直接使用
cd ..
mv redis-6.2.13 redis-6.2.13-bin
tar -zcf redis-6.2.13-bin.tgz redis-6.2.13-bin

安装哨兵集群

集群节点信息

IP ROLE Port
192.168.168.121 Master 6379 + 26379
192.168.168.122 Slave 6379 + 26379
192.168.168.123 Slave 6379 + 26379

将上面的redis-6.2.13-bin.tgz拷贝并上传到上面的所有节点,并在所有节点执行下面的命令

#使用非root用户运行redis
groupadd -r redis
useradd -r -s /sbin/nologin -d /var/lib/redis -g redis -c 'Redis Server Account' redis
mkdir /var/lib/redis /var/log/redis /etc/redis
#解压redis-6.2.13-bin.tgz并分发文件
cd redis-6.2.13-bin/src
cp redis-server redis-sentinel redis-cli redis-benchmark redis-check-aof redis-check-rdb redis-trib.rb /usr/bin/
touch /etc/redis/redis.conf /etc/redis/sentinel.conf
chown -Rf redis:redis /etc/redis /var/lib/redis /var/log/redis

配置redis服务自启动和redis-sentinel服务自启动, 我们使用systemd管理服务的启动与停止,在所有节点执行下面的动作

新增/usr/lib/systemd/system/redis-server.service, 增加下面的内容

[Unit]
Description=Advanced key-value store
After=network.target
Documentation=http://redis.io/documentation, man:redis-server(1)

[Service]
Type=notify
ExecStart=/usr/bin/redis-server /etc/redis/redis.conf
ExecStop=/bin/kill -s TERM $MAINPID
PIDFile=/run/redis/redis.pid
TimeoutStopSec=0
Restart=always
User=redis
Group=redis
RuntimeDirectory=redis
RuntimeDirectoryMode=2755

UMask=007
PrivateTmp=yes
LimitNOFILE=65535
PrivateDevices=yes
ProtectHome=yes
ReadOnlyDirectories=/
ReadWriteDirectories=-/var/lib/redis
ReadWriteDirectories=-/var/log/redis
ReadWriteDirectories=-/run/redis

NoNewPrivileges=true
CapabilityBoundingSet=CAP_SETGID CAP_SETUID CAP_SYS_RESOURCE
RestrictAddressFamilies=AF_INET AF_INET6 AF_UNIX
MemoryDenyWriteExecute=true
ProtectKernelModules=true
ProtectKernelTunables=true
ProtectControlGroups=true
RestrictRealtime=true
RestrictNamespaces=true

# redis-server can write to its own config file when in cluster mode so we
# permit writing there by default. If you are not using this feature, it is
# recommended that you replace the following lines with "ProtectSystem=full".
ProtectSystem=true
ReadWriteDirectories=-/etc/redis

[Install]
WantedBy=multi-user.target

新增/usr/lib/systemd/system/redis-sentinel.service, 增加下面的内容

[Unit]
Description=Advanced key-value store
After=network.target redis.service
Documentation=http://redis.io/documentation, man:redis-sentinel(1)

[Service]
Type=notify
ExecStart=/usr/bin/redis-sentinel /etc/redis/sentinel.conf
ExecStop=/bin/kill -s TERM $MAINPID
PIDFile=/run/sentinel/redis-sentinel.pid
TimeoutStopSec=0
Restart=always
User=redis
Group=redis
RuntimeDirectory=sentinel
RuntimeDirectoryMode=2755

UMask=007
PrivateTmp=yes
LimitNOFILE=65535
PrivateDevices=yes
ProtectHome=yes
ReadOnlyDirectories=/
ReadWriteDirectories=-/var/lib/redis
ReadWriteDirectories=-/var/log/redis
ReadWriteDirectories=-/run/sentinel

NoNewPrivileges=true
CapabilityBoundingSet=CAP_SETGID CAP_SETUID CAP_SYS_RESOURCE
RestrictAddressFamilies=AF_INET AF_INET6 AF_UNIX
MemoryDenyWriteExecute=true
ProtectKernelModules=true
ProtectKernelTunables=true
ProtectControlGroups=true
RestrictRealtime=true
RestrictNamespaces=true

# redis-sentinel can write to its own config file when in cluster mode so we
# permit writing there by default. If you are not using this feature, it is
# recommended that you replace the following lines with "ProtectSystem=full".
ProtectSystem=true
ReadWriteDirectories=-/etc/redis

[Install]
WantedBy=multi-user.target

配置Master

在Mater节点,编辑/etc/redis/redis.conf 文件, 清理原先内容,增加下面的内容

bind 0.0.0.0
protected-mode yes
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize yes
supervised systemd
pidfile /run/redis/redis.pid
loglevel notice
logfile "/var/log/redis/redis.log"
databases 16
always-show-logo no
set-proc-title yes
proc-title-template "{title} {listen-addr} {server-mode}"
save 900 1
save 300 100
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
rdb-del-sync-files no
dir /var/lib/redis
masterauth 123456
replica-serve-stale-data yes
replica-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-diskless-load disabled
repl-disable-tcp-nodelay no
replica-priority 100
min-replicas-to-write 1
acllog-max-len 128
requirepass 123456
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
replica-lazy-flush no
lazyfree-lazy-user-del no
lazyfree-lazy-user-flush no
oom-score-adj no
oom-score-adj-values 0 200 800
disable-thp yes
appendonly yes
appendfilename "appendonly.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
jemalloc-bg-thread yes

配置Slave

在所有Slave节点,编辑/etc/redis/redis.conf 文件, 清理原先内容,增加下面的内容

bind 0.0.0.0
protected-mode yes
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize yes
supervised systemd
pidfile /run/redis/redis.pid
loglevel notice
logfile "/var/log/redis/redis.log"
databases 16
always-show-logo no
set-proc-title yes
proc-title-template "{title} {listen-addr} {server-mode}"
save 900 1
save 300 100
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
rdb-del-sync-files no
dir /var/lib/redis
replicaof 192.168.168.121 6379
masterauth 123456
replica-serve-stale-data yes
replica-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-diskless-load disabled
repl-disable-tcp-nodelay no
replica-priority 100
min-replicas-to-write 1
acllog-max-len 128
requirepass 123456
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
replica-lazy-flush no
lazyfree-lazy-user-del no
lazyfree-lazy-user-flush no
oom-score-adj no
oom-score-adj-values 0 200 800
disable-thp yes
appendonly yes
appendfilename "appendonly.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
jemalloc-bg-thread yes

配置哨兵

在所有节点,编辑/etc/redis/redis-sentinel.conf 文件, 清理原先内容,增加下面的内容

port 26379
daemonize yes
supervised systemd
pidfile /run/sentinel/redis-sentinel.pid
logfile "/var/log/redis/redis-sentinel.log"
dir /var/lib/redis
sentinel monitor mymaster 192.168.168.121 6379 2
sentinel auth-pass mymaster 123456
sentinel down-after-milliseconds mymaster 30000
acllog-max-len 128
sentinel parallel-syncs mymaster 1
sentinel failover-timeout mymaster 180000
sentinel deny-scripts-reconfig yes
SENTINEL resolve-hostnames no
SENTINEL announce-hostnames no

启动集群

# 先启动master上的redis, 再启动slave上的redis
systemctl enable --now redis-server.service
# 在所有节点启动redis-sentinel哨兵
systemctl enable --now redis-sentinel.service

标签:redis6.2,13,no,max,redis,编译,sentinel,yes,true
From: https://www.cnblogs.com/zhaojli/p/17565453.html

相关文章

  • 编译安装最新的Pluto compiler,以及遇到的一些坑
    好久不见!这段时间在鼓捣一些奇奇怪怪的东西。PlutoCompiler是一款非常优秀的Polyhedral编译器。这玩意拿来优化循环和程序局部性啥的是相当好的。其安装过程涉及到整个llvm的编译过程,如果之前并没能够了解llvm的话估计会够呛,我也是基本上把坑踩了一个遍。所以干脆写篇博客给之......
  • 数据中心机房建设,务必确定这13个关键点
    下午好,我的网工朋友。关于机房、机架的相关内容,给你们说了不少。今天再给你补充个知识点,机房建设,要怎么做。熟悉机房建设的网工朋友可能都知道,一个全面的数据中心机房建设工程一般包括:综合布线、抗静电地板铺设、棚顶墙体装修、隔断装修、UPS、专用恒温恒湿空调、机房环境监控系统......
  • 从哪里找到、下载已经预编译好的二进制openjdk文件?
    openjdk在官网上都是源码,在实际使用中,需要直接用到二进制文件 尤其是基于alpine构建openjdk的基础镜像,发现...... 将linux版本的openjdk17的二进制tar.gz包,在alpine中进行解压,是无法运行的,安装glibc之后,也会有问题,很多的时候,会出现版本不匹配的问题,然后,这个问题就真的很难......
  • 苹果系统M系列芯片编译JDK18
    苹果系统M系列芯片编译JDK18MacosAppleSiliconBuildopenJDK为什么编译之前听blindpirate大佬说过,为了解决某个fastjson的bug编译了一下jdk让其报出更详细的异常信息.最近在读<深入理解java虚拟机(第三版周志明)>,第一章就是使用ubuntu18编译个openjdk12,以供接下......
  • nginx中编译安装的的模块介绍
    nginx中编译安装的的模块介绍./configure--prefix=/usr/local/nginx--with-http_dav_module--with-http_stub_status_module--with-http_addition_module--with-http_sub_module--with-http_flv_module--with-http_mp4_module--with-pcre--with-http_ssl_module--with-......
  • day13--23.7.18变量,变量作用域,常量和变量的命名规范
    变量变量是什么:就是可以变化的量Java是一种强类型语言,每个变量都必须声明其类型Java变量是程序中最基本的存储单元,其要素包括变量名,变量类型和作用域typevarName[=value][{,varNam[=value]}];//数据类型变量名=值;可以使用逗号隔开来声明多个同类型变量。每个变......
  • Golang的跨平台编译程序
    Golang支持交叉编译,也就是说你在32位平台的机器上开发,可以编译生成64位平台上的可执行程序。交叉编译依赖下面几个环境变量:$GOARCH  目标平台(编译后的目标平台)的处理器架构(386、amd64、arm)$GOOS     目标平台(编译后的目标平台)的操作系统(darwin、freebsd、linux、wind......
  • C语言多文件编译(vs.code)
    C语言多文件编译(vs.code)1.保证已经进行完第一步:配置C语言环境如果还未进行,建议来这里查看2.在扩展商店下载插件C/C++ProjectGeneratorCMakeCMakeTools3.修改settings.json也可以直接用快捷键ctrl+,搜索coderunner并找到ExecutorMap在settings.json中编辑找到......
  • centos7中yum安装gcc编译器11
     001、系统信息[root@PC1software]#cat/etc/system-releaseCentOSLinuxrelease7.6.1810(Core) 002、当前gcc编译器版本[root@PC1software]#gcc--versiongcc(GCC)4.8.520150623(RedHat4.8.5-36)Copyright(C)2015FreeSoftwareFoundation,Inc.T......
  • 题解 P2137 Gty的妹子树
    神奇的分块。假如没有\(2\)操作,我们可以直接用主席树解决。我们考虑将询问分块,每遍历完一块就将这一块内出现的所有修改更新。如果在块内,就把当前块之前的所有修改暴力算,当然只有修改的节点在询问的节点的子树内才会发生。具体的来说,我们可以用分块维护dfs序,并将块内的元素......