1.安装redis数据库


yum install redis

linux yum 安装redis

2.下载fedora的epel仓库

yum install epel-release

linux yum 安装redis


3.启动redis服务

systemctl start redis

4.查看redis状态

systemctl status redis

systemctl stop redis 停止服务

systemctl restart redis 重启服务

linux yum 安装redis
5.查看redis进程
ps -ef |grep redis

linux yum 安装redis

6.设置开机自启动

systemctl enable redis

linux yum 安装redis

7.开放端口号 (若端口已开放此步可省略,可先8后7)

firewall-cmd --zone=public --add-port=80/tcp --permanent

firewall-cmd --zone=public --add-port=6379/tcp --permanent

注意:80端口是必须要开放的

重启防火墙:systemctl restart firewalld

8.查看端口 (若此命令无效可百度自行安装)

netstat -lnp|grep 6379

9.设置redis 远程连接和密码

输入命令vi /etc/redis.conf进入编辑模式

linux yum 安装redis

    9.1        将这部注释掉,否则只有本机才能访问  bind 127.0.0.1 

        ################################## NETWORK #####################################

        # IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES
        # JUST COMMENT THE FOLLOWING LINE.
        # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        #bind 127.0.0.1

        # Protected mode is a layer of security protection, in order to avoid that
        # Redis instances left open on the internet are accessed and exploited.
        linux yum 安装redis
    9.2     保护模式修改为no
        #bind 127.0.0.1
        # Protected mode is a layer of security protection, in order to avoid that
        # Redis instances left open on the internet are accessed and exploited.
        #
        # When protected mode is on and if:
        #
        # 1) The server is not binding explicitly to a set of addresses using the
        #    "bind" directive.
        # 2) No password is configured.
        #
        # The server only accepts connections from clients connecting from the
        # IPv4 and IPv6 loopback addresses 127.0.0.1 and ::1, and from Unix domain
        # sockets.
        #
        # By default protected mode is enabled. You should disable it only if
        # you are sure you want clients from other hosts to connect to Redis
        # even if no authentication is configured, nor a specific set of interfaces
        # are explicitly listed using the "bind" directive.
        protected-mode no

linux yum 安装redis
    9.3        如果修改端口号,修改这里就可以了,本文默认6379端口
        protected-mode no

        # Accept connections on the specified port, default is 6379 (IANA #815344).
        # If port 0 is specified Redis will not listen on a TCP socket.
        port 6379

linux yum 安装redis
    9.4        修改密码为 111111
        ################################## SECURITY ###################################
        # 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 111111
        linux yum 安装redis


10.保存并退出编辑重启redis

systemctl restart redis

linux yum 安装redis

11.进入redis

    11.1:命令:redis-cli -h 127.0.0.1 -p 6379

linux yum 安装redis
    11.2:输入用户名和密码 auth 111111

linux yum 安装redis

    返回OK
    11.3:然后再输入    info

linux yum 安装redis

12.获取当前的db数 

config get databases

linux yum 安装redis

  13.操作db  select 1  (可为0-15)

linux yum 安装redis

如上,切换到正确的会显示OK。错误的会显示ERR

相关文章:

  • 2021-08-20
  • 2021-10-31
  • 2022-12-23
  • 2022-01-16
  • 2022-12-23
  • 2021-11-27
  • 2022-12-23
猜你喜欢
  • 2021-09-25
  • 2021-12-20
  • 2021-11-10
  • 2022-12-23
相关资源
相似解决方案