4. Redis集群部署

最后更新于:2022-04-02 07:45:48

## **集群注意事项** ``` 1. 众所周知,Redis集群create和reshard时,有密码会报错,所以部署时不配置密码,部署后命令行配置密码。再想扩容怎么办? 密码置空,如果不设置密码,可以以任意密码登录。 2. 下面操作前准备6台服务器+2台扩容服务器,每台上面分别部署3.2,4.0,5.0版本的Redis,每个版本端口不同,最终效果是用CacheCloud管理起来 ``` ## **部署服务** ``` # 3.2 ansible-playbook -i hosts/redis_hosts redis/redis.yml -e '{"redis_version":"3.2.13","redis_port":"6379"}' --tags install_redis # 4.0 ansible-playbook -i hosts/redis_hosts redis/redis.yml -e '{"redis_version":"4.0.9","redis_port":"6380"}' --tags install_redis # 5.0 ansible-playbook -i hosts/redis_hosts redis/redis.yml -e '{"redis_version":"5.0.12","redis_port":"6381"}' --tags install_redis ``` ## **初始化配置文件** ``` # 3.2 ansible-playbook -i hosts/redis_hosts redis/redis.yml -e '{"redis_version":"3.2.13","redis_port":"6379"}' --tags init_redis_conf # 4.0 ansible-playbook -i hosts/redis_hosts redis/redis.yml -e '{"redis_version":"4.0.9","redis_port":"6380"}' --tags init_redis_conf # 5.0 ansible-playbook -i hosts/redis_hosts redis/redis.yml -e '{"redis_version":"5.0.12","redis_port":"6381"}' --tags init_redis_conf ``` ## **开启集群配置** ``` # 3.2 ansible-playbook -i hosts/redis_hosts redis/redis.yml -e '{"redis_version":"3.2.13","redis_port":"6379"}' --tags turn_on_cluster # 4.0 ansible-playbook -i hosts/redis_hosts redis/redis.yml -e '{"redis_version":"4.0.9","redis_port":"6380"}' --tags turn_on_cluster # 5.0 ansible-playbook -i hosts/redis_hosts redis/redis.yml -e '{"redis_version":"5.0.12","redis_port":"6381"}' --tags turn_on_cluster ``` ## **启动服务** ``` # 3.2 ansible-playbook -i hosts/redis_hosts redis/redis.yml -e '{"redis_version":"3.2.13","redis_port":"6379"}' --tags start_redis # 4.0 ansible-playbook -i hosts/redis_hosts redis/redis.yml -e '{"redis_version":"4.0.9","redis_port":"6380"}' --tags start_redis # 5.0 ansible-playbook -i hosts/redis_hosts redis/redis.yml -e '{"redis_version":"5.0.12","redis_port":"6381"}' --tags start_redis ``` ## 集群管理服务器安装Ruby ``` ansible-playbook -i hosts/software_hosts software/ruby/ruby.yml -e "ruby_version=3.0.1" ``` ## 安装redis-gem ``` # Redis 3.2 需要3.3.5版本 ansible-playbook -i hosts/software_hosts software/gemsoft/gemsoft.yml -e "gem_soft_name=redis gem_soft_version=4.2.5" ``` ## 创建集群 ``` /usr/local/redis-4.0.9/bin/redis-trib.rb create --replicas 1 192.168.88.61:6380 192.168.88.62:6380 192.168.88.63:6380 192.168.88.64:6380 192.168.88.65:6380 192.168.88.66:6380 ``` ## 集群配置成功后**设置密码** ``` # 3.2 ansible-playbook -i hosts/redis_hosts redis/redis.yml -e '{"redis_version":"3.2.13","redis_port":"6379"}' --tags turn_on_local_auth,turn_on_master_auth # 4.0 ansible-playbook -i hosts/redis_hosts redis/redis.yml -e '{"redis_version":"4.0.9","redis_port":"6380"}' --tags turn_on_local_auth,turn_on_master_auth # 5.0 ansible-playbook -i hosts/redis_hosts redis/redis.yml -e '{"redis_version":"5.0.12","redis_port":"6381"}' --tags turn_on_local_auth,turn_on_master_auth ```
';