在ubuntu上安装redis

首先,通过ubuntu的软件安装命令apt-get来安装一下redis:


darkmi@ubuntu:~$ sudo apt-get install redis-server

安装完毕之后,运行一下以下命令:


darkmi@ubuntu:~$ ps -ef|grep redis
redis 3258 1 0 07:15 ? 00:00:00 /usr/bin/redis-server 127.0.0.1:6379
darkmi 3485 2284 0 07:17 pts/18 00:00:00 grep –color=auto redis

可以看到,redis已经启动了。

接下来看一下apt-get命令安装的是那个版本的redis:


darkmi@ubuntu:~$ redis-server -v
Redis server v=3.0.6 sha=00000000:0 malloc=jemalloc-3.6.0 bits=64 build=687a2a319020fa42

可以看到安装的是3.0.6,不过目前redis的最新版本已经到4了,那么我们来手工安装一下最新版本。

首先卸载到刚刚安装的redis:


darkmi@ubuntu:~/Downloads/redis-4.0.1$ sudo apt-get remove redis-server
Reading package lists… Done
Building dependency tree
Reading state information… Done
The following packages were automatically installed and are no longer required:
libjemalloc1 redis-tools snap-confine
Use ‘sudo apt autoremove’ to remove them.
The following packages will be REMOVED:
redis-server
0 upgraded, 0 newly installed, 1 to remove and 11 not upgraded.
After this operation, 918 kB disk space will be freed.
Do you want to continue? [Y/n] Y
(Reading database … 246937 files and directories currently installed.)
Removing redis-server (2:3.0.6-1) …
Processing triggers for man-db (2.7.5-1) …

卸载完成,然后下载最新的redis:


darkmi@ubuntu:~$ cd /usr/local
darkmi@ubuntu:/usr/local$ sudo mkdir redis
[sudo] password for darkmi:
darkmi@ubuntu:/usr/local$ cd redis/
darkmi@ubuntu:/usr/local/redis$ sudo wget http://download.redis.io/releases/redis-4.0.1.tar.gz
–2017-07-28 08:32:59– http://download.redis.io/releases/redis-4.0.1.tar.gz
Resolving download.redis.io (download.redis.io)… 109.74.203.151, 109.74.203.151
Connecting to download.redis.io (download.redis.io)|109.74.203.151|:80… connected.
HTTP request sent, awaiting response… 200 OK
Length: 1711660 (1.6M) [application/x-gzip]
Saving to: ‘redis-4.0.1.tar.gz’

redis-4.0.1.tar.gz 100%[======================================================>] 1.63M 440KB/s in 4.6s

2017-07-28 08:33:04 (365 KB/s) – ‘redis-4.0.1.tar.gz’ saved [1711660/1711660]

解压刚刚下载的压缩包:


sudo tar -zxvf redis-4.0.1.tar.gz

解压完毕之后进入刚刚解压的目录:


darkmi@ubuntu:/usr/local/redis/src$ cd redis-4.0.1/

执行make命令:


darkmi@ubuntu:/usr/local/redis/redis-4.0.1/src$ sudo make

make执行完毕之后会在src目录下生成redis-server和redis-cli等程序:


darkmi@ubuntu:/usr/local/redis/redis-4.0.1/src$ ls -la redis*
-rw-rw-r– 1 root root 2417 Jul 24 06:58 redisassert.h
-rwxr-xr-x 1 root root 2700968 Jul 28 08:36 redis-benchmark
-rw-rw-r– 1 root root 29559 Jul 24 06:58 redis-benchmark.c
-rw-r–r– 1 root root 131792 Jul 28 08:36 redis-benchmark.o
-rwxr-xr-x 1 root root 6155216 Jul 28 08:36 redis-check-aof
-rw-rw-r– 1 root root 7143 Jul 24 06:58 redis-check-aof.c
-rw-r–r– 1 root root 38512 Jul 28 08:36 redis-check-aof.o
-rwxr-xr-x 1 root root 6155216 Jul 28 08:36 redis-check-rdb
-rw-rw-r– 1 root root 13840 Jul 24 06:58 redis-check-rdb.c
-rw-r–r– 1 root root 69128 Jul 28 08:36 redis-check-rdb.o
-rwxr-xr-x 1 root root 2879672 Jul 28 08:36 redis-cli
-rw-rw-r– 1 root root 92423 Jul 24 06:58 redis-cli.c
-rw-r–r– 1 root root 428552 Jul 28 08:36 redis-cli.o
-rw-rw-r– 1 root root 19319 Jul 24 06:58 redismodule.h
-rwxr-xr-x 1 root root 6155216 Jul 28 08:36 redis-sentinel
-rwxr-xr-x 1 root root 6155216 Jul 28 08:36 redis-server
-rwxrwxr-x 1 root root 60843 Jul 24 06:58 redis-trib.rb

