CentOS Installation Redis Detailed tutorial

Source: Internet
Author: User

Building Redis

Redis does not currently have an official RPM installation package, we need to compile from source code, and we need to install make and GCC in order to compile.

If GCC and make are not installed, use Yum to install it.

Yum Install gcc make

Download the Tar compress package from the official website.

Curl Http://download.redis.io/releases/redis-3.0.4.tar.gz-o redis-3.  0.4.tar.gz  

Unzip.

Redis-3. 0.4. Tar. GZ   

Enter the extracted directory.

Redis-3. 0. 4 

Use make to compile the source file.

Make
Installation

Enter the directory of the source file.

CD src

Replicate Redis servers and clients to/usr/local/bin.

CP redis-server redis-cli/usr/local/bin

It is better to copy the Sentinel,benchmark and check.

CP Redis-sentinel Redis-benchmark redis-check-aof redis-check-dump/usr/local/bin   

Create a Redis configuration folder.

Mkdir/etc/redis

Create a valid directory for saving data under/var/lib/redis

Mkdir-p/var/lib/redis/6379 
System parameters

In order for Redis to work properly, some kernel parameters need to be configured.

The configuration vm.overcommit_memory is 1, which prevents data truncation, as detailed here.

Sysctl-w vm.overcommit_memory=1

The maximum number of modified backlog connections exceeds the Tcp-backlog value in Redis.conf, which is the default value of 511. You can find more information about the SYSCTL-based IP network tunnel in kernel.org.

Sysctl-w net.core.somaxconn=

The support for transparent giant page memory (transparent huge pages) is canceled because this can cause latency and memory access issues with Redis usage.

/sys/kernel/mm/transparent_hugepage/enabled
Redis.conf

Redis.conf is a Redis profile, however you will see that the file name is 6379.conf, and this number is the network port that Redis listens to. If you want to run more than one Redis instance, it is recommended to use such a name.

Copy the redis.conf of the sample to /etc/redis/6379.conf.

CP redis.conf/etc/redis/6379.conf

Now edit this file and configure the parameters.

vi/etc/redis/6379.conf
Daemonize

Setting Daemonize to NO,SYSTEMD requires it to run in the foreground, or Redis will suddenly hang up.

No
Pidfile

Set Pidfile to/var/run/redis_6379.pid.

Pidfile/Var/run/redis_6379.pid
Port

If you are not ready to use the default port, you can modify it.

6379
LogLevel

Set the log level.

Notice
LogFile

Modify the log file path.

logfile/var/log/redis_6379.  Log 
Dir

Set Directory to/var/lib/redis/6379

Dir/var/lib/redis/6379 
Safety

Here are a few things you can do to improve security.

Unix sockets

In many cases, client programs and server-side programs run on the same machine, so there is no need to listen for sockets on the network. If this is similar to your usage, you can use a UNIX socket instead of a network socket, you need to configure Port 0, and then configure the options below to enable the UNIX socket.

Sets the socket file for the UNIX socket.

Unixsocket/tmp/redis.sock

Restricts permissions on the socket file.

700

Now for REDIS-CLI to be accessible, you should use the-s parameter to point to the socket file.

-s/tmp/redis.sock
Requirepass

You may need remote access, if so, then you should set the password, which will require a password before each operation.

"BTFBX1NYYWRMTUEYNHHSCG"
Rename-command

Imagine the output of the following command. Yes, this will output the configuration of the server, so you should deny this access in any possible circumstances.

CONFIG GET *

In order to restrict or even prohibit this or other instructions you can use the Rename-command command. You must provide a command name and alternate name. To disallow it, you need to set an alternate name to an empty string, which prevents anyone from guessing that the name of the command is safe.

"Flushdb_my_salt_g0es_here09u09u" "" "config_my_s4lt_go3s_here09u09u  "

Access through a UNIX socket with a password, and modify commands

Snapshot

By default, Redis periodically dumps datasets to the dump.rdb file in the directory we set up. You can use the Save command to configure the frequency of the dump, its first parameter is the time frame in seconds, and the second parameter is the number of modifications made on the data file.

The key is changed every 15 minutes and at least once.

1

Every 5 minutes and at least 10 keys have been modified.

10

Every 1 minutes and at least 10,000 keys have been modified.

10000

The file/var/lib/redis/6379/dump.rdb contains the dump data from the in-memory data set since it was last saved. Because it creates a temporary file and then replaces the previous dump file, there is no data corruption problem, you don't have to worry, you can copy the file directly.

Start up at boot time

You can use SYSTEMD to add Redis to the system boot list.

Copy the sample's Init_script file to/ETC/INIT.D, and note the port number that the script name represents.

CP utils/redis_init_script/etc/init.d/redis_6379

Now we're going to use SYSTEMD, so create a unit file under/etc/systems/system named Redis_6379.service.

vi/etc/systemd/System/redis_6379.service

Fill in the following, details can be seen systemd.service.

[Unit]   6379[Service]type=forkingexecstart=/etc/init.d/redis_6379 startexecstop=/etc/init.d /redis_6379 stop[Install]wantedby=multi-user.target      

Now add the option that I previously modified in/etc/sysctl.conf for excessive memory usage and maximum backlog.

Vm.overcommit_memory = 1net.core.somaxconn=512

For transparent giant page memory support, there is no direct sysctl command to control, so you need to put the following command at the end of/etc/rc.local.

/sys/kernel/mm/transparent_hugepage/enabled
Summarize

So you can start, and by setting these options you can deploy the Redis service to a lot of simple scenarios, yet there are many Redis options in redis.conf for complex environments. In some cases, you can use replication and Sentinel to increase availability, or spread the data across multiple servers to create a cluster of servers. Thank you for reading.

Http://www.codeceo.com/article/centos-7-redis-server.html#0-tsina-1-89071-397232819ff9a47a7b7e80a40613cfe1

CentOS Installation Redis Detailed tutorial

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.