Redis cluster installation

Time:2021-12-23

Installation steps of redis cluster

Note: redis has been installed before the single node installation

1. Create installation directory

Create in master, node1 and node2 respectively
   

mkdir /usr/local/soft/redis-cluster

2. Copy redis to the redis cluster directory and change the name to 7000

cp -r /usr/local/soft/redis /usr/local/soft/redis-cluster
mv /usr/local/soft/redis-cluster/redis /usr/local/soft/redis-cluster/7000
Delete stand-alone cache files
rm -rf appendonly.aof
rm -rf dump.rdb

3. Modify the configuration file VIM redis conf

Daemon yes // redis runs in the background
pidfile /var/run/redis_ 7000.pid // pidfile file corresponds to 7000
Port 7000 // port 7000
Cluster enabled yes // enable the cluster and # remove the comments
cluster-config-file nodes. Conf // the configuration file of the cluster is automatically generated for the first time
Cluster node timeout 5000 // setting the request timeout to 5 seconds is enough
Appendonly yes // AOF log is enabled when necessary. It will record a log every time it writes (fully persistent)

4. Copy 7000
cp -r 7000 7001
cp -r 7000 7002
cp -r 7000 7003
cp -r 7000 7004
cp -r 7000 7005

5. Modify the configuration of each

vim 7001/bin/redis.conf
Change 7000 to the corresponding port number
pidfile /var/run/redis_7001.pid
port 7001

6. Copy to node1 at 70027003

scp -r /usr/local/soft/redis-cluster/7002 node1:/usr/local/soft/redis-cluster/
scp -r /usr/local/soft/redis-cluster/7003 node1:/usr/local/soft/redis-cluster/

7. Copy to node2 at 70047005

scp -r /usr/local/soft/redis-cluster/7004 node2:/usr/local/soft/redis-cluster/
scp -r /usr/local/soft/redis-cluster/7005 node2:/usr/local/soft/redis-cluster/

8. Start redis

Note: before starting, remember to kill the redis service running on a single node

1. Execute in master
cd /usr/local/soft/redis-cluster/7000/bin
./redis-server redis.conf
cd /usr/local/soft/redis-cluster/7001/bin
./redis-server redis.conf

2. Execute in node1
cd /usr/local/soft/redis-cluster/7002/bin
./redis-server redis.conf
cd /usr/local/soft/redis-cluster/7003/bin
./redis-server redis.conf

3. Execute in node2
cd /usr/local/soft/redis-cluster/7004/bin
./redis-server redis.conf
cd /usr/local/soft/redis-cluster/7005/bin
./redis-server redis.conf

8. Build a cluster through the tool} and install it in the master

Installation tools
        yum -y install ruby ruby-devel rubygems rpm-build
    Upload redis-3.0 0.gem  
        gem install -l redis-3.0.0.gem  

    Commands placed in the / usr / local / bin / directory can be run anywhere
    cp /usr/local/soft/redis-3.0.0/src/redis-trib.rb /usr/local/bin/redis-trib

9. Start the cluster and use it for the first time without cluster restart

#Replicas number of backup nodes per primary node
redis-trib create --replicas 1 192.168.10.12:7000 192.168.10.12:7001 192.168.10.13:7002 192.168.10.13:7003 192.168.10.14:7004 192.168.10.14:7005
10. Client access to reids cluster
#- P port number - H node IP - C auto redirect
redis-cli -p 7000 -h master -c
View cluster information
redis-cli cluster info
View node information
redis-cli cluster nodes

 

The cluster mode does not distinguish between read and write requests. If you want to query from the node, you need to execute readonly before the query

 

Recommended Today

Ios15 adaptation

Need immediate modification 1. Uinavigationbar, uitoolbar and uitabbar styles Uinavigationbar, uitoolbar and uitabbar need to use uibarappearance APIs to set colors. // UINavigationBar let navigationBarAppearance = UINavigationBarAppearance() navigationBarAppearance.backgroundColor = .red navigationController?.navigationBar.scrollEdgeAppearance = navigationBarAppearance navigationController?.navigationBar.standardAppearance = navigationBarAppearance // UIToolbar let toolBarAppearance = UIToolbarAppearance() toolBarAppearance.backgroundColor = .blue navigationController?.toolbar.scrollEdgeAppearance = toolBarAppearance navigationController?.toolbar.standardAppearance = toolBarAppearance // UITabBar let tabBarAppearance […]