下载构建

  1. mkdir -p /home/packages && cd /home/packages
  2. curl -O https://download.redis.io/releases/redis-6.2.6.tar.gz
  3. tar -zxvf redis-6.2.6.tar.gz
  4. cd redis-6.2.6
  5. make install PREFIX=/home/redis
  6. cp redis.conf /home/redis/
  7. cp sentinel.conf /home/redis/

修改配置

  1. sed -i 's/bind 127.0.0.1/bind 0.0.0.0/g' /home/redis/redis.conf
  2. sed -i 's/protected-mode yes/protected-mode no/g' /home/redis/redis.conf
  3. sed -i 's/daemonize no/daemonize yes/g' /home/redis/redis.conf
  4. # 下方语句修改redis访问密码
  5. sed -i 's/# requirepass foobared/requirepass password/g' /home/redis/redis.conf

服务化启动

  1. tee /usr/lib/systemd/system/redis.service <<- 'EOF'
  2. [Unit]
  3. Description=redis-server
  4. After=network.target
  5. Before=redis-sentinel.service
  6. [Service]
  7. Type=forking
  8. ExecStart=/home/redis/bin/redis-server /home/redis/redis.conf
  9. PrivateTmp=true
  10. [Install]
  11. WantedBy=multi-user.target
  12. EOF
  13. tee /usr/lib/systemd/system/redis-sentinel.service <<- 'EOF'
  14. [Unit]
  15. Description=redis-sentinel
  16. After=network.target redis.service
  17. Requires=redis.service
  18. BindTo=redis.service
  19. [Service]
  20. Type=forking
  21. ExecStart=/home/redis/bin/redis-server /home/redis/sentinel.conf --sentinel
  22. PrivateTmp=true
  23. [Install]
  24. WantedBy=multi-user.target
  25. EOF
  26. systemctl daemon-reload
  27. systemctl enable --now redis
  28. systemctl status redis