1、执行下面的命令下载redis:
wget https://download.redis.io/releases/redis-6.2.6.tar.gz
2.解压redis:
tar xzf redis-6.2.6.tar.gz
3、移动redis目录,一般都会将redis目录放置到 /usr/local/redis目录:
mv redis-6.2.6 /usr/local/redis
4.编译并安装 redis
cd /usr/local/redis/redis-6.2.6
make && make install
5.将 redis 安装为系统服务并后台启动
# 进⼊ utils ⽬录,并执⾏如下脚本即可
cd utils/
./install_server.sh
如果出现报错,那么编辑这个文件
vim ./install_server.sh
注释下面的代码
#bail if this system is managed by systemd
#_pid_1_exe="$(readlink -f /proc/1/exe)"
#if [ "${_pid_1_exe##*/}" = systemd ]
#then
# echo "This systems seems to use systemd."
# echo "Please take a look at the provided example service unit files in this directory, and adapt and install them. Sorry!"
# exit 1
#fi
再次执行脚本即可
./install_server.sh
默认选择,直接按回车即可
6、查看 redis 服务启动情况
systemctl status redis_6379.service
7、启动自带的 redis-cli 客户端,测试 redis
[root@xxx utils]# redis-cli
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> set k1 v1
OK
127.0.0.1:6379> get k1
"v1"
8、设置允许远程连接
编辑配置文件
vim /etc/redis/6379.conf
将原来的 bind 127.0.0.1 这行注释掉,改为 0.0.0.0
# bind 127.0.0.1
bind 0.0.0.0
9.重启 redis 服务
systemctl restart redis_6379.service
10、设置访问密码
vim /etc/redis/6379.conf
找到 # requirepass foobared,在这个注释下加一行,为 requirepass 自己的密码
# requirepass foobared
requirepass distance
保存,重启 redis 服务
systemctl restart redis_6379.service
11.再次测试
[root@xxx ~]# redis-cli
127.0.0.1:6379> ping
(error) NOAUTH Authentication required.
127.0.0.1:6379> auth distance
OK
127.0.0.1:6379> ping
PONG
12、 redis 服务管理
查看 redis 服务
ps -ef | grep redis
通过配置文件启动 redis
redis-server /etc/redis/6379.conf
redis-cli 客户端连接
[root@xxx redis]# redis-cli -p 6379
127.0.0.1:6379> auth distance
OK
127.0.0.1:6379> ping
PONG
在客户端中可以关闭 redis 服务端
127.0.0.1:6379> shutdown
not connected> exit
13、尝试远程连接,用本地 windows 的 redis-cli 来连接 linux 服务器上的 redis server,需要本地也安装了 redis
# linux 先开启 redis 服务端
redis-server /etc/redis/6379.conf
# windows 本地打开 cmd
redis-cli.exe -h 192.168.0.102 -p 6379 -a redis



