从源代码编译安装Redis 2.8.24
会使用Ubuntu 14.04.3 LTS作为操作系统进行Redis 2.8.24的源码安装。
1. 在安装之前
我会执行以下命令。
sudo apt-get update
sudo apt-get install -y tcl
2. 下载和解压源文件。
可以从 http://redis.io/download 下载源文件。
$ cd /usr/local/src
$ sudo wget http://download.redis.io/releases/redis-2.8.24.tar.gz
$ sudo tar zxvf redis-2.8.24.tar.gz
3. 安装
创建Redis用户并安装Redis。
$ sudo useradd -s /bin/false -M redis
$ cd /usr/local/src/redis-2.8.24
$ sudo make
$ sudo make install
运行 install_server.sh,并创建 redis 的配置文件。
$ cd /usr/local/src/redis-2.8.24/utils
$ sudo ./install_server.sh
Welcome to the redis service installer
This script will help you easily set up a running redis server
Please select the redis port for this instance: [6379]
Selecting default: 6379
Please select the redis config file name [/etc/redis/6379.conf]
Selected default - /etc/redis/6379.conf
Please select the redis log file name [/var/log/redis_6379.log]
Selected default - /var/log/redis_6379.log
Please select the data directory for this instance [/var/lib/redis/6379]
Selected default - /var/lib/redis/6379
Please select the redis executable path [/usr/local/bin/redis-server]
Selected config:
Port : 6379
Config file : /etc/redis/6379.conf
Log file : /var/log/redis_6379.log
Data dir : /var/lib/redis/6379
Executable : /usr/local/bin/redis-server
Cli Executable : /usr/local/bin/redis-cli
Is this ok? Then press ENTER to go on or Ctrl-C to abort.
Copied /tmp/6379.conf => /etc/init.d/redis_6379
Installing service...
System start/stop links for /etc/init.d/redis_6379 already exist.
Success!
/var/run/redis_6379.pid exists, process is already running or crashed
Installation successful!
对于install_server.sh的响应,我输入了全部的Enter键。
如果一切顺利,Redis应该已经启动了,现在我们来进行启动确认。
$ sudo service redis_6379 status
Redis is running (26622)
Redis已经启动了,对吧。
4.安装(仅安装部分)
如果选择”3.安装”,将安装所有redis的软件包。如果您只想安装一部分软件包,例如redis-cli,请参考以下安装方法。
请安装 redis-cli、redis-benchmark、redis-check-aof 和 redis-check-dump。在执行“2.下载和解压缩源代码文件”之后,请运行以下命令。
$ sudo useradd -s /bin/false -M redis
$ cd /usr/local/src/redis-2.8.24/src
$ sudo make redis-benchmark
$ sudo make redis-cli
$ sudo make redis-check-aof
$ sudo make redis-check-dump
$ sudo cp -pf redis-benchmark /usr/local/bin/
$ sudo cp -pf redis-cli /usr/local/bin/
$ sudo cp -pf redis-check-aof /usr/local/bin/
$ sudo cp -pf redis-check-dump /usr/local/bin/
在输入「redis-」后,按下tab键。
$ redis-
redis-benchmark redis-check-aof redis-check-dump redis-cli
让我们用redis-cli简要地输入一些命令试试。
$ redis-cli --version
redis-cli 2.8.24
$ redis-cli --help
redis-cli 2.8.24
Usage: redis-cli [OPTIONS] [cmd [arg [arg ...]]]
-h <hostname> Server hostname (default: 127.0.0.1).
-p <port> Server port (default: 6379).
-s <socket> Server socket (overrides hostname and port).
-a <password> Password to use when connecting to the server.
-r <repeat> Execute specified command N times.
-i <interval> When -r is used, waits <interval> seconds per command.
It is possible to specify sub-second times like -i 0.1.
-n <db> Database number.
-x Read last argument from STDIN.
-d <delimiter> Multi-bulk delimiter in for raw formatting (default: \n).
-c Enable cluster mode (follow -ASK and -MOVED redirections).
--raw Use raw formatting for replies (default when STDOUT is
not a tty).
--no-raw Force formatted output even when STDOUT is not a tty.
--csv Output in CSV format.
--stat Print rolling stats about server: mem, clients, ...
--latency Enter a special mode continuously sampling latency.
--latency-history Like --latency but tracking latency changes over time.
Default time interval is 15 sec. Change it using -i.
--latency-dist Shows latency as a spectrum, requires xterm 256 colors.
Default time interval is 1 sec. Change it using -i.
--lru-test <keys> Simulate a cache workload with an 80-20 distribution.
--slave Simulate a slave showing commands received from the master.
--rdb <filename> Transfer an RDB dump from remote server to local file.
--pipe Transfer raw Redis protocol from stdin to server.
--pipe-timeout <n> In --pipe mode, abort with error if after sending all data.
no reply is received within <n> seconds.
Default timeout: 30. Use 0 to wait forever.
--bigkeys Sample Redis keys looking for big keys.
--scan List all keys using the SCAN command.
--pattern <pat> Useful with --scan to specify a SCAN pattern.
--intrinsic-latency <sec> Run a test to measure intrinsic system latency.
The test will run for the specified amount of seconds.
--eval <file> Send an EVAL command using the Lua script at <file>.
--help Output this help and exit.
--version Output version and exit.
Examples:
cat /etc/passwd | redis-cli -x set mypasswd
redis-cli get mypasswd
redis-cli -r 100 lpush mylist x
redis-cli -r 100 -i 1 info | grep used_memory_human:
redis-cli --eval myscript.lua key1 key2 , arg1 arg2 arg3
redis-cli --scan --pattern '*:12345*'
(Note: when using --eval the comma separates KEYS[] from ARGV[] items)
When no command is given, redis-cli starts in interactive mode.
Type "help" in interactive mode for information on available commands.