编程开发

Centos下redis的编译安装

2022-06-29  本文已影响0人  升职哦

Centos下redis的安装

一、前置依赖安装

yum install gcc-c++

二、redis的安装

1.安装

redis官网下载地址: http://download.redis.io/releases/

# 下载
cd /usr/local/src
wget http://download.redis.io/releases/redis-6.2.5.tar.gz
tar -zxvf redis-6.2.5.tar.gz 
cd redis-6.2.5/
# 编译安装
# 安装指定/usr/local/redis
make PREFIX=/usr/local/redis install
make install
# redis路径
cd /usr/local/redis
mkdir conf
mkdir data
mkdir logs
cp /usr/local/src/redis-6.2.5/redis.conf /usr/local/redis/conf/

2.配置

redis.conf 配置:

# 远程访问
bind 0.0.0.0
# 是否开启后台运行
daemonize yes
# 是否开启保护模式,默认开启。要是配置里没有指定bind和密码。开启该参数后,redis只会本地进行访问,拒绝外部访问。要是开启了密码和bind,可以开启。否则最好关闭,设置为no。
protected-mode yes
# 端口
port 6379
tcp-backlog 511

timeout 0
tcp-keepalive 300
supervised no
# pid文件地址
pidfile /usr/local/redis/redis.pid
loglevel notice
# redis log地址
logfile /usr/local/redis/logs/redis.log
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
dir /usr/local/redis/data/
slave-serve-stale-data yes
dbfilename dump_6379.rdb


slave-read-only yes


repl-diskless-sync no


repl-disable-tcp-nodelay no

slave-priority 100

# 密码
requirepass 密码


lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
slave-lazy-flush no

appendonly yes


appendfilename "appendonly_6379.aof"


# appendfsync always
appendfsync everysec
# appendfsync no

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-time-limit 5000

slowlog-log-slower-than 10000

slowlog-max-len 128

latency-monitor-threshold 0

# 超时事件回调
notify-keyspace-events "Ex"

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

3.命令

配置conf后启动redis:

# 服务端启动
/usr/local/redis/bin/redis-server /usr/local/redis/conf/redis_6379.conf
##################################
# 客户端启动
/usr/local/redis/bin/redis-cli 
127.0.0.1:6379> auth 密码
OK
127.0.0.1:6379> get *
(nil)
127.0.0.1:6379> 

4.目录结构

启动后的目录结构:

tree redis/
redis/
├── bin
│   ├── redis-benchmark
│   ├── redis-check-aof -> redis-server
│   ├── redis-check-rdb -> redis-server
│   ├── redis-cli
│   ├── redis-sentinel -> redis-server
│   └── redis-server
├── conf
│   ├── redis_6379.conf
│   └── redis.conf
├── data
│   ├── appendonly_6379.aof
│   └── dump_6379.rdb
├── logs
│   └── redis.log
└── redis.pid

4 directories, 12 files

5.防火墙

防火墙开放6379端口

# 查询防火墙已开放端口
firewall-cmd --list-port
# 设置开放80端口
firewall-cmd --zone=public --add-port=6379/tcp --permanent
# 重启防火墙,生效设置
firewall-cmd --reload
上一篇 下一篇

猜你喜欢

热点阅读