当前位置: 首页 > news >正文

Mysql部署MHA高可用

部署前准备:

  mysql-8.0.27下载地址:https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.27-1.el7.x86_64.rpm-bundle.tar

  mha-manager下载地址:https://github.com/yoshinorim/mha4mysql-manager/releases/download/v0.58/mha4mysql-manager-0.58-0.el7.centos.noarch.rpm

  mha-node下载地址:https://github.com/yoshinorim/mha4mysql-node/releases/download/v0.58/mha4mysql-node-0.58-0.el7.centos.noarch.rpm

部署架构:

基本配置

4个节点逐台配置hostname和/etc/hosts文件

安装mysql8

4个节点均创建/data目录,将mysql-8.0.27-1.el7.x86_64.rpm-bundle.tar上传到/data目录下,进行解压安装

我这里使用操作系统镜像制作了本地yum源,用来解决依赖问题,命令见下图

看到如下内容,代表安装完成

 配置Mysql异步复制集群

启动hdp2、hdp3、hdp4上的mysql服务,并配置开机自启

1

systemctl enable mysqld --now

 连接3个节点的mysql数据库,数据库默认root密码通过查看日志获取

1

2

cat /var/log/mysqld.log |grep password

...... [Server] A temporary password is generated for root@localhost: euBcRQk+3tpa

3个节点数据库修改root用户密码,命令及sql如下

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

[root@hdp2 data]# mysql -uroot -p

Enter password:

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 20

Server version: 8.0.27

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> alter user 'root'@'localhost' identified by '1qaz@WSX123';

Query OK, 0 rows affected (0.01 sec)

mysql> flush privileges;

Query OK, 0 rows affected (0.01 sec)

mysql> exit;

Bye

3个节点配置数据库server_id,以root用户登录mysql进行临时配置,然后将server_id配置在/etc/my.cnf中,防止重启后失效

1

2

3

4

5

6

7

8

9

10

11

12

hdp2

mysql> set global server_id=1;

hdp3

mysql> set global server_id=2;

hdp4

mysql> set global server_id=3;

hdp2

]# echo "server_id=1" >> /etc/my.cnf

hdp3

]# echo "server_id=2" >> /etc/my.cnf

hdp4

]# echo "server_id=3" >> /etc/my.cnf

查看主库hdp2的二进制日志信息

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

[root@hdp2 data]# mysql -uroot -p

Enter password:

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 23

Server version: 8.0.27 MySQL Community Server - GPL

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show master status;

+---------------+----------+--------------+------------------+-------------------+

| File          | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |

+---------------+----------+--------------+------------------+-------------------+

| binlog.000003 |      642 |              |                  |                   |

+---------------+----------+--------------+------------------+-------------------+

1 row in set (0.00 sec)

mysql>  

在主库hdp2上建立复制专用用户,并授权

1

2

3

4

5

6

7

mysql> create user 'repl'@'%' identified with mysql_native_password by '1qaz@WSX123';

Query OK, 0 rows affected (0.01 sec)

mysql> grant replication client,replication slave on *.* to 'repl'@'%';

Query OK, 0 rows affected (0.01 sec)

mysql> 

在从库hdp3和hdp4上创建主库信息

1

2

3

4

5

6

7

8

9

10

mysql> change master to

    -> master_host='192.168.244.151',

    ->  master_port=3306,

    -> master_user='repl',

    -> master_password='1qaz@WSX123',

    -> master_log_file='binlog.000003',               #主库状态显示的File

    -> master_log_pos=642;                            #主库状态显示的Position

Query OK, 0 rows affected, 9 warnings (0.02 sec)

mysql>   

在从库启动复制并查看从库状态

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

mysql> start slave;

Query OK, 0 rows affected, 1 warning (0.01 sec)

mysql> show slave status\G

*************************** 1. row ***************************

               Slave_IO_State: Waiting for source to send event

                  Master_Host: 192.168.244.151

                  Master_User: repl

                  Master_Port: 3306

                Connect_Retry: 60

              Master_Log_File: binlog.000003

          Read_Master_Log_Pos: 1165

               Relay_Log_File: hdp3-relay-bin.000002

                Relay_Log_Pos: 844

        Relay_Master_Log_File: binlog.000003

             Slave_IO_Running: Yes

            Slave_SQL_Running: Yes

              Replicate_Do_DB:

          Replicate_Ignore_DB:

           Replicate_Do_Table:

       Replicate_Ignore_Table:

      Replicate_Wild_Do_Table:

  Replicate_Wild_Ignore_Table:

                   Last_Errno: 0

                   Last_Error:

                 Skip_Counter: 0

          Exec_Master_Log_Pos: 1165

              Relay_Log_Space: 1052

              Until_Condition: None

               Until_Log_File:

                Until_Log_Pos: 0

           Master_SSL_Allowed: No

           Master_SSL_CA_File:

           Master_SSL_CA_Path:

              Master_SSL_Cert:

            Master_SSL_Cipher:

               Master_SSL_Key:

        Seconds_Behind_Master: 0

Master_SSL_Verify_Server_Cert: No

                Last_IO_Errno: 0

                Last_IO_Error:

               Last_SQL_Errno: 0

               Last_SQL_Error:

  Replicate_Ignore_Server_Ids:

             Master_Server_Id: 1

                  Master_UUID: 7096d4eb-7378-11ec-8ec4-000c29f7d066

             Master_Info_File: mysql.slave_master_info

                    SQL_Delay: 0

          SQL_Remaining_Delay: NULL

      Slave_SQL_Running_State: Replica has read all relay log; waiting for more updates

           Master_Retry_Count: 86400

                  Master_Bind:

      Last_IO_Error_Timestamp:

     Last_SQL_Error_Timestamp:

               Master_SSL_Crl:

           Master_SSL_Crlpath:

           Retrieved_Gtid_Set:

            Executed_Gtid_Set:

                Auto_Position: 0

         Replicate_Rewrite_DB:

                 Channel_Name:

           Master_TLS_Version:

       Master_public_key_path:

        Get_master_public_key: 0

            Network_Namespace:

1 row in set, 1 warning (0.00 sec)

mysql>

配置Mysql半同步复制

在主库加载插件semisync_master.so,从库加载插件semisync_slave.so

