Redis6在Liunx系统下的安装、启动和关闭


1、Redis6在Liunx系统安装

Redis 官方网站:http://redis.io
Redis中文官方网站:http://redis.cn/

1.1、安装版本

版本选择:https://download.redis.io/releases/redis-6.2.7.tar.gz

1.1.2、安装步骤

1.1.2.0、安装wget命令 & lszrz 命令
yum -y install wget
# 使用wget下载单个文件
## 从网络下载一个文件并保存在当前目录
wget https://download.redis.io/releases/redis-6.2.7.tar.gz
## 使用wget-o下载并以不同的文件名保存
wget -O redis627.tar.gz https://download.redis.io/releases/redis-6.2.7.tar.gz
## 使用wget -limit -rate 限速下载(执行wget时,默认会占用全部可能的带宽下载,当准备下载一个大文件,而你还需要下载其他文件时就有必要限速了)
wget --limit-rate=300K https://download.redis.io/releases/redis-6.2.7.tar.gz

# ----------------------------------
yum install -y lrzsz
1.1.2.1、准备工作:下载安装最新版的gcc编译器

安装C 语言的编译环境

yum -y install gcc gcc-c++ kernel-devel

测试gcc版本

[root@iZ2zeizrxxn52st7yye6vuZ ~]# 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.
1.2.2.2、将下载的redis-6.2.7.tar.gz方/opt目录
1.2.2.3、解压上传的包或wget命令直接下载
[root@iZ2zeizrxxn52st7yye6vuZ opt]# tar -xzvf redis-6.2.7.tar.gz 
redis-6.2.7/
redis-6.2.7/.github/
redis-6.2.7/.github/ISSUE_TEMPLATE/
redis-6.2.7/.github/ISSUE_TEMPLATE/bug_report.md
redis-6.2.7/.github/ISSUE_TEMPLATE/crash_report.md
1.2.2.4、进入解压的目录
[root@iZ2zeizrxxn52st7yye6vuZ opt]# cd redis-6.2.7/
1.2.2.5、执行make命令(只是编译好)
[root@iZ2zeizrxxn52st7yye6vuZ redis-6.2.7]# make
cd src && make all
make[1]: Entering directory '/opt/redis-6.2.7/src'
    CC Makefile.dep
1.2.2.6、可能的报错信息

如果没有准备好C语言编译环境,make 会报错—Jemalloc/jemalloc.h:没有那个文件

1.2.2.7、解决办法
make distclean
1.2.2.8、再次执行make命令
1.2.2.9、执行make install 命令
[root@iZ2zeizrxxn52st7yye6vuZ redis-6.2.7]# make install
cd src && make install
make[1]: Entering directory '/opt/redis-6.2.7/src'
    CC Makefile.dep

Hint: It's a good idea to run 'make test' ;)

    INSTALL redis-server
    INSTALL redis-benchmark
    INSTALL redis-cli
make[1]: Leaving directory '/opt/redis-6.2.7/src'

2、安装目录

[root@iZ2zeizrxxn52st7yye6vuZ redis-6.2.7]# cd /usr/local/bin/
[root@iZ2zeizrxxn52st7yye6vuZ bin]# ll
total 25620
-rwxr-xr-x 1 root root      399 Apr 28 18:17 cloud-id
-rwxr-xr-x 1 root root      403 Apr 28 18:17 cloud-init
-rwxr-xr-x 1 root root     2108 Apr 28 18:17 cloud-init-per
-rwxr-xr-x 1 root root     1776 Sep 16 22:07 jemalloc-config
-rwxr-xr-x 1 root root      145 Sep 16 22:07 jemalloc.sh
-rwxr-xr-x 1 root root   179069 Sep 16 22:07 jeprof
-rwxr-xr-x 1 root root     1005 Apr 28 18:17 jsondiff
-rwxr-xr-x 1 root root     3860 Apr 28 18:17 jsonpatch
-rwxr-xr-x 1 root root     1839 Apr 28 18:17 jsonpointer
-rwxr-xr-x 1 root root      397 Apr 28 18:17 jsonschema
-rwxr-xr-x 1 root root     1461 Feb 12  2020 libmcrypt-config
lrwxrwxrwx 1 root root       12 Sep 16 22:07 luajit -> luajit-2.0.4
-rwxr-xr-x 1 root root   454104 Sep 16 22:07 luajit-2.0.4
-rwxr-xr-x 1 root root    84904 Feb 12  2020 mcrypt
lrwxrwxrwx 1 root root        6 Feb 12  2020 mdecrypt -> mcrypt
-rwxr-xr-x 1 root root      424 Apr 28 18:17 normalizer
-rwxr-xr-x 1 root root  6541408 Oct  7 12:07 redis-benchmark # 性能测试工具,可以在自己本子运行,看看自己本子性能如何
lrwxrwxrwx 1 root root       12 Oct  7 12:07 redis-check-aof -> redis-server # 修复有问题的AOF文件,rdb和aof后面讲
lrwxrwxrwx 1 root root       12 Oct  7 12:07 redis-check-rdb -> redis-server
-rwxr-xr-x 1 root root  6757792 Oct  7 12:07 redis-cli # 客户端,操作入口
lrwxrwxrwx 1 root root       12 Oct  7 12:07 redis-sentinel -> redis-server # Redis集群使用
-rwxr-xr-x 1 root root 12162184 Oct  7 12:07 redis-server # Redis服务器启动命令

