查询linux版本
cat /etc/redhat-release
http://download.redis.io/releases/
下载好的 redis-stable.tar.gz 放到/usr/local/src/目录里
yum -y install gcc gcc-c++ make automake
yum -y install tcl
cd /usr/local/src/
tar -zxvf redis-stable.tar.gz
cd redis-stable
make
7.进入src目录
cd /usr/local/src/redis-stable/src
make test
make PREFIX=/usr/local/redis install
安装成功如下:
Hint: It’s a good idea to run ‘make test’ ;)
INSTALL install
INSTALL install
INSTALL install
INSTALL install
INSTALL install
8.返回解压目录
cd /usr/local/src/redis-stable
cp redis.conf /usr/local/redis
which redis-server
/usr/local/bin/redis-server
redis-server --help
cd /usr/local/redis
vi redis.conf
修改no=yes,这里配置redis为前台启动还是后台启动一般选择后台启动
daemonize yes
cd /usr/local/redis/bin
redis-server
结果:
1161:C 28 Mar 11:10:20.852 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
1161:C 28 Mar 11:10:20.852 # Redis version=4.0.8, bits=64, commit=00000000, modified=0, pid=1161, just started
1161:C 28 Mar 11:10:20.852 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
1161:M 28 Mar 11:10:20.853 * Increased maximum number of open files to 10032 (it was originally set to 1024).
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 4.0.8 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 1161
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
1161:M 28 Mar 11:10:20.856 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
1161:M 28 Mar 11:10:20.857 # Server initialized
1161:M 28 Mar 11:10:20.857 # 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.
1161:M 28 Mar 11:10:20.857 # 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.
1161:M 28 Mar 11:10:20.857 * Ready to accept connections
Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
重新启动并指定路径
redis-server ../redis.conf
结果
1165:C 28 Mar 11:11:41.927 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
1165:C 28 Mar 11:11:41.927 # Redis version=4.0.8, bits=64, commit=00000000, modified=0, pid=1165, just started
1165:C 28 Mar 11:11:41.927 # Configuration loaded
1165:M 28 Mar 11:11:41.927 * Increased maximum number of open files to 10032 (it was originally set to 1024).
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 4.0.8 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 1165
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
1165:M 28 Mar 11:11:41.929 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
1165:M 28 Mar 11:11:41.929 # Server initialized
1165:M 28 Mar 11:11:41.929 # 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.
1165:M 28 Mar 11:11:41.929 # 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.
1165:M 28 Mar 11:11:41.929 * DB loaded from disk: 0.000 seconds
1165:M 28 Mar 11:11:41.929 * Ready to accept connections
^C1165:signal-handler (1522249966) Received SIGINT scheduling shutdown...
1165:M 28 Mar 11:12:46.826 # User requested shutdown...
1165:M 28 Mar 11:12:46.826 * Saving the final RDB snapshot before exiting.
1165:M 28 Mar 11:12:46.827 * DB saved on disk
1165:M 28 Mar 11:12:46.827 * Removing the pid file.
1165:M 28 Mar 11:12:46.827 # Redis is now ready to exit, bye bye...
发现错误
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.
内核参数overcommit_memory
它是 内存分配策略
可选值:0、1、2。
0, 表示内核将检查是否有足够的可用内存供应用进程使用;如果有足够的可用内存,内存申请允许;否则,内存申请失败,并把错误返回给应用进程。
1, 表示内核允许分配所有的物理内存,而不管当前的内存状态如何。
2, 表示内核允许分配超过所有物理内存和交换空间总和的内存
解决方法:
编辑sysctl.conf 在最后一行添加
vm.overcommit_memory = 1
vi etc/sysctl.conf
redis-server ../redis.conf
结果
1197:C 28 Mar 11:14:38.539 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
1197:C 28 Mar 11:14:38.539 # Redis version=4.0.8, bits=64, commit=00000000, modified=0, pid=1197, just started
1197:C 28 Mar 11:14:38.539 # Configuration loaded
1197:M 28 Mar 11:14:38.540 * Increased maximum number of open files to 10032 (it was originally set to 1024).
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 4.0.8 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 1197
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
1197:M 28 Mar 11:14:38.542 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
1197:M 28 Mar 11:14:38.542 # Server initialized
1197:M 28 Mar 11:14:38.542 # 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.
1197:M 28 Mar 11:14:38.542 * DB loaded from disk: 0.000 seconds
1197:M 28 Mar 11:14:38.542 * Ready to accept connections
WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
这句话的翻译大概就是:对一个高负载的环境来说tcp设置128这个值,太小了。 这是我的理解,绝体的还需到官网理解。然后我们可以手动设置,或者设置永久值.所以执行:
echo 511 > /proc/sys/net/core/somaxconn
命令就把这个问题解决了。但是这个只是暂时的。如果想要永久解决,打开etc/sysctl.conf
在最后一行添加
net.core.somaxconn= 1024
vi etc/sysctl.conf
然后执行sysctl -p 使配置文件生效
sysctl -p
redis-server ../redis.conf
1266:C 28 Mar 11:47:21.587 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
1266:C 28 Mar 11:47:21.587 # Redis version=4.0.8, bits=64, commit=00000000, modified=0, pid=1266, just started
1266:C 28 Mar 11:47:21.587 # Configuration loaded
1266:M 28 Mar 11:47:21.588 * Increased maximum number of open files to 10032 (it was originally set to 1024).
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 4.0.8 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 1266
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
1266:M 28 Mar 11:47:21.591 # Server initialized
1266:M 28 Mar 11:47:21.592 # 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.
1266:M 28 Mar 11:47:21.592 * DB loaded from disk: 0.000 seconds
1266:M 28 Mar 11:47:21.592 * Ready to accept connections
^C1266:signal-handler (1522252191) Received SIGINT scheduling shutdown...
1266:M 28 Mar 11:49:51.270 # User requested shutdown...
1266:M 28 Mar 11:49:51.271 * Saving the final RDB snapshot before exiting.
1266:M 28 Mar 11:49:51.272 * DB saved on disk
1266:M 28 Mar 11:49:51.272 * Removing the pid file.
1266:M 28 Mar 11:49:51.272 # Redis is now ready to exit, bye bye...
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.
1266:M 28 Mar 11:47:21.592 * DB loaded from disk: 0.000 seconds
意思是:你使用的是透明大页,可能导致redis延迟和内存使用问题。执行
临时解决方法:
echo never > /sys/kernel/mm/transparent_hugepage/enabled
永久解决方法:
将其写入/etc/rc.local文件中。
redis-server ../redis.conf
结果如下就启动成功了
2668:C 28 Mar 12:17:16.245 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
2668:C 28 Mar 12:17:16.246 # Redis version=4.0.8, bits=64, commit=00000000, modified=0, pid=2668, just started
2668:C 28 Mar 12:17:16.246 # Configuration loaded