Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to compile and install Redis4.0

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

Xiaobian to share with you how to compile and install Redis 4.0, I hope you have gained something after reading this article, let's discuss it together!

Mini programs test wget http://download.redis.io/releases/redis-4.0.11.tar.gz

install compilation

Environmental 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. Use make PREFIX=/usr/local/redis install

5. Copy configuration file mkdir /usr/local/redis/conf

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

WARNING: The TCP backlog setting of 511... solutions

Method 1: Temporary settings take effect: sysctl -w net.core.somaxconn = 1024

Method 2: Permanently: Modify the/etc/sysctl.conf file to add a line

net.core.somaxconn= 1024

and then execute the order.

sysctl -p

Additional:

net.core.somaxconn is a kernel parameter in Linux that indicates the backlog limit for socket listening.

Backlog is the listening queue for a socket, which enters the backlog when a request has not been processed or established.

The socket server can process all requests in the backlog at once, and the processed requests are no longer in the listening queue.

When the server processes requests so slowly that the listening queue fills up, new requests are rejected.

So net.core.somaxconn limits the size of the listening queue that receives new TCP connections.

The default of 128 is too small for a heavily loaded web services environment that handles new connections frequently. Most environments recommend increasing this value to 1024 or more.

Warning overcommit_memory is set to 0! ......) There are also two solutions.

Method 1: Temporary settings take effect: sysctl -w vm.overcommit_memory = 1

Method 2: Permanently: Modify the/etc/sysctl.conf file to add a line

vm.overcommit_memory = 1

and then execute the order.

sysctl -p

Additional:

Overcommit_memory parameter description:

Set memory allocation policy (optional, according to the actual situation of the server)

/proc/sys/vm/overcommit_memory

Optional values: 0, 1, 2.

0, indicates that the kernel will check whether there is enough memory available for the application process to use; if there is enough memory available, the memory request is allowed; otherwise, the memory request fails and an error is returned to the application process.

1 indicates that the kernel allows all physical memory to be allocated regardless of the current memory state.

2, indicates that the kernel allows more memory allocation than the sum of all physical memory and swap space

Note: redis in dump data, will fork out a child process, in theory, the child process occupied by the memory and parent is the same, such as parent occupied memory for 8G, this time also to allocate 8G of memory to the child, if the memory can not afford, often will cause redis server down machine or IO load is too high, efficiency decline. So the memory allocation policy for this comparison should be set to 1 (meaning that the kernel allows all physical memory to be allocated regardless of the current memory state).

After reading this article, I believe you have a certain understanding of "How to compile and install Redis 4.0". If you want to know more about it, welcome to pay attention to the industry information channel. Thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report