1

2

3

4

5

6

7

8

9

hda2

mysql> install plugin rpl_semi_sync_master soname 'semisync_master.so';

Query OK, 0 rows affected, 1 warning (0.01 sec)

hda3

mysql> install plugin rpl_semi_sync_slave soname 'semisync_slave.so';

Query OK, 0 rows affected, 1 warning (0.01 sec)

hda4

mysql> install plugin rpl_semi_sync_slave soname 'semisync_slave.so';

Query OK, 0 rows affected, 1 warning (0.01 sec)

启用半同步复制

1

2

3

4

5

6

7

8

9

hdp2

mysql> set global rpl_semi_sync_master_enabled=1;

Query OK, 0 rows affected (0.00 sec)

hdp3

mysql> set global rpl_semi_sync_slave_enabled=1;

Query OK, 0 rows affected (0.00 sec)

hdp4

mysql> set global rpl_semi_sync_slave_enabled=1;

Query OK, 0 rows affected (0.00 sec)

将半同步插件配置持久化到配置文件中

1

2

3

4

5

6

hda2

]# echo -e "plugin-load=\"rpl_semi_sync_master=semisync_master.so;rpl_semi_sync_slave=semisync_slave.so\"\nrpl-semi-sync-master-enabled=1\nrpl-semi-sync-slave-enabled=1" >> /etc/my.cnf

hda3

]# echo -e "plugin-load=\"rpl_semi_sync_master=semisync_master.so;rpl_semi_sync_slave=semisync_slave.so\"\nrpl-semi-sync-master-enabled=1\nrpl-semi-sync-slave-enabled=1" >> /etc/my.cnf

hda4

]# echo -e "plugin-load=\"rpl_semi_sync_master=semisync_master.so;rpl_semi_sync_slave=semisync_slave.so\"\nrpl-semi-sync-master-enabled=1\nrpl-semi-sync-slave-enabled=1" >> /etc/my.cnf

重启从库上的IO线程,否则仍然为异步复制模式,查询状态及重启命令如下

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

hdp3

mysql> show status like 'Rpl_semi_sync_slave_status';

+----------------------------+-------+

| Variable_name              | Value |

+----------------------------+-------+

| Rpl_semi_sync_slave_status | OFF   |

+----------------------------+-------+

1 row in set (0.01 sec)

mysql> stop slave io_thread;

Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> start slave io_thread;

Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> show status like 'Rpl_semi_sync_slave_status';

+----------------------------+-------+

| Variable_name              | Value |

+----------------------------+-------+

| Rpl_semi_sync_slave_status | ON    |

+----------------------------+-------+

1 row in set (0.00 sec)

mysql>

hdp4

mysql> show status like 'Rpl_semi_sync_slave_status';

+----------------------------+-------+

| Variable_name              | Value |

+----------------------------+-------+

| Rpl_semi_sync_slave_status | OFF   |

+----------------------------+-------+

1 row in set (0.01 sec)

mysql> stop slave io_thread;

Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> start slave io_thread;

Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> show status like 'Rpl_semi_sync_slave_status';

+----------------------------+-------+

| Variable_name              | Value |

+----------------------------+-------+

| Rpl_semi_sync_slave_status | ON    |

+----------------------------+-------+

1 row in set (0.00 sec)

mysql>

查询主库的半同步复制是否在运行

1

2

3

4

5

6

7

8

9

10

hdp2

mysql> show status like 'Rpl_semi_sync_master_status';

+-----------------------------+-------+

| Variable_name               | Value |

+-----------------------------+-------+

| Rpl_semi_sync_master_status | ON    |

+-----------------------------+-------+

1 row in set (0.00 sec)

mysql>

部署MHA相关组件

环境说明

组件:

  mha-manager:部署在hdp1

  mha-node:部署在hdp2、hdp3、hdp4

4个节点安装perl相关依赖

下载epel源

1

wget -O /etc/yum.repos.d/epel-7.repo http://mirrors.aliyun.com/repo/epel-7.repo

安装perl-DBD-MySQL、perl-Log-DIspatch、perl-Parallel-ForkManager、perl-Time-HiRes

1

yum -y install perl-DBD-MySQL perl-Log-DIspatch perl-Parallel-ForkManager perl-Time-HiRes

安装perl-Config-Tiny,下载地址:http://mirror.centos.org/altarch/7/os/aarch64/Packages/perl-Config-Tiny-2.14-7.el7.noarch.rpm

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

]# yum -y install http://mirror.centos.org/altarch/7/os/aarch64/Packages/perl-Config-Tiny-2.14-7.el7.noarch.rpm

Loaded plugins: fastestmirror

perl-Config-Tiny-2.14-7.el7.noarch.rpm                                                                     |  25 kB  00:00:00    

Examining /var/tmp/yum-root-Zu9UoE/perl-Config-Tiny-2.14-7.el7.noarch.rpm: perl-Config-Tiny-2.14-7.el7.noarch

Marking /var/tmp/yum-root-Zu9UoE/perl-Config-Tiny-2.14-7.el7.noarch.rpm to be installed

Resolving Dependencies

--> Running transaction check

---> Package perl-Config-Tiny.noarch 0:2.14-7.el7 will be installed

--> Finished Dependency Resolution

Dependencies Resolved

==================================================================================================================================

 Package                       Arch                Version                 Repository                                        Size

==================================================================================================================================

Installing:

 perl-Config-Tiny              noarch              2.14-7.el7              /perl-Config-Tiny-2.14-7.el7.noarch               39 k

Transaction Summary

==================================================================================================================================

Install  1 Package

Total size: 39 k

Installed size: 39 k

Downloading packages:

Running transaction check

Running transaction test

Transaction test succeeded

Running transaction

  Installing : perl-Config-Tiny-2.14-7.el7.noarch                                                                             1/1

  Verifying  : perl-Config-Tiny-2.14-7.el7.noarch                                                                             1/1

Installed:

  perl-Config-Tiny.noarch 0:2.14-7.el7                                                                                           

Complete! 

4个节点互相配置免密登录

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

]# ssh-keygen

Generating public/private rsa key pair.

Enter file in which to save the key (/root/.ssh/id_rsa):

Created directory '/root/.ssh'.

