Install Redis on Linux

1. Download redis

download link:

English version: https://redis.io/download

Chinese version: www.redis.cn/download.html

Download the redis installation package and upload it to the linux directory. This installation is redis-3.0.7.tar.gz.

[root@xiaohao-db01 vnum]# ls
keepalived-1.2.22.tar.gz  redis-3.0.7.tar.gz
[root@xiaohao-db01 vnum]# 
[root@xiaohao-db01 vnum]# 

2. Install redis

1. Unzip redis-3.0.7.tar.gz

Decompression command: tar -zxvf redis-3.0.7.tar.gz

After decompression, the redis directory can be seen: redis-3.0.7

[root@xiaohao-db01 vnum]# tar -zxvf redis-3.0.7.tar.gz^C
[root@xiaohao-db01 vnum]# 
[root@xiaohao-db01 vnum]# ls
keepalived-1.2.22.tar.gz  redis-3.0.7  redis-3.0.7.tar.gz
[root@xiaohao-db01 vnum]# 

2. Compile the redis decompressed file.

Enter the directory redis-3.0.7 and execute the make command.

[root@xiaohao-db01 vnum]# 
[root@xiaohao-db01 vnum]# cd redis-3.0.7
[root@xiaohao-db01 redis-3.0.7]# make
cd src && make all
make[1]: Entering directory `/vnum/redis-3.0.7/src'
rm -rf redis-server redis-sentinel redis-cli redis-benchmark redis-check-dump redis-check-aof *.o *.gcda *.gcno *.gcov redis.info lcov-html
(cd ../deps && make distclean)
make[2]: Entering directory `/vnum/redis-3.0.7/deps'
(cd hiredis && make clean) > /dev/null || true
(cd linenoise && make clean) > /dev/null || true
(cd lua && make clean) > /dev/null || true
(cd jemalloc && [ -f Makefile ] && make distclean) > /dev/null || true
(rm -f .make-*)
make[2]: Leaving directory `/vnum/redis-3.0.7/deps'
(rm -f .make-*)
echo STD=-std=c99 -pedantic >> .make-settings
echo WARN=-Wall -W >> .make-settings
echo OPT=-O2 >> .make-settings
echo MALLOC=jemalloc >> .make-settings
echo CFLAGS= >> .make-settings

The compilation process shows that the content is old, the compilation is successful, and the final display is generally as follows:

    LINK redis-check-dump
    CC redis-check-aof.o
    LINK redis-check-aof

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

make[1]: Leaving directory `/vnum/redis-3.0.7/src'

3. Install the redis file.

Go to the redis-3.0.7/src directory and execute the make install command.

[root@xiaohao-db01 redis-3.0.7]# 
[root@xiaohao-db01 redis-3.0.7]# ls
00-RELEASENOTES  CONTRIBUTING  deps     Makefile   README      runtest          runtest-sentinel  src    utils
BUGS             COPYING       INSTALL  MANIFESTO  redis.conf  runtest-cluster  sentinel.conf     tests
[root@xiaohao-db01 redis-3.0.7]# cd src
[root@xiaohao-db01 src]# make install

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

    INSTALL install
    INSTALL install
    INSTALL install
    INSTALL install
    INSTALL install
[root@xiaohao-db01 src]# 

4. Create a new folder redis in the directory redis-3.0.7, and copy the configuration files related to redis to this directory.

This is to put the redis related execution files in the same special directory for easy operation. Optional.

[root@xiaohao-db01 redis-3.0.7]# mkdir redis
[root@xiaohao-db01 redis-3.0.7]# ls
00-RELEASENOTES  CONTRIBUTING  deps     Makefile   README  redis.conf  runtest-cluster   sentinel.conf  tests
BUGS             COPYING       INSTALL  MANIFESTO  redis   runtest     runtest-sentinel  src            utils
[root@xiaohao-db01 redis-3.0.7]# 
[root@xiaohao-db01 redis-3.0.7]# cp -a redis.conf redis
[root@xiaohao-db01 redis-3.0.7]# cp -a /vnum/redis-3.0.7/src/redis-cli /vnum/redis-3.0.7/redis
[root@xiaohao-db01 redis-3.0.7]# cp -a /vnum/redis-3.0.7/src/redis-server /vnum/redis-3.0.7/redis
[root@xiaohao-db01 redis-3.0.7]# cp -a /vnum/redis-3.0.7/src/redis-check-dump /vnum/redis-3.0.7/redis
[root@xiaohao-db01 redis-3.0.7]# cp -a /vnum/redis-3.0.7/src/redis-check-aof /vnum/redis-3.0.7/redis
[root@xiaohao-db01 redis-3.0.7]# cp -a /vnum/redis-3.0.7/src/redis-sentinel /vnum/redis-3.0.7/redis
[root@xiaohao-db01 redis-3.0.7]# 
[root@xiaohao-db01 redis-3.0.7]# cp -a /vnum/redis-3.0.7/src/redis-trib.rb /vnum/redis-3.0.7/redis
[root@xiaohao-db01 redis-3.0.7]# cp -a /vnum/redis-3.0.7/src/mkreleasehdr.sh /vnum/redis-3.0.7/redis
[root@xiaohao-db01 redis-3.0.7]# cp -a /vnum/redis-3.0.7/src/redis-benchmark /vnum/redis-3.0.7/redis
[root@xiaohao-db01 redis-3.0.7]# 

