编程知识 cdmana.com

"Attack redis" 2. Installation and configuration under Linux and docker

Preface

  Now good guys already know Redis What is it , No , You don't know . Let's see First time to know Redis . what , You've seen , It doesn't matter. Watch it again , I don't remember to like it , Thank you, my dear brother .
Today we are here in Linux and Docker On (Windows The installation on is really fragrant , Just a little bit , Then click , All right ) Put on a Redis play , The steps are simple , But I hope you can do it yourself . what , You've already installed . No problem , Unload and reload a new one ( Don't play around in production ).
Come on, come on , Stop fighting , I continue to write .

Linux Lower installation Redis

 Linux There are usually two ways to install software under the environment , The first is to install through the software management software of each operating system , image CentOS Of yum,Ubuntu Of apt. But because of Redis The update speed of is relatively fast , And these management tools don't necessarily update to the latest version , meanwhile Redis The installation itself is not very complicated , So we use the second way : Source code way to install , With 4.0.0 Version as an example :

1. download Redis The source code of the specified version is compressed to home Catalog

 cd /home
 wget http://download.redis.io/releases/redis-4.0.0.tar.gz

2. decompression Redis Source compression package

 tar -zxvf redis-4.0.0.tar.gz

3. Build a redis Soft connection of directory , Point to redis-4.0.0, Can not do

 ln -s redis-4.0.0 redis

4. Get into redis Catalog

 cd redis-4.0.0

5. compile ( Make sure the operating system is installed before compiling gcc)

 make

6. install

 ##  The executable file after installation is in by default /usr/local/bin/, It can be executed in any directory Redis The order of 
 make install

7. verification

 ##  Can appear redis-cli 4.0.0 Version indicates that the installation is successful 
 redis-cli -v

Docker install Redis

  Good guys , Super simple . The premise is to be familiar with Docker The related commands and servers have been installed Docker, The same to 4.0.0 For example .

1. Pull the specified version image

 docker pull redis:4.0.0

2. New mount redis Directory of data and configuration

 ## 1.redis data 
 mkdir -p /usr/data/redis/data
 ## 2.redis The configuration file 
 mkdir -p /usr/data/redis/conf

3. View image name

 ##  If there's no accident, this should be redis, This can't even be done directly 4 Ministry . Don't fight. Don't fight , I dare not 
 docker images

4. function redis Containers ( Add the configuration )

 ## -p  Specify the boot and host port number ,restart always Self starting , privileged  Inside the container root Have real root jurisdiction ,-v  Mount Directory , This is mainly data and configuration files , Just behind redis Some of the parameters of 
 docker run -p 6379:6379 --restart always --privileged=true  -v /data/redis/data:/data  -v /data/redis/conf/redis.conf:/etc/redis/redis.conf --name redis:4.0.0 -d redis redis-server /etc/redis/redis.conf --requirepass "123456"  --protected-mode no  --appendonly yes

5. verification

 ##  The first way : Check the process 
 ps -ef | grep redis
 ##  The second way : Go to the container to see the version 
 ##  Get the container id
 docker ps
 ##  Into the container 
 docker exec -it [ Containers id] /bin/
 ##  View version number 
 redis-cli -v

Configuration and startup

  After successful installation according to the above steps , Configuration file in /home/redis-4.0.0 Next . Default configuration is redis.conf, You don't need to change the configuration at this stage .
start-up redis There are three ways , After successful startup, you can see Redis Version of 、 Port and other log information .

1. The default configuration starts

 redis-server

2. Run and configure to start

 ##  Command parsing ,redis-server Add the configuration name and value to be modified ( It can be many pairs of ), Configuration without setting will use the default configuration 
 redis-server --port 6389

3. Specify profile startup

 ##  It's normal to start in this way , Copy a copy of the default configuration , Then modify some of these configurations to start 
 redis-server /conf/redis/redis.conf

close

1. Linux Close down

  Redis Provides shutdown Order to stop Redis service ( It is not recommended to use kill, I won't tell you , I'm afraid you will learn to be bad ), For example, to stop 127.0.0.1 On 6379 On port Redis service , You can do the following .
 redis-cli shutdown

2. Docker Close down

 docker stop [ Containers id]
That's all for this issue , If there is something wrong, please leave a message in the comments area , in addition $\color{#FF0000}{ Please pay attention to 、 Please thumb up }$

Next :Reids Data structure of 、 Thread model and global command
Last one : First time to know Redis

版权声明
本文为[]所创,转载请带上原文链接,感谢
https://cdmana.com/2020/12/20201224135221903z.html

Scroll to Top