Linux下Redis配置全攻略,高效稳定部署,网友力荐:小白也能轻松上手

文章导读
第一步:安装Redis。yum install -y gcc gcc-c++ make wget。wget http://download.redis.io/releases/redis-6.2.6.tar.gz。tar -zxvf redis-6.2.6.tar.gz。cd redis-6.2.6。make && make install。
📋 目录
  1. 基础配置
  2. 性能优化
  3. 安全设置
  4. 持久化配置
  5. 启动服务
  6. 哨兵模式
  7. 集群配置
A A

第一步:安装Redis。yum install -y gcc gcc-c++ make wget。wget http://download.redis.io/releases/redis-6.2.6.tar.gz。tar -zxvf redis-6.2.6.tar.gz。cd redis-6.2.6。make && make install。

基础配置

cp redis.conf /etc/redis.conf。vi /etc/redis.conf。bind 127.0.0.1 改为 bind 0.0.0.0。protected-mode no。port 6379。daemonize yes。pidfile /var/run/redis_6379.pid。logfile "/var/log/redis_6379.log"。dir /var/lib/redis/。

性能优化

maxmemory 2gb。maxmemory-policy allkeys-lru。tcp-keepalive 300。timeout 0。tcp-backlog 511。databases 16。

安全设置

requirepass yourpassword。rename-command FLUSHALL ""。rename-command FLUSHDB ""。rename-command CONFIG ""。

Linux下Redis配置全攻略,高效稳定部署,网友力荐:小白也能轻松上手

持久化配置

save 900 1。save 300 10。save 60 10000。appendonly yes。appendfsync everysec。

启动服务

mkdir -p /var/lib/redis /var/log/redis。redis-server /etc/redis.conf。systemctl daemon-reload。systemctl start redis。systemctl enable redis。

哨兵模式

sentinel monitor mymaster 127.0.0.1 6379 2。sentinel down-after-milliseconds mymaster 5000。sentinel failover-timeout mymaster 60000。

Linux下Redis配置全攻略,高效稳定部署,网友力荐:小白也能轻松上手

集群配置

cluster-enabled yes。cluster-config-file nodes.conf。cluster-node-timeout 15000。cluster-slave-validity-factor 10。cluster-migration-barrier 1。

Q: Redis怎么设置密码?
A: 在redis.conf中添加requirepass yourpassword,然后重启。

Linux下Redis配置全攻略,高效稳定部署,网友力荐:小白也能轻松上手

Q: 怎么查看Redis内存使用?
A: redis-cli info memory。

Q: 持久化怎么配置?
A: 配置save和appendonly yes。

Q: 怎么开机自启?
A: systemctl enable redis。