独立安装
# 安装wget
[root@192 tools]# yum install -y wget
# 下载Redis
[root@192 tools]# wget https://download.redis.io/redis-stable.tar.gz
# 解压Redis
[root@192 tools]# tar -xzvf redis-stable.tar.gz
# 安装插件
[root@192 tools]# yum install -y devtoolset-7-gcc*
[root@192 tools]# yum install -y centos-release-scl
[root@192 tools]# yum install -y gcc-c++
# 编译&安装
[root@192 opt]# cd redis-stable/
[root@192 redis-stable]# make & make install
# 测试服务,理论上这边是可以成功的
[root@192 redis-stable]# redis-server
# 添加守护service
[root@192 redis-stable]# vim /etc/systemd/system/redis.service
[root@192 redis-stable]# cat /etc/systemd/system/redis.service
[Unit]
Description=redis-server
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/bin/redis-server /opt/redis-stable/redis.conf
PrivateTmp=true
[Install]
WantedBy=multi-user.target
# 修改配置文件,主要修改以下内容
[root@192 redis-stable]# vim redis.conf
bind 0.0.0.0
daemonize yes
requirepass vicbaily528@163
# 启动守护进程服务
[root@192 redis-stable]# systemctl daemon-reload
[root@192 redis-stable]# systemctl enable redis
[root@192 redis-stable]# systemctl start redis
# 开启防火墙
[root@192 redis-stable]# firewall-cmd --permanent --add-port=6379/tcp
[root@192 redis-stable]# firewall-cmd --reload
Docker安装
# 创建文件夹
mkdir -p /mydata/redis/conf
touch /mydata/redis/conf/redis.conf
# 下载镜像
docker pull redis
# 创建实例
docker run -p 6379:6379 --name redis -v /mydata/redis/data:/data \
-v /mydata/redis/conf/redis.conf:/etc/redis/redis.conf \
-d redis redis-server /etc/redis/redis.conf
# 在conf文件中增加以下内容
################################## NETWORK #####################################
bind 0.0.0.0
protected-mode yes
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300
################################# GENERAL #####################################
daemonize no
supervised no
pidfile /var/run/redis_6379.pid
loglevel notice
logfile ""
databases 16
always-show-logo yes
################################ SNAPSHOTTING ################################
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir ./
################################# REPLICATION #################################
slave-serve-stale-data yes
slave-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
slave-priority 100
############################# LAZY FREEING ####################################
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
slave-lazy-flush no
############################## APPEND ONLY MODE ###############################
appendonly no
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 no
################################ LUA SCRIPTING ###############################
lua-time-limit 5000
################################## SLOW LOG ###################################
slowlog-log-slower-than 10000
slowlog-max-len 128
################################ LATENCY MONITOR ##############################
latency-monitor-threshold 0
############################# EVENT NOTIFICATION ##############################
notify-keyspace-events ""
############################### ADVANCED CONFIG ###############################
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
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
aof-rewrite-incremental-fsync yes
# 客户端链接
docker exec -it redis redis-cli