preface
This paper collects and sorts out the web articles, websites and my own experience of Redis cluster construction. Limited level, only share environment build. This paper is divided into the following parts:
- Redis installation
- RVM installs the replacement source
- RVM Ruby installation, use, uninstall
- RubyGems Upgrade, Change Sources, Install Redis
- The cluster configuration
- Results of the test
Please follow the steps above to view this article
Description:
- Only for learning use, if used online, I do not assume any responsibility.
- If you have any questions, please leave a comment below.
- Some of the commands in this article don’t have sudo because I’m using root.
Redis installation
Compile the installation
Wget http://download.redis.io/releases/redis-4.0.10.tar.gz tar XZF redis - 4.0.10. Tar. Gz CD redis - 4.0.10 make PREFIX=/usr/local/redis install
Note: If you don’t want Redis to be a service, it’s already installed
Make Redis a service reference:Redis Quick Start
-
Create a directory where to store your Redis config files and your data:
# This is just a directory structure, don't worry why you don't have it, read down, [root@amor ~]# CD /usr/local/redis [directory redis]# tree. Bass Exercises - Bass Exercises - Benchmark │ ├─ Bass Exercises - Benchmark │ ├─ Bass Exercises - Benchmark │ ├─ Bass Exercises - Benchmark │ ├─ Anti-Flag ─ Anti-Flag ─ Anti-Flag ─ Anti-Flag ─ Anti-Flag ─ Anti-Flag ─ Anti-Flag ─ Anti-Flag ─ Anti-Flag ─ Anti-Flag ─ Anti-Flag ─ Anti-Flag ─ Anti-Flag ─ Anti-Flag ─ Anti-Flag ─ Anti-Flag ─ Anti-Flag ─ Anti-Flag ─ Anti-Flag ─ Anti-Flag ─ Anti-Flag ─ Anti-Flag ─ Anti-Flag ├ ─ sigma, sigma, sigma, sigma, sigma, sigma, sigma, sigma, sigma, sigma, sigma, sigma, sigma, sigma directories, 7 files
Note:
Cp/usr/SRC/redis - 4.0.10 / SRC/redis - trib. Rb/usr/local/redis/bin /
This will be used later to create the cluster -
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 you are running this instance of Redis. Copy the init script found in the Redis distribution under the utils directory into /etc/init.d We recommend calling it with the name of the port on which the Redis instance is running. For example:)
sudo cp utils/redis_init_script /etc/init.d/redis_6379
-
Edit the init script.
#! / bin/sh # # the chkconfig 2345 90 25 Linux boot startup Settings 2345 run level 90 boot priority (reference memcached head/etc/rc. D/rc3. D/S90memcached) 25 Busted priority (Refer to memcached) # Simple Redis init.d script to work on Linux systems # As it does use of the /proc filesystem. ### BEGIN INIT INFO # Provides: redis_6379 # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Redis data structure server # Description: Redis data structure server. See https://redis.io ### END INIT INFO REDISPORT=6379 EXEC = / usr/local/redis/bin/redis server # modified for their executable directory CLIEXEC = / usr/local/redis/bin/redis - cli # modified for your executable file directory /usr/local/redis/ CONF /${REDISPORT}. CONF="/usr/local/redis/ ${REDISPORT}. CONF esac
Start modifying redis.conf
Make sure to modify REDISPORT accordingly to the port you are using. Both the pid file path and the configuration file (youdao: Be sure to change the reallocation accordingly depending on the port you are using. The pid file path and configuration file name depend on the port number.
-
sudo cp redis.conf /usr/local/redis/conf/6379.conf
Modify to a directory you define. Refer to the above directory structure redis.conf in the SRC directory of your redis unzip directory. -
sudo mkdir /usr/local/redis/data/6379
Modify to a directory you define. Refer to the above directory structure) -
Edit the configuration file, making sure to perform the following changes:
- Set daemonize to yes (by default it is Set to no).
- Set the pidfile to /var/run/redis_6379.pid (modify the port if needed).
- Change the port accordingly. In our example it is not needed as the default port is already 6379. When setting up the cluster, you need to copy the configuration file and reset the port.
- Set your preferred logLevel.
- Set the logfile to /var/log/redis_6379.log Set the logfile to /var/log/redis_6379.log
- Set the dir to /var/redis/6379 (very important step!) (Redis data saving directory, need to modify the location of the custom path)
Note: the above meaning is to let you modify/usr/local/redis/conf / 6379. The conf, open, with vim search keywords can be above, refer to the following Settings (if all of the steps is to paste copied, stepped down directly modified as follows: 0.0) :
port 6379 daemonize yes pidfile /var/run/redis_6379.pid loglevel notice logfile "/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 Finally, add the new Redis init script to all default run levels with the following command 🙂
# ubuntu sudo update-rc.d redis_6379 defaults
# centos chkconfig --add redis_6379
-
You are done! Now you can try running your instance with:
sudo /etc/init.d/redis_6379 start
test
REDIS stops and starts
Yum install
- /etc/init.d/redis-server stop
- /etc/init.d/redis-server start
- /etc/init.d/redis-server restart
Source installation in three ways
Sudo/etc/init. D/redis_6379 start/usr/local/redis/bin/redis - server redis. Conf # note here the default: The configuration file path redis-cli-h 127.0.0.1-p 6379 is shutdown
Note: If only to stop local redis please do:redis-cli shutdown
Forced termination
Kill -9 process number
pkill redis
RVM installs the replacement source
Curl - sSL https://rvm.io/mpapis.asc | gpg2 - import - curl - L get. RVM. IO | bash - s stable RVM user gemsets # build user configuration directory, Echo "ruby_url=https://cache.ruby-china.org/pub/ruby" > ~/.rvm/user/db # There's still something wrong with the top one, Everybody in the following way to install GPG -- keyserver hkp://keys.gnupg.net -- recv - keys 409 b6b1796c275462a1703113804bb82d39dc0e3 curl - sSL https://get.rvm.io | bash - s stable usermod - a root - G RVM source/etc/profile. D/RVM. Sh # close shell window, Open RVM user gemsets again echo "ruby_url=https://cache.ruby-china.org/pub/ruby" > ~/.rvm/user/db
RVM Ruby installation, use, uninstall
# Rvm list known Rvm install ruby-head Rvm install ruby-head Rvm install ruby-head Rvm install ruby-head Rvm install ruby-head --default # check ruby -v gem -v # Rvm uninstall ruby # --default # check ruby -v gem -v # Rvm uninstall ruby #
RubyGems Upgrade, Change Sources, Install Redis
gem install rubygems-update
rubygems-update
gem sources --add https://gems.ruby-china.com/ --remove https://rubygems.org/
gem sources -l
gem install redis
The cluster configuration
Note: The following is my own reference to this blog post plus my familiarity with my own configuration process after Redis is installed. You can look atNRWLM-Redis Cluster Setup Detailed Guide.
Open the Redis cluster
/usr/local/redis/conf cp 6379.conf redis.conf.default # Sudo Vim redis.conf.default is used as a template for other cluster configuration files
The modifications are as follows
# Bind 192.168.2.123 # Bind the current machine IP cluster-enabled YES # Uncomment, Start the cluster pattern cluster config - the file nodes - 6379. The conf # uncomment, modified to/usr/local/redis/data / 6379 / nodes - 6379. The conf (if there are any need to establish the cluster, Falling this change to the specified path with the startup configuration file will cause the rebuilt conf file to be deleted when the cluster is set up
Creating configuration files
cd /usr/local/redis/conf
echo 9001.conf 9002.conf 9003.conf 9004.conf 9005.conf 9006.conf | xargs -n 1 cp -v redis.conf.default
sed -i 's/6379/9001/g' 9001.conf
sed -i 's/6379/9002/g' 9002.conf
sed -i 's/6379/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/data mkdir-p 9001 9002 9003 9004 9005 9006 #
Start 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 the cluster
/ usr/local/redis/bin/redis - trib. Rb create -- replicas 192.168.2.123:1 9001 192.168.2.123:9002 192.168.2.123:9003 192.168.2.123 192.168.2.123:9004 192.168.2.123:9005:9006
test
Execute the command: / usr/local/redis/bin/redis – 192.168.2.123 cli – c – h – p 9001
The problem summary
- If you encounter timeout please check your own firewall, especially pay attention to the installation pagoda, please first go to the security inside the release 9001:9006 port
- Redis cluster not only needs to open the port connected by Redis client, but also needs to open the cluster bus port. The cluster bus port is the port + 10000 connected by Redis client
-
Redis /usr/bin/env: ruby: No such file or directory
- Execute this command
rvm get stable --auto-dotfiles
Or executenvm list
– Do not install Ruby with RVM online
-
This is my own solution
# add this to /etc/profile (at the end) RVM use ruby-2.6.0-preview2
- Execute this command
Help website:
- Download RubyGems v2.7.7 – May 18, 2018
- Installing RVM
- RubyGems – Ruby China
- Redis Download