Cluster building environment, one Centos7 virtual machine (192.168.217.128), six redis nodes redis-4.0.2
Install redis: follow the steps on the official website, and we won't talk about it here. Enclosed address https://redis.io/download,
Note that there may be errors (redis tarError) during the installation process. It may be because the plug-in virtual machine required by redis is not installed. Execute the following commands in sequence
yum install -y gcc g++ gcc-c++ make
make MALLOC=libc
make install
- Create the redis cluster directory, and create the redis node directory under the cluster Directory:
cd /usr/local/program/redis
mkdir redis-cluster
cd redis-cluster
mkdir 7000 7001 7002 7003 7004 7005
- Then copy the redis configuration file redis.conf to the 7000-7005 file to modify each configuration file parameter
bind 192.168.217.128 //The default ip is 127.0.0.1, which needs to be changed to an ip accessible by other node machines. Otherwise, when creating a cluster, the corresponding port cannot be accessed and the cluster cannot be created
port 7000 //Ports 7000-7005
daemonize yes //redis running in the background
pidfile /var/run/redis_7000.pid //pidfile file corresponds to 7000-7005
dir /usr/local/program/redis/redis-cluster/7000/ //Directory of configuration files generated by each node of the cluster 7000-7005
cluster-enabled yes //Open cluster
cluster-config-file nodes_7000.conf //Automatically generate 7000-7005 for each configuration file of the cluster for the first time
cluster-node-timeout 15000 //Request timeout is 15 seconds by default and can be set by yourself
appendonly yes //aof open
cluster-require-full-coverage no //If some key space s are not covered by any nodes in the cluster, the most common is that a node hangs up, and the cluster will stop accepting writes
- Run all nodes, create running script for nodes
vim start-cluster.sh (Create startup script command)
//Script content
redis-server /usr/local/program/redis/redis-cluster/7000/redis.conf
redis-server /usr/local/program/redis/redis-cluster/7001/redis.conf
redis-server /usr/local/program/redis/redis-cluster/7002/redis.conf
redis-server /usr/local/program/redis/redis-cluster/7003/redis.conf
redis-server /usr/local/program/redis/redis-cluster/7004/redis.conf
redis-server /usr/local/program/redis/redis-cluster/7005/redis.conf
chmod 777 start-cluster.sh (Assign permissions to scripts)
sh -x start-cluster.sh (Run script command)
- Start building clusters
cd /usr/local/program/redis/redis-4.0.2/src
redis-trib.rb create --replicas 1 192.168.217.128:7000 192.168.217.128:7001 192.168.217.128:7002 192.168.217.128:7003 192.168.217.128:7004 192.168.217.128:7005
Running the above command may cause errors, because redis-trib.rb requires related ruby plug-ins and ruby installation
sudo yum install curl(First install curl)
curl -L get.rvm.io | bash -s stable
(Execute the command to prompt for signature execute the signature on the command line)
find / -name rvm -print
source /usr/local/rvm/scripts/rvm
rvm list known
rvm install 2.4.1(Select higher version)
rvm use 2.4.1(ruby Catalog: Using /usr/local/rvm/gems/ruby-2.4.1)
rvm use 2.4.1 --default(Select as default)
rvm remove 2.0.0(Delete old version)
ruby --version(View existing version)
gem install redis(Final installation redis Plugin)
After ruby is installed successfully, run redis to set up cluster again. Enter yes according to the prompt, and finally, All 16384 slots covered cluster is set up successfully
Then access the cluster, just visit a node:
redis-cli -h 192.168.217.128 -c -p 7000 //Connect 7000 nodes
cluster nodes (View all nodes of the cluster)
After the cluster is set up successfully, you only need to run the create start-cluster.sh script command to start next time