Enter passphrase (empty for no passphrase):

Enter same passphrase again:

Your identification has been saved in /root/.ssh/id_rsa.

Your public key has been saved in /root/.ssh/id_rsa.pub.

The key fingerprint is:

SHA256:xOMA98v0Perm0KZ3zwv4TlGqKzzYk3LldUzQaK8f+6M root@hdp1

The key's randomart image is:

+---[RSA 2048]----+

|    . .      o   |

|     o o    + .  |

|      . *  . o.  |

|       * + . oo  |

|        S . =+   |

|         ..+oo+  |

|       +.+*.oo o |

|      o O=++.oo. |

|       o.B+ooE=oo|

+----[SHA256]-----+

]# ssh-copy-id hdp1

/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"

The authenticity of host 'hdp1 (192.168.244.150)' can't be established.

ECDSA key fingerprint is SHA256:tPUBu2Mcd9mClNUjaV9EYZNa9g45k2Ksx5xJktP7voo.

ECDSA key fingerprint is MD5:b2:6c:2e:64:d6:76:fc:2d:1d:7d:e3:32:29:6b:1c:ff.

Are you sure you want to continue connecting (yes/no)? yes

/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed

/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys

root@hdp1's password:

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'hdp1'"

and check to make sure that only the key(s) you wanted were added.

]# ssh-copy-id hdp2

/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"

The authenticity of host 'hdp2 (192.168.244.151)' can't be established.

ECDSA key fingerprint is SHA256:tPUBu2Mcd9mClNUjaV9EYZNa9g45k2Ksx5xJktP7voo.

ECDSA key fingerprint is MD5:b2:6c:2e:64:d6:76:fc:2d:1d:7d:e3:32:29:6b:1c:ff.

Are you sure you want to continue connecting (yes/no)? yes

/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed

/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys

root@hdp2's password:

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'hdp2'"

and check to make sure that only the key(s) you wanted were added.

]# ssh-copy-id hdp3

/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"

The authenticity of host 'hdp3 (192.168.244.152)' can't be established.

ECDSA key fingerprint is SHA256:tPUBu2Mcd9mClNUjaV9EYZNa9g45k2Ksx5xJktP7voo.

ECDSA key fingerprint is MD5:b2:6c:2e:64:d6:76:fc:2d:1d:7d:e3:32:29:6b:1c:ff.

Are you sure you want to continue connecting (yes/no)? yes

/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed

/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys

root@hdp3's password:

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'hdp3'"

and check to make sure that only the key(s) you wanted were added.

]# ssh-copy-id hdp4

/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"

The authenticity of host 'hdp4 (192.168.244.153)' can't be established.

ECDSA key fingerprint is SHA256:tPUBu2Mcd9mClNUjaV9EYZNa9g45k2Ksx5xJktP7voo.

ECDSA key fingerprint is MD5:b2:6c:2e:64:d6:76:fc:2d:1d:7d:e3:32:29:6b:1c:ff.

Are you sure you want to continue connecting (yes/no)? yes

/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed

/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys

root@hdp4's password:

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'hdp4'"

and check to make sure that only the key(s) you wanted were added. 

hdp2、hdp3、hdp4安装mha-node

1

2

3

4

]# rpm -ivh mha4mysql-node-0.58-0.el7.centos.noarch.rpm

Preparing...                          ################################# [100%]

Updating / installing...

   1:mha4mysql-node-0.58-0.el7.centos ################################# [100%]

hdp1安装mha-manager和mha-node

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

]# yum -y install mha4mysql-manager-0.58-0.el7.centos.noarch.rpm mha4mysql-node-0.58-0.el7.centos.noarch.rpm

Loaded plugins: fastestmirror

Examining mha4mysql-manager-0.58-0.el7.centos.noarch.rpm: mha4mysql-manager-0.58-0.el7.centos.noarch

Marking mha4mysql-manager-0.58-0.el7.centos.noarch.rpm to be installed

Examining mha4mysql-node-0.58-0.el7.centos.noarch.rpm: mha4mysql-node-0.58-0.el7.centos.noarch

Marking mha4mysql-node-0.58-0.el7.centos.noarch.rpm to be installed

Resolving Dependencies

--> Running transaction check

---> Package mha4mysql-manager.noarch 0:0.58-0.el7.centos will be installed

---> Package mha4mysql-node.noarch 0:0.58-0.el7.centos will be installed

--> Finished Dependency Resolution

Dependencies Resolved

==================================================================================================================================

 Package                    Arch            Version                    Repository                                            Size

==================================================================================================================================

Installing:

 mha4mysql-manager          noarch          0.58-0.el7.centos          /mha4mysql-manager-0.58-0.el7.centos.noarch          328 k

 mha4mysql-node             noarch          0.58-0.el7.centos          /mha4mysql-node-0.58-0.el7.centos.noarch             106 k

Transaction Summary

==================================================================================================================================

Install  2 Packages

Total size: 434 k

Installed size: 434 k

Downloading packages:

Running transaction check

Running transaction test

Transaction test succeeded

Running transaction

Warning: RPMDB altered outside of yum.

  Installing : mha4mysql-node-0.58-0.el7.centos.noarch                                                                        1/2

  Installing : mha4mysql-manager-0.58-0.el7.centos.noarch                                                                     2/2

  Verifying  : mha4mysql-manager-0.58-0.el7.centos.noarch                                                                     1/2

  Verifying  : mha4mysql-node-0.58-0.el7.centos.noarch                                                                        2/2

Installed:

  mha4mysql-manager.noarch 0:0.58-0.el7.centos                      mha4mysql-node.noarch 0:0.58-0.el7.centos                    

Complete!

配置MHA

在hdp1上创建配置文件目录并创建配置app1.cnf

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

]# mkdir -p /etc/masterha

]# vim /etc/masterha/app1.cnf

[server default]

manager_log=/var/log/masterha/app1/manager.log

manager_workdir=/var/log/masterha/app1.log

master_binlog_dir=/var/lib/mysql

master_ip_failover_script=/usr/bin/master_ip_failover

master_ip_online_change_script=/usr/bin/master_ip_online_change

password=1qaz@WSX123

ping_interval=1

remote_workdir=/tmp

