MySQL Master master high Availability (KeepAlive)

Source: Internet
Author: User

2 New virtual machines 172.16.1.1, 172.16.1.2 ( configure yum source )

Installing the database service

which 172.16.1.1, 172.16.1.2 Run the database service and set the password for the database administrator to log on from the local computer is XZW 12345 ( mysql-server.5.6 )

TAR-XVF Mysql-5.6.rpm.tar (RPM package installation)

RPM-UVH mysql-*.rpm

/etc/init.d/mysql start; Chkconfig MySQL on

Change Password

[Email protected] ~]# Cat/root/.mysql_secret

[Email protected] ~]# MYSQL-UROOT-PJBJIFBWD

mysql> Set password for [email protected] "localhost" =password ("xzw12345");

Mysql> quit;

[Email protected] ~]# mysql-uroot-pxzw12345

Mysql>

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++

Main Master Structure

Master 203 :

mysql-uroot-pxzw12345

mysql> grant replication Slave on * * to [e-mail protected] "%" identified by "123456";

mysql>quit;

Vim/etc/my.cnf

[Mysqld]

log-bin=master203

server_id=203

: Wq

/etc/init.d/mysql restart

ls/var/lib/mysql/master203.*

mysql-uroot-pxzw12345

Mysql>show Master status;

Master 204:

Mysql-uroot-pxzw123

mysql> grant replication Slave on * * to [e-mail protected] "%" identified by "123456";

mysql>quit;

Vim/etc/my.cnf

[Mysqld]

log-bin=master204

server_id=204

: Wq

/etc/init.d/mysql restart

ls/var/lib/mysql/master204.*

mysql-uroot-pxzw12345

Mysql>show Master status;

Master 204 to master 203 initiates a synchronization operation to specify relevant parameters for the relevant master172.16.1.1

mysql-uroot-pxzw12345

mysql> Change Master to master_host= "172.16.1.1", master_user= "Slaveuser" , master_password= "123456", master_log_file= "master203.000001", master_log_pos=120;

mysql> start slave;

Mysql> show Slave status\g;

IO Yes

SQL Yes

Master 203 initiates a synchronous operation to the master204 , specifying relevant parameters for the relevant master172.16.1.2

mysql-uroot-pxzw12345

mysql> Change Master to master_host= "172.16.1.2", master_user= "Slaveuser", master_password= "123456", Master_log_ File= "master204.000001", master_log_pos=120;

mysql> start slave;

Mysql> show Slave status\g;

IO Yes

SQL Yes

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++

Test

1.master203

mysql-uroot-pxzw12345

mysql> CREATE DATABASE Bbsdb;

Mysql> Grant all on bbsdb.* to [e-mail protected] "%" identified by "123";

Mysql> quit;

2.master204

mysql-uroot-pxzw12345

Mysql>use Bbsdb;

Mysql> CREATE TABLE bbsdb.t1 (id int);

Mysql> quit;

3. On Client Access (192.168.1.200):

Ping x.x.x.1

Mysql-hx.x.x.1-ustudent-p123

mysql> INSERT into BBSDB.T1 values (101);

in master203, master204

mysql-uroot-pxzw12345

MySQL > select * from Bbsdb.t1; # can also see the record

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++

This article is for everyone to explain the MySQL error: Last_io_error:error connecting to master solution, interested students reference.

Error message:

Slave_io_running:connecting

Slave_sql_running:yes

last_io_errno:2003

Last_io_error:error connecting to master 'slaveuser@172.16.1.1:3306 '-retry-time:60 retries:1

Cause of Error:

The primary database server did not shut down the firewall.

Resolution:

1, go to the master server: 172.16.1.1 shut down the firewall.

[[Email protected] ~]# service iptables stop;chkconfig iptables off

Iptables:setting chains to Policy Accept:filter [OK]

iptables:flushing firewall rules: [OK]

iptables:unloading modules: [OK]

2, go from the server: Stop Slave;start slave;

mysql> stop Slave;

Query OK, 0 rows affected (0.01 sec)

mysql> start slave;

Query OK, 0 rows affected (0.01 sec)

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++

keepalived High Availability Server issues

Two Linux servers (172.16.1.1, 172.16.1.2), do MySQL server, and deploy keepalived high-availability software, one as a client host (192.168.1.200), to achieve the following functions:

    • Using keepalived to achieve high availability of MySQL server
    • Web server IP addresses are 172.16.1.1 and 172.16.1.2, respectively
    • Web server Drift VIP address is 172.16.1.3
    • The client accesses the MySQL service by accessing the VIP address

Steps

The implementation of this case needs to follow the steps below.

Step One: Configure the network environment

