Home > Database > Redis > body text

Detailed explanation of how to install and configure Redis (Linux environment)

青灯夜游
Release: 2021-08-30 09:51:47
forward
1932 people have browsed it

How to installRedis? The following article will introduce to you how to install and configure Redis in a Linux environment.

Detailed explanation of how to install and configure Redis (Linux environment)

[Related recommendations: Redis video tutorial]

1. Prepare the gcc environment

yum install gcc-c++
Copy after login

The following log appears, which means the installation is successful. Package gcc-c -4.8.5-39.el7.x86_64 already installed and latest version

Loaded plugins: fastestmirror
Determining fastest mirrors
base                                                                     | 3.6 kB  00:00:00     
docker-ce-stable                                                         | 3.5 kB  00:00:00     
epel                                                                     | 4.7 kB  00:00:00     
extras                                                                   | 2.9 kB  00:00:00     
nginx                                                                    | 2.9 kB  00:00:00     
updates                                                                  | 2.9 kB  00:00:00     
(1/7): epel/x86_64/group_gz                                              |  95 kB  00:00:00     
(2/7): epel/x86_64/updateinfo                                            | 1.0 MB  00:00:00     
(3/7): docker-ce-stable/x86_64/primary_db                                |  45 kB  00:00:00     
(4/7): extras/7/x86_64/primary_db                                        | 205 kB  00:00:00     
(5/7): updates/7/x86_64/primary_db                                       | 3.0 MB  00:00:00     
(6/7): epel/x86_64/primary_db                                            | 6.8 MB  00:00:00     
(7/7): nginx/x86_64/primary_db                                           |  55 kB  00:00:02     
Package gcc-c++-4.8.5-39.el7.x86_64 already installed and latest version
Nothing to do
[root@root ~]#
Copy after login

2. Download and install Redis

Execute command: wget http://download.redis.io/releases/redis-5.0.7.tar.gz. Unzip it after the download is complete. Then execute the make and make install commands successively.

[root@root /]# cd usr/java
[root@root java]# mkdir redis
[root@root java]# cd redis/
[root@root redis]# wget http://download.redis.io/releases/redis-5.0.7.tar.gz
[root@root redis]# tar -zxvf redis-5.0.7.tar.gz
[root@root redis]# cd redis-5.0.7
[root@root redis-5.0.7]# make
[root@root redis-5.0.7]# make install
Copy after login

3. Start

Enter the command: redis-server redis.conf , start Redis. Seeing the following page means the startup is successful.

[root@root redis-5.0.7]# redis-server redis.conf
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 5.0.7 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                   
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 12513
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           http://redis.io        
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'
Copy after login

But this kind of startup cannot do any operations under this tab page, because after using Ctrl c at this time, it becomes like this. That is to say, Redis is closed. This method is started in the foreground.

^C13082:signal-handler (1594381754) Received SIGINT scheduling shutdown...
13082:M 10 Jul 2020 19:49:14.132 # User requested shutdown...
13082:M 10 Jul 2020 19:49:14.132 * Saving the final RDB snapshot before exiting.
13082:M 10 Jul 2020 19:49:14.135 * DB saved on disk
13082:M 10 Jul 2020 19:49:14.135 * Removing the pid file.
13082:M 10 Jul 2020 19:49:14.135 # Redis is now ready to exit, bye bye...
Copy after login

4. Background startup

Open the redis.conf file. This is also the configuration file of Redis.

[root@root redis-5.0.7]# vim redis.conf 
#打开之后,在命令窗口按下/输入daem然后回车
Copy after login

Detailed explanation of how to install and configure Redis (Linux environment)

Change to yes

daemonize yes
Copy after login

Redis does not run as a daemon process by default. You can modify it through this configuration item and use yes to enable the daemon. Process, after enabling the daemon process, Redis will write the pid to a pidfile in the /var/run/redis_6379.pid file.

Start again

[root@root redis-5.0.7]# redis-server redis.conf 
13352:C 10 Jul 2020 19:54:34.301 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
13352:C 10 Jul 2020 19:54:34.301 # Redis version=5.0.7, bits=64, commit=00000000, modified=0, pid=13352, just started
13352:C 10 Jul 2020 19:54:34.301 # Configuration loaded
Copy after login

5. Connect to Redis

[root@root redis-5.0.7]# redis-cli 
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> config get requirepass
#查看密码
1) "requirepass"
2) ""
127.0.0.1:6379>
Copy after login

Set password

We found that we can enter Redis without a password. So how to set it up?

requirepass foobared: Set the Redis connection password. If the connection password is configured, the client needs to pass AUTH when connecting to Redis The password command provides a password, which is turned off by default.

1. Temporary setting

config set requirepass 123456
Copy after login

2. Permanent setting

[root@root redis-5.0.7]# vim redis.conf
#打开之后,在命令窗口按下/输入 requirepass 然后回车
Copy after login

Find the content as shown in the picture, release the comment and set your own password.

Detailed explanation of how to install and configure Redis (Linux environment)

Detailed explanation of how to install and configure Redis (Linux environment)

Then restart Redis.

[root@root redis-5.0.7]# redis-server redis.conf 
[root@root redis-5.0.7]# redis-cli 
127.0.0.1:6379> ping
(error) NOAUTH Authentication required.
127.0.0.1:6379> auth xxx
OK
127.0.0.1:6379> ping
PONG
127.0.0.1:6379>
Copy after login

You can see that when I ping for the first time, I am prompted that I need to authenticate. auth xxxThis is to enter the password after connecting. You can also enter when connecting:

[root@root redis-5.0.7]# redis-cli -p 6379 -a xxx
Copy after login

Online experience: try.redis.io/

This article is reproduced from: https://juejin.cn /post/6979019298543140901#heading-4

Author: Programmer Xiaojie

For more programming-related knowledge, please visit: Programming Teaching! !

The above is the detailed content of Detailed explanation of how to install and configure Redis (Linux environment). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:juejin.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!