repl_password=1qaz@WSX123

repl_user=repl

secondary_check_script=/usr/bin/masterha_secondary_check -s hdp2 -s hdp3 -s hdp4 --user=root --master_host=hdp2 --master_ip=192.168.244.151 --master_port=3306

shutdown_script=""

ssh_user=root

user=root

[server1]

hostname=192.168.244.151

ssh_port=22

candidate_master=1

[server2]

candidate_master=1

check_repl_delay=0

hostname=192.168.244.152

port=3306

[server3]

hostname=192.168.244.153

port=3306

在hdp3、hdp4设置从库relay_log_purge参数

MHA在发生主从切换的过程中,从库的恢复过程依赖于relay log,所以这里要将relay log的自动清除设置为OFF,即采用手动清除relay log的方式。

在默认情况下,从服务器上的中继日志会在SQL线程执行完毕后被自动删除。

但是在MHA环境中,这些中继日志在恢复其他从服务器时可能会被用到,因此需要禁用中继日志的自动删除功能。

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

]# mysql -uroot -p

Enter password:

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 21

Server version: 8.0.27 MySQL Community Server - GPL

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> set global relay_log_purge=0;

Query OK, 0 rows affected (0.00 sec)

mysql>

在hdp1上创建自动故障转移脚本

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

]# vim master_ip_failover

#!/usr/bin/env perl

#  Copyright (C) 2011 DeNA Co.,Ltd.

#  You should have received a copy of the GNU General Public License

#   along with this program; if not, write to the Free Software

#  Foundation, Inc.,

#  51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

## Note: This is a sample script and is not complete. Modify the script based on your environment.

use strict;

use warnings FATAL => 'all';

use Getopt::Long;

use MHA::DBHelper;

my (

  $command,        $ssh_user,         $orig_master_host,

  $orig_master_ip, $orig_master_port, $new_master_host,

  $new_master_ip,  $new_master_port,  $new_master_user,

  $new_master_password

);

my $vip = '192.168.244.154/24';

my $key = '88';

my $ssh_start_vip = "/sbin/ifconfig ens33:$key $vip";

my $ssh_stop_vip = "/sbin/ifconfig ens33:$key down";

GetOptions(

  'command=s'             => \$command,

  'ssh_user=s'            => \$ssh_user,

  'orig_master_host=s'    => \$orig_master_host,

  'orig_master_ip=s'      => \$orig_master_ip,

  'orig_master_port=i'    => \$orig_master_port,

  'new_master_host=s'     => \$new_master_host,

  'new_master_ip=s'       => \$new_master_ip,

  'new_master_port=i'     => \$new_master_port,

  'new_master_user=s'     => \$new_master_user,

  'new_master_password=s' => \$new_master_password,

);

exit &main();

sub main {

    print "\n\nIN SCRIPT TEST====$ssh_stop_vip==$ssh_start_vip===\n\n";

    if ( $command eq "stop" || $command eq "stopssh" ) {

        my $exit_code = 1;

        eval {

            print "Disabling the VIP on old master: $orig_master_host \n";

            &stop_vip();

            $exit_code = 0;

        };

        if ($@) {

            warn "Got Error: $@\n";

            exit $exit_code;

        }

        exit $exit_code;

    }

    elsif ( $command eq "start" ) {

        my $exit_code = 10;

        eval {

            print "Enabling the VIP - $vip on the new master - $new_master_host \n";

            &start_vip();

            $exit_code = 0;

        };

        if ($@) {

            warn $@;

            exit $exit_code;

        }

        exit $exit_code;

    }

    elsif ( $command eq "status" ) {

        print "Checking the Status of the script.. OK \n";

        exit 0;

    }

    else {

        &usage();

        exit 1;

    }

}

sub start_vip() {

    `ssh $ssh_user\@$new_master_host \" $ssh_start_vip \"`;

}

sub stop_vip() {

     return 0  unless  ($ssh_user);

    `ssh $ssh_user\@$orig_master_host \" $ssh_stop_vip \"`;

}

sub usage {

  print

"Usage: master_ip_failover --command=start|stop|stopssh|status --orig_master_host=host --orig_master_ip=ip --orig_master_port=port --new_master_host=host --new_master_ip=ip --new_master_port=port\n";

}

给自动故障转移脚本授权

1

]# chmod 777  /usr/bin/master_ip_failover

hdp1上检查MHA

1、检查SSH

1

2

3

4

5

6

7

8

9

10

11

12

]# masterha_check_ssh --conf=/etc/masterha/app1.cnf

Wed Jan 12 05:27:26 2022 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.

Wed Jan 12 05:27:26 2022 - [info] Reading application default configuration from /etc/masterha/app1.cnf..

Wed Jan 12 05:27:26 2022 - [info] Reading server configuration from /etc/masterha/app1.cnf..

Wed Jan 12 05:27:26 2022 - [info] Starting SSH connection tests..

Wed Jan 12 05:27:27 2022 - [debug]

Wed Jan 12 05:27:26 2022 - [debug]  Connecting via SSH from root@192.168.244.152(192.168.244.152:22) to root@192.168.244.153(192.168.244.153:22)..

Wed Jan 12 05:27:27 2022 - [debug]   ok.

Wed Jan 12 05:27:28 2022 - [debug]

Wed Jan 12 05:27:27 2022 - [debug]  Connecting via SSH from root@192.168.244.153(192.168.244.153:22) to root@192.168.244.152(192.168.244.152:22)..

Wed Jan 12 05:27:27 2022 - [debug]   ok.

Wed Jan 12 05:27:28 2022 - [info] All SSH connection tests passed successfully.

2、 检查整个复制环境状况

在hdp2执行root的登录授权,以及普通用户repl的登录授权

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

mysql> update mysql.user set host='%'  where user='root';

Query OK, 1 row affected (0.03 sec)

Rows matched: 1  Changed: 1  Warnings: 0

mysql>  flush privileges;

Query OK, 0 rows affected (0.02 sec)

mysql> alter user 'repl'@'%' identified with mysql_native_password by '1qaz@WSX123';

Query OK, 0 rows affected (0.02 sec)

mysql> FLUSH PRIVILEGES;

Query OK, 0 rows affected (0.00 sec)

