redis-6.0.13安装
- 1.创建安装目录
- 2. 上传安装包
- 3. 替换repo文件
- 4.依赖安装
- 5. redis安装
- 5.1 解压
- 5.2 编译
- 5.3 安装
- 5.4 配置
- 6. 常用命令
1.创建安装目录
mkdir -p /apps/scripts/
cd /apps/scripts/
2. 上传安装包
将redis-6.0.13.tar.gz 上传至/apps/scripts/目录下
下载链接:https://github.com/redis/redis/archive/refs/tags/6.0.13.tar.gz
若服务器中存在wget命令,可以使用wget https://github.com/redis/redis/archive/refs/tags/6.0.13.tar.gz直接从互联网拉取
3. 替换repo文件
由于自带的yum源无法使用,故需要替换为国内源
1. 备份原始repo文件
cd /etc/yum.repos.d/
mkdir bak
mv CentOS-* bak/
2.创建CentOS-Base.repo文件
1)若服务器有wget命令,可复制命令直接从互联网拉取阿里配置源到服务器
wget https://mirrors.aliyun.com/repo/Centos-7.repo -O /etc/yum.repos.d/CentOS-Base.repo
2)若服务器为没有wget命令,可以直接在/etc/yum.repos.d/目录下,创建名称为CentOS-Base.repo的文件,把下述内容复制到配置文件中
3.清除缓存并重新创建缓存
yum clean all
yum makecache
CentOS-Base.repo文件全内容如下
4.依赖安装
yum -y install cpp binutils glibc glibc-kernheaders glibc-common glibc-devel gcc bzip2
5. redis安装
5.1 解压
cd /apps/scripts/
tar -zxf redis-6.0.13.tar.gz
5.2 编译
cd redis-6.0.13
make
# 部署redis 6版本依赖与gcc 5.3以上,若gcc版本太低,在编译过程中会报错
# 升级gcc可参考博客:https://blog.csdn.net/ym5209999/article/details/142355493
5.3 安装
make install
安装完成后,默认目录为:/usr/local/bin/
5.4 配置
1. 将redis复制到/apps/redis/目录下
mkdir /apps/redis/
cp /usr/local/bin/redis-* /apps/redis/
2. 复制redis.conf到/apps/redis/目录下
cp /apps/scripts/redis-6.0.13/redis.conf /apps/redis/
3. 按需修改redis.conf
cd /apps/redis/
vim redis.conf
修改以下参数:
bind 192.168.2.65 //监听的网卡地址,改为实际内网ip地址
port 6379 //服务监听端口
daemonize yes //以独立进程打开
#logfile //关闭redis日志
appendonly no //关闭AOF持久化
requirepass ABCabc123 //配置redis密码,根据需要修改
配置完后,redis.conf内容如下
[root@localhost redis]# cat redis.conf | grep -v "#" | grep -v "^$"
bind 192.168.2.65
protected-mode yes
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize yes
supervised no
pidfile /var/run/redis_6379.pid
loglevel notice
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
rdb-del-sync-files no
dir ./
replica-serve-stale-data yes
replica-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-diskless-load disabled
repl-disable-tcp-nodelay no
replica-priority 100
acllog-max-len 128
requirepass ABCabc123
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
replica-lazy-flush no
lazyfree-lazy-user-del no
oom-score-adj no
oom-score-adj-values 0 200 800
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 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
jemalloc-bg-thread yes
6. 常用命令
启动redis实例
/apps/redis/redis-server /apps/redis/redis.conf
停止redis实例
方法一:连接redis后命令停止
redis-cli -h 192.168.2.65 -a ABCabc123
连接后输入:shutdown
方法二:查出进程号直接停止
ps -ef | grep redis
查出进程pid数字,执行kill -9 进程pid数字