1) Set MySQL server network parameters

[Email protected] ~]# vim/etc/sysconfig/network-scripts/ifcfg-eth1
Device=eth1
Type=ethernet
Onboot=yes
Nm_controlled=yes
Bootproto=none
ipaddr=172.16.1.1
netmask=255.255.255.0
#DNS2 =221.4.8.1
#GATEWAY =192.168.1.1
#DNS1 =192.168.9.1
Ipv6init=no
Userctl=no

[Email protected] ~]# vim/etc/sysconfig/network-scripts/ifcfg-eth1

Device=eth1
Type=ethernet
Onboot=yes
Nm_controlled=yes
Bootproto=none
ipaddr=172.16.1.2
netmask=255.255.255.0
#DNS2 =221.4.8.1
#GATEWAY =192.168.1.1
#DNS1 =192.168.9.1
Ipv6init=no
Userctl=no

Step Two: Install keepalived software

Note: The two MySQL servers do the same operation.

  1. [Email protected] ~]# yum install- y gcc kernel-devel OpenSSL-devel popt-devel
  2. [Email protected] ~]# tar -xzf keepalived-1.2.7. Tar. GZ
  3. [[email protected] ~]# CD keepalived-1.2.7
  4. [[email protected] keepalived-1.2.7]# . /configure--sysconf=/etc
  5. [[email protected] keepalived-1.2.7]# make && make install
  6. [[email protected] keepalived-1.2.7]# Ln -s /usr/local/sbin/ keepalived /sbin/
  7. [[email protected] keepalived-1.2.7]# chkconfig keepalived on
  8. [Email protected] ~]# yum install- y gcc kernel-devel OpenSSL-devel popt-devel
  9. [Email protected] ~]# tar -xzf keepalived-1.2.7. Tar. GZ
  10. [[email protected] ~]# CD keepalived-1.2.7
  11. [[email protected] keepalived-1.2.7]# . /configure--sysconf=/etc
  12. [[email protected] keepalived-1.2.7]# make && make install
  13. [[email protected] keepalived-1.2.7]# Ln -s /usr/local/sbin/ keepalived /sbin/
  14. [[email protected] keepalived-1.2.7]# chkconfig keepalived on

Step three: Deploy the keepalived service

1) Modify the WEB1 server keepalived configuration file

  1. [Email protected] ~]# vim /etc/keepalived/keepalived. conf
  2. Global_defs {
  3. Notification_email {
  4. [Email protected] . com. CN //Set alert recipient mailbox
  5. }
  6. Notification_email_from [email protected] //Set sender
  7. Smtp_server 127.0.0.1 //define mail server
  8. Smtp_connect_timeout
  9. router_id web1 //Set route ID number
  10. }
  11. Vrrp_instance vi_1 {
  12. State master //master server is Master
  13. interface eth0 //define network interface
  14. virtual_router_id //Main and auxiliary vrid must be the same
  15. Priority/server precedence
  16. Advert_int 1
  17. Authentication {
  18. Auth_type Pass
  19. Auth_pass Forlvs //Primary and secondary server passwords must be the same
  20. }
  21. Virtual_ipaddress { 172.16.0.1 }
  22. }

2) Modify the WEB2 server keepalived configuration file

  1. [Email protected] ~]# vim /etc/keepalived/keepalived. conf
  2. Global_defs {
  3. Notification_email {
  4. [Email protected] . com. CN //Set alert recipient mailbox
  5. }
  6. Notification_email_from [email protected] //Set sender
  7. Smtp_server 127.0.0.1 //define mail server
  8. Smtp_connect_timeout
  9. router_id web2 //Set route ID number
  10. }
  11. Vrrp_instance vi_1 {
  12. State SLAVE //from server to SLAVE
  13. interface eth0 //define network interface
  14. virtual_router_id //Main and auxiliary vrid must be the same
  15. Priority/server precedence
  16. Advert_int 1
  17. Authentication {
  18. Auth_type Pass
  19. Auth_pass Forlvs //Primary and secondary server passwords must be the same
  20. }
  21. Virtual_ipaddress { 172.16.0.1 }
  22. }

3) Start the service

    1. [[email protected] ~]# service keepalived start
    2. [[email protected] ~]# service keepalived start

Step Four: Test

1) Log in to two Web servers to view VIP information

    1. [[email protected] ~]# IP addr Show
    2. [[email protected] ~]# IP addr Show

2) Client Access

The client uses the Curl command to connect to the http://172.16.0.1, view the Web page, turn off the network card of the WEB1 server, and the client accesses http://172.16.0.1 again to verify that the service is properly accessible.

MySQL Master master high Availability (KeepAlive)

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.