mysql> alter user 'root'@'%' identified with mysql_native_password by '1qaz@WSX123';

Query OK, 0 rows affected (0.01 sec)

mysql> FLUSH PRIVILEGES;

Query OK, 0 rows affected (0.01 sec)

进行复制环境检查

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

]# masterha_check_repl --conf=/etc/masterha/app1.cnf

Wed Jan 12 05:49:57 2022 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.

Wed Jan 12 05:49:57 2022 - [info] Reading application default configuration from /etc/masterha/app1.cnf..

Wed Jan 12 05:49:57 2022 - [info] Reading server configuration from /etc/masterha/app1.cnf..

Wed Jan 12 05:49:57 2022 - [info] MHA::MasterMonitor version 0.58.

Wed Jan 12 05:49:58 2022 - [info] GTID failover mode = 0

Wed Jan 12 05:49:58 2022 - [info] Dead Servers:

Wed Jan 12 05:49:58 2022 - [info] Alive Servers:

Wed Jan 12 05:49:58 2022 - [info]   192.168.244.151(192.168.244.151:3306)

Wed Jan 12 05:49:58 2022 - [info]   192.168.244.152(192.168.244.152:3306)

Wed Jan 12 05:49:58 2022 - [info]   192.168.244.153(192.168.244.153:3306)

Wed Jan 12 05:49:58 2022 - [info] Alive Slaves:

Wed Jan 12 05:49:58 2022 - [info]   192.168.244.152(192.168.244.152:3306)  Version=8.0.27 (oldest major version between slaves) log-bin:enabled

Wed Jan 12 05:49:58 2022 - [info]     Replicating from 192.168.244.151(192.168.244.151:3306)

Wed Jan 12 05:49:58 2022 - [info]     Primary candidate for the new Master (candidate_master is set)

Wed Jan 12 05:49:58 2022 - [info]   192.168.244.153(192.168.244.153:3306)  Version=8.0.27 (oldest major version between slaves) log-bin:enabled

Wed Jan 12 05:49:58 2022 - [info]     Replicating from 192.168.244.151(192.168.244.151:3306)

Wed Jan 12 05:49:58 2022 - [info] Current Alive Master: 192.168.244.151(192.168.244.151:3306)

Wed Jan 12 05:49:58 2022 - [info] Checking slave configurations..

Wed Jan 12 05:49:58 2022 - [info]  read_only=1 is not set on slave 192.168.244.152(192.168.244.152:3306).

Wed Jan 12 05:49:58 2022 - [info]  read_only=1 is not set on slave 192.168.244.153(192.168.244.153:3306).

Wed Jan 12 05:49:58 2022 - [info] Checking replication filtering settings..

Wed Jan 12 05:49:58 2022 - [info]  binlog_do_db= , binlog_ignore_db=

Wed Jan 12 05:49:58 2022 - [info]  Replication filtering check ok.

Wed Jan 12 05:49:58 2022 - [info] GTID (with auto-pos) is not supported

Wed Jan 12 05:49:58 2022 - [info] Starting SSH connection tests..

Wed Jan 12 05:50:00 2022 - [info] All SSH connection tests passed successfully.

Wed Jan 12 05:50:00 2022 - [info] Checking MHA Node version..

Wed Jan 12 05:50:01 2022 - [info]  Version check ok.

Wed Jan 12 05:50:01 2022 - [info] Checking SSH publickey authentication settings on the current master..

Wed Jan 12 05:50:01 2022 - [info] HealthCheck: SSH to 192.168.244.151 is reachable.

Wed Jan 12 05:50:02 2022 - [info] Master MHA Node version is 0.58.

Wed Jan 12 05:50:02 2022 - [info] Checking recovery script configurations on 192.168.244.151(192.168.244.151:3306)..

Wed Jan 12 05:50:02 2022 - [info]   Executing command: save_binary_logs --command=test --start_pos=4 --binlog_dir=/var/lib/mysql --output_file=/tmp/save_binary_logs_test --manager_version=0.58 --start_file=binlog.000003

Wed Jan 12 05:50:02 2022 - [info]   Connecting to root@192.168.244.151(192.168.244.151:22)..

  Creating /tmp if not exists..    ok.

  Checking output directory is accessible or not..

   ok.

  Binlog found at /var/lib/mysql, up to binlog.000003

Wed Jan 12 05:50:02 2022 - [info] Binlog setting check done.

Wed Jan 12 05:50:02 2022 - [info] Checking SSH publickey authentication and checking recovery script configurations on all alive slave servers..

Wed Jan 12 05:50:02 2022 - [info]   Executing command : apply_diff_relay_logs --command=test --slave_user='root' --slave_host=192.168.244.152 --slave_ip=192.168.244.152 --slave_port=3306 --workdir=/tmp --target_version=8.0.27 --manager_version=0.58 --relay_dir=/var/lib/mysql --current_relay_log=hdp3-relay-bin.000003  --slave_pass=xxx

Wed Jan 12 05:50:02 2022 - [info]   Connecting to root@192.168.244.152(192.168.244.152:22)..

  Checking slave recovery environment settings..

    Relay log found at /var/lib/mysql, up to hdp3-relay-bin.000003

    Temporary relay log file is /var/lib/mysql/hdp3-relay-bin.000003

    Checking if super_read_only is defined and turned on.. not present or turned off, ignoring.

    Testing mysql connection and privileges..

mysql: [Warning] Using a password on the command line interface can be insecure.

 done.

    Testing mysqlbinlog output.. done.

    Cleaning up test file(s).. done.

Wed Jan 12 05:50:02 2022 - [info]   Executing command : apply_diff_relay_logs --command=test --slave_user='root' --slave_host=192.168.244.153 --slave_ip=192.168.244.153 --slave_port=3306 --workdir=/tmp --target_version=8.0.27 --manager_version=0.58 --relay_dir=/var/lib/mysql --current_relay_log=hdp4-relay-bin.000003  --slave_pass=xxx

Wed Jan 12 05:50:02 2022 - [info]   Connecting to root@192.168.244.153(192.168.244.153:22)..

  Checking slave recovery environment settings..

    Relay log found at /var/lib/mysql, up to hdp4-relay-bin.000003

    Temporary relay log file is /var/lib/mysql/hdp4-relay-bin.000003

    Checking if super_read_only is defined and turned on.. not present or turned off, ignoring.

    Testing mysql connection and privileges..

