阿里云Centos8服务器安装redis

1、下载

wget https://download.redis.io/releases/redis-6.2.4.tar.gz

2、解压

tar xzf redis-6.2.4.tar.gz

3、编译

#进入文件夹
cd redis-6.2.4
#编译
make

4、移动文件

方便后期统一管理(下载的压缩包默认在/root/文件夹中)

移动到/usr/local/redis文件夹下

mv /root/redis-6.2.4 /usr/local/redis

5、重新编译

cd /usr/local/redis/
make

6、安装

cd ./src/
make install

7、统一管理文件

[root@xxx src]# cd ../
[root@xxx redis]# mkdir etc
[root@xxx redis]# mkdir bin
[root@xxx redis]# ls
00-RELEASENOTES  BUGS          COPYING  etc      Makefile   README.md   runtest          runtest-moduleapi  sentinel.conf  tests utils
bin              CONTRIBUTING  deps     INSTALL  MANIFESTO  redis.conf  runtest-cluster  runtest-sentinel   src            TLS.md
[root@xxx redis]# mv ./redis.conf  ./etc/
[root@xxx redis]# cd ./src/
[root@xxx src]# mv mkreleasehdr.sh redis-benchmark redis-check-aof redis-check-rdb redis-cli redis-server ../bin/
[root@xxx src]# cd ../bin/
[root@xxx bin]# ls
mkreleasehdr.sh  redis-benchmark  redis-check-aof  redis-check-rdb  redis-cli  redis-server
[root@xxx bin]#

8、启动


[root@xxx bin]# ./redis-server

9、设置后台启动

–编辑conf文件,将daemonize属性改为yes(表明需要在后台运行)

按 i 键入编辑,编辑完成后,按ESC键退出编辑,输入 :wq + 回车键保存退出文件。

[root@xxx bin]# vim ../etc/redis.conf

或者直接使用ModbSterm远程连接,直接编辑文档。

10、启动服务

再次启动redis服务,并指定启动服务配置文件

[root@xxx bin]# ./redis-server  ../etc/redis.conf
[root@xxx bin]# ./redis-cli
xxx.x.x.x:xxxx> ping
PONG
xxx.x.x.x:xxxx>

11、开放端口

[root@xxx bin]# sudo firewall-cmd --zone=public --add-port=6379/tcp --permanent
success
[root@xxx bin]# sudo firewall-cmd --reload
success
[root@xxx bin]#

如果报FirewallD is not running异常,需要先开启防火墙:

11.1、查看firewalld状态

systemctl status firewalld

如果是dead状态,即防火墙未开启。

11.2、开启防火墙

systemctl start firewalld

11.3、再次查看firewalld状态

systemctl status firewalld

如果是running状态,即防火墙开启。

11.4、开放6379端口号

如步骤11开头所示。
开放端口完成后,需要再次关闭防火墙

11.5、关闭防火墙

systemctl stop firewalld

12、开启远程连接

打开配置文件把 bind 127.0.0.1 注释掉

[root@xxx bin]# vim ../etc/redis.conf
# Examples:
#
# bind 192.168.1.100 10.0.0.1
# bind 127.0.0.1 ::1
#
# ~~~ WARNING ~~~ If the computer running Redis is directly exposed to the
# internet, binding to all the interfaces is dangerous and will expose the
# instance to everybody on the internet. So by default we uncomment the
# following bind directive, that will force Redis to listen only on the
# IPv4 loopback interface address (this means Redis will only be able to
# accept client connections from the same host that it is running on).
#
# IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES
# JUST COMMENT OUT THE FOLLOWING LINE.
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 允许远程访问
#bind 127.0.0.1

13、设置密码

打开配置文件,找到 # requirepass foobared放开并把foobared替换成自己的密码

# IMPORTANT NOTE: starting with Redis 6 "requirepass" is just a compatibility
# layer on top of the new ACL system. The option effect will be just setting
# the password for the default user. Clients will still authenticate using
# AUTH <password> as usually, or more explicitly with AUTH default <password>
# if they follow the new protocol: both will work.
#
# requirepass foobared
requirepass 123
# Command renaming (DEPRECATED).

14、再次启动服务

再次启动redis服务,并指定启动服务配置文件重新测试

[root@xxx bin]# ./redis-cli
xxx.x.x.x:xxxx> shutdown
not connected>
[root@xxx bin]# ./redis-server  ../etc/redis.conf
[root@xxx bin]# ./redis-cli
#登录
xxx.x.x.x:xxxx> auth 123
OK
xxx.x.x.x:xxxx> ping
PONG
[root@xxx bin]#

参考文档:https://blog.csdn.net/weixin_42759726/article/details/110432310

注:能力有限,还请谅解,争取早日能够写出有质量的文章!

我是皮蛋布丁,一位爱吃皮蛋的热爱运动的废铁程序猿。

在这里插入图片描述

感谢各位大佬光临寒舍~

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值