可以手工把redis-server及redis-cli拷贝到/usr/local/bin目录下:


sudo cp src/redis-server /usr/local/bin/
sudo cp src/redis-cli /usr/local/bin/

也可以执行make install:


darkmi@ubuntu:/usr/local/redis/redis-4.0.1$ sudo make install
cd src && make install
make[1]: Entering directory ‘/usr/local/redis/redis-4.0.1/src’
CC Makefile.dep

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

INSTALL install
INSTALL install
INSTALL install
INSTALL install
INSTALL install
make[1]: Leaving directory ‘/usr/local/redis/redis-4.0.1/src’

然后看一下/usr/local/bin目录已经有了redis的二进制程序:


darkmi@ubuntu:/usr/local/redis/redis-4.0.1$ cd /usr/local/bin/
darkmi@ubuntu:/usr/local/bin$ ls -la redis*
-rwxr-xr-x 1 root root 2700968 Jul 28 08:42 redis-benchmark
-rwxr-xr-x 1 root root 6155216 Jul 28 08:42 redis-check-aof
-rwxr-xr-x 1 root root 6155216 Jul 28 08:42 redis-check-rdb
-rwxr-xr-x 1 root root 2879672 Jul 28 08:42 redis-cli
lrwxrwxrwx 1 root root 12 Jul 28 08:42 redis-sentinel -> redis-server
-rwxr-xr-x 1 root root 6155216 Jul 28 08:42 redis-server

启动redis:


darkmi@ubuntu:~$ redis-server
8089:C 28 Jul 08:47:27.097 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
8089:C 28 Jul 08:47:27.097 # Redis version=4.0.1, bits=64, commit=00000000, modified=0, pid=8089, just started
8089:C 28 Jul 08:47:27.097 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
8089:M 28 Jul 08:47:27.098 * Increased maximum number of open files to 10032 (it was originally set to 1024).
_._
_.-“__ ”-._
_.-“ `. `_. ”-._ Redis 4.0.1 (00000000/0) 64 bit
.-“ .-“`. “`\/ _.,_ ”-._
( ‘ , .-` | `, ) Running in standalone mode
|`-._`-…-` __…-.“-._|’` _.-‘| Port: 6379
| `-._ `._ / _.-‘ | PID: 8089
`-._ `-._ `-./ _.-‘ _.-‘
|`-._`-._ `-.__.-‘ _.-‘_.-‘|
| `-._`-._ _.-‘_.-‘ | http://redis.io
`-._ `-._`-.__.-‘_.-‘ _.-‘
|`-._`-._ `-.__.-‘ _.-‘_.-‘|
| `-._`-._ _.-‘_.-‘ |
`-._ `-._`-.__.-‘_.-‘ _.-‘
`-._ `-.__.-‘ _.-‘
`-._ _.-‘
`-.__.-‘

8089:M 28 Jul 08:47:27.098 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
8089:M 28 Jul 08:47:27.098 # Server initialized
8089:M 28 Jul 08:47:27.098 # 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.
8089:M 28 Jul 08:47:27.098 # 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.
8089:M 28 Jul 08:47:27.098 * Ready to accept connections

测试一下是否能够连接到redis:


darkmi@ubuntu:~$ redis-cli ping
PONG
darkmi@ubuntu:~$

参考文档:https://redis.io/topics/quickstart

此条目发表在lnmpa分类目录,贴了, , 标签。将固定链接加入收藏夹。

发表评论

电子邮件地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据