Centos 7.6 yum安装Redis(更新时间2020/1/9 09:46)

1. 安装

[root@VM_0_3_centos ~]# yum -y install redis

2. 启动/关闭/重启

# 配置文件启动 &表示后台运行
[root@VM_0_3_centos ~]# redis-server /etc/redis.conf &

# 关闭
[root@VM_0_3_centos ~]# redis-cli shutdown

# 或者
[root@VM_0_3_centos ~]# ps -ef | grep redis
redis    30440     1  0 15:04 ?        00:00:00 /usr/bin/redis-server *:6379
root     30898 28840  0 15:07 pts/1    00:00:00 grep --color=auto redis
# 直接杀死进程
[root@VM_0_3_centos ~]# kill -9 30440

3. 访问 

[root@VM_0_3_centos ~]# redis-cli 
127.0.0.1:6379> set userName "admin"
OK
127.0.0.1:6379> get userName
"admin"
127.0.0.1:6379> exit
[root@VM_0_3_centos ~]# 
# 说明可以正常使用。

 4. Redis 密码设置

# 其实设置密码有两种方式: ① 命令 ② 修改配置,先尝试第一种

# 我们通过命令来设置密码, 默认是没有密码的
127.0.0.1:6379> CONFIG get requirepass
1) "requirepass"
2) ""
127.0.0.1:6379> 
# 设置密码
127.0.0.1:6379> CONFIG set requirepass "123123"
OK
# 验证密码
127.0.0.1:6379> auth "123123"
127.0.0.1:6379> CONFIG get requirepass
1) "requirepass"
2) "123123"
# 密码设置完毕, 测试一下
[root@VM_0_3_centos ~]# redis-cli 
127.0.0.1:6379> get userName
(error) NOAUTH Authentication required.
127.0.0.1:6379> auth 123123
OK
127.0.0.1:6379> get userName
"admin"
127.0.0.1:6379> exit
[root@VM_0_3_centos ~]# 

# 通过修改配置文件来修改密码, 同样的找到
[root@VM_0_3_centos ~]# vim /etc/redis.conf 
################################## SECURITY ###################################
# Require clients to issue AUTH <PASSWORD> before processing any other
# commands.  This might be useful in environments in which you do not trust
# others with access to the host running redis-server.
#
# This should stay commented out for backward compatibility and because most
# people do not need auth (e.g. they run their own servers).
#
# Warning: since Redis is pretty fast an outside user can try up to
# 150k passwords per second against a good box. This means that you should
# use a very strong password otherwise it will be very easy to break.
#
requirepass 123123
# 这应该不言而喻了吧

5. Windows用户可以安装redis-desktop-manager,Linux用户想必大家也没必要用桌面工具,网盘地址

  1. 安装之后准备连接
  2. 如果连接失败,修改配置文件
    # 打开redis配置文件, 找到 bind 127.0.0.1 将其注释, 所在位置上面点。
    [root@VM_0_3_centos ~]# vim /etc/redis.conf
    
    # 注释bind 127.0.0.1或者改为0.0.0.0
    # bind 127.0.0.1
    
    # 找到 protected-mode yes 将其改为 no 
    protected-mode no
    # 然后重启
    [root@VM_0_3_centos ~]# systemctl restart redis.service
    
    
    # 最后还要设置防火墙规则, 开放端口, centos 7如果用的iptables就如下配置。
    iptables -A INPUT -p tcp --dport 6379 -j ACCEPT
    
    # 保存防火墙规则
    [root@VM_0_3_centos ~]# service iptables save
    
    # 用firewall防火墙的朋友
    firewall-cmd --zone=public --add-port=6379/tcp --permanent
    # 生效配置
    firewall-cmd --complete-reload
    
    

     

  3. 再次连接。连接成功

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

cocosum

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

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

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

打赏作者

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

抵扣说明:

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

余额充值