目录
redis架构
功能配置 | 10.0.0.65 | 10.0.0.66 | 10.0.0.67 |
---|---|---|---|
hostname | 65 | 66 | 67 |
hsots | cat > /etc/hosts <<EOF10.0.0.65 6510.0.0.66 6610.0.0.67 67EOF | cat > /etc/hosts <<EOF10.0.0.65 6510.0.0.66 6610.0.0.67 67EOF | cat > /etc/hosts <<EOF10.0.0.65 6510.0.0.66 6610.0.0.67 67EOF |
主从复制 | 主库哨兵 | 从库 | 从库 |
集群高可用 | master | slave | slave |
安装
65
rm -rf /root/.ssh /bin/ssh-keygen -t rsa -f /root/.ssh/id_rsa -P ""sshpass -p123456 ssh-copy-id -i ~/.ssh/id_rsa.pub 10.0.0.66 -o StrictHostKeyChecking=nosshpass -p123456 ssh-copy-id -i ~/.ssh/id_rsa.pub 10.0.0.67 -o StrictHostKeyChecking=no
65\66\67
mkdir -p /data/softmkdir -p /data/redis_cluster/redis_6379mkdir -p /opt/redis_cluster/redis_6379/{conf,pid,logs}cd /data/soft/wget http://download.redis.io/releases/redis-5.0.0.tar.gztar zxf redis-5.0.0.tar.gz -C /opt/redis_cluster/ln -s /opt/redis_cluster/redis-5.0.0/ /opt/redis_cluster/rediscd /opt/redis_cluster/redismake && make installyum makecache fastyum install rubygems -ygem sources --remove https://rubygems.org/gem sources -a http://mirrors.aliyun.com/rubygems/gem update –systemgem install redis -v 3.3.5ruby -vgem -vyum install python-pip gcc -ypip install --upgrade pippip install rdbtools
65
cat > /opt/redis_cluster/redis_6379/conf/redis_6379.conf <
66
cat > /opt/redis_cluster/redis_6379/conf/redis_6379.conf <
67
cat > /opt/redis_cluster/redis_6379/conf/redis_6379.conf <
65\66\67
#启动redis数据库redis-server /opt/redis_cluster/redis_6379/conf/redis_6379.conf#进入redis数据库redis-cli#关闭redis数据库 redis-cli shutdown
主从复制
66\67
redis-cliSLAVEOF 10.0.0.65 6379
查看主从复制状态
主库65
127.0.0.1:6379> info replication# Replicationrole:masterconnected_slaves:2
从库66\67
[root@66 ~]# redis-cli127.0.0.1:6379> info replication# Replicationrole:slavemaster_host:10.0.0.65master_port:6379-----------------------------[root@67 ~]# redis-cli127.0.0.1:6379> info replication# Replicationrole:slavemaster_host:10.0.0.65master_port:6379
哨兵
65 (主)
cat > /opt/redis_cluster/redis_26379/conf/redis_26379.conf<
redis集群
修改配置文件
65
cat > /opt/redis_cluster/redis_6379/conf/redis_6379.conf <
66
cat > /opt/redis_cluster/redis_6379/conf/redis_6379.conf <
67
cat > /opt/redis_cluster/redis_6379/conf/redis_6379.conf <
65、66、67
redis-server /opt/redis_cluster/redis_6379/conf/redis_6379.conf
发现所有节点
65
redis-cli -h 10.0.0.65 -p 6379 cluster meet 10.0.0.66 6379redis-cli -h 10.0.0.65 -p 6379 cluster meet 10.0.0.67 6379redis-cli #查看节点127.0.0.1:6379> cluster nodes
分配槽位---槽位共16383
65
redis-cli -h 10.0.0.65 -p 6379 cluster addslots {0..16383}10.0.0.65:6379> CLUSTER NODES #槽位26b0bac41e4fff8039152104309340b16cfd3e14 10.0.0.67:6379 master - 0 1562253484470 2 connectedce47edb5daa884bf5366f902a4e78068813ba0df 10.0.0.66:6379 master - 0 1562253488498 1 connectedf7dd5b276f31507b41f6f6bf41519b1df6491a8f 10.0.0.65:6379 myself,master - 0 0 0 connected 0-16383
高可用
66\67
10.0.0.66:6379> CLUSTER REPLICATE f7dd5b276f31507b41f6f6bf41519b1df6491a8f10.0.0.67:6379> CLUSTER REPLICATE f7dd5b276f31507b41f6f6bf41519b1df6491a8f10.0.0.65:6379> CLUSTER NODESce47edb5daa884bf5366f902a4e78068813ba0df 10.0.0.66:6379 slave f7dd5b276f31507b41f6f6bf41519b1df6491a8f 0 1562254234804 1 connected26b0bac41e4fff8039152104309340b16cfd3e14 10.0.0.67:6379 slave f7dd5b276f31507b41f6f6bf41519b1df6491a8f 0 1562254235814 2 connectedf7dd5b276f31507b41f6f6bf41519b1df6491a8f 10.0.0.65:6379 master - 0 0 0 connected 0-16383
==扩展redis管理脚本==
65、66、67
[root@65 ~]# cat redis_shell.sh #!/bin/bashUSAG(){ echo "sh $0 {start|stop|restart|login|ps|tail} PORT"}if [ "$#" = 1 ]then REDIS_PORT='6379'elif [ "$#" = 2 -a -z "$(echo "$2"|sed 's#[0-9]##g')" ]then REDIS_PORT="$2"else USAG exit 0fiREDIS_IP=$(hostname -I|awk '{print $1}')PATH_DIR=/opt/redis_cluster/redis_${REDIS_PORT}/PATH_CONF=/opt/redis_cluster/redis_${REDIS_PORT}/conf/redis_${REDIS_PORT}.c onfPATH_LOG=/opt/redis_cluster/redis_${REDIS_PORT}/logs/redis_${REDIS_PORT}.lo gCMD_START(){ redis-server ${PATH_CONF}}CMD_SHUTDOWN(){ redis-cli -c -h ${REDIS_IP} -p ${REDIS_PORT} shutdown}CMD_LOGIN(){ redis-cli -c -h ${REDIS_IP} -p ${REDIS_PORT}}CMD_PS(){ ps -ef|grep redis}CMD_TAIL(){ tail -f ${PATH_LOG}}case $1 in start) CMD_START CMD_PS ;; stop) CMD_SHUTDOWN CMD_PS ;; restart) CMD_START CMD_SHUTDOWN CMD_PS ;; login) CMD_LOGIN ;; ps) CMD_PS ;; tail) CMD_TAIL ;; *) USAGesac