CentOS 7 安装 Redis

Yum 安装方式 - 推荐

# yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
# yum -y install https://rpms.remirepo.net/enterprise/remi-release-7.rpm
# yum-config-manager --enable remi
# yum install -y redis
# systemctl enable redis && sudo systemctl start redis

编译安装方式 - 可选

# wget http://download.redis.io/releases/redis-5.0.7.tar.gz
# tar -zxvf redis-5.0.7.tar.gz -C /usr/local
# mv redis-5.0.7/ redis
# cd redis/
# make MALLOC=libc
# cd src && make install
  • 修改redis.conf,服务器安装一点注意修改redis连接密码
# vim /usr/local/redis/redis.conf
# 修改对应配置值
bind 0.0.0.0 # Redis默认localhost访问,修改后可远程连接
protected-mode no
daemonize no
requirepass yourpassword #添加此项,设置redis连接密码,服务器必须设置
  • 设置软链接
# ln -s /usr/local/redis/src/redis-server /usr/bin/redis-server
# ln -s /usr/local/redis/src/redis-sentinel /usr/bin/redis-sentinel
  • 启动redis
# nohup redis-server /usr/local/redis/redis.conf &
  • 启动哨兵模式
# nohup redis-sentinel /usr/local/redis/sentinel.conf &
  • 设置 redis 开机自启动
  • 在/etc目录下新建redis目录
# mkdir redis
  • 将/usr/local/redis/redis.conf 文件复制一份到/etc/redis目录下,并命名为6379.conf
# cp /usr/local/redis/redis.conf /etc/redis/6379.conf
  • 将redis的启动脚本复制一份放到/etc/init.d目录下
# cp /usr/local/redis/utils/redis_init_script /etc/init.d/redisd
  • 切换到/etc/init.d目录下,执行自启命令
# chkconfig redisd on
  • 启动 Redis
# service redisd start
若出现:service redisd does not support chkconfig
使用vim编辑redisd文件,在第一行加入如下两行注释,保存退出

# vim /etc/init.d/redisd

# chkconfig:   2345 90 10
# description:  Redis is a persistent key-value database

Redis完整配置

bind 127.0.0.1
protected-mode no
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize yes
supervised no
pidfile /var/run/redis_6379.pid
loglevel notice
logfile ""
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.rdb
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
requirepass 123456
maxmemory-policy volatile-lru
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
replica-lazy-flush no
appendonly yes
appendfilename "appendonly.aof"
appendfsync always
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


标题:CentOS 7 安装 Redis
作者:Mune
地址:https://cnxiaobai.com/articles/2021/04/21/1619003077564.html

    评论
    0 评论
avatar

取消