MariaDB+Keepalived双主高可用配置MySQL-HA_MySQL
MariaDB
bitsCN.com 利用keepalived构建高可用MySQL-HA,保证两台MySQL数据的一致性,然后用keepalived实现虚拟VIP,通过keepalived自带的服务监控功能来实现MySQL故障时自动切换。 硬件拓扑如下: VIP:192.168.1.200mysql1:192.168.1.201mysql2:192.168.1.202 操作系统:CentOS release 6.3(32位)MySQL版本:MariaDB 5.5.31 Stable下载地址(64位请下载64版本):https://downloads.mariadb.org/f/mariadb-5.5.31/kvm-tarbake-jaunty-x86/mariadb-5.5.31.tar.gz/from/http:/mirrors.scie.in/mariadbKeepalived版本:Version 1.2.7下载地址:http://www.keepalived.org/software/keepalived-1.2.7.tar.gz 一、配置Centos运行环境: 执行:rpm -qa|grep mysqlrpm -e mysqlyum -y remove mysql-server mysqlyum -y remove php-mysql移除系统自带的mysql yum -y install yum-fastestmirroryum -y update更新系统软件; rm -rf /etc/localtimeln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime yum install -y ntpntpdate -d cn.pool.ntp.orgdate设置时区并同步系统时间 #Disable SeLinuxif [ -s /etc/selinux/config ]; thensed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/configfildconfig关闭安全增强 cat >>/etc/security/limits.conf>/etc/sysctl.conf二、安装maridDB: 1、下载相关软件源码包[root@localhost down]# wget https://downloads.mariadb.org/f/mariadb-5.5.31/kvm-tarbake-jaunty-x86/mariadb-5.5.31.tar.gz/from/http:/mirrors.scie.in/mariadb 2、配置编译器,提高性能CFLAGS="-O3"CXX=gccCXXFLAGS="-O3 -felide-constructors -fno-exceptions -fno-rtti" 3、开始安装mariadb添加mysql用户和用户组[root@localhost down]# groupadd mysql[root@localhost down]# useradd -s /sbin/nologin -M -g mysql mysql 解压mariadb[root@localhost down]# tar -zxvf mariadb-5.5.31[root@localhost down]# cd mariadb-5.5.31 安装到/usr/local/mariamysql目录:[root@localhost down]# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mariamysql -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DENABLED_LOCAL_INFILE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_DEBUG=0 -DBUILD_CONFIG=mysql_release -DFEATURE_SET=community -DWITH_EMBEDDED_SERVER=OFF && make && make install 复制配置文件到/etc/my.cnf[root@localhost down]# cp /usr/local/mariamysql/support-files/my-huge.cnf /etc/my.cnf 设置mariamysql为系统服务[root@localhost down]# cp /usr/local/mariamysql/support-files/mysql.server /etc/init.d/mariamysql 初始化mariaDB数据库:[root@localhost down]# /usr/local/mariamysql/scripts/mysql_install_db --basedir=/usr/local/mariamysql/ --datadir=/usr/local/mariamysql/data/ --user=mysql 至此mariaDB安装完成。 三、keepalived安装: 1、下载源码包:wget http://www.keepalived.org/software/keepalived-1.2.7.tar.gz



log-bin=mysql-bin #启动二进制文件
server-id=1 #服务器ID



MariaDB [(none)]> grant replication slave on *.* to 'backup'@'192.168.1.202' identified by 'backup'; flush privileges;
显示master状态:MariaDB [(none)]> show master status;

六、配置202数据库服务器: [root@localhost /]# vi /etc/my.cnf 确保/etc/my.cnf中有如下参数,没有的话需手工添加,并重启mysql服务。[mysqld]
log-bin=mysql-bin #启动二进制文件
server-id=10(此处要设置的跟201不同)#服务器ID



Slave_IO_Running: Yes Slave_SQL_Running: Yes两项都显示Yes时说明从201同步数据成功。至此201为主202为从的主从架构数据设置成功! 七、设置201和202互为主从: 1、202机器上增加一个帐号专门用于同步数据:MariaDB [(none)]> grant replication slave on *.* to 'backup'@'192.168.1.201' identified by 'backup'; flush privileges;







