马哥博客作业第二十一周

1、搭建一个 redis 哨兵集群

  准备三台主机,搭建一个一主两从的redis哨兵集群

  10.0.0.7:主

  10.0.0.212,10.0.0.215:从

  1)、在三台主机上安装redis服务,修改redis配置文件,并配置主从关系,修改内容如下:

     [root@localhost redis-5.0.9]#vim redis.conf

      bind 0.0.0.0

      daemonize yes

      replicaof 10.0.0.207 6379

      masterauth 123456

      requirepass 123456

  2)、启动redis服务,验证主从复制关系    

    127.0.0.1:6379> INFO replication
    # Replication
    role:master
    connected_slaves:2
    slave0:ip=10.0.0.212,port=6379,state=online,offset=1904,lag=1
    slave1:ip=10.0.0.215,port=6379,state=online,offset=1904,lag=1
    master_replid:70ea5f1e36b836b5d2fec6e347425a1fbad9ea91
    master_replid2:0000000000000000000000000000000000000000
    master_repl_offset:1904
    second_repl_offset:-1
    repl_backlog_active:1
    repl_backlog_size:1048576
    repl_backlog_first_byte_offset:1
    repl_backlog_histlen:1904

  3)、修改sentinel配置信息,启动redis-sentinel服务开启哨兵模式

    [root@localhost redis-5.0.9]#vim sentinel.conf

    daemonize yes

    sentinel monitor mymaster 10.0.0.207 6379 2

    sentinel auth-pass mymaster 123456

  4)、关闭主10.0.0.207上的redis服务,sentinel重新选举了10.0.0.212为主   

    127.0.0.1:6379> INFO replication
    # Replication
    role:master
    connected_slaves:2
    slave0:ip=10.0.0.215,port=6379,state=online,offset=183879,lag=0
    slave1:ip=10.0.0.207,port=6379,state=online,offset=183744,lag=1
    master_replid:4ad939b7eb8f47c5748e212c80aa82f2b2110d33
    master_replid2:1d4108364b87d6baeb20c24ebf767301a08c3650
    master_repl_offset:183879
    second_repl_offset:174044
    repl_backlog_active:1
    repl_backlog_size:1048576
    repl_backlog_first_byte_offset:1
    repl_backlog_histlen:183879

    

2、实现 redis cluster 的部署

  准备6台主机,搭建基于redis5版本的cluster集群

  6台主机地址:10.0.0.202  10.0.0.207  10.0.0.212  10.0.0.214  10.0.0.215  10.0.0.216

  1)、6台主机都安装redis服务,版本都为5

    dnf -y install redis

  2)、修改每个节点的redis配置文件,开启cluster功能,修改内容如下:

    [root@localhost ~]#vim redis.conf

    bind 0.0.0.0

    masterauth 123456

    requirepass 123456

    cluster-enabled yes

    cluster-config-file nodes-6379.conf

    cluster-require-full-coverage no

   3)、创建集群

    [root@localhost ~]#redis-cli -a 123456 --cluster create 10.0.0.202:6379 10.0.0.207:6379 10.0.0.212:6379 10.0.0.214:6379 10.0.0.215:6379 10.0.0.216:6379 --cluster-replicas 1

  4)、验证集群状态   

    [root@localhost ~]#redis-cli -a 123456
    Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
    127.0.0.1:6379> CLUSTER INFO
    cluster_state:ok
    cluster_slots_assigned:16384
    cluster_slots_ok:16384
    cluster_slots_pfail:0
    cluster_slots_fail:0
    cluster_known_nodes:6
    cluster_size:3
    cluster_current_epoch:6
    cluster_my_epoch:1
    cluster_stats_messages_ping_sent:197
    cluster_stats_messages_pong_sent:177
    cluster_stats_messages_meet_sent:5
    cluster_stats_messages_sent:379
    cluster_stats_messages_ping_received:177
    cluster_stats_messages_pong_received:202
    cluster_stats_messages_received:379

  5)、查看集群节点主从对应关系

    [root@localhost ~]#redis-cli -a 123456 CLUSTER NODES   

    Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
    589dd0c73e46429a7de414bed35b623da5791bda 10.0.0.212:6379@16379 master - 0 1603959305436 3 connected 10923-16383
    0dff98d3b4543090850b95794a784393140d58f1 10.0.0.215:6379@16379 slave bfa48a7ce412e9baa13b29fa08184ed8dfd8a549 0 1603959304000 1 connected
    62f19caaf36d5a72be447d3ea57290652316eae4 10.0.0.214:6379@16379 myself,slave 589dd0c73e46429a7de414bed35b623da5791bda 0 1603959306000 4 connected
    39a90696c56ef9ce40f94966755eba0edd788ec5 10.0.0.216:6379@16379 slave 594da0691cd90e761970c06ed77e1b520c88f2df 0 1603959302414 6 connected
    594da0691cd90e761970c06ed77e1b520c88f2df 10.0.0.207:6379@16379 master - 0 1603959304429 2 connected 5461-10922
    bfa48a7ce412e9baa13b29fa08184ed8dfd8a549 10.0.0.202:6379@16379 master - 0 1603959306443 1 connected 0-5460

     

3、部署一个 tomcat 服务

  1)、首先安装java开发工具包openjdk

  [root@localhost ~]#yum -y install java-1.8.0-openjdk.x86_64

  2)、二进制安装tomcat-8.5.59

    先将二进制源码包从apache官网下载到指定目录,再进行解压缩安装

    [root@localhost src]#tar xf apache-tomcat-8.5.59.tar.gz

    [root@localhost src]#ln -s apache-tomcat-8.5.59 tomcat  #创建一个软链接

    [root@localhost src]#echo "PATH=/usr/local/src/tomcat/bin:$PATH" > /etc/profile.d/tomcat.sh  #指定PATH变量,并使其生效
    [root@localhost src]#. /etc/profile.d/tomcat.sh

  3)、启动tomcat服务

    [root@localhost src]#startup.sh
    Using CATALINA_BASE: /usr/local/src/tomcat
    Using CATALINA_HOME: /usr/local/src/tomcat
    Using CATALINA_TMPDIR: /usr/local/src/tomcat/temp
    Using JRE_HOME: /usr
    Using CLASSPATH: /usr/local/src/tomcat/bin/bootstrap.jar:/usr/local/src/tomcat/bin/tomcat-juli.jar
    Using CATALINA_OPTS:
    Tomcat started.

     

 

 

posted @ 2020-10-30 20:52  富儿代  阅读(84)  评论(0编辑  收藏  举报