zl程序教程

您现在的位置是:首页 >  数据库

当前栏目

CentOS 7 yum安装 Redis

2023-09-14 09:16:41 时间

1、下载fedora的epel仓库

yum install epel-release

2、安装redis数据库

yum install redis -y

3、启动redis

systemctl start redis   # 启动redis
systemctl stop redis    # 停止redis
systemctl status redis    # 查看redis运行状态
ps -ef | grep redis       # 查看redis进程

4、设置开机启动

systemctl enable redis

5、开放防火墙

vi /etc/sysconfig/iptables
-A INPUT -p tcp -m state --state NEW -m tcp --dport 6379 -j ACCEPT  #添加

6、修改配置文件

vi /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 123456  #修改密码 123456

# Command renaming.
#
# It is possible to change the name of dangerous commands in a shared
# environment. For instance the CONFIG command may be renamed into something
# hard to guess so that it will still be available for internal-use tools
# but not available for general clients.
# ~~~ 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 into
# the IPv4 lookback interface address (this means Redis will be able to
# accept connections only from clients running into the same computer it
# is running).
#
# IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES
# JUST COMMENT THE FOLLOWING LINE.
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

添加注释,远程可以访问
# bind 127.0.0.1  

# yes 改 no
protected-mode no 

7、使用端口登陆

[root@centos7 ~] redis-cli -h 127.0.0.1 -p 6379   #测试
127.0.0.1:6379> ping                 #ping命令
(error) NOAUTH Authentication required.      #提示输入密码
127.0.0.1:6379> auth 123456             #输入密码
OK                           #成功