一、操作系统(准备环境)
1、Linux版本:CentOS 7.6 x64位
2、Rdis版本: redis-5.0.4.tar.gz
二、下载指定安装包
1、redis-5.0.4.tar.gz
2、地址连接:mysql-8.0.22-el7-x86_64.tar.gz-Linux文档类资源-CSDN下载
三、新建安装路径
[root@izwz9z local]# mkdir redis #新建redis包
[root@izwz9z redis]# tar -zxvf redis-5.0.4.tar.gz #解压
redis-5.0.4/
redis-5.0.4/runtest-sentinel
........
四、安装依赖
[root@izwz9z redis-5.0.4]# yum install gcc-c++ #安装依赖
五、编译及安装
[root@izwz9z redis-5.0.4]# make #编译
[root@izwz9z redis-5.0.4]# make PREFIX=/usr/local/redis install #安装在指定路径
d src && make install
make[1]: Entering directory `/usr/local/redis/src'
Hint: It's a good idea to run 'make test' ;)
INSTALL install
INSTALL install
INSTALL install
INSTALL install
INSTALL install
出现这就安装成功
六、复制/修改redis.conf
[root@izwz9z redis-5.0.4]# cp redis.conf ../../redis/ #复制配置文件
[root@izwz9z redis-5.0.4]# cd ..
[root@izwz9z redis]# vi redis.conf #修改配置文件【具体配置请往下看第九点】
六、启动redis
[root@izwz9z redis]# ./bin/redis-server ./redis.conf #启动redis
2473:C 17 Oct 2021 16:43:36.785 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
2473:C 17 Oct 2021 16:43:36.785 # Redis version=5.0.4, bits=64, commit=00000000, modified=0, pid=2473, just started
2473:C 17 Oct 2021 16:43:36.785 # Configuration loaded
[root@izwz9z redis]# ps -ef | grep redis #查看状态,恭喜启动成功
root 2621 1 0 16:53 ? 00:00:00 ./bin/redis-server 127.0.0.1:6379
root 2629 1618 0 16:54 pts/0 00:00:00 grep --color=auto redis
七、客户端链接测试
[root@izwz9z redis]# cd bin #到指定路径查看
[root@izwz9z bin]# ll
total 54284
-rwxr-xr-x 1 root root 9202923 Oct 17 16:40 redis-benchmark
-rwxr-xr-x 1 root root 12266146 Oct 17 16:40 redis-check-aof
-rwxr-xr-x 1 root root 12266146 Oct 17 16:40 redis-check-rdb
-rwxr-xr-x 1 root root 9579960 Oct 17 16:40 redis-cli
lrwxrwxrwx 1 root root 12 Oct 17 16:40 redis-sentinel -> redis-server
-rwxr-xr-x 1 root root 12266146 Oct 17 16:40 redis-server
[root@izwz9z bin]# ./redis-cli
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> #再次恭喜连接没有问题
八、开启防火墙及开放端口
[root@izwz9z redis]# sudo firewall-cmd --zone=public --add-port=6379/tcp --permanent
FirewallD is not running #没有开启防火墙报的错
[root@izwz9z redis]# systemctl start firewalld #开启防火墙
[root@izwz9z redis]# sudo firewall-cmd --zone=public --add-port=6379/tcp --permanent
success
[root@izwz9z redis]# sudo firewall-cmd --reload #立即生效配置
success
关于防火墙问题,给大家路径借鉴下:解决FirewallD is not running问题 - WayneLiu123 - 博客园
九、开启远程连接,并设置redis密码
[root@izwz9z redis]# vi redis.conf #打开配置文件
---------- 1、 在redis.conf找到该代码,注释掉 允许远程访问 ---------------------
#bind 127.0.0.1
---------- 2、默认是前台启动、但是不推荐,直接改成后台启动 -----------------------
# daemonize no 改成 daemonize yes
-----------3、 在redis.conf找到该代码,设置redis密码 -------------------------
# requirepass foobared
requirepass 密码
[root@izwz9z redis]# cd bin
[root@izwz9z bin]# ./redis-cli #关闭redis
127.0.0.1:6379> shutdown
not connected>
[root@izwz9z bin]# cd ..
[root@izwz9z redis]# ./bin/redis-server ./redis.conf #再次启动
2620:C 17 Oct 2021 16:53:35.632 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
2620:C 17 Oct 2021 16:53:35.632 # Redis version=5.0.4, bits=64, commit=00000000, modified=0, pid=2620, just started
2620:C 17 Oct 2021 16:53:35.632 # Configuration loaded
------------------------修改配置后,重新测试redis----------------------------
[root@izwz9z redis]# cd bin
[root@izwz9z bin]# ./redis-cli
127.0.0.1:6379> ping
(error) NOAUTH Authentication required. 因为没有输入密码,所以无法进去
127.0.0.1:6379> auth 密码
OK
127.0.0.1:6379> #恭喜你设置成功,可以在你本地远程测试