After the copy is completed, the redis directory is as follows:

[root@xiaohao-db01 redis-3.0.7]# cd ..
[root@xiaohao-db01 vnum]# ls
keepalived-1.2.22.tar.gz  redis-3.0.7  redis-3.0.7.tar.gz
[root@xiaohao-db01 vnum]# cd redis-3.0.7
[root@xiaohao-db01 redis-3.0.7]# cd redis
[root@xiaohao-db01 redis]# ls
mkreleasehdr.sh  redis-benchmark  redis-check-aof  redis-check-dump  redis-cli  redis.conf  redis-sentinel  redis-server  redis-trib.rb
[root@xiaohao-db01 redis]# 

Third, test redis.

1. Start redis.

Start command: /vnum/redis-3.0.7/redis/redis-server /vnum/redis-3.0.7/redis/redis.conf &

It is recommended to modify the configuration file first, the default background start: daemonize yes

[root@xiaohao-db01 redis]# 
[root@xiaohao-db01 redis]# /vnum/redis-3.0.7/redis/redis-server /vnum/redis-3.0.7/redis/redis.conf
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 3.0.7 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                   
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 26183
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           http://redis.io        
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               

26183:M 19 Apr 14:58:16.466 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
26183:M 19 Apr 14:58:16.466 # Server started, Redis version 3.0.7
26183:M 19 Apr 14:58:16.467 # 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.
26183:M 19 Apr 14:58:16.468 # 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.
26183:M 19 Apr 14:58:16.468 * The server is now ready to accept connections on port 6379

2. Log in to redis and test read and write data.

Login command:

/vnum/redis-3.0.7/redis/redis-cli -h 127.0.0.1 -p 6379

/vnum/redis-3.0.7/redis/redis-cli  -p 6379

After logging in, use the get and set commands to simply test:

[root@xiaohao-db01 redis]# 
[root@xiaohao-db01 redis]# /vnum/redis-3.0.7/redis/redis-cli -h 127.0.0.1 -p 6379
127.0.0.1:6379> 
127.0.0.1:6379> 
127.0.0.1:6379> set test "haha"
OK
127.0.0.1:6379> get "haha"
(nil)
127.0.0.1:6379> get "test"
"haha"
127.0.0.1:6379> del "test"
(integer) 1
127.0.0.1:6379> get "test"
(nil)
127.0.0.1:6379> 

3. Close redis.

Shutdown command: /vnum/redis-3.0.7/redis/redis-cli -p 6379 shutdown

[root@xiaohao-db01 redis]# 
[root@xiaohao-db01 redis]# ps -ef | grep redis
root     26229 20949  0 14:59 pts/0    00:00:00 /vnum/redis-3.0.7/redis/redis-server *:6379                            
root     26447 20949  0 15:02 pts/0    00:00:00 grep redis
[root@xiaohao-db01 redis]# 
[root@xiaohao-db01 redis]# 
[root@xiaohao-db01 redis]# /vnum/redis-3.0.7/redis/redis-cli -p 6379 shutdown
26229:M 19 Apr 15:02:57.769 # User requested shutdown...
26229:M 19 Apr 15:02:57.769 * Saving the final RDB snapshot before exiting.
26229:M 19 Apr 15:02:57.772 * DB saved on disk
26229:M 19 Apr 15:02:57.772 # Redis is now ready to exit, bye bye...
[1]+  Done                    /vnum/redis-3.0.7/redis/redis-server /vnum/redis-3.0.7/redis/redis.conf
[root@xiaohao-db01 redis]# 
[root@xiaohao-db01 redis]# ps -ef | grep redis
root     26450 20949  0 15:03 pts/0    00:00:00 grep redis
[root@xiaohao-db01 redis]# 

Fourth, the configuration of redis.

After installing the file, you can change the redis.conf configuration to enable common functions such as local persistence and active/standby synchronization. This will not be written here for the time being.

Guess you like

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