准备好Redis的安装包: 链接:https://pan.baidu.com/s/1S4ci92nJbbRjE1YpDjG6mQ 提取码:1234
#进入我们的local文件夹
cd usr/local
#创建 一个名为redis的文件夹
mkdir redis
在安装之前需要查看gcc的版本,因为redis 5.0及以上的需要gcc 5.3以上版本,我在安装的时候也出现在了下面的错误,是因为linux centos7默认安装的是gcc4.8.5
gcc -v
查看之后发现确实是版本太低,我们需要升级版本,以下三条命令进行升级
yum -y install centos-release-scl
yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils
scl enable devtoolset-9 bash
如果要长期使用gcc 9.3的话:需要加上这个命令
echo -e “\nsource /opt/rh/devtoolset-9/enable” >>/etc/profile
我再用gcc -v命名查看gcc版本,发现已经升级成9.3.1了
然后进入我们刚才创建的redis文件目录,用我们的远程工具把redis的安装包传到redis文件夹下面,直接拖过去
#进入local目录
[root@localhost ~]# cd /usr/local
#进入redis目录
[root@localhost local]# cd redis
#查看目录下的文件
[root@localhost redis]# ls
redis-6.0.6.tar.gz
# 解压安装包
[root@localhost redis]# tar -zxvf redis-6.0.6.tar.gz
#查看
[root@localhost redis]# ls
# 进入安装包
[root@localhost redis]# cd redis-6.2.5/
# 编译
[root@localhost redis]# make MALLOC=libc
#编译成功后,进入src文件夹,执行make install进行Redis安装。
[root@localhost redis]# cd src
#安装 我在网上看到有编译和安装一起的指令,但是我这失败了,我找了方法一步一步来
[root@localhost src]# make install
#安装完成之后,查看文件
[root@localhost src]# ls
# 在安装目录下创建一个 bin 目录
[root@node01 redis-6.0.6]# mkdir bin
#进入src文件夹
[root@localhost redis-6.0.6]# cd src
# 将 redis-server 和 redis-cli 移动到 bin 目录中
[root@localhost src]# cp redis-server ../bin/
[root@localhost src]# cp redis-cli ../bin/
[root@localhost src]# cd ..
[root@localhost redis-6.0.6]# ls
00-RELEASENOTES COPYING Makefile runtest sentinel.conf utils
bin deps MANIFESTO runtest-cluster src
BUGS etc README.md runtest-moduleapi tests
CONTRIBUTING INSTALL redis.conf runtest-sentinel TLS.md
[root@localhost redis-6.0.6]# cp redis.conf bin/
[root@localhost redis-6.0.6]# cd bin/
#查看当前目录下的文件
[root@localhost bin]# ls
redis-cli redis.conf redis-server
#启动redis服务
[root@localhost bin]# ./redis-server redis.conf
10107:C 25 Mar 2022 17:11:12.753 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
10107:C 25 Mar 2022 17:11:12.753 # Redis version=6.0.6, bits=64, commit=00000000, modified=0, pid=10107, just started
10107:C 25 Mar 2022 17:11:12.753 # Configuration loaded
[root@localhost bin]# ./redis-cli
127.0.0.1:6379> keys *
(error) NOAUTH Authentication required.
#如果设置了密码,需要输入密码,格式:auth "密码"
127.0.0.1:6379> auth "123456"
OK
不在一同一个用户下面安装:
[root@localhost leyou]# chmod 755 redis-4.0.9.tar.gz
[root@localhost leyou]# mv redis-4.0.9.tar.gz redis
[root@localhost leyou]# ll
总用量 3108
drwxr-xr-x. 10 8980 users 258 4月 3 11:23 FastDFS
drwxrwxr-x. 3 500 500 47 5月 4 2014 fastdfs-nginx-module
-rw-r--r--. 1 root root 17510 4月 3 10:53 fastdfs-nginx-module_v1.16.tar.gz
-rw-r--r--. 1 root root 344620 4月 3 10:53 FastDFS_v5.08.tar.gz
drwxr-xr-x. 4 root root 124 4月 3 11:07 libfastcommon-master
-rw-r--r--. 1 root root 161971 4月 3 10:53 libfastcommon-master.zip
drwxr-xr-x. 9 leyou leyou 186 4月 3 11:54 nginx-1.10.0
-rw-r--r--. 1 root root 908954 4月 3 10:53 nginx-1.10.0.tar.gz
drwxr-xr-x. 2 root root 175 4月 14 22:07 rabbitmq
-rwxr-xr-x. 1 root root 1737022 4月 15 21:32 redis
drwxr-xr-x. 2 root root 6 4月 3 11:39 storage
drwxr-xr-x. 2 root root 6 4月 3 11:39 tracker
#应该解压之后再重命名,记录一下,为了解决以后出现同样的问题
#删除文件
[root@localhost leyou]# rm -f redis
[root@localhost leyou]# ll
总用量 1408
drwxr-xr-x. 10 8980 users 258 4月 3 11:23 FastDFS
drwxrwxr-x. 3 500 500 47 5月 4 2014 fastdfs-nginx-module
-rw-r--r--. 1 root root 17510 4月 3 10:53 fastdfs-nginx-module_v1.16.tar.gz
-rw-r--r--. 1 root root 344620 4月 3 10:53 FastDFS_v5.08.tar.gz
drwxr-xr-x. 4 root root 124 4月 3 11:07 libfastcommon-master
-rw-r--r--. 1 root root 161971 4月 3 10:53 libfastcommon-master.zip
drwxr-xr-x. 9 leyou leyou 186 4月 3 11:54 nginx-1.10.0
-rw-r--r--. 1 root root 908954 4月 3 10:53 nginx-1.10.0.tar.gz
drwxr-xr-x. 2 root root 175 4月 14 22:07 rabbitmq
drwxr-xr-x. 2 root root 6 4月 3 11:39 storage
drwxr-xr-x. 2 root root 6 4月 3 11:39 tracker
#解压
[root@localhost leyou]#tar -xvf redis-4.0.9.tar.gz
#重命名
[root@localhost leyou]# mv redis-4.0.9 redis
[root@localhost leyou]# ll
总用量 3112
drwxr-xr-x. 10 8980 users 258 4月 3 11:23 FastDFS
drwxrwxr-x. 3 500 500 47 5月 4 2014 fastdfs-nginx-module
-rw-r--r--. 1 root root 17510 4月 3 10:53 fastdfs-nginx-module_v1.16.tar.gz
-rw-r--r--. 1 root root 344620 4月 3 10:53 FastDFS_v5.08.tar.gz
drwxr-xr-x. 4 root root 124 4月 3 11:07 libfastcommon-master
-rw-r--r--. 1 root root 161971 4月 3 10:53 libfastcommon-master.zip
drwxr-xr-x. 9 leyou leyou 186 4月 3 11:54 nginx-1.10.0
-rw-r--r--. 1 root root 908954 4月 3 10:53 nginx-1.10.0.tar.gz
drwxr-xr-x. 2 root root 175 4月 14 22:07 rabbitmq
drwxrwxr-x. 6 root root 4096 3月 27 2018 redis
-rwxr-xr-x. 1 root root 1737022 4月 15 21:35 redis-4.0.9.tar.gz
drwxr-xr-x. 2 root root 6 4月 3 11:39 storage
drwxr-xr-x. 2 root root 6 4月 3 11:39 tracker
[root@localhost leyou]# cd redis
#编译并安装
[root@localhost redis]# make && make install
cd src && make all
redis的配置文件中搜索配置字段
esc / 加搜索字段
简单使用
[root@localhost redis]# redis-cli
127.0.0.1:6379> ping
PONG
#查看当前的数据
127.0.0.1:6379> keys *
(empty list or set)
127.0.0.1:6379> set key1 value1
OK
127.0.0.1:6379> keys *
1) "key1"
127.0.0.1:6379> get key1
"value1"
127.0.0.1:6379> hset user username zhangsan
(integer) 1
127.0.0.1:6379> hget user user username
(error) ERR wrong number of arguments for 'hget' command
127.0.0.1:6379> hget user username
"zhangsan"
127.0.0.1:6379> hset age 20
(error) ERR wrong number of arguments for 'hset' command
127.0.0.1:6379> hset user age 20
(integer) 1
127.0.0.1:6379> getall user
(error) ERR unknown command 'getall'
127.0.0.1:6379> hgetall user
1) "username"
2) "zhangsan"
3) "age"
4) "20"