Redis Installation

Redis Installation

Basic Info

  • OS: CentOS 7.3
  • Redis Version: 4.0.6

Install Redis

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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
[root@localhost ~]# cd /opt/software
## You can also can download Redis on https://redis.io/
[root@localhost software]# wget http://download.redis.io/redis-stable.tar.gz
[root@localhost software]# tar -zxvf redis-stable.tar.gz
[root@localhost software]# cd redis-stable/
[root@localhost redis-stable]# ll
total 280
-rw-r--r-- 1 root root 142334 Dec 4 09:01 00-RELEASENOTES
-rw-r--r-- 1 root root 53 Dec 4 09:01 BUGS
-rw-r--r-- 1 root root 1815 Dec 4 09:01 CONTRIBUTING
-rw-r--r-- 1 root root 1487 Dec 4 09:01 COPYING
drwxr-xr-x 6 root root 124 Dec 4 09:01 deps
-rw-r--r-- 1 root root 11 Dec 4 09:01 INSTALL
-rw-r--r-- 1 root root 151 Dec 4 09:01 Makefile
-rw-r--r-- 1 root root 4223 Dec 4 09:01 MANIFESTO
-rw-r--r-- 1 root root 20543 Dec 4 09:01 README.md
-rw-r--r-- 1 root root 57764 Dec 4 09:01 redis.conf
-rwxr-xr-x 1 root root 271 Dec 4 09:01 runtest
-rwxr-xr-x 1 root root 280 Dec 4 09:01 runtest-cluster
-rwxr-xr-x 1 root root 281 Dec 4 09:01 runtest-sentinel
-rw-r--r-- 1 root root 7606 Dec 4 09:01 sentinel.conf
drwxr-xr-x 3 root root 4096 Dec 4 09:01 src
drwxr-xr-x 10 root root 167 Dec 4 09:01 tests
drwxr-xr-x 8 root root 4096 Dec 4 09:01 utils
[root@localhost redis-stable]# make
## ...
LINK redis-server
INSTALL redis-sentinel
CC redis-cli.o
LINK redis-cli
CC redis-benchmark.o
LINK redis-benchmark
INSTALL redis-check-rdb
INSTALL redis-check-aof
Hint: Its a good idea to run make test ;)
make[1]: Leaving directory /opt/software/redis-stable/src
[root@localhost redis-stable]# make install
cd src && make install
make[1]: Entering directory /opt/software/redis-stable/src
CC Makefile.dep
make[1]: Leaving directory /opt/software/redis-stable/src
make[1]: Entering directory /opt/software/redis-stable/src
Hint: Its a good idea to run make test ;)
INSTALL install
INSTALL install
INSTALL install
INSTALL install
INSTALL install
make[1]: Leaving directory /opt/software/redis-stable/src
## 執行安裝後,/usr/local/bin會有Redis執行所需的二進制檔案
[root@localhost redis-stable]# ll /usr/local/bin | grep redis
total 22108
-rwxr-xr-x 1 root root 2450856 Jan 22 22:48 redis-benchmark
-rwxr-xr-x 1 root root 5752656 Jan 22 22:48 redis-check-aof
-rwxr-xr-x 1 root root 5752656 Jan 22 22:48 redis-check-rdb
-rwxr-xr-x 1 root root 2616056 Jan 22 22:48 redis-cli
lrwxrwxrwx 1 root root 12 Jan 22 22:48 redis-sentinel -> redis-server
-rwxr-xr-x 1 root root 5752656 Jan 22 22:48 redis-server

Binary File Description

  • redis-server:Redis服務端啟動程式
  • redis-cli:Redis客戶端操作工具
  • redis-benchmark:Redis性能測試工具
  • redis-check-aof:數據修復工具
  • redis-check-dump:檢查導出工具

Configure Redis

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
30
31
32
33
34
35
36
[root@localhost redis-stable]# cd ..
## 創建Redis執行時所需的資料夾
[root@localhost software]# mkdir redis
[root@localhost software]# cd redis
[root@localhost redis]# mkdir data log run conf
## 配置Redis執行時的conf文件
[root@localhost redis]# cp ../redis-stable/redis.conf ./conf/redis_6379.conf
[root@localhost redis]# vim conf/redis_6379.conf
## ...
# Creating a pid file is best effort: if Redis is not able to create it
# nothing bad happens, the server will start and run normally.
pidfile /opt/software/redis/run/redis_6379.pid
## ...
# The working directory.
#
# The DB will be written inside this directory, with the filename specified
# above using the 'dbfilename' configuration directive.
#
# The Append Only File will also be created inside this directory.
#
# Note that you must specify a directory here, not a file name.
dir /opt/software/redis/data
## ...
# Specify the log file name. Also the empty string can be used to force
# Redis to log on the standard output. Note that if you use standard
# output for logging but daemonize, logs will be sent to /dev/null
logfile /opt/software/redis/log/redis.log
## ...
# By default Redis does not run as a daemon. Use 'yes' if you need it.
# Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
daemonize yes

Set Redis as Service

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
[root@localhost redis]# cd ../redis-stable/
[root@localhost redis-stable]# cp ./utils/redis_init_script /etc/init.d/redis
[root@localhost redis-stable]# cd /etc/init.d
[root@localhost init.d]# vim redis
#!/bin/sh
# Add this for solving the error message "service redis does not support chkconfig"
# chkconfig: 2345 90 10
# description: Redis is a persistent key-value database
#
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.
REDISPORT=6379
EXEC=/usr/local/bin/redis-server
CLIEXEC=/usr/local/bin/redis-cli
## 對應先前設定Redis Configuration路徑
PIDFILE=/opt/software/redis/run/redis_${REDISPORT}.pid
CONF="/opt/software/redis/conf/redis_${REDISPORT}.conf"
## Test the settings is okay or not
[root@localhost init.d]# service redis start
Starting Redis server...

Set Redis as Auto-start Services on Boot

1
2
3
4
5
6
7
8
## if occur error message "service redis does not support chkconfig", add the chkconfig description in file named redis
[root@localhost init.d]# chkconfig redis on
## Reboot system for testing the auto-start settings
## Use ps command to check Redis service running state
[datacenter@localhost ~]$ ps -aux | grep redis
root 998 0.1 0.1 145248 7548 ? Ssl 01:44 0:00 /usr/local/bin/redis-server 127.0.0.1:6379
datacen+ 2759 0.0 0.0 112652 1004 pts/1 S+ 01:46 0:00 grep --color=auto redis

Use Redis Client

1
2
3
4
5
6
7
8
9
10
11
12
13
14
[datacenter@localhost ~]$ redis-cli
127.0.0.1:6379> help
redis-cli 4.0.6
To get help about Redis commands type:
"help @<group>" to get a list of commands in <group>
"help <command>" for help on <command>
"help <tab>" to get a list of possible help topics
"quit" to exit
To set redis-cli preferences:
":set hints" enable online hints
":set nohints" disable online hints
Set your preferences in ~/.redisclirc
127.0.0.1:6379>