linux安装redis详细步骤

image-20210730204801426

1、从redis官网下载linux压缩包

2、把压缩包保存至服务器

3、在 /usr/local/ 下创建 redis 文件夹

mkdir /usr/local/redis

4、解压安装包

tar zxvf redis-6.2.4.tar.gz -C /usr/local/redis

解压完之后, /usr/local/redis 目录中应该有一个相关目录

[root@xxx software]# ls /usr/local/redis
redis-6.2.4

5、编译并安装 redis

cd /usr/local/redis/redis-6.2.4
make && make install

6、将 redis 安装为系统服务并后台启动

# 进⼊ utils ⽬录,并执⾏如下脚本即可
cd utils/
./install_server.sh

如果出现报错,那么编辑这个文件

image-20210731171900592


 

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

image-20210731172018766

再次执行脚本即可

./install_server.sh

image-20210731172126852


 

7、查看 redis 服务启动情况

systemctl status redis_6379.service

8、启动自带的 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"

9、设置允许远程连接

编辑配置文件

vim /etc/redis/6379.conf

将原来的 bind 127.0.0.1 这行注释掉,改为 0.0.0.0

# bind 127.0.0.1
bind 0.0.0.0

image-20210731172353517

重启 redis 服务

systemctl restart redis_6379.service

10、设置访问密码

vim /etc/redis/6379.conf

找到 # requirepass foobared,在这个注释下加一行,为 requirepass 自己的密码

# requirepass foobared
requirepass distance

image-20210731172724221

保存,重启 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

image-20210731174249027

redis-cli 客户端连接

[root@xxx redis]# redis-cli -p 6379
127.0.0.1:6379> auth distance
OK
127.0.0.1:6379> ping
PONG

image-20210731174337626

在客户端中可以关闭 redis 服务端

127.0.0.1:6379> shutdown
not connected> exit


 

image-20210731174515927

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

image-20210731172937779

远程连接成功!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

佛係老李

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值