安装部署redis_Centos 7 安装 Redis 5.0.8 单实例

2980cbf984335106adf8ed9af496339f.png

本教程是单实例部署,根据公司实际情况,是否用于生产,不建议用于生产,生产至少需要部署一个集群,测试环境需要安装一个,简单记录下。

1. 下载

wget http://download.redis.io/releases/redis-5.0.8.tar.gz

2. 安装依赖包

yum -y install gcc*

3. 解压并编译

tar -zxf redis-5.0.8.tar.gz 
cd redis-5.0.8 && make

4. 安装

将/data/redis-5.0.8/src目录下的文件加到/usr/local/bin目录

[root@localhost redis-5.0.8]# cd src
[root@localhost src]# make install
    CC Makefile.dep


Hint: It's a good idea to run 'make test' ;)
    INSTALL install
    INSTALL install
    INSTALL install
    INSTALL install
    INSTALL install
[root@localhost src]#

5. 创建数据目录及日志目录 

mkdir -p /data/redis/data/ && mkdir -p /data/redis/logs

6. 配置文件修改

[root@localhost redis-5.0.8]# cat redis.conf |grep -viP "^#"|grep -v "^$"
bind 0.0.0.0          # 监听地址
protected-mode no         # 关闭保护模式
port 6379  

tcp-backlog 511
timeout 30  

tcp-keepalive 300
daemonize yes # 后台启动
supervised no
pidfile /data/redis/logs/redis_6379.pid # pid 文件路径
loglevel notice
logfile /data/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
dbfilename dump.rdb
dir /data/redis/data/ # 数据目录
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
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
replica-lazy-flush no
appendonly yes
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
[root@localhost redis-5.0.8]#

7. 配置开机启动

配置文件移动到/etc/目录 

cp /data/redis-5.0.8/redis.conf /etc/redis/redis.conf

 编辑 systemctl 服务配置文件 

cat /lib/systemd/system/redis.service


[Unit]
Description=Redis
After=network.target


[Service]
Type=forking
PIDFile=/data/redis/logs/redis_6379.pid
ExecStart=//usr/local/bin/redis-server /etc/redis/redis.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true


[Install]
WantedBy=multi-user.target

8. 启动测试

[root@localhost logs]# systemctl daemon-reload
[root@localhost logs]# systemctl start redis
[root@localhost logs]# systemctl status redis
● redis.service - Redis
   Loaded: loaded (/usr/lib/systemd/system/redis.service; enabled; vendor preset: disabled)
   Active: active (running) since Wed 2020-04-15 14:37:42 CST; 8s ago
  Process: 32698 ExecStart=/usr/local/bin/redis-server /etc/redis/redis.conf (code=exited, status=0/SUCCESS)
 Main PID: 32699 (redis-server)
   CGroup: /system.slice/redis.service
           └─32699 /usr/local/bin/redis-server 0.0.0.0:6379


Apr 15 14:37:42 localhost.localdomain systemd[1]: Starting Redis...
Apr 15 14:37:42 localhost.localdomain systemd[1]: New main PID 32441 does not exist or is a zombie.
Apr 15 14:37:42 localhost.localdomain systemd[1]: Started Redis.
[root@localhost logs]#

9. 设置开机启动

[root@localhost logs]# systemctl enable redis
Created symlink from /etc/systemd/system/multi-user.target.wants/redis.service to /usr/lib/systemd/system/redis.service.
[root@localhost logs]#

10. 总结 

Redis 安装相对简单,但集群部署方式适合用于生产,后续总结生产部署集群的方式 。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值