文章目录
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