部署3主3从redis伪集群
安装redis
mkdir -p /data/apps
yum -y install gcc tcl make gcc++
wget http://download.redis.io/releases/redis-4.0.0.tar.gz
tar xzf redis-4.0.0.tar.gz
cd redis-4.0.0
make && make install PREFIX=/data/apps/redis
cd /data/apps/redis
mkdir conf
cp /opt/redis-4.0.0/redis.conf ./conf
useradd -M redis
chown -R redis.redis /data/apps/redis
chmod g+s /data/apps/redis
mkdir -pv cluster/{7000,7007,7002,7003,7004,7005}
cp conf/redis.conf cluster/7000/redis.conf
cd cluster
vim 7000/redis.conf
# 端口号
port 7000
# 后台启动
daemonize yes
# 开启集群
cluster-enabled yes
#集群节点配置文件
cluster-config-file nodes-7000.conf
# 集群连接超时时间
cluster-node-timeout 5000
# 进程pid的文件位置
pidfile /var/run/redis-7000.pid
# 开启aof
appendonly yes
# aof文件路径
appendfilename "appendonly-7005.aof"
# rdb文件路径
dbfilename dump-7000.rdb
cp 7000/redis.conf ./{7001,7002,7003,7004,7005}/
sed -i 's/7000/7001/p' cluster/7001/redis.conf
sed -i 's/7000/7002/p' cluster/7002/redis.conf
sed -i 's/7000/7003/p' cluster/7003/redis.conf
sed -i 's/7000/7004/p' cluster/7004/redis.conf
sed -i 's/7000/7005/p' cluster/7005/redis.conf
cat <<EOF > start.sh
bin/redis-server cluster/7000/redis.conf
bin/redis-server cluster/7001/redis.conf
bin/redis-server cluster/7002/redis.conf
bin/redis-server cluster/7003/redis.conf
bin/redis-server cluster/7004/redis.conf
bin/redis-server cluster/7005/redis.conf
chmod +x start.sh
./start.sh
安装ruby
yum install ruby rubygems -y
gem install redis -y
安装rvm
1 导入秘钥
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
** 或提示找不到有效OpenPGP 数据,执行
curl -sSL https://rvm.io/mpapis.asc | gpg2 --import -
2. 安装rvm
curl -sSL https://get.rvm.io | bash -s stable
source /etc/profile.d/rvm.sh
rvm install 2.3.0
rvm use 2.3.0 --default
ruby -v
gem -v
** 修改gem默认源
gem sources --add https://gems.ruby-china.org/ --remove https://rubygems.org/
redis-trib create --replicas 1 ip:7000 ip:7001 ip:7002 ip:7003 ip:7004 ip:7005
# 连接
redis-cli -c -h ip -p port
# 插值时错误(error)CLUSTERDOWN Hash slot not served 解决方法
redis-trib.rb check ip:7000
redis-trib.rb fix ip:7000