mysql: [Warning] Using a password on the command line interface can be insecure.

 done.

    Testing mysqlbinlog output.. done.

    Cleaning up test file(s).. done.

Wed Jan 12 05:50:03 2022 - [info] Slaves settings check done.

Wed Jan 12 05:50:03 2022 - [info]

192.168.244.151(192.168.244.151:3306) (current master)

 +--192.168.244.152(192.168.244.152:3306)

 +--192.168.244.153(192.168.244.153:3306)

Wed Jan 12 05:50:03 2022 - [info] Checking replication health on 192.168.244.152..

Wed Jan 12 05:50:03 2022 - [info]  ok.

Wed Jan 12 05:50:03 2022 - [info] Checking replication health on 192.168.244.153..

Wed Jan 12 05:50:03 2022 - [info]  ok.

Wed Jan 12 05:50:03 2022 - [info] Checking master_ip_failover_script status:

Wed Jan 12 05:50:03 2022 - [info]   /usr/bin/master_ip_failover --command=status --ssh_user=root --orig_master_host=192.168.244.151 --orig_master_ip=192.168.244.151 --orig_master_port=3306

IN SCRIPT TEST====/sbin/ifconfig ens33:88 down==/sbin/ifconfig ens33:88 192.168.244.144/24===

Checking the Status of the script.. OK

Wed Jan 12 05:50:03 2022 - [info]  OK.

Wed Jan 12 05:50:03 2022 - [warning] shutdown_script is not defined.

Wed Jan 12 05:50:03 2022 - [info] Got exit code 0 (Not master dead).

MySQL Replication Health is OK.

 3、检查MHA Manager的状态

1

2

]# masterha_check_status --conf=/etc/masterha/app1.cnf

app1 is stopped(2:NOT_RUNNING). 

启动MHA Manager

1

2

3

4

5

]# mkdir -p /var/log/masterha/app1

]# nohup  masterha_manager --conf=/etc/masterha/app1.cnf  --remove_dead_master_conf --ignore_last_failover < /dev/null > /var/log/masterha/app1/manager.log 2>&1 &

[1] 15338

]# masterha_check_status --conf=/etc/masterha/app1.cnf

app1 (pid:15338) is running(0:PING_OK), master:192.168.244.151

4、查看启动日志:tailf /var/log/masterha/app1/manager.log

功能测试

在 hdp2上初始绑定VIP

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

]# ifconfig ens33:1 192.168.244.154

]# ip a

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000

    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00

    inet 127.0.0.1/8 scope host lo

       valid_lft forever preferred_lft forever

    inet6 ::1/128 scope host

       valid_lft forever preferred_lft forever

2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000

    link/ether 00:0c:29:f7:d0:66 brd ff:ff:ff:ff:ff:ff

    inet 192.168.244.151/24 brd 192.168.244.255 scope global noprefixroute ens33

       valid_lft forever preferred_lft forever

    inet 192.168.244.154/24 brd 192.168.244.255 scope global secondary ens33:1

       valid_lft forever preferred_lft forever

    inet6 fe80::20c:29ff:fef7:d066/64 scope link

       valid_lft forever preferred_lft forever

模拟主从延时,关闭hd3的slave IO线程

1

2

mysql> stop slave io_thread;

Query OK, 0 rows affected, 1 warning (0.00 sec) 

在hdp2上生成数据,这里使用sysbench

hdp2安装sysbench

1

]# yum -y install sysbench

在hdp2上生成数据

1

2

mysql> create database sbtest;

Query OK, 1 row affected (0.01 sec)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

]# sysbench /usr/share/sysbench/tests/include/oltp_legacy/oltp.lua --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=root --mysql-password=1qaz@WSX123 --oltp-test-mode=complex --oltp-tables-count=10 --oltp-table-size=10000 --threads=10 --time=120 --report-interval=10 --db-driver=mysql prepare

sysbench 1.0.17 (using system LuaJIT 2.0.4)

Creating table 'sbtest1'...

Inserting 10000 records into 'sbtest1'

Creating secondary indexes on 'sbtest1'...

Creating table 'sbtest2'...

Inserting 10000 records into 'sbtest2'

Creating secondary indexes on 'sbtest2'...

Creating table 'sbtest3'...

Inserting 10000 records into 'sbtest3'

Creating secondary indexes on 'sbtest3'...

Creating table 'sbtest4'...

Inserting 10000 records into 'sbtest4'

Creating secondary indexes on 'sbtest4'...

Creating table 'sbtest5'...

Inserting 10000 records into 'sbtest5'

Creating secondary indexes on 'sbtest5'...

Creating table 'sbtest6'...

Inserting 10000 records into 'sbtest6'

Creating secondary indexes on 'sbtest6'...

Creating table 'sbtest7'...

Inserting 10000 records into 'sbtest7'

Creating secondary indexes on 'sbtest7'...

Creating table 'sbtest8'...

Inserting 10000 records into 'sbtest8'

Creating secondary indexes on 'sbtest8'...

Creating table 'sbtest9'...

Inserting 10000 records into 'sbtest9'

Creating secondary indexes on 'sbtest9'...

Creating table 'sbtest10'...

Inserting 10000 records into 'sbtest10'

Creating secondary indexes on 'sbtest10'...

停止主服务器hdp2的MySQL服务

1

]# systemctl stop mysqld

验证VIP漂移

在hdp3上查看ip

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

]# ip a

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000

    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00

    inet 127.0.0.1/8 scope host lo

       valid_lft forever preferred_lft forever

    inet6 ::1/128 scope host

       valid_lft forever preferred_lft forever

2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000

    link/ether 00:0c:29:73:a4:20 brd ff:ff:ff:ff:ff:ff

    inet 192.168.244.152/24 brd 192.168.244.255 scope global noprefixroute ens33

       valid_lft forever preferred_lft forever

    inet 192.168.244.154/24 brd 192.168.244.255 scope global secondary ens33:88

       valid_lft forever preferred_lft forever

    inet6 fe80::20c:29ff:fe73:a420/64 scope link

       valid_lft forever preferred_lft forever

