Note that all IP addresses and ports provided in this document should be changed to your own
Note that all IP addresses and ports provided in this document should be changed to your own
Note that all IP addresses and ports provided in this document should be changed to your own
0. Set the hosts file
Cat << EOF > /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4. Localdomain4 ::1 localhost Localhost. Localdomain localhost6 localhost6. localDomain6 192.168.200.141 RedIS -1 192.168.200.142 Redis -2 192.168.200.143 Redis-3 192.168.200.144 Redis-4 192.168.200.145 Redis-5 192.168.200.146 reDIS-6 EOFCopy the code
1. Download Redis source code
Wget HTTP: / / https://kuberocker.oss-cn-shenzhen.aliyuncs.com/redis-src/redis-6.0.9.tar.gzCopy the code
If the network speed is particularly slow, you can use thunderbolt to download
2. Install and configure SCL (SoftwareCollections) and the GCC 9 environment
yum -y install centos-release-scl yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils scl enable GCC 9 >> /etc/profileCopy the code
3. Compile and install Redis
/usr/local/ SRC / # /usr/local/ SRC / Tar ZXVF /usr/local/src/redis-6.0.tar. gz CD /usr/local/src/redis-6.0.9 make && make installCopy the code
4. Check whether the redis-server executable file exists
Redis-server = /usr/local/bin/redis-serverCopy the code
Create Redis Systemd Unit File
cat << EOF > /etc/systemd/system/redis-server.service
[Unit]
Description=Redis data structure server
Documentation=https://redis.io/documentation
[Service]
ExecStart=/usr/local/bin/redis-server /usr/local/etc/redis.conf
ExecStop=/usr/local/bin/redis-cli shutdown
Restart=always
LimitNOFILE=10032
NoNewPrivileges=yes
Type=forking
UMask=0077
[Install]
WantedBy=multi-user.target
EOF
chmod 777 /etc/systemd/system/redis-server.service
Copy the code
6. Set redis.conf
cat << EOF > /usr/local/etc/redis.conf daemonize yes port 6379 dir /var/lib/redis cluster-enabled yes Cluster-config-file redis-cluster.conf cluster-node-timeout 5000 bind 0.0.0.0 protected-mode no save "" appendonly no requirepass dolphin@Redis! Cluster masterauth dolphin@Redis! Cluster logfile "/var/log/redis/redis.log" EOFCopy the code
7. Set the password-free login for each node and copy the prepared files to other nodes
# at any one node performs SSH - the keygen -t rsa - P '-f/root /. SSH/id_rsa for I ` in tail - n 6 / etc/hosts | awk' {print $1} '`; do ssh-copy-id $i; done for i in `tail -n 6 /etc/hosts | awk '{print $1}'`; do scp /etc/hosts $i:/etc/; done for i in `tail -n 6 /etc/hosts | awk '{print $1}'`; do ssh $i mkdir -p /var/log/redis/ /var/lib/redis/ ; done for i in `tail -n 6 /etc/hosts | awk '{print $1}'`; do scp /usr/local/bin/redis-* $i:/usr/local/bin/; done for i in `tail -n 6 /etc/hosts | awk '{print $1}'`; do scp /usr/local/etc/redis.conf $i:/usr/local/etc/; done for i in `tail -n 6 /etc/hosts | awk '{print $1}'`; do scp /etc/systemd/system/redis-server.service $i:/etc/systemd/system/; done for i in `tail -n 6 /etc/hosts | awk '{print $1}'`; do ssh $i "systemctl daemon-reload"; done for i in `tail -n 6 /etc/hosts | awk '{print $1}'`; do ssh $i "systemctl enable redis-server && systemctl start redis-server"; doneCopy the code
8. Create a cluster
redis-cli -a dolphin@Redis! Cluster -- Cluster create --cluster-replicas 1 192.168.200.141:6379 192.168.200.142:6379 192.168.200.143:6379 192.168.200.146 192.168.200.144:6379 192.168.200.145:6379:6379Copy the code
9. Check the cluster status
Redis -cli --cluster check 192.168.200.141:6379 -a dolphin@Redis! ClusterCopy the code