I. centos >7.3
1.install lib
yum -y install patch libyaml-devel libffi-devel glibc-headers autoconf gcc-c++ glibc-devel readline-devel zlib-devel bzip2 automake libtool bison
2. install rvm
curl -sSL https://rvm.io/mpapis.asc | sudo gpg2 --import -
curl -sSL https://rvm.io/pkuczynski.asc | sudo gpg2 --import -
curl -L get.rvm.io | bash -s stable
source /etc/profile.d/rvm.sh
rvm reload
3. install ruby
rvm install 2.3.0
4. install env redis
gem install redis
II. centos <7.3
1. install lib
yum -y install patch libyaml-devel libffi-devel glibc-headers autoconf gcc-c++ glibc-devel readline-devel zlib-devel bzip2 automake libtool bison
2. install ruby
yum -y install ruby gcc ruby-devel rubygems
3. install rvm
curl -sSL https://rvm.io/mpapis.asc | gpg --import -
curl -L get.rvm.io | bash -s stable
source /etc/profile.d/rvm.sh
rvm reload
4. optimize system
echo never >/sys/kernel/mm/transparent_hugepage/enabled
vim /etc/sysctl.conf
vm.overcommit_memory = 1
---
sysctl -w net.core.somaxconn=512
----------
* soft nofile 196000
* hard nofile 196000
* hard nproc 65536
* soft nproc 65536
* soft stack 32768
zredis soft nproc 65536
zredis hard nproc 65536
------
B. Deploy
172.27.10.37 zpapp1
172.27.10.38 zpapp2
172.27.10.39 zpapp3
1. Thông tin cluster redis
Port Master: 8000
Port Slave: 8001,8002
Mo hinh shard:
Shard 1: 172.27.10.37:8000 - zpapp2:8001 - zpapp3:8002
Shard 2: zpapp2:8000 - zpapp3:8001 - 172.27.10.37:8002
Shard 3: zpapp3:8000 - 172.27.10.37:8001 - zpapp2:8002
2.tạo user zredis để start redis instance
useraddradd zredis
3. set quyền folder /zvccb/redis
chown -R zredis. /zvccb/redis
----
sysctl -w net.core.somaxconn=512
4. start all instance tren cac 172.27.10.37,zpapp2,zpapp3
/zvccb/redis/bin/redis-server /zvccb/redis/conf/8000.conf
/zvccb/redis/bin/redis-server /zvccb/redis/conf/8001.conf
/zvccb/redis/bin/redis-server /zvccb/redis/conf/8002.conf
5. Tạo cluster redis
/zvccb/redis/bin/redis-trib.rb create 172.27.10.37:8000 172.27.10.38:8000 172.27.10.39:8000
6. Check cluster states:
/zvccb/redis/bin/redis-cli -h 172.27.10.37 -p 8000 -c cluster nodes
/zvccb/redis/bin/redis-cli -h 172.27.10.38 -p 8000 -c cluster nodes
/zvccb/redis/bin/redis-cli -h 172.27.10.39 -p 8000 -c cluster nodes
61f8b86b5c875d50811a346c3b9f8652d21bda7d zpapp3:8000 master - 0 1578558765480 3 connected 10923-16383
2fb15487b6a95d4c43e4fda3dc67c785ada4e38b 172.27.10.37:8000 myself,master - 0 0 1 connected 0-5460
537f2ecb13452cd2c6bf6c1417687792c3d0e6ee zpapp2:8000 master - 0 1578558767484 2 connected 5461-10922
7. Add slave-node
---------
----------
/zvccb/redis/bin/redis-trib.rb add-node --slave --master-id f283e5fe9ec7128a2711e02e7ab9aa9410a65366 172.27.10.38:8001 172.27.10.37:8000
/zvccb/redis/bin/redis-trib.rb add-node --slave --master-id 9fe89332e3cbf87343a3361ec4b336ceb4a477a8 172.27.10.37:8001 172.27.10.39:8000
/zvccb/redis/bin/redis-trib.rb add-node --slave --master-id 3d42b987a7b342e3e46560ce70e4ebfd5b8e44b7 172.27.10.39:8001 172.27.10.38:8000
/zvccb/redis/bin/redis-trib.rb add-node --slave --master-id f283e5fe9ec7128a2711e02e7ab9aa9410a65366 172.27.10.38:8002 172.27.10.37:8000
/zvccb/redis/bin/redis-trib.rb add-node --slave --master-id 9fe89332e3cbf87343a3361ec4b336ceb4a477a8 172.27.10.37:8002 172.27.10.39:8000
/zvccb/redis/bin/redis-trib.rb add-node --slave --master-id 3d42b987a7b342e3e46560ce70e4ebfd5b8e44b7 172.27.10.39:8002 172.27.10.38:8000
==============
======
8. check cluster states 9 instance
/zvccb/redis/bin/redis-cli -h 172.27.10.38 -p 8000 -c cluster nodes
.
9. force failover: khi xay ra tinh trang nhay states cluster tu master -> slave, slave ->master tien hanh force lai theo dung mo hinh ban dau
/zvccb/redis/bin/redis-cli -h 172.27.10.37 -p 8000 -c CLUSTER FAILOVER
Check lai sau khi failover
10. restart lai cac services chay redis
-----------
systemctl daemon-reload
@reboot sleep 60 && /zvccb/redis/zredis_fo.sh
1 ---auto
redis start tự động = script /etc/init.d/redis với user zredis
sau 60s thì lấy lại Master = command trong crontab của root " @reboot sleep 60 && /zvccb/redis/zredis_fo.sh "
2 -- manual
su - root
pkill -u zredis # kill redis process
su - zredis
sh /zvccb/redis/zredis.sh # start redis
sh /zvccb/redis/zredis_fo.sh # lấy lại master