redis 数据库架构安装部署及操作

目录

  • redis 命令大全
  • redis架构
    • 安装
      • 65
      • 65\66\67
      • 65
      • 66
      • 67
      • 65\66\67
    • 主从复制
      • 66\67
      • 查看主从复制状态
    • 哨兵
      • 65 (主)
    • redis集群
      • 修改配置文件
      • 发现所有节点
      • 分配槽位---槽位共16383
      • 高可用
    • ==扩展redis管理脚本==
      • 65、66、67

redis 命令大全

redis架构

功能配置 10.0.0.65 10.0.0.66 10.0.0.67
hostname 65 66 67
hsots cat > /etc/hosts <10.0.0.65 65
10.0.0.66 66
10.0.0.67 67
EOF
cat > /etc/hosts <10.0.0.65 65
10.0.0.66 66
10.0.0.67 67
EOF
cat > /etc/hosts <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=no
sshpass -p123456 ssh-copy-id -i ~/.ssh/id_rsa.pub 10.0.0.67 -o StrictHostKeyChecking=no

65\66\67

mkdir -p /data/soft
mkdir -p /data/redis_cluster/redis_6379
mkdir -p /opt/redis_cluster/redis_6379/{conf,pid,logs}
cd /data/soft/
wget http://download.redis.io/releases/redis-5.0.0.tar.gz
tar zxf redis-5.0.0.tar.gz -C /opt/redis_cluster/
ln -s /opt/redis_cluster/redis-5.0.0/ /opt/redis_cluster/redis
cd /opt/redis_cluster/redis
make && make install
yum makecache fast
yum install rubygems -y
gem sources --remove https://rubygems.org/
gem sources -a http://mirrors.aliyun.com/rubygems/
gem update –system
gem install redis -v 3.3.5
ruby -v
gem -v
yum install python-pip gcc -y
pip install --upgrade pip
pip 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-cli
SLAVEOF 10.0.0.65 6379

查看主从复制状态

主库65

127.0.0.1:6379> info replication
# Replication
role:master
connected_slaves:2

从库66\67

[root@66 ~]# redis-cli
127.0.0.1:6379> info replication
# Replication
role:slave
master_host:10.0.0.65
master_port:6379
-----------------------------
[root@67 ~]# redis-cli
127.0.0.1:6379> info replication
# Replication
role:slave
master_host:10.0.0.65
master_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 6379
redis-cli -h 10.0.0.65 -p 6379 cluster meet 10.0.0.67 6379
redis-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 connected
ce47edb5daa884bf5366f902a4e78068813ba0df 10.0.0.66:6379 master - 0 1562253488498 1 connected
f7dd5b276f31507b41f6f6bf41519b1df6491a8f 10.0.0.65:6379 myself,master - 0 0      0 connected 0-16383

高可用

66\67

10.0.0.66:6379> CLUSTER REPLICATE f7dd5b276f31507b41f6f6bf41519b1df6491a8f
10.0.0.67:6379> CLUSTER REPLICATE f7dd5b276f31507b41f6f6bf41519b1df6491a8f

10.0.0.65:6379> CLUSTER NODES
ce47edb5daa884bf5366f902a4e78068813ba0df 10.0.0.66:6379 slave f7dd5b276f31507b41f6f6bf41519b1df6491a8f 0 1562254234804 1 connected
26b0bac41e4fff8039152104309340b16cfd3e14 10.0.0.67:6379 slave f7dd5b276f31507b41f6f6bf41519b1df6491a8f 0 1562254235814 2 connected
f7dd5b276f31507b41f6f6bf41519b1df6491a8f 10.0.0.65:6379 master - 0 0      0 connected 0-16383

==扩展redis管理脚本==

65、66、67

[root@65 ~]# cat redis_shell.sh 
#!/bin/bash
USAG(){
    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 0
fi

REDIS_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    onf
PATH_LOG=/opt/redis_cluster/redis_${REDIS_PORT}/logs/redis_${REDIS_PORT}.lo    g

CMD_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
        ;;
    *)
        USAG
esac

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

你可能感兴趣的:(redis 数据库架构安装部署及操作)