global_defs {
router_id mysql-ha
}
vrrp_instance VI_1 {
state BACKUP
interface eth0
virtual_router_id 201
priority 100
advert_int 1
nopreempt
authentication {
auth_type PASS
auth_pass 123456
}
virtual_ipaddress {
192.168.1.200
}
}
virtual_server 192.168.1.200 3306 {
delay_loop 2
lb_algo rr
lb_kind DR
persistence_timeout 60
protocol TCP
real_server 192.168.1.201 3306 {
weight 1
notify_down /usr/local/keepalived/etc/keepalived/mysql.sh
TCP_CHECK {
connect_port 3306
connect_timeout 3
nb_get_retry 2
delay_before_retry 1
}
}
}
~


pkill keepalived



Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Home monitoring is generally kept for one to two weeks. Detailed introduction: 1. The larger the storage capacity, the longer the video can be saved; 2. The larger the capacity of the hard disk, the longer the video can be saved; 3. According to the requirements of different regions and laws and regulations, the number of surveillance videos The storage time may vary; 4. Some advanced surveillance systems can also trigger recording based on motion detection or specific events, thereby saving storage space and providing more useful recordings.

In today's digital age, being aware of the latest changes on your website is crucial for a variety of purposes, such as tracking updates on your competitors' websites, monitoring product availability, or staying informed of important information. Manually checking your website for changes can be time-consuming and inefficient. This is where automation comes into play. In this blog post, we will explore how to create a Python script to monitor website changes. By leveraging the power of Python and some handy libraries, we can automate the process of retrieving website content, comparing it to previous versions, and notifying us of any changes. This allows us to remain proactive and react promptly to updates or modifications to the sites we monitor. Setting up the environment Before we start writing scripts to monitor website changes, we need to set up P

How to implement request logging and monitoring in FastAPI Introduction: FastAPI is a high-performance web framework based on Python3.7+. It provides many powerful functions and features, including automated request and response model verification, security, and performance optimization. wait. In actual development, we often need to record request logs in the application for debugging and monitoring analysis. This article will introduce how to implement request logging and monitoring in FastAPI and provide corresponding code examples. 1. Installation

If we don’t have a mobile phone at hand, only a computer, but we have to take pictures, we can use the computer’s built-in surveillance camera to take pictures, so how to turn on the win10 surveillance camera, in fact, we only need to download a camera application. The specific method to open the win10 surveillance camera. How to open photos from win10 surveillance camera: 1. First, use the disk shortcut key Win+i to open settings. 2. After opening, enter the personal privacy settings. 3. Then turn on access restrictions under camera phone permissions. 4. Once opened, you just need to open the camera application software. (If not, you can go to the Microsoft store to download one) 5. After opening, if the computer has a built-in surveillance camera or an external surveillance camera is assembled, you can take pictures. (Because people don’t have cameras installed

Real-time log monitoring and analysis under Linux In daily system management and troubleshooting, logs are a very important data source. Through real-time monitoring and analysis of system logs, we can detect abnormal situations in time and handle them accordingly. This article will introduce how to perform real-time log monitoring and analysis under Linux, and provide corresponding code examples. 1. Real-time log monitoring Under Linux, the most commonly used log system is rsyslog. By configuring rsyslog, we can combine the logs of different applications

LinuxMint is an Ubuntu-based operating system with a user-friendly interface and ease of use. It is suitable for a variety of desktop and laptop computers and can run smoothly if certain hardware requirements are met. The following will introduce the hardware requirements of LinuxMint and provide some specific code examples to help readers learn more. Processor Requirements LinuxMint can work with a variety of processors, but it is recommended to use the latest 64-bit processors for better performance and compatibility

Monitoring errors in Laravel is an important part of improving application stability. During the development process, various errors will inevitably be encountered, and how to detect and resolve these errors in a timely manner is one of the keys to ensuring the normal operation of the application. Laravel provides a wealth of tools and functions to help developers monitor and handle errors. This article will introduce some of the important methods and attach specific code examples. 1. Use logging Logging is one of the important means of monitoring errors. Laravel has a powerful logging system built-in, developers

How to turn on hardware acceleration With the development of technology, hardware acceleration has become one of the important means to improve computer performance. By using hardware acceleration, we can speed up the computer's running speed, improve graphics processing capabilities, and make the computer more efficient and stable. So, how to turn on hardware acceleration? This article will introduce it to you in detail. First, we need to clarify the concept of hardware acceleration. Hardware acceleration generally refers to the use of dedicated computer hardware for acceleration processing, rather than through software. Common hardware acceleration includes GPU (graphics processing unit) plus
