Linux
Posted 记录每天
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux相关的知识,希望对你有一定的参考价值。
# 本次实验四台机器
# 10.0.0.21 - centos 7 - MHA服务器
# 10.0.0.15,16,17 - Centos 8 - mysql Master, Slave1, Slave2
# 先从gitbub大神那里下载mha manage包和node包
Release mha4mysql-manager-0.58 · yoshinorim/mha4mysql-manager · GitHub
Release mha4mysql-node-0.58 · yoshinorim/mha4mysql-node · GitHub
# MHA服务器,需要都安装这两个
# mysql服务器需要安装node
# 实现基于key验证,可用脚本实现(参考其他大神作品写的)
[23:31:39 root@centos8 ~]#cat /data/push_ssh_key.sh #!/bin/bash # #************************************************************************************** #Author: Noise Lys #QQ: 578110218 #Date: 2021-05-27 #Filename: push_ssh_key.sh #URL: https://www.cnblogs.com/noise/ #Description: The test script #Copyright (C): 2021 All rights reserved #************************************************************************************** PASS=123456 #设置网段最后的地址,4-255之间,越小扫描越快 END=254 #挑选出当前IP IP=`ip a s eth0 | awk -F\'[ /]+\' \'NR==3{print $3}\'` #挑选出当前IP的前3位 NET=${IP%.*}. #先删除原来的key和log file rm -f /root/.ssh/id_rsa [ -e ./SCANIP.log ] && rm -f SCANIP.log #循环ping当前IP所有的主机从10.0.0.3~10.0.0.254,ping成功将其IP存入log for((i=3;i<="$END";i++));do ping -c 1 -w 1 ${NET}$i &> /dev/null && echo "${NET}$i" >> SCANIP.log & done wait #生成key ssh-keygen -P "" -f /root/.ssh/id_rsa #查询是否存在包sshpass,用来传输密码 rpm -q sshpass || yum -y install sshpass #传输密码到IP sshpass -p $PASS ssh-copy-id -o StrictHostKeyChecking=no $IP #将log里面的所有IP存入变量,以便后续遍历传输密码和key AliveIP=(`cat SCANIP.log`) for n in ${AliveIP[*]};do sshpass -p $PASS scp -o StrictHostKeyChecking=no -r /root/.ssh root@${n}: done #把.ssh/known_hosts拷贝到所有主机,使它们第一次互相访问时不需要输入回车 for n in ${AliveIP[*]};do scp /root/.ssh/known_hosts ${n}:.ssh/ done
# 编辑配置文件
[23:33:11 root@centos7 ~]#cat -A /etc/mastermha/app1.cnf (需要提前建立/etc/mastermha文件夹) [server default]$ user=mhauser$ password=123456$ manager_workdir=/data/mastermha/app1/$ manager_log=/data/mastermha/app1/manager.log$ remote_workdir=/data/mastermha/app1/$ ssh_user=root$ repl_user=repluser$ repl_password=123456$ ping_interval=1$ $ master_ip_failover_script=/usr/local/bin/master_ip_failover$ report_script=/usr/local/bin/sendmail.sh$ master_binlog_dir=/data/mysql/$ $ [server1]$ hostname=10.0.0.15$ candidate_master=1$ $ [server2]$ hostname=10.0.0.16$ candidate_master=1$ $ [server3]$ hostname=10.0.0.17$
# 邮件服务
[23:33:22 root@centos7 ~]#cat /usr/local/bin/sendmail.sh #!/bin/bash # #************************************************************************************** #Author: Noise Lys #QQ: 578110218 #Date: 2021-06-27 #Filename: /usr/local/bin/sendmail.sh #URL: https://www.cnblogs.com/noise/ #Description: The test script #Copyright (C): 2021 All rights reserved #************************************************************************************** echo "MySQL is down" | mail -s "MHA Warning" root@centos720091.com [23:36:20 root@centos7 ~]#chmod +x /usr/local/bin/sendmail.sh
# vip飘逸脚本(类似keepalived)
#!/usr/bin/env perl use strict; use warnings FATAL => \'all\'; use Getopt::Long; my ( $command, $ssh_user, $orig_master_host, $orig_master_ip, $orig_master_port, $new_master_host, $new_master_ip, $new_master_port ); my $vip = \'10.0.0.100/24\'; my $gateway = \'10.0.0.254\'; my $interface = \'eth0\'; my $key = "1"; my $ssh_start_vip = "/sbin/ifconfig $interface:$key $vip;/sbin/arping -I $interface -c 3 -s $vip $gateway >/dev/null 2>&1"; my $ssh_stop_vip = "/sbin/ifconfig $interface:$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, ); 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"; `ssh $ssh_user\\@$orig_master_host \\" $ssh_start_vip \\"`; exit 0; } else { &usage(); exit 1; } } sub start_vip() { `ssh $ssh_user\\@$new_master_host \\" $ssh_start_vip \\"`; } sub stop_vip() { `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"; }
[23:38:46 root@centos7 ~]#chmod +x /usr/local/bin/master_ip_failover
# mysql master 配置文件
[23:20:04 root@centos8 ~]#cat /etc/my.cnf.d/mysql-server.cnf # # This group are read by MySQL server. # Use it for options that only the server (but not clients) should see # # For advice on how to change settings please see # http://dev.mysql.com/doc/refman/en/server-configuration-defaults.html # Settings user and group are ignored when systemd is used. # If you need to run mysqld under a different user or group, # customize your systemd unit file for mysqld according to the # instructions in http://fedoraproject.org/wiki/Systemd [mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock log-error=/var/log/mysql/mysqld.log pid-file=/run/mysqld/mysqld.pid server_id=15 log-bin=/data/mysql/mysql-bin skip_name_resolve=1 general_log
# 并创建user和记录下当前logbin (主从需要)
mysql> create user repluser@\'10.0.0.%\' identified by \'magedu\'; mysql> grant replication slave on *.* to repluser@\'10.0.0.%\'; mysql> create user mhauser@\'10.0.0.%\' identified by \'magedu\'; mysql> grant all on *.* to mhauser@\'10.0.0.%\';
# mysql slave 配置文件
[23:40:04 root@centos8 ~]#cat /etc/my.cnf.d/mysql-server.cnf # # This group are read by MySQL server. # Use it for options that only the server (but not clients) should see # # For advice on how to change settings please see # http://dev.mysql.com/doc/refman/en/server-configuration-defaults.html # Settings user and group are ignored when systemd is used. # If you need to run mysqld under a different user or group, # customize your systemd unit file for mysqld according to the # instructions in http://fedoraproject.org/wiki/Systemd [mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock log-error=/var/log/mysql/mysqld.log pid-file=/run/mysqld/mysqld.pid server_id=17 log-bin=/data/mysql/mysql-bin read_only relay_log_purge=0 skip_name_resolve=1 general_log
# 给mysql master设立vip
[22:38:12 root@centos8 ~]#ifconfig eth0:1 10.0.0.100/24 [22:39:48 root@centos8 ~]#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: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000 link/ether 00:0c:29:b7:3e:e4 brd ff:ff:ff:ff:ff:ff inet 10.0.0.15/24 brd 10.0.0.255 scope global noprefixroute eth0 valid_lft forever preferred_lft forever inet 10.0.0.100/24 brd 10.0.0.255 scope global secondary eth0:1 valid_lft forever preferred_lft forever inet6 fe80::20c:29ff:feb7:3ee4/64 scope link valid_lft forever preferred_lft forever
#在manager上检查mha配置
2021-06-28T15:19:37.345677Z 13 Query SELECT 1 As Value
2021-06-28T15:19:38.339499Z 13 Query SELECT 1 As Value
2021-06-28T15:19:39.340015Z 13 Query SELECT 1 As Value
2021-06-28T15:19:40.340974Z 13 Query SELECT 1 As Value
2021-06-28T15:19:41.340748Z 13 Query SELECT 1 As Value
2021-06-28T15:19:42.341860Z 13 Query SELECT 1 As Value
2021-06-28T15:19:43.343077Z 13 Query SELECT 1 As Value
2021-06-28T15:19:44.343118Z 13 Query SELECT 1 As Value
2021-06-28T15:19:45.344224Z 13 Query SELECT 1 As Value
2021-06-28T15:19:46.344526Z 13 Query SELECT 1 As Value
2021-06-28T15:19:47.345494Z 13 Query SELECT 1 As Value
2021-06-28T15:19:48.347683Z 13 Query SELECT 1 As Value
2021-06-28T15:19:48.801340Z 8 Quit
2021-06-28T15:19:49.348587Z 13 Query SELECT 1 As Value
2021-06-28T15:19:50.348986Z 13 Query SELECT 1 As Value
2021-06-28T15:19:51.349671Z 13 Query SELECT 1 As Value
2021-06-28T15:19:52.351619Z 13 Query SELECT 1 As Value
2021-06-28T15:19:53.351102Z 13 Query SELECT 1 As Value
2021-06-28T15:19:54.351510Z 13 Query SELECT 1 As Value
2021-06-28T15:19:55.353596Z 13 Query SELECT 1 As Value
2021-06-28T15:19:56.361825Z 13 Query SELECT 1 As Value
#当mha运行后,down掉master
[23:19:07 root@centos7 ~]#tail -f /data/mastermha/app1/manager.log Mon Jun 28 23:19:37 2021 - [warning] secondary_check_script is not defined. It is highly recommended setting it to check master reachability from two or more routes. Mon Jun 28 23:19:37 2021 - [info] Starting ping health check on 10.0.0.15(10.0.0.15:3306).. Mon Jun 28 23:19:37 2021 - [info] Ping(SELECT) succeeded, waiting until MySQL doesn\'t respond.. Mon Jun 28 23:19:56 2021 - [warning] Got error on MySQL select ping: 1053 (Server shutdown in progress) Mon Jun 28 23:19:56 2021 - [info] Executing SSH check script: save_binary_logs --command=test --start_pos=4 --binlog_dir=/data/mysql/ --output_file=/data/mastermha/app1//save_binary_logs_test --manager_version=0.58 --binlog_prefix=mysql-bin Mon Jun 28 23:19:56 2021 - [info] HealthCheck: SSH to 10.0.0.15 is reachable. Mon Jun 28 23:19:57 2021 - [warning] Got error on MySQL connect: 2003 (Can\'t connect to MySQL server on \'10.0.0.15\' (111)) Mon Jun 28 23:19:57 2021 - [warning] Connection failed 2 time(s).. Mon Jun 28 23:19:58 2021 - [warning] Got error on MySQL connect: 2003 (Can\'t connect to MySQL server on \'10.0.0.15\' (111)) Mon Jun 28 23:19:58 2021 - [warning] Connection failed 3 time(s).. Mon Jun 28 23:19:59 2021 - [warning] Got error on MySQL connect: 2003 (Can\'t connect to MySQL server on \'10.0.0.15\' (111)) Mon Jun 28 23:19:59 2021 - [warning] Connection failed 4 time(s).. Mon Jun 28 23:19:59 2021 - [warning] Master is not reachable from health checker! Mon Jun 28 23:19:59 2021 - [warning] Master 10.0.0.15(10.0.0.15:3306) is not reachable! Mon Jun 28 23:19:59 2021 - [warning] SSH is reachable. Mon Jun 28 23:19:59 2021 - [info] Connecting to a master server failed. Reading configuration file /etc/masterha_default.cnf and /etc/mastermha/app1.cnf again, and trying to connect to all servers to check server status.. Mon Jun 28 23:19:59 2021 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping. Mon Jun 28 23:19:59 2021 - [info] Reading application default configuration from /etc/mastermha/app1.cnf.. Mon Jun 28 23:19:59 2021 - [info] Reading server configuration from /etc/mastermha/app1.cnf.. Mon Jun 28 23:20:00 2021 - [info] GTID failover mode = 0 Mon Jun 28 23:20:00 2021 - [info] Dead Servers: Mon Jun 28 23:20:00 2021 - [info] 10.0.0.15(10.0.0.15:3306) Mon Jun 28 23:20:00 2021 - [info] Alive Servers: Mon Jun 28 23:20:00 2021 - [info] 10.0.0.16(10.0.0.16:3306) Mon Jun 28 23:20:00 2021 - [info] 10.0.0.17(10.0.0.17:3306) Mon Jun 28 23:20:00 2021 - [info] Alive Slaves: Mon Jun 28 23:20:00 2021 - [info] 10.0.0.16(10.0.0.16:3306) Version=8.0.21 (oldest major version between slaves) log-bin:enabled Mon Jun 28 23:20:00 2021 - [info] Replicating from 10.0.0.15(10.0.0.15:3306) Mon Jun 28 23:20:00 2021 - [info] Primary candidate for the new Master (candidate_master is set) Mon Jun 28 23:20:00 2021 - [info] 10.0.0.17(10.0.0.17:3306) Version=8.0.21 (oldest major version between slaves) log-bin:enabled Mon Jun 28 23:20:00 2021 - [info] Replicating from 10.0.0.15(10.0.0.15:3306) Mon Jun 28 23:20:00 2021 - [info] Checking slave configurations.. Mon Jun 28 23:20:00 2021 - [info] read_only=1 is not set on slave 10.0.0.16(10.0.0.16:3306). Mon Jun 28 23:20:00 2021 - [info] Checking replication filtering settings.. Mon Jun 28 23:20:00 2021 - [info] Replication filtering check ok. Mon Jun 28 23:20:00 2021 - [info] Master is down! Mon Jun 28 23:20:00 2021 - [info] Terminating monitoring script. Mon Jun 28 23:20:00 2021 - [info] Got exit code 20 (Master dead). Mon Jun 28 23:20:00 2021 - [info] MHA::MasterFailover version 0.58. Mon Jun 28 23:20:00 2021 - [info] Starting master failover. Mon Jun 28 23:20:00 2021 - [info] Mon Jun 28 23:20:00 2021 - [info] * Phase 1: Configuration Check Phase.. Mon Jun 28 23:20:00 2021 - [info] Mon Jun 28 23:20:01 2021 - [info] GTID failover mode = 0 Mon Jun 28 23:20:01 2021 - [info] Dead Servers: Mon Jun 28 23:20:01 2021 - [info] 10.0.0.15(10.0.0.15:3306) Mon Jun 28 23:20:01 2021 - [info] Checking master reachability via MySQL(double check)... Mon Jun 28 23:20:01 2021 - [info] ok. Mon Jun 28 23:20:01 2021 - [info] Alive Servers: Mon Jun 28 23:20:01 2021 - [info] 10.0.0.16(10.0.0.16:3306) Mon Jun 28 23:20:01 2021 - [info] 10.0.0.17(10.0.0.17:3306) Mon Jun 28 23:20:01 2021 - [info] Alive Slaves: Mon Jun 28 23:20:01 2021 - [info] 10.0.0.16(10.0.0.16:3306) Version=8.0.21 (oldest major version between slaves) log-bin:enabled Mon Jun 28 23:20:01 2021 - [info] Replicating from 10.0.0.15(10.0.0.15:3306) Mon Jun 28 23:20:01 2021 - [info] Primary candidate for the new Master (candidate_master is set) Mon Jun 28 23:20:01 2021 - [info] 10.0.0.17(10.0.linux打开终端如何启动scala,如何在终端下运行Scala代码片段?Android 逆向Linux 文件权限 ( Linux 权限简介 | 系统权限 | 用户权限 | 匿名用户权限 | 读 | 写 | 执行 | 更改组 | 更改用户 | 粘滞 )(代码片段
-bash: /usr/bin/ls: /lib64/ld-linux-x86-64.so.2: bad ELF interpreter: No such file or directory(代码片段