[root@redis-master ~]# docker exec -it redis-master redis-cli -p 6666 -a 123456 info replication
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe. # Replication role:master # 当前为主节点 connected_slaves:2 # 连接两个从节点 slave0:ip=172.19.0.102,port=7777,state=online,offset=42,lag=1 # 从节点1 slave1:ip=172.19.0.103,port=8888,state=online,offset=42,lag=1 # 从节点2 master_failover_state:no-failover master_replid:f0214d7b9870fe4c5cbabdddf1ee743317ae74e5 master_replid2:0000000000000000000000000000000000000000 master_repl_offset:42 second_repl_offset:-1 repl_backlog_active:1 repl_backlog_size:1048576 repl_backlog_first_byte_offset:1 repl_backlog_histlen:42
[root@redis-slave1 ~]# docker exec -it redis-slave1 redis-cli -p 7777 -a 123456 info replication Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe. # Replication role:slave master_host:172.19.0.101 master_port:6666 master_link_status:up master_last_io_seconds_ago:10 master_sync_in_progress:0 slave_read_repl_offset:322 slave_repl_offset:322 slave_priority:100 slave_read_only:1 replica_announced:1 connected_slaves:0 master_failover_state:no-failover master_replid:f0214d7b9870fe4c5cbabdddf1ee743317ae74e5 master_replid2:0000000000000000000000000000000000000000 master_repl_offset:322 second_repl_offset:-1 repl_backlog_active:1 repl_backlog_size:1048576 repl_backlog_first_byte_offset:15 repl_backlog_histlen:308
[root@redis-slave2 ~]# docker exec -it redis-slave2 redis-cli -p 8888 -a 123456 info replication Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe. # Replication role:slave master_host:172.19.0.101 master_port:6666 master_link_status:up master_last_io_seconds_ago:7 master_sync_in_progress:0 slave_read_repl_offset:420 slave_repl_offset:420 slave_priority:100 slave_read_only:1 replica_announced:1 connected_slaves:0 master_failover_state:no-failover master_replid:f0214d7b9870fe4c5cbabdddf1ee743317ae74e5 master_replid2:0000000000000000000000000000000000000000 master_repl_offset:420 second_repl_offset:-1 repl_backlog_active:1 repl_backlog_size:1048576 repl_backlog_first_byte_offset:29 repl_backlog_histlen:392
5.测试主从复制
master
1 2 3 4 5 6
[root@redis-master ~]# docker exec -it redis-master redis-cli -p 6666 -a 123456 set name stave Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe. OK # 成功写入数据 [root@redis-master ~]# docker exec -it redis-master redis-cli -p 6666 -a 123456 get name Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe. "stave"# 成功读取
slave1
1 2 3 4 5 6 7
[root@redis-slave1 ~]# docker exec -it redis-slave1 redis-cli -p 7777 -a 123456 get name Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe. "stave"# slave1 成功读取数据 [root@redis-slave1 ~]# docker exec -it redis-slave1 redis-cli -p 7777 -a 123456 set name stave Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe. (error) READONLY You can't write against a read only replica. # 由于从节点只读,所以写入数据报错
slave2
1 2 3 4 5 6 7
[root@redis-slave2 ~]# docker exec -it redis-slave2 redis-cli -p 8888 -a 123456 get name Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe. "stave" [root@redis-slave2 ~]# docker exec -it redis-slave2 redis-cli -p 8888 -a 123456 set name stave Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe. (error) READONLY You can't write against a read only replica. # 同slave1,可以成功读取数据但不能写入数据
# slave1 [root@redis-slave1 /]# docker exec -it redis-slave1 redis-cli -p 7777 -a 123456 info replication Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe. # Replication role:master connected_slaves:1 slave0:ip=172.19.0.103,port=8888,state=online,offset=180670,lag=1 master_failover_state:no-failover master_replid:8a814c929ed52b786c36b5d1e07ebad1b907a7dc master_replid2:e7107664d2c67a733e3f6901252ba88823eb51e6 master_repl_offset:180670 second_repl_offset:172840 repl_backlog_active:1 repl_backlog_size:1048576 repl_backlog_first_byte_offset:15 repl_backlog_histlen:180656
# slave2 [root@node2 /]# docker exec -it redis-slave2 redis-cli -p 8888 -a 123456 info replication Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe. # Replication role:slave master_host:172.19.0.102 master_port:7777 master_link_status:up master_last_io_seconds_ago:1 master_sync_in_progress:0 slave_read_repl_offset:184084 slave_repl_offset:184084 slave_priority:100 slave_read_only:1 replica_announced:1 connected_slaves:0 master_failover_state:no-failover master_replid:8a814c929ed52b786c36b5d1e07ebad1b907a7dc master_replid2:e7107664d2c67a733e3f6901252ba88823eb51e6 master_repl_offset:184084 second_repl_offset:172840 repl_backlog_active:1 repl_backlog_size:1048576 repl_backlog_first_byte_offset:29 repl_backlog_histlen:184056
[root@redis-master /]# docker exec -it redis-master redis-cli -p 6666 -a 123456 info replication Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe. # Replication role:slave master_host:172.19.0.102 master_port:7777 master_link_status:down master_last_io_seconds_ago:-1 master_sync_in_progress:0 slave_read_repl_offset:184150 slave_repl_offset:184150 master_link_down_since_seconds:-1 slave_priority:100 slave_read_only:1 replica_announced:1 connected_slaves:0 master_failover_state:no-failover master_replid:14a30a8a3b44d169f4dc071a059ab38be7b4759a master_replid2:e7107664d2c67a733e3f6901252ba88823eb51e6 master_repl_offset:184150 second_repl_offset:172840 repl_backlog_active:1 repl_backlog_size:1048576 repl_backlog_first_byte_offset:172840 repl_backlog_histlen:11311
redis集群读取数据需要以 redis-cli -p 6381 -c 集群的方式连接,否则会添加数据时会出现 (error) MOVED 12706 192.168.8.89:6382
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
[root@node2 ~]# docker exec -it redis-node-1 bash root@node2:/data# redis-cli -p 6381 -c 127.0.0.1:6381> set k1 v1 -> Redirected to slot [12706] located at 192.168.8.89:6383 OK 192.168.8.89:6383> set k2 v2 -> Redirected to slot [449] located at 192.168.8.89:6381 OK 192.168.8.89:6381> set k3 v3 OK 192.168.8.89:6381> 192.168.8.89:6381> set k4 v4 -> Redirected to slot [8455] located at 192.168.8.89:6382 OK 192.168.8.89:6382> 192.168.8.89:6382> keys * 1) "k4"
Mysql备份表及部分数据 有时候我们只需要备份某个表里面的部分数据,快速恢复关键业务。 【原理】:使用 like 命令快速复制一个表(结构一模一样),将要备份的部分数据查询出来备份到新表里面,使用完了以后再恢复回去。
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#示例: mysql -h10.*.*.9 -P3306 -uroot -p"密码" use db_mystorage; #step1:拷贝一份新的表结构 create table tb_staff_bak like tb_staff; #step2:将要备份的部分数据查询出来备份到新表里面 insert into tb_staff_bk select * from tb_staff where name in ('xiong','zhang'); #step3:清理目标数据 delete from tb_staff where name in ('xiong','zhang'); #回滚与恢复: insert into tb_staff select * from tb_staff_bk;
[root@docker-node-1 etcd]# docker compose ps -a NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS etcd-s1 quay.io/coreos/etcd:v3.5.12 "/usr/local/bin/etcd…" etcd 53 seconds ago Up 53 seconds 0.0.0.0:2379-2380->2379-2380/tcp, :::2379-2380->2379-2380/tcp
[root@docker-node-1 etcd]# docker compose ps -a NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS etcd-s1 quay.io/coreos/etcd:v3.5.12 "/usr/local/bin/etcd" etcd 17 seconds ago Up 16 seconds 0.0.0.0:2379-2380->2379-2380/tcp, :::2379-2380->2379-2380/tcp
4. etcd 服务可用性测试
为了测试 etcd 服务的可用性,额外再找一台机器安装 etcd 客户端工具用于验证测试。
下载并解压软件包
1 2 3 4
cd /srv wget https://github.com/etcd-io/etcd/releases/download/v3.5.12/etcd-v3.5.12-linux-amd64.tar.gz tar xvf etcd-v3.5.12-linux-amd64.tar.gz cd etcd-v3.5.12-linux-amd64
#完成后将会看到如下输出 Running handlers complete Chef Client finished, 432/613 resources updated in 03 minutes 43 seconds gitlab Reconfigured!
Notes: Default admin account has been configured with following details: Username: root Password: You didn't opt-in to print initial root password to STDOUT. Password stored to /etc/gitlab/initial_root_password. This file will be cleaned up in first reconfigure run after 24 hours.
Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub.