在 Ubuntu 系统安装 Redis 可以使用以下命令:
$sudo apt-get update
$sudo apt-get install redis-server
启动 Redis
$ redis-server
启动之后如果出现警告,可以按照警告的说明进行修改配置
1.第一个警告:The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
2.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.
1和2 警告解决方案:
sudo vim /etc/sysctl.conf
在最后添加以下两句:
net.core.somaxconn= 1024
vm.overcommit_memory = 1
3.第三个警告:o fix thisissue 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 thesetting after a reboot. Redis must be restarted after THP is disabled.
sudo vim /etc/rc.local
配置文件最后添加:
(如果只用sudo,会提示权限不够,需要用root权限 )
sudo sh -c 'echo never > /sys/kernel/mm/transparent_hugepage/enabled'
打开以下终端:
$ redis-cli
redis 127.0.0.1:6379>
127.0.0.1 是本机 IP ,6379 是 redis 服务端口。现在我们输入 PING 命令。
redis 127.0.0.1:6379> ping
PONG
以上说明我们已经成功安装了redis。