博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
redis 数据库架构安装部署及操作
阅读量:5325 次
发布时间:2019-06-14

本文共 4545 字,大约阅读时间需要 15 分钟。

目录

redis架构

功能配置 10.0.0.65 10.0.0.66 10.0.0.67
hostname 65 66 67
hsots cat > /etc/hosts <<EOF
10.0.0.65 65
10.0.0.66 66
10.0.0.67 67
EOF
cat > /etc/hosts <<EOF
10.0.0.65 65
10.0.0.66 66
10.0.0.67 67
EOF
cat > /etc/hosts <<EOF
10.0.0.65 65
10.0.0.66 66
10.0.0.67 67
EOF
主从复制 主库
哨兵
从库 从库
集群高可用 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

转载于:https://www.cnblogs.com/jiangyatao/p/11365652.html

你可能感兴趣的文章
在线图床工具的使用 https://sm.ms/
查看>>
MySQL5.7 error log时间显示问题
查看>>
Java学习1
查看>>
ThreadLocalDemo
查看>>
jquery发起get/post请求_或_获取html页面数据
查看>>
编程语言python
查看>>
Cordova学习笔记之入门
查看>>
C# winform 设置WebBowser 内核版本
查看>>
Uint8Array 对象
查看>>
ResGen.exe”已退出,代码为2 问题处理
查看>>
TopFreeTheme精选免费模板【20130629】
查看>>
【转】C++ 类中的static,const,及引用类型的初始化
查看>>
find命令
查看>>
2019ICPC西安邀请赛 - B. Product - 数论
查看>>
Windows Store App JavaScript 开发:文件选取器
查看>>
ios修改产品名
查看>>
C++中string erase函数的使用
查看>>
PostgreSQL 对字段大小写敏感
查看>>
TCP和UDP的"保护消息边界”
查看>>
SQL游标使用实例
查看>>