How to install redis on Ubuntu 16.04
今天,我们一起介绍一下如何在Ubuntu 16.04中安装最新版的Redis服务器。
add repository
lwk@ubuntu:~$ apt add-repository ppa:chris-lea/redis-server
[sudo] password for lwk:
Sorry, try again.
[sudo] password for lwk:
Redis is an open source, advanced key-value store. It is often referred to as a data structure server since keys can contain strings, hashes, lists, sets and sorted sets.
More info: https://launchpad.net/~chris-lea/+archive/ubuntu/redis-server
Press [ENTER] to continue or ctrl-c to cancel adding it
gpg: keyring `/tmp/tmpwo5j6dfn/secring.gpg' created
gpg: keyring `/tmp/tmpwo5j6dfn/pubring.gpg' created
gpg: requesting key C7917B12 from hkp server keyserver.ubuntu.com
gpg: /tmp/tmpwo5j6dfn/trustdb.gpg: trustdb created
gpg: key C7917B12: public key "Launchpad chrislea" imported
gpg: Total number processed: 1
gpg: imported: 1 (RSA: 1)
OK
lwk@ubuntu:~$
Update index
lwk@ubuntu:~$ apt update
Get:1 http://security.ubuntu.com/ubuntu xenial-security InRelease [102 kB]
Hit:2 http://us.archive.ubuntu.com/ubuntu xenial InRelease
Get:3 http://ppa.launchpad.net/chris-lea/redis-server/ubuntu xenial InRelease [17.5 kB]
Get:4 http://us.archive.ubuntu.com/ubuntu xenial-updates InRelease [102 kB]
Hit:5 http://ppa.launchpad.net/webupd8team/java/ubuntu xenial InRelease
Get:6 http://us.archive.ubuntu.com/ubuntu xenial-backports InRelease [102 kB]
Get:7 http://ppa.launchpad.net/chris-lea/redis-server/ubuntu xenial/main amd64 Packages [1168 B]
Get:8 http://us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 Packages [757 kB]
Get:9 http://ppa.launchpad.net/chris-lea/redis-server/ubuntu xenial/main i386 Packages [1176 B]
Get:10 http://ppa.launchpad.net/chris-lea/redis-server/ubuntu xenial/main Translation-en [688 B]
Get:11 http://us.archive.ubuntu.com/ubuntu xenial-updates/main i386 Packages [701 kB]
Get:12 http://us.archive.ubuntu.com/ubuntu xenial-updates/universe amd64 Packages [620 kB]
Get:13 http://us.archive.ubuntu.com/ubuntu xenial-updates/universe i386 Packages [574 kB]
Fetched 2980 kB in 3s (826 kB/s)
Reading package lists... Done
Building dependency tree
Reading state information... Done
54 packages can be upgraded. Run 'apt list --upgradable' to see them.
lwk@ubuntu:~$
Find redis
lwk@ubuntu:~$ apt list |grep redis
WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
erlang-redis-client/xenial 1.0.8-1 amd64
golang-github-xyproto-simpleredis-dev/xenial,xenial 2.0-1 all
golang-gopkg-redis.v2-dev/xenial,xenial 2.3.2-1 all
kamailio-redis-modules/xenial 4.3.4-1.1ubuntu2 amd64
libanyevent-redis-perl/xenial,xenial 0.24-2 all
libchi-driver-redis-perl/xenial,xenial 0.10-1 all
libhiredis-dbg/xenial 0.13.3-2 amd64
libhiredis-dev/xenial 0.13.3-2 amd64
libhiredis0.13/xenial 0.13.3-2 amd64
libphp-predis/xenial 0.8.3-1 amd64
libredis-perl/xenial,xenial 2:1.9820-1 all
libtest-mock-redis-perl/xenial,xenial 0.19-1 all
lua-nginx-redis/xenial,xenial 0.20-1 all
lua-nginx-redis-connector/xenial,xenial 0.03-1 all
lua-redis/xenial,xenial 2.0.4-2 all
lua-redis-dev/xenial,xenial 2.0.4-2 all
node-node-redis/xenial,xenial 0.1.7-1 all
node-redis/xenial,xenial 0.12.1-2 all
php-nrk-predis/xenial 1.0.0-1 amd64
php-redis/xenial 2.2.7-389-g2887ad1+2.2.7-1 amd64
python-django-websocket-redis/xenial,xenial 0.4.5-2 all
python-hiredis/xenial 0.2.0-1build1 amd64
python-redis/xenial,xenial 2.10.5-1ubuntu1 all
python3-aioredis/xenial,xenial 0.2.4-1 all
python3-django-websocket-redis/xenial,xenial 0.4.5-2 all
python3-hiredis/xenial 0.2.0-1build1 amd64
python3-redis/xenial,xenial 2.10.5-1ubuntu1 all
redis-sentinel/xenial 4:4.0.9-1chl1~xenial1 amd64
redis-server/xenial 4:4.0.9-1chl1~xenial1 amd64
redis-server-dbg/xenial 3:3.0.7-1chl1~xenial1 amd64
redis-tools/xenial 4:4.0.9-1chl1~xenial1 amd64
redis-tools-dbg/xenial 3:3.0.7-1chl1~xenial1 amd64
ruby-em-hiredis/xenial,xenial 0.3.0-3 all
ruby-em-hiredis-doc/xenial,xenial 0.3.0-3 all
ruby-em-redis/xenial,xenial 0.3.0+gh-2 all
ruby-fakeredis/xenial,xenial 0.5.0-1 all
ruby-hiredis/xenial 0.6.1-1build2 amd64
ruby-redis/xenial,xenial 3.2.2-1 all
ruby-redis-actionpack/xenial,xenial 4.0.0-2 all
ruby-redis-activesupport/xenial,xenial 4.1.0-1 all
ruby-redis-namespace/xenial,xenial 1.5.2-3 all
ruby-redis-rack/xenial,xenial 1.5.0-7 all
ruby-redis-rails/xenial,xenial 4.0.0-1 all
ruby-redis-store/xenial,xenial 1.1.6-1 all
syslog-ng-mod-redis/xenial 3.5.6-2.1 amd64
lwk@ubuntu:~$
Install redis-server
lwk@ubuntu:~$ apt install redis-server -y
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
redis-tools
Suggested packages:
ruby-redis
The following NEW packages will be installed:
redis-server redis-tools
0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
Need to get 802 kB of archives.
After this operation, 4019 kB of additional disk space will be used.
Get:1 http://ppa.launchpad.net/chris-lea/redis-server/ubuntu xenial/main amd64 redis-tools amd64 4:4.0.9-1chl1~xenial1 [714 kB]
Get:2 http://ppa.launchpad.net/chris-lea/redis-server/ubuntu xenial/main amd64 redis-server amd64 4:4.0.9-1chl1~xenial1 [88.1 kB]
Fetched 802 kB in 2s (276 kB/s)
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = (unset),
LC_ALL = (unset),
LC_MONETARY = "zh_CN.UTF-8",
LC_ADDRESS = "zh_CN.UTF-8",
LC_TELEPHONE = "zh_CN.UTF-8",
LC_NAME = "zh_CN.UTF-8",
LC_MEASUREMENT = "zh_CN.UTF-8",
LC_IDENTIFICATION = "zh_CN.UTF-8",
LC_NUMERIC = "zh_CN.UTF-8",
LC_PAPER = "zh_CN.UTF-8",
LANG = "en_US.UTF-8"
are supported and installed on your system.
perl: warning: Falling back to a fallback locale ("en_US.UTF-8").
locale: Cannot set LC_ALL to default locale: No such file or directory
Selecting previously unselected package redis-tools.
(Reading database ... 96356 files and directories currently installed.)
Preparing to unpack .../redis-tools_4%3a4.0.9-1chl1~xenial1_amd64.deb ...
Unpacking redis-tools (4:4.0.9-1chl1~xenial1) ...
Selecting previously unselected package redis-server.
Preparing to unpack .../redis-server_4%3a4.0.9-1chl1~xenial1_amd64.deb ...
Unpacking redis-server (4:4.0.9-1chl1~xenial1) ...
Processing triggers for man-db (2.7.5-1) ...
Processing triggers for systemd (229-4ubuntu21.2) ...
Processing triggers for ureadahead (0.100.0-19) ...
Setting up redis-tools (4:4.0.9-1chl1~xenial1) ...
Setting up redis-server (4:4.0.9-1chl1~xenial1) ...
Processing triggers for systemd (229-4ubuntu21.2) ...
Processing triggers for ureadahead (0.100.0-19) ...
lwk@ubuntu:~$
Manager redis server
lwk@ubuntu:~$ sudo systemctl status redis-server
● redis-server.service - Advanced key-value store
Loaded: loaded (/lib/systemd/system/redis-server.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2018-04-17 16:41:52 CST; 1min 34s ago
Docs: http://redis.io/documentation,
man:redis-server(1)
Main PID: 21530 (redis-server)
CGroup: /system.slice/redis-server.service
└─21530 /usr/bin/redis-server 127.0.0.1:6379
Apr 17 16:41:52 toolmall systemd[1]: Starting Advanced key-value store...
Apr 17 16:41:52 toolmall run-parts[21520]: run-parts: executing /etc/redis/redis-server.pre-up
Apr 17 16:41:52 toolmall run-parts[21531]: run-parts: executing /etc/redis/redis-server.post-u
Apr 17 16:41:52 toolmall systemd[1]: Started Advanced key-value store.
lwk@ubuntu:~$
Connect to redis server
lwk@ubuntu:~$ redis-cli
127.0.0.1:6379>
127.0.0.1:6379> quit
lwk@ubuntu:~$ redis-cli
lwk@ubuntu:~$ sudo vim /etc/redis/redis.conf
lwk@ubuntu:~$ sudo systemctl restart redis-server
lwk@ubuntu:~$ sudo systemctl status redis-server
● redis-server.service - Advanced key-value store
Loaded: loaded (/lib/systemd/system/redis-server.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2018-04-17 16:57:47 CST; 14s ago
Docs: http://redis.io/documentation,
man:redis-server(1)
Process: 21666 ExecStopPost=/bin/run-parts --verbose /etc/redis/redis-server.post-down.d (code=
Process: 21661 ExecStop=/bin/kill -s TERM $MAINPID (code=exited, status=0/SUCCESS)
Process: 21657 ExecStop=/bin/run-parts --verbose /etc/redis/redis-server.pre-down.d (code=exite
Process: 21683 ExecStartPost=/bin/run-parts --verbose /etc/redis/redis-server.post-up.d (code=e
Process: 21680 ExecStart=/usr/bin/redis-server /etc/redis/redis.conf (code=exited, status=0/SUC
Process: 21675 ExecStartPre=/bin/run-parts --verbose /etc/redis/redis-server.pre-up.d (code=exi
Main PID: 21682 (redis-server)
Tasks: 4
Memory: 6.4M
CPU: 64ms
CGroup: /system.slice/redis-server.service
└─21682 /usr/bin/redis-server *:6379
Apr 17 16:57:46 toolmall systemd[1]: Starting Advanced key-value store...
Apr 17 16:57:47 toolmall run-parts[21675]: run-parts: executing /etc/redis/redis-server.pre-up.d/
Apr 17 16:57:47 toolmall run-parts[21683]: run-parts: executing /etc/redis/redis-server.post-up.d
Apr 17 16:57:47 toolmall systemd[1]: Started Advanced key-value store.
lines 1-22/22 (END)
参考文献