《Linux运维总结:Centos7.6源码安装单实例redis6.2.8》

一、部署redis服务

1.1、环境信息

环境信息如下:

主机IP操作系统Redis版本CPU架构
192.168.1.191Centos7.66.2.8x86_64

1.2、二进制方式

1、安装环境依赖

[root@localhost ~]# yum -y install gcc

2、安装包下载

[root@localhost ~]# wget https://download.redis.io/releases/redis-6.2.8.tar.gz

3、把redis安装到指定目录

[root@localhost ~]# tar axf redis-6.2.8.tar.gz
[root@localhost ~]# cd redis-6.2.8
[root@localhost redis-6.2.8]# make
[root@localhost redis-6.2.8]# make install PREFIX=/opt/redis6

说明:这时候,我们就能在/opt/redis6.0下面看到一个bin目录,redis的可执行文件都被复制到这里了,如下图所示:
在这里插入图片描述

4、把redis执行文件加入到path中

[root@localhost ~]# vim /etc/profile
export REDIS_HOME=/opt/redis6
export PATH=$PATH:$REDIS_HOME/bin
[root@localhost ~]# source /etc/profile

5、安装redis的配置

说明:在redis源码包utils目录下,有一个install_server.sh脚本文件,这是redis自带的安装程序,安装期间可以自己配置端口号等信息,也可以使用默认值,默认后台运行,开机自动启动,很方便。

在这里插入图片描述
执行install_server.sh脚本,报错如下所示:
在这里插入图片描述

解决方法:注释掉下面几行
在这里插入图片描述

接续执行脚本,如下图所示:
在这里插入图片描述

6、修改redis配置文件

参考:redis配置文件详解

[root@localhost ~]# egrep -Ev "^#|^$" /etc/redis/7000.conf
bind 0.0.0.0
protected-mode yes
port 7000
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize yes
pidfile /var/run/redis_7000.pid
loglevel notice
logfile /var/log/redis_7000.log
databases 16

#rdb持久化配置
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
rdb-del-sync-files no
dir /var/lib/redis/7000

#redis密码
requirepass 1UEJjjGfYZU7dCWy

#aof持久化配置
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

7、重启redis服务

[root@localhost ~]# /etc/init.d/redis_7000 restart
Stopping ...
Redis stopped
Starting Redis server...

1.3、Service unit 的方式

1、安装环境依赖

[root@localhost ~]# yum -y install gcc systemd-devel 

2、安装包下载

[root@localhost ~]# wget https://download.redis.io/releases/redis-6.2.8.tar.gz

3、把redis安装到指定目录

[root@localhost ~]# tar axf redis-6.2.8.tar.gz
[root@localhost ~]# cd redis-6.2.8
[root@localhost redis-6.2.8]# make USE_SYSTEMD=yes
[root@localhost redis-6.2.8]# make install PREFIX=/opt/redis6

说明:这时候,我们就能在/opt/redis6.0下面看到一个bin目录,redis的可执行文件都被复制到这里了,如下图所示:
在这里插入图片描述

4、把redis执行文件加入到path中

[root@localhost ~]# vim /etc/profile
export REDIS_HOME=/opt/redis6
export PATH=$PATH:$REDIS_HOME/bin
[root@localhost ~]# source /etc/profile

5、创建相关目录

##创建etl目录,存放redis配置文件
[root@localhost redis-6.2.8]# mkdir /opt/redis6/etc

##创建logs目录,存放redis日志文件
[root@localhost redis-6.2.8]# mkdir /opt/redis6/logs

#创建data目录,存放redis持久化化数据
[root@localhost redis-6.2.8]# mkdir /opt/redis6/data

6、复制并修改配置文件

[root@localhost redis-6.2.8]# cp redis.conf /opt/redis6/etc
[root@localhost redis-6.2.8]# vim /opt/redis6/etc/redis.conf
bind 0.0.0.0
protected-mode yes
port 7000
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize yes
pidfile /var/run/redis_7000.pid
loglevel notice
logfile /opt/redis6/logs/redis_7000.log
databases 16

#rdb持久化配置
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
rdb-del-sync-files no
dir /opt/redis6/data

#redis密码
requirepass 1UEJjjGfYZU7dCWy

#aof持久化配置
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

7、设置systemd启动守护进程

[root@localhost utils]# vim /etc/systemd/system/redis.service 
[Unit]
Description=Redis Server
After=network.target

[Service]
User=root
Group=root
Type=notify
LimitNOFILE=65535
ExecStart=/opt/redis6/bin/redis-server /opt/redis6/etc/redis.conf --supervised systemd
ExecStop=/bin/kill -SIGTERM $MAINPID

[Install]
WantedBy=multi-user.target

8、启动redis服务

[root@localhost utils]# systemctl daemon-reload
[root@localhost utils]# systemctl start redis
[root@localhost utils]# systemctl enable redis
[root@localhost utils]# systemctl status redis

总结:整理不易,如果对你有帮助,可否点赞关注一下?

更多详细内容请参考:《Linux运维篇:Linux系统运维指南》

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

东城绝神

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值