Here it will record Redis common tips
Global use redis-cli
commands such as
Before we are doing at Redis commands directory by ./redis-cli
accessing this form, if you use redis-cli
will be reported if the command does not recognize the error:
-bash: redis-cli: command not found
Setting method:
1) Edit /etc/profile
the file
[root@VM_0_15_centos redis4]# vim /etc/profile
2) adding to Redis installation directory PAHT
path
export PATH=$JAVA_HOME/bin:/usr/local/ruby/bin:$PATH:/usr/local/redis/redis4
3) refresh configuration
[root@VM_0_15_centos redis4]# source /etc/profile
4) perform any directory redis-cli
command
# 返回根目录
[root@VM_0_15_centos redis4]# cd /
# 启动服务
[root@VM_0_15_centos /]# redis-server /usr/local/redis/redis4/config/redis-7000.conf
# 客户端连接
[root@VM_0_15_centos /]# redis-cli -p 7000
Remote Connection
Redis allows only local connections by default, if you need to start a remote connection, then you need to edit redic.conf
to modify the following two configurations:
1) Notes Binding Machine Access
# bind 127.0.0.1 #
2) After redis3.2 also configure protected-mode
protected-mode no
Prohibit the use of command
In a production environment disable some dangerous commands, such as:
- flushdb: Empty database
- flushall: clear all records, databases
- config: The client can configure the server connection
- keys: The client connection can view all existing keys
Disable way
In redis.conf
Find the configuration file SECURITY
options, add the following command:
rename-command FLUSHALL ""
rename-command FLUSHDB ""
rename-command CONFIG ""
rename-command KEYS ""
If you want to keep order, but can not easily use, you can rename command set:
rename-command FLUSHALL adsfdsafsfsdfdsf1
rename-command FLUSHDB adsfdsafsfsdfdsf2
rename-command CONFIG adsfdsafsfsdfdsf3
rename-command KEYS adsfdsafsfsdfdsf4
After this restart the server, you need to use a new command to perform the operation or the server will complain unknown command
. For the FLUSHALL
command, you need to set the configuration file appendonly no
, otherwise the server does not start