可以看到VIP已经从hdp2(master)漂移到了hdp3(slave1)

通过VIP连接数据库,查看表数据

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

]# mysql -h192.168.244.154 -uroot -p

Enter password:

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 64

Server version: 8.0.27 MySQL Community Server - GPL

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> use sbtest;

Reading table information for completion of table and column names

You can turn off this feature to get a quicker startup with -A

Database changed

mysql> show tables;

+------------------+

| Tables_in_sbtest |

+------------------+

| sbtest1          |

| sbtest10         |

| sbtest2          |

| sbtest3          |

| sbtest4          |

| sbtest5          |

| sbtest6          |

| sbtest7          |

| sbtest8          |

| sbtest9          |

+------------------+

10 rows in set (0.00 sec)

mysql> select count(*) from sbtest5;

+----------+

| count(*) |

+----------+

|    10000 |

+----------+

1 row in set (0.01 sec)

至此,MHA基本搭建完毕!!

相关文章:

Mysql部署MHA高可用

部署前准备&#xff1a; mysql-8.0.27下载地址&#xff1a;https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.27-1.el7.x86_64.rpm-bundle.tar mha-manager下载地址&#xff1a;https://github.com/yoshinorim/mha4mysql-manager/releases/download/v0.58/mha4mysql-mana…...

