Installation:
1. Obtain redis resources
cd /opt
wget http://download.redis.io/rele...
2. Decompression
tar xzvf redis-5.0.7.tar.gz
3. Installation
cd redis-5.0.7 make cd src make install PREFIX=/usr/local/redis
4. Move the configuration file to the installation directory
cd ../ mkdir /usr/local/redis/etc mv redis.conf /usr/local/redis/etc
5. Configure redis
Configuration item name | Configuration item value range | explain |
---|---|---|
daemonize | yes,no | yes indicates that the daemon is enabled. The default is no, that is, it does not run as a daemon. The daemon mode is not supported under Windows system |
port | Specify the Redis listening port. The default port is 6379 | |
bind | The bound host address. If remote access needs to be set, you can directly note this attribute or change it to bind *. This attribute and the protected mode below control whether remote access is possible. | |
protected-mode | yes ,no | Protection mode, which controls whether the external network can connect to redis service. The default is yes, so our external network cannot be accessed by default. If you need to connect to rendis service from the external network, you need to change this attribute to no. |
timeout | 300 | When the client is idle for how long, close the connection. If 0 is specified, it means that the function is closed |
loglevel | debug,verbose,notice,warning | Log level. The default is notice |
databases | 16 | Set the number of databases. The default database is 0. The whole can be seen through the client tool |
rdbcompression | yes,no | Specifies whether to compress the data when stored in the local database. The default is yes. Redis adopts LZF compression. If you want to save CPU time, you can turn this option off, but the database file will become huge. |
dbfilename | dump.rdb | Specify the local database file name. The default value is dump.rdb |
dir | Specify local database storage directory | |
requirepass | Set the Redis connection password. If the connection password is configured, the client needs to provide the password through the auth < password > command when connecting to Redis. It is closed by default | |
maxclients | 0 | Set the maximum number of client connections at the same time. By default, there is no limit. The number of client connections that Redis can open at the same time is the maximum number of file descriptors that Redis process can open. If maxclients 0 is set, it means there is no limit. When the number of client connections reaches the limit, Redis will close the new connection and return the max number of clients reached error message to the client. |
maxmemory | Specify the maximum memory limit of redis. When redis starts, it will load data into memory. When the maximum memory is reached, redis will first try to clear the expired or about to expire keys. After this method is processed, it still reaches the maximum memory setting, and can no longer write, but can still read. Redis's new vm mechanism will store the Key in memory and the Value in the swap area. XXX in the configuration item Value range column is a Value. |
vi /usr/local/redis/etc/redis.conf / / change daemon no to daemon yes
6. Add redis to startup
vi /etc/rc.local / / add content to it: / usr / local / redis / bin / redis server / usr / local / redis / etc / redis.conf
7. Enable redis
/usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf
8. Copy redis CLI and redis server to bin so that redis cli instructions can be used directly in any directory
cp /usr/local/redis/bin/redis-server /usr/local/bin/ cp /usr/local/redis/bin/redis-cli /usr/local/bin/
9. Set redis password
Method 1:
a.Run command: redis-cli b.View existing redis password(Optional operation, no) Run command: config get requirepass c.set up redis password Run command: config set requirepass ****(****For the password you want to set),If the setting is successful, it will be returned'OK'word d.Test connection restart redis service redis-cli -h 127.0.0.1 -p 6379 -a ****(****Password set for you) input redis-cli Enter command mode and use auth '*****' (****Login (password set for you)
10. Enable the Internet to access redis
a.Configure firewall: firewall-cmd --zone=public --add-port=6379/tcp --permanent(Open (6379 port) systemctl restart firewalld(Restart firewall for configuration to take effect immediately) View all open ports of the system: firewall-cmd --zone=public --list-ports b.At this time, although the firewall opens port 6379, the external network is still inaccessible because redis It's 127.0.0.1: 6379,Does not listen for requests from the Internet. (1) Put the folder in the directory redis.conf In the configuration file bind 127.0.0.1 Front plus#Comment out (2) Command: redis-cli connection to redis After, through config get daemonize and config get protected-mode Is it all for no,If not, use it config set The configuration name property is changed to no.
Common commands
redis-server /usr/local/redis/etc/redis.conf //Start redis pkill redis //Stop redis uninstall redis: rm -rf /usr/local/redis //Delete installation directory rm -rf /usr/bin/redis-* //Delete all redis related command scripts rm -rf /opt/redis-5.0.7 //Delete redis decompression folder
Detect whether the background process exists
ps -aux |grep redis
Detect whether port 6379 is listening
netstat -lanp | grep 6379
Use redis cli client to check whether the connection is normal
redis-cli 127.0.0.1:6379> keys * (empty list or set) 127.0.0.1:6379> set key "hello world" OK 127.0.0.1:6379> get key "hello world"
Stop redis:
redis-cli shutdown