Install Redis on Linux

1. Install gcc 
1. The installation of Redis on linux must first install gcc, which is used to compile the source files of redis. First you need to switch to the root user:

[cheny@localhost ~]$ su
Password: 
[root@localhost cheny]# 

  • 1
  • 2
  • 3
  • 4
  • 5

2. Then start installing gcc:

[root@localhost /]# yum install gcc-c++
//这个命令是在线安装的,所以在这之前你的VM必须能够上网,需要在   VM中把网卡设置成NAT模式 ,因为我使用的是centos,在网络设置中需要把网卡开启,反正我在装完系统之后它是默认关闭的
  • 1
  • 2

3. After that, the download file interface will appear: 
gcc download interface 
4. The confirmation interface will appear twice, just enter y 
write picture description here 

6. If the following code appears, the installation is successful:

Installed:
  gcc-c++.x86_64 0:4.8.5-11.el7                               

Dependency Installed:
  cpp.x86_64 0:4.8.5-11.el7                                   
  gcc.x86_64 0:4.8.5-11.el7                                   
  glibc-devel.x86_64 0:2.17-157.el7_3.5                       
  glibc-headers.x86_64 0:2.17-157.el7_3.5                     
  kernel-headers.x86_64 0:3.10.0-514.26.2.el7                 
  libmpc.x86_64 0:1.0.1-3.el7                                 
  libstdc++-devel.x86_64 0:4.8.5-11.el7                       

Dependency Updated:
  glibc.x86_64 0:2.17-157.el7_3.5                             
  glibc-common.x86_64 0:2.17-157.el7_3.5                      

Complete!
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18

Download the redis package: first go to the official website to download the compressed package and then upload it to the server, or you can directly download it online using wget

wget http://download.redis.io/releases/redis-4.0.2.tar.gz
  • 1

Unzip after downloading

tar -zxvf redis-4.0.2.tar.gz
  • 1

Then enter the unzipped folder to compile

make
  • 1

Install after compiling

[root@VM_75_51_centos redis-4.0.2]# make PREFIX=/usr/local/redis install
cd src && make install
make[1]: Entering directory `/tmp/redis-4.0.2/src'
    CC Makefile.dep
make[1]: Leaving directory `/tmp/redis-4.0.2/src'
make[1]: Entering directory `/tmp/redis-4.0.2/src'

Hint: It's a good idea to run 'make test' ;)

    INSTALL install
    INSTALL install
    INSTALL install
    INSTALL install
    INSTALL install
make[1]: Leaving directory `/tmp/redis-4.0.2/src'
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

Then we enter the /usr/local/redis/bin directory to see if the installation is successful

[root@VM_75_51_centos bin]# cd /usr/local/redis/bin/
[root@VM_75_51_centos bin]# ls -l
total 21820
-rwxr-xr-x 1 root root 2450686 Sep 28 09:29 redis-benchmark
-rwxr-xr-x 1 root root 5746298 Sep 28 09:29 redis-check-aof
-rwxr-xr-x 1 root root 5746298 Sep 28 09:29 redis-check-rdb
-rwxr-xr-x 1 root root 2604968 Sep 28 09:29 redis-cli
lrwxrwxrwx 1 root root      12 Sep 28 09:29 redis-sentinel -> redis-server
-rwxr-xr-x 1 root root 5746298 Sep 28 09:29 redis-server
[root@VM_75_51_centos bin]# 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

You can see that there are a series of executable files in the directory

  • redis-benchmark performance testing tool
  • redis-check-aof AOF file repair tool
  • redis-check-rdb RDB file check tool
  • redis-cli client
  • redis-server server

After that, we need to copy the redis.conf configuration file in the directory we decompressed before to our redis installation directory

[root@VM_75_51_centos redis]# cp /tmp/redis-4.0.2/redis.conf ./redis.conf
[root@VM_75_51_centos redis]# ls
bin  redis.conf
  • 1
  • 2
  • 3

At this point, our Redis installation is complete and can be started. First enter the bin directory and run redis-server

[root@VM_75_51_centos bin]# ./redis-server 
21203:C 28 Sep 09:37:08.713 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
21203:C 28 Sep 09:37:08.713 # Redis version=4.0.2, bits=64, commit=00000000, modified=0, pid=21203, just started
21203:C 28 Sep 09:37:08.713 # Warning: no config file specified, using the default config. In order to specify a config file use ./redis-server /path/to/redis.conf
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 4.0.2 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                   
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 21203
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           http://redis.io        
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               

21203:M 28 Sep 09:37:08.714 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
21203:M 28 Sep 09:37:08.714 # Server initialized
21203:M 28 Sep 09:37:08.714 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
21203:M 28 Sep 09:37:08.714 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
21203:M 28 Sep 09:37:08.714 * DB loaded from disk: 0.000 seconds
21203:M 28 Sep 09:37:08.714 * Ready to accept connections
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29

However, this kind of startup is the foreground startup. After the startup is completed, the current interface can no longer be operated. Therefore, it is necessary to change the startup method and run the redis service in the background.

First open the redis.conf file copied before

change daemonize no todaemonize yes

Start the redis service in the background

[root@VM_75_51_centos redis]# ./bin/redis-server ./redis.conf 
21535:C 28 Sep 09:41:40.394 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
21535:C 28 Sep 09:41:40.394 # Redis version=4.0.2, bits=64, commit=00000000, modified=0, pid=21535, just started
21535:C 28 Sep 09:41:40.394 # Configuration loaded
  • 1
  • 2
  • 3
  • 4

Check to see if it starts

[root@VM_75_51_centos redis]# ps -ef | grep redis
root     21536     1  0 09:41 ?        00:00:00 ./bin/redis-server 127.0.0.1:6379
root     21601 17018  0 09:42 pts/2    00:00:00 grep --color=auto redis
  • 1
  • 2
  • 3

Next, you can use redis

[root@VM_75_51_centos redis]# ./bin/redis-cli 
127.0.0.1:6379> ping
PONG
  • 1
  • 2
  • 3

stop redis service

[root@VM_75_51_centos redis]# ./bin/redis-cli shutdown
[root@VM_75_51_centos redis]# ps -ef | grep redis
root     21691 17018  0 09:43 pts/2    00:00:00 grep --color=auto redis

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325393321&siteId=291194637