2.1.1、前台启动(不推荐)

前台启动,命令行窗口不能关闭,否则服务器停止

[root@iZ2zeizrxxn52st7yye6vuZ bin]# ./redis-server 
431264:C 07 Oct 2022 12:11:23.547 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
431264:C 07 Oct 2022 12:11:23.547 # Redis version=6.2.7, bits=64, commit=00000000, modified=0, pid=431264, just started
431264:C 07 Oct 2022 12:11:23.547 # Warning: no config file specified, using the default config. In order to specify a config file use ./redis-server /path/to/redis.conf
431264:M 07 Oct 2022 12:11:23.548 * monotonic clock: POSIX clock_gettime
431264:M 07 Oct 2022 12:11:23.548 # A key '__redis__compare_helper' was added to Lua globals which is not on the globals allow list nor listed on the deny list.
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 6.2.7 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                  
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 431264
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           https://redis.io       
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               

431264:M 07 Oct 2022 12:11:23.548 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
431264:M 07 Oct 2022 12:11:23.548 # Server initialized
431264:M 07 Oct 2022 12:11:23.548 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
431264:M 07 Oct 2022 12:11:23.548 * Ready to accept connections

2.1.2、后台启动

2.1.2.1、备份redis.conf

拷贝一份redis.conf 到其他目录,如/myredis

[root@iZ2zeizrxxn52st7yye6vuZ /] cp /opt/redis-6.2.7/redis.conf /myredis/
2.1.2.2、后台启动设置daemonize no 改成 yes
 修改redis.conf(259)文件将里面的daemonize no 改成 yes,让服务在后台启动
2.1.2.3、Redis启动
# 记得安装目录是/usr/local/bin/,所以在/usr/local/bin/下执行下面的命令
[root@iZ2zeizrxxn52st7yye6vuZ bin] ./redis-server /myredis/redis.conf
2.1.2.4、用客户端连接访问
[root@iZ2zeizrxxn52st7yye6vuZ bin] ./redis-cli 
127.0.0.1:6379>
2.1.2.5、指定端口访问
[root@iZ2zeizrxxn52st7yye6vuZ bin] ./redis-cli -p 6379
127.0.0.1:6379>
2.1.2.6、测试验证
127.0.0.1:6379> ping
PONG
2.1.2.7、Redis关闭

单实例关闭

[root@iZ2zeizrxxn52st7yye6vuZ bin] ./redis-cli shutdown(进去之后直接 shutdown)
[root@iZ2zeizrxxn52st7yye6vuZ bin] ps -ef|grep redis
root      431425  426784  0 12:25 pts/0    00:00:00 grep --color=auto redis

也可以进入终端后关闭

[root@iZ2zeizrxxn52st7yye6vuZ bin] ./redis-server /myredis/redis.conf 
[root@iZ2zeizrxxn52st7yye6vuZ bin] ./redis-cli -p 6379
127.0.0.1:6379> shutdown
not connected>

也可以指定端口关闭

redis-cli -p 6379 shutdown
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
redis安装 1: 下载redis-5.0.4.tar.gz 2: 解压源码并进入目录 tar zxvf redis-5.0.4.tar.gz cd redis-5.0.4 3: 不用configure 4: 直接make (如果是32位机器 make 32bit) 查看linux机器是32位还是64位的方法:file /bin/ls 注:易碰到的问题,时间错误. 原因: 源码是官方configure过的,但官方configure时,生成的文件有时间戳信息, Make只能发生在configure之后, 如果你的虚拟机的时间不对,比如说是2012年 解决: date -s ' yyyy-mm-dd hh:mm:ss ' 重写时间 再 clock -w 写入cmos 5: 可选步骤: make test 测试编译情况 (可能出现: need tcl >8.4这种情况, yum -y install tcl ) 6: 安装到指定的目录,比如 /usr/local/redis make PREFIX=/usr/local/redis install 注: PREFIX要大写 7: 复制配置文件 cp redis.conf /usr/local/redis 注path为解压后的安装包路径 /root/gsj/redis-3.0.6 8: 让redis以后台进程的形式运行 vim /usr/local/redis/redis.conf 编辑redis.conf配置文件,修改如下内容; daemonize yes 9: make install之后,cd /usr/local/redis/bin得到如下几个文件 redis-benchmark 性能测试工具 redis-check-aof 日志文件检测工(比如断电造成日志损坏,可以检测并修复) redis-check-dump 快照文件检测工具,效果类上 redis-cli 客户端 redis-server 服务端 10: 启动与连接 启动redis并指定配置文件 cd /usr/local/redis ./bin/redis-server ./redis.conf #设置随机启动 vim /etc/rc.local 最后添加: /usr/local/redis/bin/redis-server /usr/local/redis/redis.conf 连接: 用redis-cli cd /usr/local/redis/bin/ ./redis-cli #进入 exit /quit #退出 关闭redis pkill redis-server #关闭 ./redis-cli shutdown #关闭 查看是否启动成功 ps -ef | grep redis #查看端口是否占用 netstat -tunpl | grep 6379 11: 测试 String(字符串)类型: set name lijie #设置键name的值为lijie get name #获取name的值。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值