【算法学习】射线法判断点在多边形内外(C#)以及确定内外两点连线与边界的交点

1.前言&#xff1a; 在GIS开发中&#xff0c;经常会遇到确定一个坐标点是否在一块区域的内部这一问题。 如果这个问题不是一个单纯的数学问题&#xff0c;例如&#xff1a;在判断DEM、二维图像像素点、3D点云点等含有自身特征信息的这些点是否在一个区域范围内部的时候&#x…...

SQL语句(DML)

DML英文全称是Data Manipulation Language&#xff08;数据操作语言&#xff09;&#xff0c;用来对数据库中表的数据记录进行增删改等操作 DML-添加数据 insert into employee(id, workno, name, gender, age, idcard) values (1,1,Itcast,男,10,123456789012345678);select *…...

uniapp小程序打开地图导航

uniapp uni.getLocation({type: gcj02, //返回可以用于uni.openLocation的经纬度success: function (res) {const latitude res.latitude;const longitude res.longitude;uni.openLocation({latitude: latitude,longitude: longitude,success: function () {console.log(suc…...

webstorm格式化或保存时 vue3引入的组件被删除了

解决办法 保存时设置 格式化设置...

Java时间转换

一、线程不安全 Date date new Date(); SimpleDateFormat dateFormat new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String prefix dateFormat.format(date);二、线程安全,建议使用 String t1 LocalDateTime.now().format(DateTimeFormatter.ofPattern("y…...

Spring Boot与WebFlux的实战案例

Spring Boot与WebFlux的实战案例 大家好&#xff0c;我是免费搭建查券返利机器人省钱赚佣金就用微赚淘客系统3.0的小编&#xff0c;也是冬天不穿秋裤&#xff0c;天冷也要风度的程序猿&#xff01;今天&#xff0c;我们将探讨如何利用Spring Boot和WebFlux构建响应式应用的实战…...

vue3引入本地静态资源图片

一、单张图片引入 import imgXX from /assets/images/xx.png二、多张图片引入 说明&#xff1a;import.meta.url 是一个 ESM 的原生功能&#xff0c;会暴露当前模块的 URL。将它与原生的 URL 构造器 组合使用 注意&#xff1a;填写自己项目图片存放的路径 /** vite的特殊性…...

git 禁止dev合并到任何其他分支

创建 pre-merge-commit 钩子 导航到 Git 仓库的钩子目录&#xff1a; cd /path/to/your/repo/.git/hooks创建或编辑 pre-merge-commit 钩子&#xff1a; 也可以通过指令创建 nano pre-merge-commit在钩子文件中添加以下代码&#xff1a; #!/bin/sh# 获取当前分支名称 curr…...

第二节:如何使用thymeleaf渲染html(自学Spring boot 3.x的第一天)

大家好&#xff0c;我是网创有方&#xff0c;今天来学习如何使用thymeleaf渲染html。该模板运用不广泛&#xff0c;所以本节内容了解既可。 第一步&#xff1a;创建html文件。 在模板templates目录下创建一个html文件。 编写代码如下&#xff1a; <!DOCTYPE html> <…...

计算机相关术语科普之什么叫网关(Gateway)

网关&#xff08;Gateway&#xff09;是一个在计算机网络中起到关键作用的设备或系统&#xff0c;它扮演着网络间连接器或协议转换器的角色。 一、定义与功能 1&#xff09;定义&#xff1a; 网关是在不同网络之间实现互连的复杂设备&#xff0c;仅用于两个高层协议不同的网…...

B站网页部分API

https://www.bilibili.com/ 数据结构 mid: 用户id name: 用户名 face: 用户头像url noface.jpg为默认头像 sign&#xff1a; 签名level: b站等级 coins: b站硬币粉丝 https://api.bilibili.com/x/relation/fans?vmid{mid}&pn{pn}&ps{limit}&orderdesc&…...

使用Spring Boot和Spring Security保护你的应用

使用Spring Boot和Spring Security保护你的应用 大家好&#xff0c;我是免费搭建查券返利机器人省钱赚佣金就用微赚淘客系统3.0的小编&#xff0c;也是冬天不穿秋裤&#xff0c;天冷也要风度的程序猿&#xff01;今天我们将深入探讨如何利用Spring Boot和Spring Security来保护…...

CVE-2019-12272 Openwrt可视页面LuCi命令注入漏洞复现(完结)

声明 本文所使用的一些源代码等内容已经上传至github&#xff0c;具体地址如下 Vulnerability_POC-EXP/OpenWrt/CVE-2019-12272 at main a2148001284/Vulnerability_POC-EXP GitHub 漏洞简介 参考内容&#xff1a; CVE-2019-12272 OpenWrt图形化管理界面LuCI命令注入分析 |…...

【多线程开发 4】从源码学习LockSupport

从源码学习LockSupport 2024年6月30日 大家好啊&#xff0c;好久没写博客了&#xff0c;今天打算写一下&#xff0c;讲一下JUC里面LockSupport这个类。 这个是一个工具类&#xff0c;实际上也是为了线程通信开发的。它的源码比较短&#xff0c;也只引用了Unsafe一个类。所以…...

gameui C++的代码

gameui C的代码 #include <graphics.h> #include "gameboard.h" const int WIDTH 560; const int HEIGHT 780; const int GRID_SIZE 120; class GameUi { private: public:GameUi(GameBoard& gb) {// 初始化图形窗口initgraph(WIDTH, HEIGHT);// 设置…...

1.什么是js?特点是什么?组成部分?

Js是一种直译式脚本语言&#xff0c;一种动态类型&#xff0c;弱类型&#xff0c;基于原型的高级语言。 直译式&#xff1a;js程序运行过程中直接编译成机器语言。 脚本语言&#xff1a;在程序运行过程中逐行进行解释说明&#xff0c;不需要预编译。 动态类型&#xff1a;js…...

爬虫是什么?

目录 1.什么是互联网爬虫&#xff1f; 2.爬虫核心? 3.爬虫的用途? 4.爬虫分类&#xff1f; 5.反爬手段&#xff1f; 1.什么是互联网爬虫&#xff1f; 如果我们把互联网比作一张大的蜘蛛网&#xff0c;那一台计算机上的数据便是蜘蛛网上的一个猎物&#xff0c;而爬虫程序…...

深入理解Presto分页查询:方法与最佳实践

目录 引言为什么需要分页查询Presto简介分页查询的基本概念Presto分页查询的实现方法 使用LIMIT和OFFSET使用游标分页结合外部工具和框架 分页查询的性能优化 索引优化查询计划优化数据分区 实际案例分析最佳实践与常见问题 大数据集分页复杂查询分页实时性要求高的场景 总结 …...

如何使用Go语言中的并发函数实现网络爬虫的分布式部署?

如何使用go语言中的并发函数实现网络爬虫的分布式部署&#xff1f; 在当今的互联网时代&#xff0c;大量的信息蕴藏在各个网站中&#xff0c;爬虫成为了一种重要的工具。而对于大规模的数据爬取任务&#xff0c;采用分布式部署能够更有效地提升爬取速度和效率。Go语言的并发机…...

STM32第九课:DHT11温湿度传感器

文章目录 需求一、DHT11温湿度传感器二、模块配置流程1.配置时钟和IO2.读取数据3.数据处理 三、导入语音模块四、关键代码总结 需求 1.完成DHT11温湿度检测模块的配置。 2.处理DHT11获取的数据&#xff0c;在串口打印处理后的实时数据。 2.通过Su-03t语音识别模块实现实时温湿…...

JVM线上监控环境搭建Grafana+Prometheus+Micrometer

架构图 一: SpringBoot自带监控Actuator SpringBoot自带监控功能Actuator&#xff0c;可以帮助实现对程序内部运行情况监控&#xff0c;比如监控内存状况、CPU、Bean加载情况、配置属性、日志信息、线程情况等。 使用步骤&#xff1a; 1. 导入依赖坐标 <dependency><…...

MyBatis(17)MyBatis 如何处理枚举类型

MyBatis 处理枚举类型的机制相对直接&#xff0c;它提供了一种灵活的方式来处理Java枚举&#xff08;enum&#xff09;类型和数据库之间的映射。在MyBatis中&#xff0c;你可以通过两种方式处理枚举类型&#xff1a;使用枚举的名称&#xff08;name&#xff09;或者枚举的序号&…...

云数据中心运维新纪元:让Linux服务器如虎添翼

文章目录 一、Linux系统管理的高级技巧1. 性能调优与监控&#xff1a;2. 自动化与脚本编写&#xff1a;3. 文件系统与存储管理&#xff1a; 二、服务器配置优化的策略1. 硬件选型与配置&#xff1a;2. 网络配置与优化&#xff1a;3. 应用部署与调优&#xff1a; 三、安全策略的…...

C# 多线程造成CPU占用率高

当线程多的时候就会造成CPU内存占用率过高 private void button1_Click(object sender, EventArgs e){Thread TH1, TH2, TH3, TH4, TH5;TH1 new Thread(Thread1){IsBackground true};TH2 new Thread(Thread2){IsBackground true};TH3 new Thread(Thread3){IsBackground t…...

谈谈在不同公司中的SAP职位

今天反客为主&#xff0c;聊一下这个HR的话题&#xff0c;考虑到SAP职位的专业性&#xff0c;感觉还是有必要谈一谈这个话题。最近跟几位HR的小伙伴聊了一下&#xff0c;讨论了下不同公司的SAP职位的招聘要求&#xff0c;感觉还是有那么几个存在的问题&#xff1a; 追求完美的…...

服务器连接不上

记录今天2024/07/02的问题&#xff1a; 我今天真的是非常无语&#xff0c;今天在连服务器的时候&#xff0c;突然发现连不上了。 后来才意识到&#xff0c;原来是我笔记本先是开了全局代理&#xff0c;然后再用easy connected连接。当时还跳出了一个窗口如下&#xff0c;我当时…...

论文辅导 | 基于贝叶斯优化-卷积神经网络-双向长短期记忆神经网络的锂电池健康状态评估

辅导文章 模型描述 准确估计电池健康状态是设备稳定运行的关键。针对当前健康状态研究中容量难以直接测量、估计模型调参费时等问题&#xff0c;提出基于多健康特征的贝叶斯优化&#xff08;BO&#xff09;算法优化卷积神经网络&#xff08;CNN&#xff09;与双向长短期记忆&a…...

安卓实现微信聊天气泡

一搜没一个能用的&#xff0c;我来&#xff1a; 布局文件&#xff1a; <?xml version"1.0" encoding"utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android"http://schemas.android.com/apk/res/android"xml…...

软件测试(功能、接口、性能、自动化)详解 | 测试人生路

一、软件测试功能测试 测试用例编写是软件测试的基本技能&#xff1b;也有很多人认为测试用例是软件测试的核心&#xff1b;软件测试中最重要的是设计和生成有效的测试用例&#xff1b;测试用例是测试工作的指导&#xff0c;是软件测试的必须遵守的准则。 黑盒测试常见测试用…...