Linux source code installation

Redis repository: https://download.redis.io/releases/ can choose according to their needs to download the corresponding version of this article is using a version 4.0.2

download

Wget HTTP: / / https://download.redis.io/releases/redis-4.0.2.tar.gzCopy the code

Unzip the source package

The tar XZF redis - 4.0.2. Tar. GzCopy the code

The decompressed directory is redis-4.0.2

The installation

#The decompressed directory is displayedCD redis - 4.0.2
#compile
make
Copy the code

After the make command is executed, the compiled Redis service program redis-server and the client program redis-cli will appear in the SRC directory of Redis-4.0.2

Start the service

There are several ways to start the Redis service, on demand

Methods a

As simple as this, go to the SRC directory of redis-4.0.2 and execute redis-server

cd src

./redis-server
Copy the code

The following screen indicates that the server is successfully started

Way 2

Specify a configuration file to boot on the basis of the first

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

Conf file is in the same directory as SRC. It is the configuration file of redis. Please refer to the screenshot of method 1

A fragment in the redis.conf configuration file

# Redis configuration file example.
#Example Redis configuration file.
#
# Note that in order to read the configuration file, Redis must be
# started with the file path as first argument:
#Note that in order to read the configuration file, Redis must start with the file path as the first argument:
#
# ./redis-server /path/to/redis.conf
Copy the code

Methods three

Both of the above are input foreground mode, and the current window cannot be closed. After Ctrl + C, it will automatically exit, as shown below:

There will be no such problem in the background running mode, which is also one of the more common ways. The implementation is as follows:

Go back to the root directory of redis-4.0.2 and find the redis.conf configuration file

Conf configuration file using vi or vim command. It is recommended that you read the contents of the configuration file

The default bind 127.0.0.1 is uncommented, so you can comment # him if you want to start a remote connection, or specify an IP address

By default, protected-mode yes is enabled for protected mode. If you need to connect remotely, set it to protected-mode no

Daemonize No is not run as a daemon by default, if you want to run daemonize yes

The above operations are the configurations that need to be adjusted when remote connection to Redis is required. The following is how to start Redis in the background

#1. Copy the server to the specified directory, in my case /usr/local/bin/redis, you may not have a redis directory that needs to be created manually
#Create the redis directory
mkdir redis

#Copy your redis source code to redis-server from SRC.Cp/redis - 4.0.2 / SRC/redis server/usr/local/bin/redis/redis - master server
#2. Copy the client for verification after startupCp/redis - 4.0.2 / SRC/redis - cli/usr/local/bin/redis/redis - master - the cli
#3. Copy the configuration file to /etc/redis. If there is no redis directory, create oneCp/redis - 4.0.2 / redis. Conf/etc/redis/redis - master - 6379. Conf
#4. Enter/usr /localStart in /bin/redis and specify configuration file (background mode)
cd /usr/local/bin/redis

./redis-master-server /etc/redis/redis-master-6379.conf

Copy the code

The redis-master-server runs successfully

Client redis-master-CLI test

Remote connection test (if you have remote enabled)

If you need to set a password, go back to your redis.conf configuration file

Methods four

Using the Redis startup script and setting it to boot after startup is a way I’m using myself, find the /redis-4.0.2/utils directory

Find the redis_init_script and I suggest you open it on vim before following my instructions

Copy the startup script to the /etc/init.d directory and rename the startup script to redisd (usually ends with D to indicate that it is the background self-start service).

Cp/redis - 4.0.2 / utils/redis_init_script/etc/init. D/redisdCopy the code

Open vim Redisd to view the content. Remind me that there is a level of directory missing in the screenshot. If you configure it exactly the way I do, please note that you will not step on the pit:

#One redis directory is missing
EXEC=/usr/local/bin/redis/redis-master-server
CLIEXEC=/usr/local/bin/redis/redis-master-cli
Copy the code

So much configuration is for the convenience of starting and stopping, the command line is as follows:

#Start the Redis service
service redisd start

#Stop the Redis service
service redisd stop
Copy the code

Enable automatic startup

Write a comment # chkconfig: 2345 90 10 in the redisd script to change the runlevel, save it and try again

Write in the last

If you have any questions or omissions, please feel free to comment in the comments section

If it helps you all, please remember to like the collection oh ~ (ha ha ha, I forgot how to install it for a long time.