如何为Redis设置密码? [英] How to set password for Redis?

查看:43
本文介绍了如何为Redis设置密码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的本地机器上使用 redis,所以我真的不需要设置密码来使用我的 php 客户端连接到服务器(我使用 predis 作为客户端).但是,我正在将我的应用程序移至实时服务器,因此我想设置一个密码以连接到我的 redis 服务器.

I'm working with redis on my local machine so I dont really need to set up a password to connect to the server with my php client (I'm using predis as a client). However, I'm moving my app to a live server, so I want to set up a password to connect to my redis server.

我有几个问题:

  • 我在网上查了有关如何设置密码的信息,看起来我需要在 redis.conf 中添加密码.我找不到我应该在配置文件中添加什么来设置密码.

  • I checked all over the internet about how to set up the password and it looks like I need to add the password in the redis.conf. I couldnt find though what I should add exactly to the configuration file to set up the password.

也在 predis 中我应该如何添加密码.我正在使用以下参数数组连接到 redis 服务器

also in predis how should I add the password. I'm using the following array of parameters to connect to the redis server

$my_server = array('host' => '127.0.0.1','port' =>6379,'数据库'=> 1);

$my_server = array('host' => '127.0.0.1','port' => 6379,'database' => 1);

我应该这样添加密码吗?

should I add the password this way?

> $my_server = array('host'     => '127.0.0.1','port'     =>
> 6379,'database' => 1,'password'=>password);

  • 最后一个问题,我试图在实时服务器上停止我的 redis-server.每次输入以下命令时,我都会收到相同的错误消息

    • last question, I'm trying to stop my redis-server on the live server. Every time I enter the following command , I keep getting the same error message

      redis-server 停止

      redis-server stop

      [23925] 9 月 23 日 20:23:03 # 致命错误,无法打开配置文件停止"

      [23925] 23 Sep 20:23:03 # Fatal error, can't open config file 'stop'

      通常在我的本地机器上输入

      usually on my local machine I enter

      /etc/init.d/redis-server 停止

      /etc/init.d/redis-server stop

    • 停止 redis 服务器,但它在我的实时服务器上不起作用,因为我的/etc/init.d 中没有名为 redis-server 的进程

      to stop redis server but its not working on my live server since there is no process called redis-server in my /etc/init.d

      推荐答案

      要设置密码,编辑你的redis.conf文件,找到这一行

      To set the password, edit your redis.conf file, find this line

      # requirepass foobared
      

      然后取消注释并将 foobared 更改为您的密码.确保你选择的内容很长,32 个字符左右可能会很好,正如配置文件中提到的那样,外部用户很容易每秒猜出 150k 以上的密码.

      Then uncomment it and change foobared to your password. Make sure you choose something pretty long, 32 characters or so would probably be good, it's easy for an outside user to guess upwards of 150k passwords a second, as the notes in the config file mention.

      要使用 predis 使用您的新密码进行身份验证,您显示的语法是正确的.只需添加密码作为连接参数之一即可.

      To authenticate with your new password using predis, the syntax you have shown is correct. Just add password as one of the connection parameters.

      要关闭 redis... 检查您的配置文件中的 pidfile 设置,它可能是

      To shut down redis... check in your config file for the pidfile setting, it will probably be

      pidfile /var/run/redis.pid
      

      从命令行运行:

      cat /var/run/redis.pid
      

      这会给你正在运行的服务器的进程 id,然后使用该 pid 终止进程:

      That will give you the process id of the running server, then just kill the process using that pid:

      kill 3832
      

      更新

      我还想补充一点,你也可以让 /etc/init.d/redis-server stop 你习惯在你的实时服务器上工作./etc/init.d/中的所有文件都只是 shell 脚本,从本地服务器上取下 redis-server 脚本,然后将其复制到同一位置的实时服务器上,然后看看它对 vi 或其他东西做了什么喜欢用的,可能需要修改一些路径之类的,不过应该挺简单的.

      I also wanted to add, you could also make the /etc/init.d/redis-server stop you're used to work on your live server. All those files in /etc/init.d/ are just shell scripts, take the redis-server script off your local server, and copy it to the live server in the same location, and then just look what it does with vi or whatever you like to use, you may need to modify some paths and such, but it should be pretty simple.

      这篇关于如何为Redis设置密码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