温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Redis4.0如何编译安装

发布时间:2021-11-16 11:35:59 来源:亿速云 阅读:211 作者:小新 栏目:云计算

小编给大家分享一下Redis4.0如何编译安装,希望大家阅读完这篇文章之后都有所收获,下面让我们一起去探讨吧!

  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(表示内核允许分配所有的物理内存,而不管当前的内存状态如何)。

看完了这篇文章,相信你对“Redis4.0如何编译安装”有了一定的了解,如果想了解更多相关知识,欢迎关注亿速云行业资讯频道,感谢各位的阅读!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI