Redis安装(单机)
1.下载redis源代码,我的版本是4.0.9
官方下载地址:https://redis.io/download
或者此处下载:
链接:https://pan.baidu.com/s/1Xh756lygYXiz0SHSgg1zxQ 密码:1ey9
2.将redis源码拷贝到Linux中并解压
3.编译
需要提前安装好gcc相关的包( yum install -y open-ssl-devel gcc glibc gcc-c*)
[root@store01 redis-4.0.9]# cd /home/redis-4.0.9/
[root@store01 redis-4.0.9]# male MALLOC=libc
cd src && make install PREFIX=/usr/local/redis
此处可能会编译不成功并提示执行make test,可能会出现问题(如果成功编译,跳过此处):
Redis need tcl 8.5 or newer
解决方法为:
wget http://downloads.sourceforge.net/tcl/tcl8.6.1-src.tar.gz
sudo tar xzvf tcl8.6.1-src.tar.gz -C /usr/local/
cd /usr/local/tcl8.6.1/unix/
sudo ./configure
sudo make
sudo make install
4.复制默认配置文件
mkdir -p /usr/local/redis/conf
cp /home/redis-4.0.9/redis.conf /usr/local/redis/conf/
5.启动redis
[[email protected] redis] cd /usr/local/redis
[[email protected] redis]# bin/redis-server ./conf/redis.conf
58853:C 02 Apr 16:23:04.439 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
58853:C 02 Apr 16:23:04.439 # Redis version=4.0.9, bits=64, commit=00000000, modified=0, pid=58853, just started
58853:C 02 Apr 16:23:04.439 # Configuration loaded
58853:M 02 Apr 16:23:04.441 * Increased maximum number of open files to 10032 (it was originally set to 1024).
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 4.0.9 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 58853
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
58853:M 02 Apr 16:23:04.445 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/c/somaxconn is set to the lower value of 128.
58853:M 02 Apr 16:23:04.445 # Server initialized
58853:M 02 Apr 16:23:04.445 # WARNING overcommit_memory is set to 0! Background save may fail under low memory cition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'ctl vm.overcommit_memory=1' for this to take effect.
58853:M 02 Apr 16:23:04.445 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. Thisll create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernem/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after aboot. Redis must be restarted after THP is disabled.
58853:M 02 Apr 16:23:04.445 * Ready to accept connections
6.上面有三条WARNING信息
6.1.WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
解决方式:
第一种:无需重启系统即可生效;但重启以后信息丢失
[[email protected] ~]# echo 511 >/proc/sys/net/core/somaxconn
第二种:即可生效,重启不会丢失
1. 编辑/etc/sysctl.conf文件,在其后追加
net.core.somaxconn = 511
2. sysctl.conf生效
[[email protected] ~]# sysctl -p
6.2.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.
解决方法:
第一种:无需重启系统即可生效;但重启以后信息丢失
[[email protected] ~]# echo 1 > /proc/sys/vm/overcommit_memory
第二种:即可生效,重启不会丢失
1. 编辑/etc/sysctl.conf文件,在其后追加
vm.overcommit_memory=1
2. sysctl.conf生效
[[email protected] ~]# sysctl -p
6.3.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.
解决方式:
第一种方式我试了没起作用,所以用的第二种。
第一种方法:重启生效,不会丢失
1. 编辑/etc/rc.local,在最后新增如下内容:
if test -f /sys/kernel/mm/transparent_hugepage/enabled; then
echo never > /sys/kernel/mm/transparent_hugepage/enabled
fi
2. 重新启动系统
[root@localhost redis]# reboot
第二种方法:及时生效,重启丢失
[root@localhost redis]# echo never > /sys/kernel/mm/transparent_hugepage/enabled
7.设置后台启动
现在redis不是后台启动的,当前用户关闭窗口或停止进程,redis会被关闭。
设置后台启动:
vi /usr/local/redis/conf/redis.conf
修改其中的daemonize属性为 yes
再次启动redis:
redis-server /usr/local/redis/conf/redis.conf
7.客户端连接
redis-cli
具体操作见参考[3]中。
参考blog:
[1]https://www.cnblogs.com/thomaschen750215/p/7206991.html
[2]https://www.cnblogs.com/wangchunniu1314/p/6339416.html
[3]https://www.cnblogs.com/xiewenming/p/7687364.html
上一篇: 2020年最火小鲜肉排行榜:陈情令两男主均上榜,邓伦第六
下一篇: Redis单机安装