This article to share the content is about the Redis cluster Construction Tutorial Summary, the content is very detailed, the need for friends can refer to, hope can help everyone.
Objective
This paper collects and collates the network text, website and experience of Redis cluster. The level is limited, only to share the environment to build. This article is divided into the following sections:
Redis Installation
RVM Installing the replacement source
RVM Ruby Install, use, uninstall
RubyGems upgrade, replace source, install Redis
Cluster configuration
Results testing
Please follow the above steps to view this article
Description
Only for learning, if used on the line, I do not assume any responsibility.
If you have any questions, please leave a comment below.
Some of the commands do not have sudo, because I use root privileges.
Redis Installation
Compiling the installation
wget http://download.redis.io/releases/redis-4.0.10.tar.gztar xzf redis-4.0.10.tar.gzcd redis-4.0.10make prefix=/ Usr/local/redis Install
Note: If you do not want to use Redis as a service, it is already installed
Make Redis a service reference: Redis Quick Start
Create a directory where to store your Redis config files and your data: (Youdao dictionary: Creating a Directory to store Redis profiles and data:)
# It's just a directory structure, everybody don't worry why don't you, look down, step by step [Root@amor ~]# cd/usr/local/redis[root@amor redis]# tree.├──bin # Automatically generate directories and files after compiling and installing the specified directory │ ├──redis-benchmark│ ├──redis-check-aof│ ├──redis-check-rdb│ ├──redis-cli│ ├──redis-sentinel-redis-server│ └──redis-server├──conf # Self-established directory of storage profiles and individual Redis profiles created by yourself │ └── 6379.conf└──data # Self-built directory of REDIS data storage and a single Redis service data store directory └──63794 directories, 7 files
Note: cp /usr/src/redis-4.0.10/src/redis-trib.rb /usr/local/redis/bin/
the subsequent creation of the cluster will use
Copy the init script that you'll find in the Redis distribution under the Utils directory INTO/ETC/INIT.D. We suggest calling it with the name of the port where is running this instance of Redis. For example: (Youdao dictionary: Copy the init script found in the Redis distribution in the Utils directory to/ETC/INIT.D we recommend that you call it using the name of the port that is running the Redis instance. For example:)
sudo cp utils/redis_init_script/etc/init.d/redis_6379
Edit the Init script. (Youdao dictionary: Editing init scripts.) )
#!/bin/sh# chkconfig 2345 # Linux boot setup 2345 run level 90 start priority (Reference memcached head/etc/rc.d/rc3.d/s90memcached) 25 Turn off priority (ref. Memcached) # simple Redis INIT.D script conceived to work on Linux systems# as it does use of THE/PROC filesystem . # # # BEGIN INIT info# provides: redis_6379# Default-start: 2 3 4 AA Default-stop: 0 1 6# short-description:
REDIS data Structure server# Description: REDIS data Structure server. See https://redis.io### END INIT inforedisport=6379exec=/usr/local/redis/bin/redis-server # Modify the directory where your executable file is located cliexec=/usr/local/redis/bin/redis-cli # to modify the directory where your executable file is located pidfile=/var/run/redis_${redisport}. PID # Default is good conf= "/usr/local/redis/conf/${redisport}.conf" # Modify for your own configuration file directory ... Omit ... Esac
Start modifying redis.conf
Make sure to modify redisport accordingly to the port is using. Both the PID file path and the configuration file name depend on the port number. (Youdao dictionary: Make sure that you modify the reallocation based on the port you are using.) Both the PID file path and the configuration file name depend on the port number. )
Set daemonize to Yes (by default it was set to No). (Need to be modified to Yes)
Set the pidfile to/var/run/redis_6379.pid (Modify the port if needed). (default)
Change the port accordingly. In our example it isn't needed as the default port is already 6379. (By default, you need to copy the configuration file and reset the port when setting up the cluster)
Set your preferred loglevel. (default)
Set the logfile to/var/log/redis_6379.log (default appears to be empty, need to be modified)
Set the dir to/var/redis/6379 (very important step!) (Redis Data Save directory, you need to modify the location of the custom path)
sudo cp redis.conf /usr/local/redis/conf/6379.conf
(Modify the directory to your own definition.) Refer to the above directory structure redis.conf in the SRC directory of your Redis extract directory)
sudo mkdir /usr/local/redis/data/6379
(Modify the directory to your own definition.) Refer to the above directory structure)
Edit the configuration file, making sure to perform the following changes: (Youdao Dictionary: Edit the profile to make sure that the following changes are performed:)
Note: Above means let you modify/usr/local/redis/conf/6379.conf, with vim open, search the above keyword can, refer to the following settings (if all the steps are pasted copy of the walk down, directly modified to the following: 0.0):
Port 6379daemonize yespidfile/var/run/redis_6379.pidloglevel noticelogfile "/var/log/redis_6379.log" dir/usr/local/ redis/data/6379
Finally add the new Redis init script to all the default runlevels using the following command: (Youdao dictionary: Finally, use the following command to add the new Redis INI T script is added to all default runlevel:)
# Ubuntusudo UPDATE-RC.D redis_6379 Defaults
# Centoschkconfig--add redis_6379
You are done! Now you can try running your instance with:
sudo/etc/init.d/redis_6379 start
Test
Redis Stop, start
Yum Installation
/etc/init.d/redis-server stop
/etc/init.d/redis-server start
/etc/init.d/redis-server restart
Three ways of installing source code
sudo/etc/init.d/redis_6379 start/usr/local/redis/bin/redis-server redis.conf # Note Here The default: Configuration file path redis-cli-h 127.0.0.1-p 6379 shutdown
Note: If you just stop local redis, do this:redis-cli shutdown
Forced termination
RVM Installing the replacement source
Curl-ssl HTTPS://RVM.IO/MPAPIS.ASC | GPG2--import-curl-l Get.rvm.io | Bash-s stable RVM User Gemsets # Set up a directory of users and need to write configuration information to the DB file when replacing the source echo "Ruby_url=https://cache.ruby-china.org/pub/ruby" ; ~/.RVM/USER/DB # replacing the source
RVM Ruby Install, use, uninstall
RVM List KNOWNRVM Install 2.6RVM use 2.6yum-y remove Ruby # uninstall CentOS Yum installed version 1.8 ruby--VERSIONRVM Uninstall Ruby # here with Self Test without version
RubyGems upgrade, replace source, install Redis
Gem install rubygems-update rubygems-updategem sources--add https://gems.ruby-china.com/--remove https:// Rubygems.org/gem sources-l gem Install Redis
Cluster configuration
Note: The following is my own reference to this blog post plus I am familiar with Redis installation after the configuration process. You can refer to the Nrwlm-redis cluster to build detailed guidance.
Turn on Redis cluster
CD/USR/LOCAL/REDIS/CONFCP 6379.conf redis.conf.default # used as a blueprint for other configuration files in the cluster sudo vim redis.conf.default
Modify the content as follows
Bind 192.168.2.123 # bind current Machine ipcluster-enabled Yes # Uncomment, launch cluster mode cluster-config-file nodes-6379.conf # Uncomment, modify to/usr/ Local/redis/data/6379/nodes-6379.conf (if you encounter a need to re-establish the cluster, do not modify the item to the specified path, and the startup configuration file will cause the cluster to be deleted when the Rebuild conf file is removed) Cluster-node-timeout 15000 # Uncomment appendonly Yes # Modify No to Yes
Creating a configuration file
Cd/usr/local/redis/confecho 9001.conf 9002.conf 9003.conf 9004.conf 9005.conf 9006.conf | Xargs-n 1 cp-v redis.conf.defaultsed-i ' s/6379/9001/g ' 9001.conf sed-i ' s/6379/9002/g ' 9002.conf sed-i ' s/637 9/9003/g ' 9003.conf sed-i ' s/6379/9004/g ' 9004.conf sed-i ' s/6379/9005/g ' 9005.conf sed-i ' s/6379/9006/ G ' 9006.conf
Create a data store file
CD/USR/LOCAL/REDIS/DATAMKDIR-P 9001 9002 9003 9004 9005 9006# later may need to delete the file under the file for rebuilding the cluster, so the delete command also writes RM-RF 900*/*
Starting the Redis cluster node
/usr/local/redis/bin/redis-server/usr/local/redis/conf/9001.conf/usr/local/redis/bin/redis-server/usr/local/ redis/conf/9002.conf/usr/local/redis/bin/redis-server/usr/local/redis/conf/9003.conf/usr/local/redis/bin/ redis-server/usr/local/redis/conf/9004.conf/usr/local/redis/bin/redis-server/usr/local/redis/conf/9005.conf/ Usr/local/redis/bin/redis-server/usr/local/redis/conf/9006.conf
Create a cluster
/usr/local/redis/bin/redis-trib.rb create --replicas 1 192.168.2.123:9001 192.168.2.123:9002 192.168.2.123:9003 192.168.2.123:9004 192.168.2.123:9005 192.168.2.123:9006
Test
Execute command:/usr/local/redis/bin/redis-cli -c -h 192.168.2.123 -p 9001
Summary of issues
If you encounter timeout please check your firewall, installation of the pagoda's special attention, please first go to the safe to release 9,001:9,006 of the port
Redis cluster waiting for the cluster to join waits for the Redis cluster not only to open the Redis client connection port, but also to open the cluster bus port, the cluster bus port is the Redis Client connection port + 1000
redis /usr/bin/env: ruby: 没有那个文件或目录
Related recommendations:
CentOS7 system Installation and configuration Memcached method
php the application of the lock mechanism