服务器:Centos 7
Redis:5.0.10
因为要安装最新的Redis 6.0.9,需要在服务器安装一堆新的依赖,懒得弄,所以安装旧版redis
安装
$ tar xzf redis-5.0.10.tar.gz
$ cd redis-5.0.10
$ make
配置
修改目录下的redis.conf
文件
- 运行方式使用后台模式
# By default Redis does not run as a daemon. Use 'yes' if you need it.
# Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
daemonize yes
- 对方开放访问
由于本地开发需要访问服务器的redis,所以必须对外提供访问接口,redis对外接口是6379
,防火墙需要对外开放此端口
# ~~~ 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 loopback 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 test.host.com
使用配置文件启动
$ src/redis-server redis.conf
设置密码
在redis.conf
中找到requirepass
设置密码
# 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 123456
再次使用cli工具会报以下错误
127.0.0.1:6379> keys *
(error) NOAUTH Authentication required.
需使用src/redis-cli -a [password]
登录即可。
关闭Redis
$ src/redis-cli shutdown
使用cli工具
$ src/redis-cli
127.0.0.1:6379> keys *
(empty list or set)