Mysql入门MySQL下高可用故障转移方案MHA的超级部署教程
《Mysql入门MySQL下高可用故障转移方案MHA的超级部署教程》要点: MYSQL应用MHA介绍 MYSQL应用
MYSQL应用2、服务器说明
MYSQL应用???????? 三台服务器都安装mysql,将manager作为管理节点 MYSQL应用3、配置等价性 MYSQL应用???????? manager: MYSQL应用
ssh-keyger -t rsa
ssh-coyp-id -i /root/.ssh/id_rsa.pub root@192.168.216.50
ssh-coyp-id -i /root/.ssh/id_rsa.pub root@192.168.216.51
ssh-coyp-id -i /root/.ssh/id_rsa.pub root@192.168.216.52
ssh 192.168.216.50 date
ssh 192.168.216.51 date
ssh 192.168.216.52 date
MYSQL应用???????? master: MYSQL应用
ssh-keyger -t rsa
ssh-coyp-id -i /root/.ssh/id_rsa.pub root@192.168.216.50
ssh-coyp-id -i /root/.ssh/id_rsa.pub root@192.168.216.51
ssh-coyp-id -i /root/.ssh/id_rsa.pub root@192.168.216.52
ssh 192.168.216.50 date
ssh 192.168.216.51 date
ssh 192.168.216.52 date
MYSQL应用???????? slave: MYSQL应用
ssh-keyger -t rsa
ssh-coyp-id -i /root/.ssh/id_rsa.pub root@192.168.216.50
ssh-coyp-id -i /root/.ssh/id_rsa.pub root@192.168.216.51
ssh-coyp-id -i /root/.ssh/id_rsa.pub root@192.168.216.52
ssh 192.168.216.50 date
ssh 192.168.216.51 date
ssh 192.168.216.52 date
MYSQL应用4、安装mysql MYSQL应用
groupadd mysql
useradd -g mysql -s /bin/nologin -M mysql
mkdir -pv /data/mysql
tar -zxvf mysql-5.6.16-linux-glibc2.5-x86_64.tar.gz
mv mysql-5.6.16-linux-glibc2.5-x86_64 /usr/local/mysql
cd /usr/local/mysql/script
./ mysql_install_db Cuser=mysql Cbasedir=/usr/local/mysql Cdatadair=/data/mysql
MYSQL应用???????? 创建mysql配置文件 MYSQL应用
vim /usr/local/mysql/my.cnf
MYSQL应用? MYSQL应用
[mysql]
# CLIENT #
port = 3306
socket = /tmp/mysql.sock
[mysqld]
# GENERAL #
user = mysql
default-storage-engine = InnoDB
socket = /tmp/mysql.sock
pid-file = /data/mysql/mysql.pid
# MyISAM #
key-buffer-size = 32M
myisam-recover = FORCE,BACKUP
# SAFETY #
max-allowed-packet = 16M
max-connect-errors = 1000000
# DATA STORAGE #
datadir = /data/mysql/
# BINARY LOGGING #
server_id = 1 #不同服务器不一样
log-bin = /data/mysql/mysql-bin
expire-logs-days = 14
sync-binlog = 1
# CACHES AND LIMITS #
tmp-table-size = 32M
max-heap-table-size = 32M
query-cache-type = 0
query-cache-size = 0
max-connections = 500
thread-cache-size = 50
open-files-limit = 65535
table-definition-cache = 1024
table-open-cache = 2048
# INNODB #
innodb-flush-method = O_DIRECT
innodb-log-files-in-group = 2
innodb-log-file-size = 64M
innodb-flush-log-at-trx-commit = 1
innodb-file-per-table = 1
innodb-buffer-pool-size = 592M
# LOGGING #
log-error = /data/mysql/mysql-error.log
log-queries-not-using-indexes = 1
slow-query-log = 1
slow-query-log-file = /data/mysql/mysql-slow.log
MYSQL应用5、配置权限 MYSQL应用???????? manager: MYSQL应用
grant all privileges on *.* to root@'127.0.0.1' identified by 'root';
grant all privileges on *.* to root@'localhost' identified by 'root';
grant all privileges on *.* to root@'192.168.216.50' identified by 'root';
grant replication slave on *.* to slave@'192.168.216.50' identified by 'slave';
grant replication slave on *.* to slave@'192.168.216.51' identified by 'slave';
grant replication slave on *.* to slave@'192.168.216.52' identified by 'slave';
MYSQL应用???????? master: MYSQL应用
grant all privileges on *.* to root@'127.0.0.1' identified by 'root';
grant all privileges on *.* to root@'localhost' identified by 'root';
grant all privileges on *.* to root@'192.168.216.50' identified by 'root';
grant replication slave on *.* to slave@'192.168.216.50' identified by 'slave';
grant replication slave on *.* to slave@'192.168.216.51' identified by 'slave';
grant replication slave on *.* to slave@'192.168.216.52' identified by 'slave';
MYSQL应用???????? slave: MYSQL应用
grant all privileges on *.* to root@'127.0.0.1' identified by 'root';
grant all privileges on *.* to root@'localhost' identified by 'root';
grant all privileges on *.* to root@'192.168.216.50' identified by 'root';
grant all privileges on *.* to root@'192.168.216.51' identified by 'root';
grant replication slave on *.* to slave@'192.168.216.50' identified by 'slave';
grant replication slave on *.* to slave@'192.168.216.51' identified by 'slave';
grant replication slave on *.* to slave@'192.168.216.52' identified by 'slave';
MYSQL应用6、安装依赖包 MYSQL应用???????? 管理服务器manager需要安装以下全部 MYSQL应用
perl-Config-Tiny
perl-Params-Validate
perl-Parallel-ForkManager
perl-Log-Dispatch
|- perl-MIME-Lite-3.027-2.el6.noarch.rpm
|- perl-MIME-Types-1.28-2.el6.noarch.rpm
|- perl-Email-Date-Format-1.002-5.el6.noarch.rpm
|- perl-MailTools-2.04-4.el6.noarch.rpm
|- perl-TimeDate-1.16-11.1.el6.noarch.rpm
|- perl-Data-ShowTable-3.3-3.4.noarch.rpm
|- perl-Mail-Sender-0.8.22-21.1.noarch.rpm
|- perl-IO-Socket-SSL-1.31-2.el6.noarch.rpm
|- perl-Net-LibIDN-0.12-3.el6.x86_64.rpm
|- perl-Net-SSLeay-1.35-9.el6.x86_64.rpm
|-perl-Win32API-Registry
|- perl-Mail-Sendmail-0.79_16-4.2.noarch.rpm
MYSQL应用? MYSQL应用
rpm -ivh ncftp-debuginfo-3.2.3-1.3.x86_64.rpm
rpm -ivh perl-Parallel-ForkManager-0.7.5-2.2.el6.rf.noarch.rpm
rpm -ivh perl-Params-Validate-0.91-2.4.x86_64.rpm
rpm -ivh perl-Config-Tiny-2.12-7.1.el6.noarch.rpm
rpm -ivh perl-MIME-Types-1.28-2.el6.noarch.rpm
rpm -ivh perl-Email-Date-Format-1.002-5.el6.noarch.rpm
rpm -ivh perl-TimeDate-1.16-11.1.el6.noarch.rpm
rpm -ivh perl-Data-ShowTable-3.3-3.4.noarch.rpm
rpm -ivh perl-MailTools-2.04-4.el6.noarch.rpm
rpm -ivh perl-MIME-Lite-3.027-2.el6.noarch.rpm
rpm -ivh perl-Net-LibIDN-0.12-3.el6.x86_64.rpm
rpm -ivh perl-Net-SSLeay-1.35-9.el6.x86_64.rpm
rpm -ivh perl-IO-Socket-SSL-1.31-2.el6.noarch.rpm
rpm -ivh perl-Mail-Sendmail-0.79_16-4.2.noarch.rpm
rpm -ivh perl-Mail-Sender-0.8.22-21.1.noarch.rpm
rpm -ivh perl-Log-Dispatch-2.22-7.3.noarch.rpm
MYSQL应用? MYSQL应用???????? 如果安perl-DBD-MySQL-4.013-3.el6.x86_64.rpm在检查rep是报错则需要手动编译安装 MYSQL应用
tar -zxvf DBD-mysql-4.027.tar.gz
cd DBD-mysql-4.0.27
perl Makefile.PL
make && make install
MYSQL应用???????? 节点服务器安装 MYSQL应用
rpm -ivh ncftp-debuginfo-3.2.3-1.3.x86_64.rpm
rpm -ivh perl-DBD-MySQL-4.013-3.el6.x86_64.rpm
MYSQL应用7、创建软连接 MYSQL应用
ln -s /usr/local/mysql/bin/mysqlbinlog /usr/bin/mysqlbinlog
ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql
MYSQL应用???????? 导出mysql库搜索路径 MYSQL应用
vim /etc/ld.so.conf.d/mysql-x86_64.conf
/usr/local/mysql/lib
ldconfig
MYSQL应用8、在所有服务器上安装mha4mysql-node-0.54.tar.gz MYSQL应用
tar -zxvf mha4mysql-node-0.54.tar.gz
cd mha4mysql-node-0.54
perl Makefile.PL
make && make install
MYSQL应用9、在管理服务上安装 mha4mysql-manager-0.54.tar.gz MYSQL应用
tar -zxvf mha4mysql-manager-0.54.tar.gz
cd mha4mysql-manager-0.54
perl Makefile.PL
make && make install
mkdir -pv /etc/masterha
mkdir -pv /masterha/app1
cp samples/conf/* /etc/masterha
cp samples/scripts/* /usr/local/bin
MYSQL应用? MYSQL应用
vim /etc/masterha/app1.cnf
MYSQL应用
[server default]
manager_workdir=/masterha/app1
manager_log=/masterha/app1/manager.log
user=root
password=root
ssh_user=root
repl_user=slave
repl_password=slave
shutdown_script=""
#master_ip_failover_script="/usr/local/bin/masterha_ip_failover"
master_ip_online_change_script="/usr/local/bin/masterha_ip_failover "
report_script=""
[server1]
hostname=192.168.216.50
master_binlog_dir="/data/mysql/"
candidate_master=1
[server2]
hostname=192.168.216.51
master_binlog_dir="/data/mysql/"
candidate_master=1
[server3]
hostname=192.168.216.52
master_binlog_dir="/data/mysql/"
candidate_master=1
MYSQL应用10、测试ssh连接 MYSQL应用
masterha_check_ssh Cconf=/etc/masterha/app1.cnf
MYSQL应用11、测试replication MYSQL应用
masterha_check_repl Cconf=/etc/masterha/app1.cnf
MYSQL应用12、开启管理节点进程 MYSQL应用? MYSQL应用
masterha_manager Cconf=/etc/masterha/app1.cnf
MYSQL应用13、测试故障转移 MYSQL应用?????? 关闭主库mysql,查看从库的的状态是否将同步ip切换到新的主库 MYSQL应用14、设置故障转移的ip MYSQL应用
vim /etc/masterha/app1.cnf
MYSQL应用
master_ip_failover_script="/usr/local/bin/masterha_ip_failover "
master_ip_online_change_script="/usr/local/bin/masterha_ip_failover "
MYSQL应用???????? 编辑故障转移脚本,将vip设置成192.168.216.100 MYSQL应用
vim /usr/local/bin/masterha_ip_failover
MYSQL应用
#!/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 = '172.16.21.119/24'; # Virtual IP
my $vip = '192.168.216.100/24'; # Virtual IP
my $key = "1";
my $ssh_start_vip = "/sbin/ifconfig eth0:$key $vip";
my $ssh_stop_vip = "/sbin/ifconfig eth0:$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 "nnIN SCRIPT TEST====$ssh_stop_vip==$ssh_start_vip===nn";
if ( $command eq "stop" || $command eq "stopssh" ) {
# $orig_master_host,$orig_master_port are passed.
# If you manage master ip address at global catalog database,# invalidate orig_master_ip here.
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" ) {
# all arguments are passed.
# If you manage master ip address at global catalog database,# activate new_master_ip here.
# You can also grant write access (create user,set read_only=0,etc) here.
my $exit_code = 10;
eval {
print "Enabling the VIP C $vip on the new master C $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@cluster1 " $ssh_start_vip "`;
exit 0;
}
else {
&usage();
exit 1;
}
}
# A simple system call that enable the VIP on the new master
sub start_vip() {
`ssh $ssh_user@$new_master_host " $ssh_start_vip "`;
}
# A simple system call that disable the VIP on the old_master
sub stop_vip() {
`ssh $ssh_user@$orig_master_host " $ssh_stop_vip "`;
}
sub usage {
print
"Usage: master_ip_failover Ccommand=start|stop|stopssh|status Corig_master_host=host Corig_master_ip=ip Corig_master_port=port Cnew_master_host=host Cnew_master_ip=ip Cnew_master_port=portn";
}
MYSQL应用? MYSQL应用测试脚本 MYSQL应用
/usr/local/bin/masterha_ip_failover Ccommand=status Cssh_user=root Corig_master_host=192.168.216.51 Corig_master_ip=192.168.216.51 Corig_master_port=3306
MYSQL应用虚拟ip要手动启动,在主库故障后会自动转移. MYSQL应用
/usr/local/bin/masterha_ip_failover Ccommand=start Cssh_user=root Corig_master_host=192.168.216.51 Corig_master_ip=192.168.216.51 Corig_master_port=3306 Cnew_master_host=192.168.216.51
MYSQL应用测试ip故障转移: MYSQL应用关闭主库mysql,查看vip是否转移的新的主库上. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |