Installation:

1. Obtain redis resources

wget http://download.redis.io/releases/redis-4.08..tar.gz
Copy the code

2. Unzip

tar xzvf redis-4.08..tar.gz
Copy the code

3. The installation

cd redis-4.08.
make
cd src
make install PREFIX=/usr/local/redis
Copy the code

4. Move the configuration file to the installation directory

cd .. / mkdir /usr/local/redis/etc mv redis.conf /usr/local/redis/etcCopy the code

5. Configure Redis as the background boot device

Vi/usr/local/redis/etc/redis. Conf / / change daemonize no to daemonize yesCopy the code

6. Add Redis to boot

Run the vi /etc/rc.local // command to add /usr/local/redis/bin/ redis server/usr/local/redis/etc/redis. Conf (which means boot call this open redis command)Copy the code

7. Open redis

/usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf 
Copy the code

 

8. Copy redis-cli and redis-server to bin so that the redis-cli commands can be directly used in any directory

cp /usr/local/redis/bin/redis-server /usr/local/bin/
cp /usr/local/redis/bin/redis-cli /usr/local/bin/
Copy the code

9. Set a Redis password

A. Run the redis-cli command b. View the existing redis password (optional). Run the config get requirepass command. If no password has been set, the following figure is displayed. To set the redis password, run the config commandsetRequirepass ****(**** is the password you want to set), which returns an 'OK' d on success. Test connection restart redis service // (redis-cli -h127.0. 01. -p 6379-a **** (**** for the password you set)) enter redis-cli to enter command mode and use auth'* * * * *'(**** set your password for you) loginCopy the code

10. Make Redis accessible to the extranet

A. Configure the firewall: **firewall-cmd --zone=public --add-port=6379/ TCP --permanent** (open **6379**systemctl restart firewalld** check all open ports in the system: firewall-cmd --zone=public --list-ports b. The firewall is enabled6379Port, but the external network is still not accessible, because redis is listening to127.0. 01.:6379Does not listen for requests from the Internet. Conf configuration file in the redis.conf folder127.0. 01.The front and# comment outAfter connecting to redis, run config get daemonize and config get protected-mode to check whether the values are no. If not, use configsetChange the configuration name attribute to no.Copy the code

Common commands

Redis server/usr/local/redis/etc/redis. Conf / / start redis

Pkill redis // Stop redis

Uninstall redis:

Rm -rf /usr/local/redis // Delete the installation directory

Rm -rf /usr/bin/redis-* // Delete all redis-related command scripts

Rm -rf /root/download/redis-4.0.4 // Delete the decompressed redis folder

Start the redis:

Two ways:

Redis -server & with an ampersand makes Redis run as a backend applicationCopy the code

Or is it

redis-server
Copy the code

Check whether background processes exist

ps -ef |grep redis
Copy the code

Check whether port 6379 is listening

netstat -lntp | grep 6379
Copy the code

Sometimes exceptions are reported

Cause: Redis has been started

Solution: Shut down Redis and restart it

redis-cli shutdown
redis-server
Copy the code

Then you can see Redis running happily.

useredis-cliThe client checks whether the connection is normal

redis-cli
>127.0. 01.:6379> keys *
>(empty list or set)
>127.0. 01.:6379set key "hello world" 
>OK
>127.0. 01.:6379> get key
>"hello world"
Copy the code

Stop redis:

Using the client

redis-cli shutdown
Copy the code

Because Redis can handle SIGTERM signals properly, it is also possible to kill -9 PID

Start the Redis server

$ src/redis-server

Start the Redis client

$ src/redis-cli

Check if Redis is installed on Linux and redis starts

Check whether redis-CLI and redis-server are installed

[root@localhost bin]# whereis redis-cli
redis-cli: /usr/bin/redis-cli
[root@localhost bin]# whereis redis-server
redis-server: /usr/bin/redis-server
Copy the code

Set the password of Redis in Linux

Redis password:

1. Go to the command line of redis operation and run the redis-cli command

2. Check the existing redis password (optional) run the config get requirepass command. If no password has been set, the result will look like the following figure

Run the config set requirepass **** command (**** is the password you want to set). ‘OK’ will be returned if the password is set successfully

4, restart the redis service CTRL +C exit the current command line mode and run the following command: redis-cli -h 127.0.0.1 -p 6379 -a **** (**** set password for your heart)