Installing Redis on Linux on the pit process

Source: Internet
Author: User
Tags redis install redis

Redis use very widely, I no longer wordy, I follow the online tutorial want to install on Linux, began the pit, online bought a Linux centos7.3, drip cloud, giant pit incomparable Ah, do not recommend that everyone use this! Redis is 4.0,

1. Log in to the cloud service and download the installation:

First login is not root user, need to switch, execute sudo su to root user, feel this very inconvenient, so consulting, reply is like this:

(1) Then switch back to the root user, start wget download, the prompt does not have this command, OK, start installing it yum-y install wget

After downloading, unzip, execute:tar xzf redis-4.0.9. Tar. GZ

(2) go to CD redis-4.0.9, execute make, there may be an error at this time:

GCC -std=c99-pedantic-c-o3-fpic-wall-w-wstrict-prototypes-wwrite-strings-g-ggdb net.c similar; then to install the GCC environment , yum-y install gcc automake autoconf libtool make

Reference Link: 50984420

(3) Installation success, start before starting to prepare, modify the redis.conf bind IP, directly comment out this line, let the outside network can access, if it is 3.2 later version, also need to modify the protection mode Protected-mode Yes to No, notice after modifying this configuration , the next time you start to specify redis.conf, otherwise it won't work!

2. Start Start

If you have no problem with Linux, you may start the success directly, but there are sometimes 3 warnings, such as I met, 2.8 not, 4.0 will, conjecture may be 4.0 memory requirements high

First Warning: The TCP backlog setting of 511 cannot be enforced because/proc/sys/net/core/somaxconn are set to the lower value of 128.

The TCP backlog setting value, 511 did not succeed, because/proc/sys/net/core/somaxconn this setting is smaller by 128.

Temporary workaround: (that is, you need to modify this value for the next boot)

Echo 511 >/proc/sys/net/core/somaxconn

Permanent workaround: (that is, you will need to modify this value for later launch)

Write it to the/etc/rc.local file.

Of course above this solution is online, I tried, directly change somaxconn next start still this, and write to rc.local I do not know how to write, direct write is useless, so I found another method is possible

Add the following in the/etc/sysctl.conf

Net.core.somaxconn = 2048, This value is defined according to your memory, more than 511

Second 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.overcomm It_memory=1 ' for the take effect.

This means: The Overcommit_memory parameter is set to 0! In the case of low memory, the daemon save may fail. It is recommended that you change overcommit_memory to 1 in file/etc/sysctl.conf.

The handling of this warning I have forgotten whether this is effective, should be effective

The third warning: you are Transparent Huge Pages (THP) support with enabled in your kernel. This would create latency and memory usage issues with Redis. To fix thisissue 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 thesetting after a reboot. Redis must be restarted after THP is disabled.

This means that you are using transparent large pages that can cause Redis latency and memory usage issues. Perform echo never >/sys/kernel/mm/transparent_hugepage/enabled fix the problem.

Interim workaround:

echo Never >/sys/kernel/mm/transparent_hugepage/enabled.

Permanent Solution:

Write it to the/etc/rc.local file.

This solution is also online, but it doesn't work at all, at least I'm useless here, so I'm taking this, modifying Etc/default/grub, grub_cmdline_linux= "Console=tty0 Crashkernel=auto console=ttys0,115200 Transparent_hugepage=never "

After this line, add Transparent_hugepage=never, and execute, reference connection: 72968215

The pro-test is effective.

3. Remote connection

Finally successfully launched, the boot sequence is this: CD/REDIS/REDIS-4.0.9/SRC, then execute ./Redis-server. /redis. conf, remember, be sure to specify the conf file, otherwise the above modification of IP and protection mode is useless.

Not easy Ah, now start in another window into Redis, CD/REDIS/REDIS-4.0.9/SRC, execute./REDIS-CLI, enter the Redis,set key to remove see if normal, and then start to enter the remote connection;

My local use of springboot, recommended for everyone to use, sprinboot self-springboot-redis function, will automatically load Redis configuration file, but it uses the redistemplate feeling is not good, so at this time I use or Jedis

but a visit to the error, caused By:java. Net. Sockettimeoutexception: Connect timed out, and then I try to turn off the firewall as follows:

Firewall-cmd--state #查看默认防火墙状态 (show notrunning after turn off, show running when turned on)

Systemctl Stop Firewalld.service #停止

Firewall systemctl Disable Firewalld.service #禁止firewall开机启动

Init 6 #重启虚拟机, and then enter the first command to view the firewall status

In centos7.2 such operation firewall is no problem, and then no use, or time out, tried a lot of methods or not, the local can ping, is not access, at this point suddenly think of my pit cargo cloud, where is the access whitelist settings,

I have set up a 6379-port white list, but forgot to bind the server, here the DC2 equivalent to Ali's ECS, the results have been reported overtime, helpless, changed this after, immediately can.

Then the following error is reported:

JedisConnectionException:java.net.SocketException:Software caused connection Abort:socket write error "exception

Or: Unable to validate object

Or there may be a large segment of the error: Exception in thread "main" Redis.clients.jedis.exceptions.JedisDataException:DENIED Redis was running in Protected mode because protected mode is enabled, no bind address were specified, no authentication password is requested T o clients. The This mode connections is only accepted from the loopback interface. If you want-to-connect from external computers to Redis-adopt one of the following solutions:1) Just disable prot ected mode sending the command ' CONFIG SET protected-mode No ' from the loopback interface by connecting to Redis from the Same host the server is running, however make sure Redis are not publicly accessible from Internet if your do so. Use CONFIG REWRITE to make this change permanent. 2) Alternatively you can just disable the protected mode by editing the Redis configuration file, and setting the PROTECTE d mode option to ' No ', and then restarting the server 3) If you started the server manually just for testing, restart it W ith the '--protected-modeNo ' option. 4) Setup A bind address or an authentication password. Note:you only need to does one of the above things in order for the server to start accepting connections from the outside.

At this point the redis.conf set does not work, indicating that you forgot to specify the Conf on startup, and then the correct method to start./redis.server. /redis.conf, you can finally ping it.

Summary: After you install Redis, modify the Bindip, and protect the mode, and modify the server firewall port access, the server can access Redis, if the remote can not access, check whether the use of cloud server and cloud server IP and port restrictions are set to normal.

In addition, there are other settings, such as whether to use a password, time-out wait, persistence policy, and more next time.

Installing Redis on Linux on the pit process

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.