Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”.

This article has participated in the “Digitalstar Project” and won a creative gift package to challenge the creative incentive money.

1. Create an installation directory


In order to conveniently manage the installation directory of our general unified software, the installation directory selected here is ->

/usr/local/soft

Download Redis


We through the wget command from redis website to download package – > redis. IO/download the latest version of the current address – > download. Redis. IO/releases/re…

cd /usr/local/soft
wget https://download.redis.io/releases/
Copy the code

3, decompression


The tar - ZXVF redis - 6.2.4. Tar. GzCopy the code

4. Install GCC dependencies


Redis is compiled in C language, compilation needs GCC redis6.x. x version support multi-threading, need GCC version is greater than 4.9, we need to view the default GCC version, if the version is too low, need to upgrade

gcc -v
Copy the code

My newly installed VIRTUAL machine CentOS shows ->\



GCC -> install GCC -> install GCC

yum install gcc
Copy the code



Check the installed version again, find it is 4.8.5, this is the default CentOS version, we need to upgrade GCC ->

yum -y install centos-release-scl

yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils

scl enable devtoolset-9 bash

echo "source /opt/rh/devtoolset-9/enable" >>/etc/profile
Copy the code

View the upgraded version ->\

5. Compile and install

CD redis - 6.2.4 / SRC make installCopy the code

The compilation process is as follows ->\



Compile successfully if you see the following output ->\



Or server and client scripts appear in the SRC directory ->

redis-sentinel
redis-server
redis-cli
Copy the code

6. Modify the configuration file

The configuration file for Redis is in the unzip directory redis.conf\

6.1 First set the background startup to prevent the service from hanging up once the window is closed

The default background startup parameter is **no **->

# By default Redis does not run as a daemon. Use 'yes' if you need it.
# Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
# When Redis is supervised by upstart or systemd, this parameter has no impact.
daemonize no
Copy the code

Change to **yes **->

# By default Redis does not run as a daemon. Use 'yes' if you need it.
# Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
# When Redis is supervised by upstart or systemd, this parameter has no impact.
daemonize yes
Copy the code

6.2 Allow Access from other hosts

According to Redis documentation configuration notes, there are several ways to run other host access ->

  1. You can configure the IP address for accessing the host
  2. Bind * -::* allows access to all other hosts
  3. Bind 0.0.0.0 allows access to all other hosts
  4. Direct comments are equivalent to allowing access by all other hosts
# bind 192.168.1.100 10.0.0.1     # listens on two specific IPv4 addresses
# bind 127.0.0.1 ::1              # listens on loopback IPv4 and IPv6
# bind * -::*                     # like the default, all available interfaces
Copy the code

I deal with it by installing a note to the document to configure \

6.3 Configuring an Access Password

If you want to consider security, you must configure the password, find the RequirePass configuration, and add the following configuration (Ali Cloud and other cloud services must be configured for external network access, the author was hacked, the whole server can not restart restart, heavy losses, but poor, the official processing needs Money, we suggest to be cautious)

requirepass yourpassword
Copy the code

7. Start Redis

Start with redis-server as follows ->

/ usr/local/soft/redis - 6.2.4 / SRC/redis server/usr/local/soft/redis - 6.2.4 / redis. ConfCopy the code

Or this one too ->

cd /src redis-server .. /redis.confCopy the code

Check whether the port is started successfully ->

netstat -an|grep 6379 
Copy the code

8. Client

Enter the client as follows: ->

/ usr/local/soft/redis - 6.2.4 / SRC/redis - cliCopy the code

9. Stop Redis

There are two ways to stop Redis: First, run SHUTDOWN on the client

SHUTDOWN
Copy the code

Method two: Kill -9 with violence

ps -aux | grep redis
kill -9 57927
Copy the code

10. Configure the alias

To make it easy to start Redis and access the client, you can configure an alias to do this

vim ~/.bashrc
Copy the code

Add the following configuration,

  • It’s important to notice
  • Redis and rcli = must not have Spaces
Alias redis = '/ usr/local/soft/redis - 6.2.4 / SRC/redis server/usr/local/soft/redis - 6.2.4 / redis. Conf' alias Rcli = '/ usr/local/soft/redis - 6.2.4 / SRC/redis - cli'Copy the code

Make the configuration take effect

source ~/.bashrc
Copy the code

Now we can start the Redis service through Redis and use rCLI to enter the Redis client \