Redis mining without verification
/ / step 1: instantiate the redis object
$redis = new redis()
/ / step 2: set the IP and port of PHP client
$redis - & gt; connect(" 127.0.0.1",& quot; 6379");
/ / Part 3: configure the connection password to detect the connection status of the redis server
/ / if the connection fails, it ends directly and outputs
$auth = $redis - & gt; auth(' zhenai') or die(" Redis server connection failed & quot;)< br />// var_ mp($auth); If the connection is successful, return true, otherwise return false
/ / the fourth step is available, but do not use
echo $connect_ status=$redis-> ping();< br />if($connect_ status==="+ PONG")< br />{
echo " Redis server connected successfully & quot
}
/ / it's so simple
after downloading, the location
CD to D: &; Java\ The directory location in the 64 bit graph is
so the startup is successful
to set the redis password, you need to find the requirepass keyword in redis.conf, set the password to 123456
redis-cli.exe to enter the client
and then auth 123456 notes: auth password
set object name [a] value [123]
get object name [a]
after that, you can use the local redis
note: redis does not need to set the password, so it does not need to execute the command of auth.
1.通过配置文件进行配置
yum方式安装的redis配置文件通常在/etc/redis.conf中,打开配置文件找到
<pre name="code" class="plain">#requirepass foobared</pre>
去掉行前的注释,并修改密码为所需的密码,保存文件
<pre name="code" class="plain">requirepass myRedis</pre>
重启redi
<pre name="code" class="plain">sudo service redis restart #或者 sudo service redis stop sudo redis-server /etc/redis.conf</pre>
这个时候尝试登录redis,发现可以登上,但是执行具体命令是提示操作不允许
<pre name="code" class="plain">redis-cli -h 127.0.0.1 -p 6379 redis 127.0.0.1:6379> redis 127.0.0.1:6379> keys * (error) ERR operation not permitted redis 127.0.0.1:6379> select 1 (error) ERR operation not permitted redis 127.0.0.1:6379[1]> </pre>
尝试用密码登录并执行具体的命令看到可以成功执行
<pre name="code" class="plain">redis-cli -h 127.0.0.1 -p 6379 -a myRedis redis 127.0.0.1:6379> keys * 1) "myset" 2) "mysortset" redis 127.0.0.1:6379> select 1 OK redis 127.0.0.1:6379[1]> config get requirepass 1) "requirepass" 2) "myRedis"</pre>
2.通过命令行进行配置
<pre name="code" class="plain">redis 127.0.0.1:6379[1]> config set requirepass my_redis OK redis 127.0.0.1:6379[1]> config get requirepass 1) "requirepass" 2) "my_redis"</pre>
无需重启redi
使用第一步中配置文件中配置的老密码登录redis,会发现原来的密码已不可用,操作被拒绝
<pre name="code" class="plain">redis-cli -h 127.0.0.1 -p 6379 -a myRedis redis 127.0.0.1:6379> config get requirepass (error) ERR operation not permitted</pre>
使用修改后的密码登录redis,可以执行相应操作
<pre name="code" class="plain">redis-cli -h 127.0.0.1 -p 6379 -a my_redis redis 127.0.0.1:6379> config get requirepass 1) "requirepass" 2) "my_redis </pre>
尝试重启一下redis,用新配置的密码登录redis执行操作,发现新的密码失效,redis重新使用了配置文件中的密码
<pre name="code" class="plain">sudo service redis restart Stopping redis-server: [ OK ] Starting redis-server: [ OK ] redis-cli -h 127.0.0.1 -p 6379 -a my_redis redis 127.0.0.1:6379> config get requirepass (error) ERR operation not permitted redis-cli -h 127.0.0.1 -p 6379 -a myRedis redis 127.0.0.1:6379> config get requirepass 1) "requirepass" 2) "myRedis"</pre>
除了在登录时通过 -a 参数制定密码外,还可以登录时不指定密码,而在执行操作前进行认证
<pre name="code" class="plain">redis-cli -h 127.0.0.1 -p 6379 redis 127.0.0.1:6379> config get requirepass (error) ERR operation not permitted redis 127.0.0.1:6379> auth myRedis OK redis 127.0.0.1:6379> config get requirepass 1) "requirepass" 2) "myRedis" </pre>
3.master配置了密码,slave如何配置
若master配置了密码则slave也要配置相应的密码参数否则无法进行正常复制的
lave中配置文件内找到如下行,移除注释,修改密码即可
<pre name="code" class="plain">#masterauth mstpassword</pre>
1. The safer way is to control by binding IP
please find the following configuration in redis.conf file
? If you want you can bind a single interface, if the bind option is not
? Specified all the interfaces will listen for incoming connections.
? Bind 127.0.0.1
remove the comment before bind 127.0.0.1, Then change 127.0.0.1 to the IP address where you are allowed to access your redis server, which means that only this IP is allowed to access
in this case, we can no longer use redis server when starting redis server: redis server path / redis.conf, which specifies the configuration file to be loaded when starting, where path / is the directory where the redis configuration file you modified above is located, This method is not very good. I can't help but have multiple machines accessing a redis service
2. Set the password to provide remote login
open the redis.conf configuration file, find the requirepass, and then modify it as follows:
requirepass yourpassword
yourpassword is the password of redis verification. After setting the password, it is found that you can login, but you cannot execute the command
the command is as follows:
redis cli - H yourip - P yourport / / start the redis client and connect to the server
keys * / / output all the keys in the server
report an error as follows
(error) err operation not permitted
at this time, you can use the authorization command to authorize, and no error will be reported
the command is as follows:
auth youpassword
in addition, When connecting to the server, you can specify the login password to avoid entering the above authorization command separately.
the command is as follows:
redis cli - H yourip-p yourport - a youpassword
in addition to configuring the verification password in the configuration file redis.conf, you can also set the password through the command line on the started redis server, but this method is temporary, When the server restarts, the password must be reset. The way to set the password on the command line is as follows:
config set requirepass your password
sometimes we don't know whether the current redis server has set the verification password, or we forget what the password is. We can enter the command through the command line to view the password, The command is as follows:
config get requirepass
if the redis server does not have a password configured, it will get nil. If the password is configured, but when the redis client connects to the redis server, it does not log in with a password for verification, and it will prompt: operation not permitted. At this time, you can use the command: auth yourpassword to verify the password, If you execute config set requirepass again, you will see yourpassword
because redis has a strong concurrency ability and only uses passwords, the attacker may send a large number of password guessing requests in a short time, which is easy to crack violently. Therefore, it is suggested that the longer the password, the better, for example, 20 bits The password is clear in the conf file, so don't worry about forgetting it.)