In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
mysql master copy and keepalived high availability
Keepalived+mysql dual master to achieve MySQL-HA, we must ensure that the data of the two MySQL databases are exactly the same, the basic idea is that the two MySQL are mutually master-slave relationship (dual master), through Keepalived configuration virtual IP, when one of the MySQL database downtime, the application can automatically switch to another MySQL database, to ensure high availability of the system.
Basic experimental topology:
Master-master synchronization is the master-slave relationship between two machines, and writing on any machine will be synchronized.
Add the following parameter to the master1 mysql configuration file (/etc/my.cnf)
Add the following parameters to the master2 mysql master configuration file
Stop firewall service (master copy must pass through firewall, firewall will block, you can add policy)
Create an authorized user on master1
View binlog status information
Set as slave on master2
Check if the following two values are yes, yes means synchronization is possible
Add authorized users to master2
View binllog status information on master2
Set to slave in master1
Check if both parameters are yes.
Master1 is the master of Master2, Master2 is the master of Master1, and Master2 is the master of Master1, so they are the master of each other.
Create databases, tables, insert data, test whether the other party can synchronize
Check the synchronization on the second mysql server
From the above view, mysql master copy is fine, very perfect (id plus one in the above table is related to automatic growth in the configuration file, you can comment it out and restart)
High availability with keepalived
keepalived installation configuration
Install keepalived dependency packages as shown below
tarpack compile install keepalived
The above compilation and installation must be installed on both machines (use the above method on centos7, if it is 6.x, you need to add--with-kernel-dir= the location of the kernel file in front of make)
Modify keepalived profile (for host one)
! Configuration File for keepalived \Comment Information
global_defs {
router_id mysql-1
}
vrrp_instance VI_1 {
state BACKUP
interface eno16777736
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.119.100
}
}
virtual_server 192.168.119.100 3306 {
delay_loop 6
lb_algo rr
lb_kind DR
persistence_timeout 50
protocol TCP
real_server 192.168.119.132 3306 {
weight 1
notify_down /etc/keepalived/bin/mysql.sh
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
connect_port 3306
}
}
}
Configure the configuration file for Host 2 (several changes needed)
Write a script on both servers to create notify_down exactly where the keepalived profile specifies
and grant X privileges.
Start keepalived service
Both sides have to be activated.
View master1 cluster virtual ip address
Check if master2 cluster IP is available
You can see that when host 1 is running, host 2 does not have a virtual ip
Test our host to see if virtual ip changes.
View Host 2's
You can see that when host 1 goes down, keepalived service will automatically switch virtual ip to host 2. The reason is related to our priority setting in keepalived configuration file.
Let's test using client access hosts
Add logged-in authorized users on both servers
As you can see from the figure below, you can connect to the database
We put master1 down to see if the virtual ip can be connected. When clicking database master1 to view the table, it cannot be connected anymore.
Check whether the virtual ip database can be viewed
From the above figure, we know that the virtual ip is automatically switched, and it does not affect access.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.