centos8(linux):源码编译安装redis7(Redis server v=7.0.5)

一,下载redis7

1,官网:
https://redis.io/
2,下载页面:
https://redis.io/download/
如图:
3,复制7.0.5的链接地址,从命令行下载:
[lhdop@blog redis]$ wget https://github.com/redis/redis/archive/7.0.5.tar.gz
4,解压:
[lhdop@blog redis]$ tar -zxvf 7.0.5.tar.gz

说明:刘宏缔的架构森林是一个专注架构的博客,

网站:https://blog.imgtouch.com
本文: https://blog.imgtouch.com/index.php/2023/06/03/centos8-linux-yuan-ma-bian-yi-an-zhuang-redis7-redis-server/

         对应的源码可以访问这里获取: https://github.com/liuhongdi/
         或: https://gitee.com/liuhongdi

说明:作者:刘宏缔 邮箱: 371125307@qq.com

二,准备安装:

1,因为是编译安装,安装前先检查gcc
 
[root@blog ~]# gcc --version
gcc (GCC) 8.5.0 20210514 (Red Hat 8.5.0-4)
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
   如果不存在,则可用yum安装,
   yum 命令:
yum install gcc
2,查看是否已安装make命令
[root@blog ~]# make --version
GNU Make 4.2.1
Built for x86_64-redhat-linux-gnu
Copyright (C) 1988-2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

三,安装

1,install
[root@blog ~]# cd /usr/local/source/redis/redis-7.0.5/
[root@blog redis-7.0.5]# make PREFIX=/usr/local/soft/redis7 install
查看目录:
[root@blog redis-7.0.5]# ls /usr/local/soft/redis7/
bin

可以看到已安装成功

 
2,生成配置文件
[root@blog redis-7.0.5]# mkdir /usr/local/soft/redis7/conf
[root@blog redis-7.0.5]# cp redis.conf /usr/local/soft/redis7/conf/

就是把源码目录的配置文件复制到安装目录下

 
3,安装完成后,查看安装的redis的版本:
[root@blog utils]# /usr/local/soft/redis7/bin/redis-server -v
Redis server v=7.0.5 sha=00000000:0 malloc=jemalloc-5.2.1 bits=64 build=458269479d5778cb

四,配置redis

1,生成供redis运行用的目录:
[root@blog ~]# mkdir /data/redis6388
[root@blog ~]# cd /data/redis6388
[root@blog redis6388]# mkdir logs
[root@blog redis6388]# mkdir data
2,修改配置文件:
[root@blog conf]# vi redis.conf
设置端口
#port 6379
port 6388
设置是否以daemon方式运行
#daemonize no
daemonize yes
设置pid文件
#pidfile /var/run/redis_6379.pid
pidfile /var/run/redis_6388.pid
设置日志文件
#logfile ""
logfile "/data/redis6388/logs/redis6388.log"
指定数据存储目录(默认是当前目录)
#dir ./
dir /data/redis6388/data/
指定最大内存数量
# maxmemory <bytes>
maxmemory 128MB

五,启动redis:

1,创建供systemd使用的service文件
   说明:可参考源码中的 utils/systemd-redis_server.service
[root@blog redis6388]# vi /lib/systemd/system/redis6388.service
[root@blog redis6388]# more /lib/systemd/system/redis6388.service
[Unit]
Description=Redis
After=network.target
 
[Service]
Type=forking
PIDFile=/var/run/redis_6388.pid
ExecStart=/usr/local/soft/redis7/bin/redis-server /usr/local/soft/redis7/conf/redis.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
 
[Install]
WantedBy=multi-user.target
2,启动
重新加载service
[root@blog redis6388]# systemctl daemon-reload
启动服务
[root@blog redis6388]# systemctl start redis6388.service
查看服务状态:
[root@blog redis6388]# systemctl status redis6388.service
● redis6388.service - Redis
   Loaded: loaded (/usr/lib/systemd/system/redis6388.service; disabled; vendor preset: disabled)
   Active: active (running) since Sun 2022-10-23 18:20:52 CST; 1min 12s ago
  Process: 30725 ExecStart=/usr/local/soft/redis7/bin/redis-server /usr/local/soft/redis7/conf/redis.conf (code=exited, status=0/SUCCESS)
Main PID: 30726 (redis-server)
    Tasks: 5 (limit: 26213)
   Memory: 2.3M
   CGroup: /system.slice/redis6388.service
           └─30726 /usr/local/soft/redis7/bin/redis-server 127.0.0.1:6388
 
Oct 23 18:20:52 blog systemd[1]: Starting Redis...
Oct 23 18:20:52 blog systemd[1]: redis6388.service: Can't open PID file /var/run/redis_6388.pid (yet?) after start: No such file or directory
Oct 23 18:20:52 blog systemd[1]: Started Redis.

可以看到已正常启动

六,测试效果:

从客户端访问
# -h : 指定host
#-p:  指定port
[root@blog utils]# /usr/local/soft/redis7/bin/redis-cli -h 127.0.0.1 -p 6388
127.0.0.1:6388> keys *
(empty array)
127.0.0.1:6388> set name laoliu
OK
127.0.0.1:6388> get name
"laoliu"
127.0.0.1:6388

七,查看linux的版本

[lhdop@blog ~]$ cat /etc/os-release
NAME="CentOS Linux"
VERSION="8 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="8"
PLATFORM_ID="platform:el8"
PRETTY_NAME="CentOS Linux 8 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:8"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"
CENTOS_MANTISBT_PROJECT="CentOS-8"
CENTOS_MANTISBT_PROJECT_VERSION="8"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="8"

 

posted @ 2022-10-23 18:42  刘宏缔的架构森林  阅读(892)  评论(0编辑  收藏  举报