MySQL database is highly available

Source: Internet
Author: User

Mysql database is highly available

Mysql (5.7.19) +keepalive (1.3.0) +rhel6.5

Mysql

Https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.19-linux-glibc2.12-x86_64.tar.gz

keepalived Address

Http://www.keepalived.org/software/keepalived-1.3.0.tar.gz

Plan as follows


Ip

Port

Note

mysql1

172.25.254.120

3306


mysql2

172.25.254.130

3306


Keepalived

172.25.254.111



First: build the primary master database

Copy the compression package to the system/mnt

cd/mnt/

Tar xvf mysql-5.7.19-linux-glibc2.12-x86_64.tar.gz

Cp-a Mysql-5.7.19-linux-glibc2.12-x86_64/usr/local/mysql

Useradd MySQL

cd/usr/local/mysql/

CD bin/

./mysqld--initialize

./mysql_install_db--user=mysql--basedir=/var/lib/mysql--datadir=/var/lib/mysql/data

Chown-r mysql/var/lib/mysql/data/

./mysqld_safe--user=mysql

Cd..

CP Support-files/mysql.server/etc/init.d/mysqld

Rm-rf/etc/my.cnf

Cat <<eof >/ETC/MY.CNF

[Mysqld]

Datadir=/var/lib/mysql

Socket=/var/lib/mysql/mysql.sock

User=mysql

# Disabling Symbolic-links is recommended to prevent assorted security risks

Symbolic-links=0

[Mysqld_safe]

Log-error=/var/log/mysqld.log

Pid-file=/var/run/mysqld/mysqld.pid

Eof

Ln-s/usr/local/mysql/bin/mysql/bin/mysql

CD bin/

Service mysqld Start

Sed-i ' 5askip-grant-tables '/etc/my.cnf

Sed-i ' $a [MySQL] '/etc/my.cnf

Sed-i ' $asocket =/var/lib/mysql/mysql.sock '/etc/my.cnf

Service mysqld Restart

MYSQL-E "Update mysql.user set Authentication_string=password (' 123456 ') where user= ' root ' and host= ' localhost ';"

Sed-i '/skip-grant-tables/d '/etc/my.cnf

Service mysqld Restart

mysql-uroot-p123456

Sql>set Password = password (' 123456 ');

Sed-i '/\[mysqld\]$/alog-bin=/var/lib/mysql/log-bin '/etc/my.cnf

sed-i '/\[mysqld\]$/aserver_id=130 '/etc/my.cnf # Two different IDs can be

Service mysqld Restart

Two databases completed

Two: Main Building

mysql-uroot-p123456 # Login Database

grant replication Slave on * * to [e-mail protected] "172.25.254.120" identified by "123456"; Configure on #130

grant replication Slave on * * to [e-mail protected] "172.25.254.130" identified by "123456"; Configure on #120

Whether the login test was successful

mysql> Show Master status\g; # View two nodes separately

1. Row ***************************

file:log-bin.000001

position:154

log-bin.000001 ", master_log_pos= 154 ; #130 action

Change master to master_host= "172.25.254.130", master_user= "Slaveuser", master_password= "123456", Master_log_ file= "log-bin.000001", master_log_pos=154; operation on #120

start slave; # Two nodes open separately

show slave status\g;

Slave_io_running:yes

Slave_sql_running:yes

You can test it yourself.

Three:keepalived Construction

cd/mnt/

Tar xvf keepalived-1.3.0.tar.gz

Yum-y Install gcc gcc-c++ openssl-devel

CD keepalived-1.3.0

./configure

Make && make install

Mkdir/etc/keepalived

cd/usr/local/etc/

Cp-a keepalived/keepalived.conf/etc/keepalived/

CP sysconfig/keepalived/etc/sysconfig/


Cat/etc/keepalived/keepalived.conf

! Configuration File for Keepalived

Global_defs {

router_id

}

Vrrp_sync_group vgm{

group{

HA

}

}

Vrrp_script Check_mysql {

Script " /root/check_mysql.sh " # script file

Interval 5

}

Vrrp_instance HA {

State MASTER # from BACKUP

Interface eth0

VIRTUAL_ROUTER_ID 51

Priority # from the

Advert_int 1

Authentication {

Auth_type PASS

Auth_pass 1111

}

virtual_ipaddress {

172.25.254.111/24 Dev eth0

}

Track_script {

Check_mysql

}

}

cat/root/check_mysql.sh # script file

PS aux | grep MySQL | grep sqld

If [$? = = 1]

Then

Service mysqld Restart

If [$?! = 0]

Then

Kill-9 ' ps aux | grep Keep | grep lived | awk ' {print $} '

Fi

Fi

Test, and boot not in the secondary test, can be self-testing


This article is from the "13262050" blog, please be sure to keep this source http://13272050.blog.51cto.com/13262050/1969254

MySQL database is highly available

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.