logo头像

分享技术,品味人生

瑞吉实战15-Redis安装运维

瑞吉实战15–Redis

实验内容

-

-

一、redis单机安装

linux安装:源来自官网 Download | Redis,版本选择7.0 stable

# 1.将Redis安装包上传到Linux
# 2.解压安装包,命令:
tar -zxvf redis-7.0.5.tar.gz

# 3.安装Redis的依赖环境gcc,命令:
yum install gcc-c++

# 4.不指定prefix会编译到/usr/local/bin,指定后删除/usr/local/redis,方便删除redis
cd /root/redis-7.0.5
make && make PREFIX=/usr/local/redis install

服务设置

cat << EOF > /usr/local/redis/redis.conf
protected-mode yes
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize yes
supervised systemd 
pidfile /var/run/redis_6379.pid
loglevel notice
logfile ""
databases 16
always-show-logo no
set-proc-title yes
proc-title-template "{title} {listen-addr} {server-mode}"
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 yes
repl-diskless-sync-delay 5
repl-diskless-sync-max-replicas 0
repl-diskless-load disabled
repl-disable-tcp-nodelay no
replica-priority 100
acllog-max-len 128
requirepass 123456 
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
replica-lazy-flush no
lazyfree-lazy-user-del no
lazyfree-lazy-user-flush no
oom-score-adj no
oom-score-adj-values 0 200 800
disable-thp yes
appendonly no
appendfilename "appendonly.aof"
appenddirname "appendonlydir"
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
aof-timestamp-enabled no
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-listpack-entries 512
hash-max-listpack-value 64
list-max-listpack-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-listpack-entries 128
zset-max-listpack-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
EOF

cat << EOF > /usr/lib/systemd/system/redis.service
[Unit]
Description=Redis In-Memory Data Store
Documentation=https://redis.io/
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/redis.conf
ExecStop=/usr/local/redis/bin/redis-cli shutdown
ExecReload=/bin/kill -s HUP $MAINPID
Restart=always

[Install]
WantedBy=multi-user.target
EOF

服务指令

# 设置开机自启动:
systemctl enable redis

# 关闭开机自动启动:
systemctl disable redis

# 启动redis服务:
systemctl start redis

# 停止服务:
systemctl stop redis

# 重新加载redis配置文件:
systemctl reload redis

# 查看所有已启动的服务:
systemctl list-units --type=service

#查看服务当前状态:
systemctl status redis

二、简易测试

# 启动服务
redis-server

# 测试
redis-cli
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> keys *
(empty array)
redis> set foo bar
OK
redis> get foo
"bar"

三、生产配置

这里演示的是两台干净主机的初识配置,如果是主从不一致,需要重新同步具体看下一节

配置文件

# 采用配置文件启动
redis-server /root/redis-7.0.5/redis.conf

# 关于配置文件的主要配置
daemonize yes # 以守护进程方式启动
supervised systemd # 可以跟systemd进程进行交互

#其他配置供参考
bind 0.0.0.0 #任意ip都可以连接
protected-mode no #关闭保护,允许非本地连接
port 6379 #端口号
pidfile /var/run/redis_6379.pid #进程守护文件,就是存放该进程号相关信息的地方
dir /usr/loacl/redis-6.0.10/data/ #db等相关目录位置
logfile "/usr/local/redis-6.0.10/logs/redis_6379.log"
appendonly yes #开启日志形式
requirepass 123456 #密码

设置开机自启

客户端

可以搜索安装 another redis desktop manager,原版已经收费了~

[qishibo/AnotherRedisDesktopManager: 🚀🚀🚀A faster, better and more stable redis desktop manager GUI client], compatible with Linux, Windows, Mac. What’s more, it won’t crash when loading massive keys. (github.com)

评论系统未开启,无法评论!