您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
redis配置了密码后如何连接?如何指定连接的redis服务的地址及端口?
发布时间:2021-10-24 18:42:15编辑:雪饮阅读()
当redis配置了密码后,如果客户端redis-cli直接执行是连接不上的。像是这样:
[root@localhost ~]# /usr/local/redis-6.2.5/src/redis-cli
127.0.0.1:6379> ping
(error) NOAUTH Authentication required.
127.0.0.1:6379>
那么首先我们要知道密码,一般的可以这样查看密码:
[root@localhost ~]# cat /usr/local/redis-6.2.5/redis.conf | grep "pass"
# 2) No password is configured.
# If the key file is encrypted using a passphrase, it can be included here
# tls-key-file-pass secret
# If the key file is encrypted using a passphrase, it can be included here
# tls-client-key-file-pass secret
# If the master is password protected (using the "requirepass" configuration
# masterauth <master-password>
# master using the new AUTH form: AUTH <username> <password>.
# partial resync is enough, just passing the portion of data the replica
# 1 million passwords per second against a modern box. This means that you
# should use very strong passwords, otherwise they will be very easy to break.
# Note that because the password is really a shared secret between the client
# and the server, and should not be memorized by any human, the password
# long and unguessable password no brute force attack will be possible.
# has the "nopass" rule, then new connections will be immediately authenticated
# as the "default" user without the need of any password provided via the
# AUTH command. Otherwise if the "default" user is not flagged with "nopass"
# ><password> Add this password to the list of valid password for the user.
# For example >mypass will add "mypass" to the list.
# This directive clears the "nopass" flag (see later).
# <<password> Remove this password from the list of valid passwords.
# nopass All the set passwords of the user are removed, and the user
# is flagged as requiring no password: it means that every
# password will work against this user. If this directive is
# any explicit AUTH command required. Note that the "resetpass"
# resetpass Flush the list of allowed passwords. Moreover removes the
# "nopass" status. After "resetpass" the user has no associated
# passwords and there is no way to authenticate without adding
# some password (or setting it as "nopass" later).
# reset Performs the following actions: resetpass, resetkeys, off,
# passwords, then flags, or key patterns. However note that the additive
# user alice on +@all -DEBUG ~* >somepassword
# user alice on -DEBUG +@all ~* >somepassword
# IMPORTANT NOTE: starting with Redis 6 "requirepass" is just a compatibility
# the password for the default user. Clients will still authenticate using
# AUTH <password> as usually, or more explicitly with AUTH default <password>
# The requirepass is not compatable with aclfile option and the ACL LOAD
# command, these will cause requirepass to be ignored.
requirepass foobared
# deletion, which can be controlled by passing the [SYNC|ASYNC] flags into the
# commands. When neither flag is passed, this directive will be used to determine
# Once a password is set:
# So use the 'requirepass' option to protect your instance.
得到密码后我们可以通过-a参数来指定连接密码。
那么如何指定连接的redis服务的地址及端口呢?用h参数指定地址,用p参数指定端口。
那么如下实例符合以上知识点:
[root@localhost ~]# /usr/local/redis-6.2.5/src/redis-cli -h 127.0.0.1 -p 6379 -a "foobared"
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
127.0.0.1:6379> ping
PONG
这里虽然有一个警告,不过也只是一个警告。
大概意思是:
在命令行界面上使用带有“-a”或“-u”选项的密码可能不安全。
关键字词:redis,密码,地址,端口,指定
上一篇:redis多库的概念