第21周作业 --redis
1、搭建一个 redis 哨兵集群
回答:3台服务器上分别安装redis和修改配置文件。
[root@centos8 ~]# yum -y install redis
[root@centos8 ~]# vim /etc/redis.conf
bind 0.0.0.0
masterauth 123456
requirepass 123456
[root@centos8 ~]# vim /etc/redis-sentinel.conf
port 26379
daemonize yes
sentinel monitor mymaster 10.0.0.8 6379 2
sentinel auth-pass mymaster 123456
sentinel down-after-milliseconds mymaster 30000
sentinel parallel-syncs mymaster 1
sentinel failover-timeout mymaster 180000
sentinel deny-scripts-reconfig yes
[root@centos8 ~]# systemctl start redis
[root@centos8 ~]# systemctl start redis-sentinel.conf
检查端口是否开启成功
[root@centos8 ~]# ss -tnl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 511 0.0.0.0:26379 0.0.0.0:*
LISTEN 0 511 0.0.0.0:6379 0.0.0.0:*
LISTEN 0 128 [::]:22 [::]:*
[root@centos8 ~]# redis-cli -p 26379
127.0.0.1:26379> info sentinel
# Sentinel
sentinel_masters:1
sentinel_tilt:0
sentinel_running_scripts:0
sentinel_scripts_queue_length:0
sentinel_simulate_failure_flags:0
master0:name=mymaster,status=ok,address=10.0.0.8:6379,slaves=2,sentinels=3
[root@centos8 ~]# 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> info replication
# Replication
role:master
connected_slaves:2
slave0:ip=10.0.0.28,port=6379,state=online,offset=277057,lag=0
slave1:ip=10.0.0.18,port=6379,state=online,offset=277057,lag=0
master_replid:9739b6a56a1eb5667efa31dde4b891f6d3abdc0f
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:277057
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1
repl_backlog_histlen:277057
2、实现 redis cluster 得部署
回答:部署6台服务器,分别为master:10.0.0.8,10.0.0.18,10.0.0.28;slave:10.0.0.38,10.0.0.48,10.0.0.58。
所有主机安装和修改redis配置
[root@centos8 ~]# yum -y install redis
[root@centos8 ~]# vim /etc/redis.conf
[root@centos8 ~]# grep -vE "^#|^$" /etc/redis.conf
bind 0.0.0.0
masterauth 123456
cluster-enabled yes
cluster-config-file nodes-6379.conf
cluster-require-full-coverage no
[root@centos8 ~]# systemctl enable --now redis
[root@centos8 ~]# ss -tnl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 0.0.0.0:6379 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 0.0.0.0:16379 0.0.0.0:*
LISTEN 0 128 [::]:22 [::]:*
创建集群
[root@centos8 ~]# redis-cli -a 123456 --cluster create 10.0.0.8:6379 10.0.0.18:6379 10.0.0.28:6379 10.0.0.38:6379 10.0.0.48:6379 10.0.0.58:6379 --cluster-replicas 1
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
>>> Performing hash slots allocation on 6 nodes...
Master[0] -> Slots 0 - 5460
Master[1] -> Slots 5461 - 10922
Master[2] -> Slots 10923 - 16383
Adding replica 10.0.0.38:6379 to 10.0.0.8:6379
Adding replica 10.0.0.48:6379 to 10.0.0.18:6379
Adding replica 10.0.0.58:6379 to 10.0.0.28:6379
M: f058ea41b014b156e13ff644a7de445526e93454 10.0.0.8:6379
slots:[0-5460] (5461 slots) master
M: 18c3d9a017dfdd2083aca6b49650bd2b7d67e9fa 10.0.0.18:6379
slots:[5461-10922] (5462 slots) master
M: 277b510e11657179da2e9133465227b07dd19e71 10.0.0.28:6379
slots:[10923-16383] (5461 slots) master
S: 4696c1f20472de2b8c2b1817d63cb83b95bd18e4 10.0.0.38:6379
replicates f058ea41b014b156e13ff644a7de445526e93454
S: 012b6fd68fb09f667a238c03e033895efa60eddd 10.0.0.48:6379
replicates 18c3d9a017dfdd2083aca6b49650bd2b7d67e9fa
S: 790635b17a302aed057876ca925602ee6ee8ffc7 10.0.0.58:6379
replicates 277b510e11657179da2e9133465227b07dd19e71n I set the above configuration? (type 'yes' to accept): yes
>>> Nodes configuration updated
>>> Assign a different config epoch to each node
>>> Sending CLUSTER MEET messages to join the cluster
Waiting for the cluster to join
......
>>> Performing Cluster Check (using node 10.0.0.8:6379)
M: f058ea41b014b156e13ff644a7de445526e93454 10.0.0.8:6379
slots:[0-5460] (5461 slots) master
1 additional replica(s)
M: 18c3d9a017dfdd2083aca6b49650bd2b7d67e9fa 10.0.0.18:6379
slots:[5461-10922] (5462 slots) master
1 additional replica(s)
S: 4696c1f20472de2b8c2b1817d63cb83b95bd18e4 10.0.0.38:6379
slots: (0 slots) slave
replicates f058ea41b014b156e13ff644a7de445526e93454
S: 012b6fd68fb09f667a238c03e033895efa60eddd 10.0.0.48:6379
slots: (0 slots) slave
replicates 18c3d9a017dfdd2083aca6b49650bd2b7d67e9fa
M: 277b510e11657179da2e9133465227b07dd19e71 10.0.0.28:6379
slots:[10923-16383] (5461 slots) master
1 additional replica(s)
S: 790635b17a302aed057876ca925602ee6ee8ffc7 10.0.0.58:6379
slots: (0 slots) slave
replicates 277b510e11657179da2e9133465227b07dd19e71
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
查看集群信息
[root@centos8 ~]# redis-cli -a 123456 cluster nodes
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
18c3d9a017dfdd2083aca6b49650bd2b7d67e9fa 10.0.0.18:6379@16379 master - 0 1600263931313 2 connected 5461-10922
4696c1f20472de2b8c2b1817d63cb83b95bd18e4 10.0.0.38:6379@16379 slave f058ea41b014b156e13ff644a7de445526e93454 0 1600263930275 4 connected
012b6fd68fb09f667a238c03e033895efa60eddd 10.0.0.48:6379@16379 slave 18c3d9a017dfdd2083aca6b49650bd2b7d67e9fa 0 1600263929236 5 connected
277b510e11657179da2e9133465227b07dd19e71 10.0.0.28:6379@16379 master - 0 1600263930584 3 connected 10923-16383
790635b17a302aed057876ca925602ee6ee8ffc7 10.0.0.58:6379@16379 slave 277b510e11657179da2e9133465227b07dd19e71 0 1600263927159 6 connected
f058ea41b014b156e13ff644a7de445526e93454 10.0.0.8:6379@16379 myself,master - 0 0 1 connected 0-5460
验证集群信息
[root@centos8 ~]# redis-cli -c -h 10.0.0.8 -a 123456
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
10.0.0.8:6379> set name mage
-> Redirected to slot [5798] located at 10.0.0.18:6379
OK
[root@centos8 ~]# redis-cli -c -h 10.0.0.28 -a 123456
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
10.0.0.28:6379> get name
-> Redirected to slot [5798] located at 10.0.0.18:6379
"mage"
3、部署一个 tomcat 服务
回答:安装jdk软件包
[root@centos8 ~]# yum -y install java-1.8.0-openjdk-devel.x86_64 java-1.8.0-openjdk.x86_64
centos8上的yum源没有tomcat软件,因此要进行二进制安装
[root@centos8 ~]# yum list tomcat
AppStream 417 B/s | 4.3 kB 00:10
BaseOS 14 kB/s | 3.9 kB 00:00
Extras 2.9 kB/s | 1.5 kB 00:00
Extra Packages for Enterprise Linux Modular 8 - x86_64 1.4 kB/s | 8.7 kB 00:06
Extra Packages for Enterprise Linux 8 - x86_64 2.3 kB/s | 3.8 kB 00:01
错误:没有匹配的软件包可以列出
官方下载源:https://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/
[root@centos8 local]# cd /usr/local/
[root@centos8 local]# wget https://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-8/v8.5.59/bin/apache-tomcat-8.5.59.tar.gz
[root@centos8 tomcat]# tar -xf apache-tomcat-8.5.59.tar.gz -C /usr/local/
[root@centos8 tomcat]# ln -s apache-tomcat-8.5.59 tomcat
[root@centos8 tomcat]# echo 'PATH=/usr/local/tomcat/bin:$PATH' > /etc/profile.d/tomcat.sh
[root@centos8 tomcat]# . /etc/profile.d/tomcat.sh
[root@centos8 tomcat]# catalina.sh start
[root@centos8 tomcat]# ss -tnl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 1 [::ffff:127.0.0.1]:8005 *:*
LISTEN 0 100 *:8080 *:*
LISTEN 0 128 [::]:22 [::]:*

浙公网安备 33010602011771号