更新时间:2024-04-23 GMT+08:00
分享

Redis部署

登录云服务器ECS

创建命名空间

# kubectl create ns applife
# kubectl create ns daas
# kubectl create ns daas-web
# kubectl create ns kong
# kubectl create ns openkube
# kubectl create ns nfs

RedisGraph安装

安装路径约定,安装机器:中间件服务器

安装目录:/opt/redis-6.0.0

配置文件:/opt/redis-6.0.0/config/redis.conf 和 /opt/redis-6.0.0/config/sentinel/sentinel.conf

数据目录:/data/redis-6.0.0/data

日志目录:/data/redis-6.0.0/logs

插件目录:/opt/redis-6.0.0/modules/redisgraph.so

安装Redis主从

  1. 解压,上传压缩包redis-6.0.0-linux.tar.gz到/soft/redis并解压
    # tar -vxf redis-6.0.0-linux.tar.gz
    # mv redis-6.0.0 /opt
    # mkdir /opt/redis-6.0.0/bin
    # cd /opt/redis-6.0.0/src
    # cp redis-benchmark redis-check-aof redis-check-rdb redis-cli redis-sentinel redis-server -t ../bin/
  2. 创建数据目录及授权
    # mkdir -p /data/redis-6.0.0/{data,logs}
    # chmod 755 /opt/redis-6.0.0/modules/redisgraph.so

    redisgraph.so要授权可执行,否则会导致redis启动失败。

  3. 配置环境变量
    # vim /etc/profile
    export REDIS_HOME=/opt/redis-6.0.0
    export PATH=$REDIS_HOME/bin:$PATH
    图1 配置环境变量
  4. 新增主redis配置文件

    /opt/redis-6.0.0/config/redis.conf文件不存在,注意文件不要有特殊空格字符,踩过坑!

    # vim /opt/redis-6.0.0/config/redis.conf
    bind 0.0.0.0
    port 6379
    daemonize yes
    pidfile /var/run/redis.pid
    loglevel notice
    logfile /data/redis-6.0.0/logs/redis.log
    dir /data/redis-6.0.0/data
    masterauth Mypwd@123456
    requirepass Mypwd@123456
    appendonly yes
    loadmodule /opt/redis-6.0.0/modules/redisgraph.so
    # 确保有1个从节点写入,且延时不超过10s,否则主节点会停止写入请求(防止数据丢失)
    min-replicas-to-write 1
    min-replicas-max-lag 10
  5. 新增从redis配置文件

    在安装redis-slave机器上,重复上面5.4.2.1 到5.4.2.4过程,并使用下面配置。

    如果/opt/redis-6.0.0/config/redis.conf文件不存在就新增。

    # vim /opt/redis-6.0.0/config/redis.conf
    bind 0.0.0.0
    port 6379
    daemonize yes
    pidfile /var/run/redis.pid
    loglevel notice
    logfile /data/redis-6.0.0/logs/redis.log
    dir /data/redis-6.0.0/data
    masterauth Mypwd@123456
    requirepass Mypwd@123456
    appendonly yes
    loadmodule /opt/redis-6.0.0/modules/redisgraph.so
    # 确保有1个从节点写入,且延时不超过10s,否则主节点会停止写入请求(防止数据丢失)
    min-replicas-to-write 1
    min-replicas-max-lag 10
    #配置连接主redis
    replicaof 192.168.0.82 6379
  6. 启动redis-server

    分别在主从创建redis-server系统启动文件

    # vim /etc/systemd/system/redis-server.service
    [Unit]
    Description=redis
    After=network.target
    [Service]
    Type=forking
    PIDFile=/var/run/redis.pid
    ExecStart=/opt/redis-6.0.0/bin/redis-server /opt/redis-6.0.0/config/redis.conf
    ExecStop=/opt/redis-6.0.0/bin/redis-cli -h 127.0.0.1 -p 6379 shutdown
    PrivateTmp=true
    [Install]
    WantedBy=multi-user.target
  7. 重新加载systemctl配置
    # systemctl daemon-reload
  8. 设置跟随linux启动,并启动es
    # systemctl start redis-server && systemctl enable redis-server
  9. 查看redis角色
    # redis-cli -h 192.168.0.82 -p 6379 -a Mypwd@123456 INFO | grep role

配置哨兵

  1. 创建哨兵数据目录
    # mkdir /data/redis-6.0.0/data/sentinel
  2. 新增配置文件
    # vim /opt/redis-6.0.0/config/sentinel/sentinel.conf
  3. 分别在主从redis创建sentinel配置文件(3个实例一样)
    port 16379
    daemonize yes
    pidfile /var/run/redis-sentinel.pid
    logfile /data/redis-6.0.0/logs/sentinel.log
    dir /data/redis-6.0.0/data/sentinel
    sentinel deny-scripts-reconfig yes
    #配置主redis的地址,“2”表示集群中有2个Sentinel认为master退出了就切换
    sentinel monitor redisMaster 192.168.0.82 6379 2
    sentinel auth-pass redisMaster Mypwd@123456
    sentinel config-epoch redisMaster 1
    sentinel leader-epoch redisMaster 1
  4. 启动哨兵,分别在主从redis创建redis-sentinel系统启动文件
    # vim /etc/systemd/system/redis-sentinel.service
    [Unit]
    Description=The redis-sentinel Process Manager
    After=syslog.target network.target
    [Service]
    Type=forking
    PIDFile=/var/run/redis-sentinel.pid
    ExecStart=/opt/redis-6.0.0/bin/redis-sentinel /opt/redis-6.0.0/config/sentinel/sentinel.conf
    ExecStop=/opt/redis-6.0.0/bin/redis-cli -h 127.0.0.1 -p 16379 shundown
    PrivateTmp=true
    [Install]
    WantedBy=multi-user.target
  5. 重新加载systemctl配置
    # systemctl daemon-reload
  6. 设置跟随linux启动,并启动es
    # systemctl start redis-sentinel && systemctl enable redis-sentinel
  7. 查看启动日志
    # cat /data/redis-6.0.0/logs/sentinel.log
    图2 查看启动日志
  8. 检查redis主从状态
    # redis-cli -h 127.0.0.1 -p 6379 -a Mypwd@123456 info replication
    图3 查看启动日志
    # Replication
    role:master          #角色master或者slave
    connected_slaves:2    #连接的slave个数
    min_slaves_good_slaves:2
    slave0:ip=192.168.0.228 ,port=6379,state=online,offset=288218,lag=0   #slave1节点信息
    slave1:ip=192.168.0.56,port=6379,state=online,offset=288078,lag=1   #slave2节点信息
    master_replid:2ac8c63f0185a38189010b192e42b761e69f549a
    master_replid2:4490ff668a9d41d5636e6a382ff1e80ca31892cf
    master_repl_offset:288218
    master_repl_meaningful_offset:288218
    second_repl_offset:69703
    repl_backlog_active:1
    repl_backlog_size:1048576
    repl_backlog_first_byte_offset:1
    repl_backlog_histlen:288218

相关文档