Centos7 install rediscluster in vmware

Source: Internet
Author: User

Centos7 install rediscluster in vmware

System Environment: Centos7 vmware
Redis version: redis3.2.5
Redis3.2.5 requires a later version of ruby and gem. The latest version 2.3.3 is used for ruby on our side. errors may occur when a later version of ruby creates a cluster.
Installation steps:

I. Initialization of required tools

1. Install the SDK

#yum install openssl* openssl-devel zlib-devel gcc gcc-c++ make autoconf readline-devel curl-devel expat-devel gettext-devel

Openssl, zlib, and gcc are required when installing ruby and gem.2. Install ruby

# wget https://cache.ruby-lang.org/pub/ruby/2.3/ruby-2.3.3.tar.gz# tar zxvf ruby-2.0.0-p247.tar.gz# cd ruby-2.0.0-p247# ./configure # make && make install# ruby -v 

3. Install redis-gem

# wget https://rubygems.global.ssl.fastly.net/gems/redis-3.2.1.gem# gem install redis-3.2.1.gem 

Ii. rediscluster Construction1. Download and install redis

# wget http://download.redis.io/releases/redis-3.2.5.tar.gz # tar -zxf redis-3.2.5.tar.gz# cd redis-3.2.5# make && make install

2. Create six redis. conf files for cluster configuration (the cluster requires at least 6 nodes)

# Mkdir conf # cd conf # vi redis-6379.conf # cp redis-6379.conf redis-6380.conf # cp redis-6379.conf # cp redis-6381.conf redis-6379.conf # cp redis-6382.conf redis-6379.conf # cp redis-6383.conf redis-6379.conf 6379 daemonize yesdir/data/redis/redis-6384.confport/data /redis/redis-7000/redis-6379.logpidfile/var/run/redis-6379.pid dbfilename dump-6379.rdb appendonly yes appendfilename "appendonly-6379.aof" cluster-enabled yes cluster-config-file nodes-6379.conf cluster-node-timeout 5000 protected-mode no # disable protection mode

Note: For more information about the protected-mode function, see the following link.

Http://arui.me/index.php/archives/151/

3. Start the service

# ./src/redis-server conf/redis-6379.conf# ./src/redis-server conf/redis-6380.conf# ./src/redis-server conf/redis-6381.conf# ./src/redis-server conf/redis-6382.conf# ./src/redis-server conf/redis-6383.conf# ./src/redis-server conf/redis-6384.conf

4. Create a cluster using the second IP address. The jediscluster created with 127.0.0.1 cannot be connected.-replicas 1 indicates that each master has one slave.

# ./src/redis-trib.rb create --replicas 1 127.0.0.1:6379 127.0.0.1:6380 127.0.0.1:6381 127.0.0.1:6382 127.0.0.1:6383 127.0.0.1:6384# ./src/redis-trib.rb create --replicas 1 172.21.20.25:6379 172.21.20.25:6380 172.21.20.25:6381 172.21.20.25:6382 172.21.20.25:6383 172.21.20.25:6384


5. Cluster Detection

#redis-cli -h 172.21.20.25 -p 6379

3. jediscluster used by the client to connect to the client, springboot 1 and maven jar

<dependency> <groupId>redis.clients</groupId> <artifactId>jedis</artifactId> <version>2.9.0</version><!--$NO-MVN-MAN-VER$--></dependency>

2. bean Injection

package com.hive.data.redis.config;import org.apache.commons.pool2.impl.GenericObjectPoolConfig;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.boot.context.properties.EnableConfigurationProperties;import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.Configuration;import redis.clients.jedis.HostAndPort;import redis.clients.jedis.JedisCluster;import java.util.HashSet;import java.util.List;import java.util.Set;@Configuration@EnableConfigurationProperties(RedisSettings.class)public class JedisClusterConfig { @Autowired private RedisSettings redisSettings; @Bean public JedisCluster jedisCluster() { Set<HostAndPort> set = new HashSet<HostAndPort>(); List<String> hostPorts = redisSettings.getNodes(); if (null != hostPorts && hostPorts.size() > 0) { String[] ipPortPair; for (String hostPort : hostPorts) { ipPortPair = hostPort.split(":"); set.add(new HostAndPort(ipPortPair[0], Integer.parseInt(ipPortPair[1]))); } } return new JedisCluster(set,300000); } @Bean public GenericObjectPoolConfig genericObjectPoolConfig(){ GenericObjectPoolConfig config=new GenericObjectPoolConfig(); config.setMaxTotal(500); config.setMaxIdle(5); config.setMaxWaitMillis(1000*100); config.setTestOnBorrow(true); return config; }}package com.hive.data.redis.config;import org.springframework.boot.context.properties.ConfigurationProperties;import java.util.List;@ConfigurationProperties(locations = "classpath:redis.properties",prefix = "redis.cluster")public class RedisSettings { private List<String> nodes; public List<String> getNodes() { return nodes; } public void setNodes(List<String> nodes) { this.nodes = nodes; }}redis.propertiesredis.cluster.nodes[0] =172.21.20.25:6379redis.cluster.nodes[1] =172.21.20.25:6380redis.cluster.nodes[2] =172.21.20.25:6381redis.cluster.nodes[3] =172.21.20.25:6382redis.cluster.nodes[4] =172.21.20.25:6383redis.cluster.nodes[5] =172.21.20.25:6384

4. Firewall Shutdown

My virtual machine is the default firewall of centos7, and iptables is used by default under 7.

Systemctl stop firewalld. service # disable firewall systemctl stop firewalld. service # stop firewallsystemctl disable firewalld. service # disable firewall startup

The iptables setting method takes effect permanently after restart: Enable: chkconfig iptables on Disable: chkconfig iptables off takes effect immediately, and expires after restart: Enable: service iptables start

Close: service iptables stop restart: service iptables restart save configuration: service iptables save or/etc/rc. d/init. d/iptables save to set the firewall to start systemctl enable iptables when it is started. disable/sbin/chkconfig-level 2345 iptables off when the firewall is started.

References:

Cluster password Settings> http://www.07net01.com/2016/10/1691935.html

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.