前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >研发:Redis4.0 编译安装

研发:Redis4.0 编译安装

作者头像
heidsoft
发布2018-10-18 14:46:02
8180
发布2018-10-18 14:46:02
举报
  1. 小程序测试wget http://download.redis.io/releases/redis-4.0.11.tar.gz
  2. 安装编译
  3. 环境centos7

It is as simple as: % make You can run a 32 bit Redis binary using: % make 32bit After building Redis, it is a good idea to test it using: % make test Fixing build problems with dependencies or cached build options --------- Redis has some dependencies which are included into the `deps` directory. `make` does not automatically rebuild dependencies even if something in the source code of dependencies changes. When you update the source code with `git pull` or when code inside the dependencies tree is modified in any other way, make sure to use the following command in order to really clean everything and rebuild from scratch: make distclean This will clean: jemalloc, lua, hiredis, linenoise. Also if you force certain build options like 32bit target, no C compiler optimizations (for debugging purposes), and other similar build time options, those options are cached indefinitely until you issue a `make distclean` command. Fixing problems building 32 bit binaries --------- If after building Redis with a 32 bit target you need to rebuild it with a 64 bit target, or the other way around, you need to perform a `make distclean` in the root directory of the Redis distribution. In case of build errors when trying to build a 32 bit binary of Redis, try the following steps: * Install the packages libc6-dev-i386 (also try g++-multilib). * Try using the following command line instead of `make 32bit`: `make CFLAGS="-m32 -march=native" LDFLAGS="-m32"` Allocator --------- Selecting a non-default memory allocator when building Redis is done by setting the `MALLOC` environment variable. Redis is compiled and linked against libc malloc by default, with the exception of jemalloc being the default on Linux systems. This default was picked because jemalloc has proven to have fewer fragmentation problems than libc malloc. To force compiling against libc malloc, use: % make MALLOC=libc To compile against jemalloc on Mac OS X systems, use: % make MALLOC=jemalloc Verbose build ------------- Redis will build with a user friendly colorized output by default. If you want to see a more verbose output use the following: % make V=1 Running Redis ------------- To run Redis with the default configuration just type: % cd src % ./redis-server If you want to provide your redis.conf, you have to run it using an additional parameter (the path of the configuration file): % cd src % ./redis-server /path/to/redis.conf It is possible to alter the Redis configuration by passing parameters directly as options using the command line. Examples: % ./redis-server --port 9999 --slaveof 127.0.0.1 6379 % ./redis-server /etc/redis/6379.conf --loglevel debug All the options in redis.conf are also supported as options using the command line, with exactly the same name. Playing with Redis ------------------ You can use redis-cli to play with Redis. Start a redis-server instance, then in another terminal try the following: % cd src % ./redis-cli redis> ping PONG redis> set foo bar OK redis> get foo "bar" redis> incr mycounter (integer) 1 redis> incr mycounter (integer) 2 redis> You can find the list of all the available commands at http://redis.io/commands. Installing Redis ----------------- In order to install Redis binaries into /usr/local/bin just use: % make install You can use `make PREFIX=/some/other/directory install` if you wish to use a different destination. Make install will just install binaries in your system, but will not configure init scripts and configuration files in the appropriate place. This is not needed if you want just to play a bit with Redis, but if you are installing it the proper way for a production system, we have a script doing this for Ubuntu and Debian systems: % cd utils % ./install_server.sh


4. 采用make PREFIX=/usr/local/redis install

5. 拷贝配置文件mkdir /usr/local/redis/conf

6. cp redis.conf sentinel.conf /usr/local/redis/conf

第1个警告(WARNING: The TCP backlog setting of 511 ......)解决办法

方法1: 临时设置生效: sysctl -w net.core.somaxconn = 1024

方法2: 永久生效: 修改/etc/sysctl.conf文件,增加一行

net.core.somaxconn= 1024

然后执行命令

sysctl -p

补充:

net.core.somaxconn是linux中的一个kernel参数,表示socket监听(listen)的backlog上限。

backlog是socket的监听队列,当一个请求(request)尚未被处理或建立时,他会进入backlog。

而socket server可以一次性处理backlog中的所有请求,处理后的请求不再位于监听队列中。

当server处理请求较慢,以至于监听队列被填满后,新来的请求会被拒绝。

所以说net.core.somaxconn限制了接收新 TCP 连接侦听队列的大小。

对于一个经常处理新连接的高负载 web服务环境来说,默认的 128 太小了。大多数环境这个值建议增加到 1024 或者更多。

第2个警告(WARNING overcommit_memory is set to 0! ......)同样也有两个解决办法

方法1: 临时设置生效: sysctl -w vm.overcommit_memory = 1

方法2: 永久生效: 修改/etc/sysctl.conf文件,增加一行

vm.overcommit_memory = 1

然后执行命令

sysctl -p

补充:

overcommit_memory参数说明:

设置内存分配策略(可选,根据服务器的实际情况进行设置)

/proc/sys/vm/overcommit_memory

可选值:0、1、2。

0, 表示内核将检查是否有足够的可用内存供应用进程使用;如果有足够的可用内存,内存申请允许;否则,内存申请失败,并把错误返回给应用进程。

1, 表示内核允许分配所有的物理内存,而不管当前的内存状态如何。

2, 表示内核允许分配超过所有物理内存和交换空间总和的内存

注意:redis在dump数据的时候,会fork出一个子进程,理论上child进程所占用的内存和parent是一样的,比如parent占用的内存为8G,这个时候也要同样分配8G的内存给child,如果内存无法负担,往往会造成redis服务器的down机或者IO负载过高,效率下降。所以这里比较优化的内存分配策略应该设置为 1(表示内核允许分配所有的物理内存,而不管当前的内存状态如何)。

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2018-09-22,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 云数智圈 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
云数据库 Redis
腾讯云数据库 Redis(TencentDB for Redis)是腾讯云打造的兼容 Redis 协议的缓存和存储服务。丰富的数据结构能帮助您完成不同类型的业务场景开发。支持主从热备,提供自动容灾切换、数据备份、故障迁移、实例监控、在线扩容、数据回档等全套的数据库服务。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档