MHA项目网站
https://code.google.com/p/mysql-master-ha/
一.环境介绍
1.主机部署
manager机:10.10.54.154
master机:10.10.54.156
slave1机:10.10.54.155(备用master)
slave2机:10.10.54.157
2.大致步骤
A.首先用ssh-keygen实现四台主机之间相互免密钥登录
B.安装MHAmha4mysql-node,mha4mysql-manager 软件包
C.建立master,slave1,slave2之间主从复制
D.管理机manager上配置MHA文件
E.masterha_check_ssh工具验证ssh信任登录是否成功
F.masterha_check_repl工具验证mysql复制是否成功
G.启动MHA manager,并监控日志文件
H.测试master(156)宕机后,是否会自动切换
3.说明:下面中括号中的主机名说明了当前操作是在哪台机子上进行的
二.首先用ssh-keygen实现四台主机之间相互免密钥登录
[manager机]
shell> ssh-keygen -t rsa -b 2048
shell> scp-copy-id root@10.10.54.155
shell> scp-copy-id root@10.10.54.156
shell> scp-copy-id root@10.10.54.157
在另外三台机子重复此步骤,使四台机子中的任何两台之间可以免密码登录
三.安装MHAmha4mysql-node,mha4mysql-manager 软件包
1.四台主机上安装MHAmha4mysql-node
12345[manager,master,slave1,slave2]<code class="bash plain">shell> yum update<code class="bash plain">shell> yum -y <code class="bash functions">install <code class="bash plain">perl-DBD-MySQL ncftp<code class="bash plain">shell> wget http:<code class="bash plain">//mysql-master-ha<code class="bash plain">.googlecode.com<code class="bash plain">/files/mha4mysql-node-0<code class="bash plain">.53-0.noarch.rpm<code class="bash plain">sehll> rpm -ivh mha4mysql-node-0.53-0.noarch.rpm<p>2.在manager机子上安装mha4mysql-manager</p>123456789101112131415161718192021<code class="bash plain">[manager]<code class="bash plain">shell> yum <code class="bash functions">install <code class="bash plain">perl<code class="bash plain">shell> yum <code class="bash functions">install <code class="bash plain">cpan<code class="bash plain">shell> rpm -ivh mha4mysql-manager-0.53-0.el6.noarch.rpm<code class="bash plain">error:<code class="bash plain">perl(Config::Tiny) is needed by mha4mysql-manager-0.53-0.noarch<code class="bash plain">perl(Log::Dispatch) is needed by mha4mysql-manager-0.53-0.noarch<code class="bash plain">perl(Log::Dispatch::File) is needed by mha4mysql-manager-0.53-0.noarch<code class="bash plain">perl(Log::Dispatch::Screen) is needed by mha4mysql-manager-0.53-0.noarch<code class="bash plain">perl(Parallel::ForkManager) is needed by mha4mysql-manager-0.53-0.noarch<code class="bash plain">perl(Time::HiRes) is needed by mha4mysql-manager-0.53-0.noarch<code class="bash plain">[solution]<code class="bash plain">shell> wget <code class="bash functions">ftp<code class="bash plain">:<code class="bash plain">//ftp<code class="bash plain">.muug.mb.ca<code class="bash plain">/mirror/centos/5<code class="bash plain">.10<code class="bash plain">/os/x86_64/CentOS/perl-5<code class="bash plain">.8.8-41.el5.x86_64.rpm<code class="bash plain">shell> wget <code class="bash functions">ftp<code class="bash plain">:<code class="bash plain">//ftp<code class="bash plain">.muug.mb.ca<code class="bash plain">/mirror/centos/6<code class="bash plain">.5<code class="bash plain">/os/x86_64/Packages/compat-db43-4<code class="bash plain">.3.29-15.el6.x86_64.rpm<code class="bash plain">shell> wget http:<code class="bash plain">//downloads<code class="bash plain">.naulinux.ru<code class="bash plain">/pub/NauLinux/6x/i386/sites/School/RPMS/perl-Log-Dispatch-2<code class="bash plain">.27-1.el6.noarch.rpm<code class="bash plain">shell> wget http:<code class="bash plain">//dl<code class="bash plain">.fedoraproject.org<code class="bash plain">/pub/epel/6/i386/perl-Parallel-ForkManager-0<code class="bash plain">.7.9-1.el6.noarch.rpm<code class="bash plain">shell> wget http:<code class="bash plain">//dl<code class="bash plain">.fedoraproject.org<code class="bash plain">/pub/epel/6/i386/perl-Mail-Sender-0<code class="bash plain">.8.16-3.el6.noarch.rpm<code class="bash plain">shell> wget http:<code class="bash plain">//dl<code class="bash plain">.fedoraproject.org<code class="bash plain">/pub/epel/6/i386/perl-Mail-Sendmail-0<code class="bash plain">.79-12.el6.noarch.rpm<code class="bash plain">shell> wget http:<code class="bash plain">//mirror<code class="bash plain">.centos.org<code class="bash plain">/centos/6/os/x86_64/Packages/perl-Time-HiRes-1<code class="bash plain">.9721-136.el6.x86_64.rpm<code class="bash plain">shell> rpm -ivh perl-Parallel-ForkManager-0.7.9-1.el6.noarch.rpm perl-Log-Dispatch-2.27-1.el6.noarch.rpm perl-Mail-Sender-0.8.16-3.el6.noarch.rpm perl-Mail-Sendmail-0.79-12.el6.noarch.rpm perl-Time-HiRes-1.9721-136.el6.x86_64.rpm<code class="bash plain">shell> rpm -ivh mha4mysql-manager-0.53-0.el6.noarch.rpm<p>四.建立master,slave1,slave2之间主从复制<br></p>12345678910111213141516171819<code class="bash plain">[master:156]<code class="bash plain">1.shell> vim <code class="bash plain">/etc/my<code class="bash plain">.cnf<code class="bash comments">#server-id 改为1<code class="bash plain">server-<code class="bash functions">id<code class="bash plain">=1<code class="bash plain">log-bin=mysql-bin<code class="bash plain">binlog_format=mixed<code class="bash comments">#授权操作<code class="bash plain">2.mysql> GRANT ALL PRIVILEGES ON *.* TO <code class="bash string">'rep'<code class="bash plain">@<code class="bash string">'10.10.54.%' <code class="bash plain">IDENTIFIED BY <code class="bash string">'rep123'<code class="bash plain">;<code class="bash plain">mysql> flush privileges;<code class="bash plain">3.mysql> show master status;<code class="bash plain">[slave1,slave2]<code class="bash plain">4.change master操作<code class="bash plain">mysql> change master to<code class="bash plain">master_host=<code class="bash string">'10.10.54.156'<code class="bash plain">,<code class="bash plain">master_port=3306,<code class="bash plain">master_user=<code class="bash string">'rep'<code class="bash plain">,<code class="bash plain">master_password=<code class="bash string">'rep123'<code class="bash plain">,<code class="bash plain">master_log_file=<code class="bash string">'mysql-bin.000001'<code class="bash plain">,<code class="bash plain">master_log_pos=112;<p>注意:slave1机子上也要授权,因为这个是备用master<br>[slave1:155]<br>5.mysql> GRANT ALL PRIVILEGES ON *.* TO 'rep'@'10.10.54.%' IDENTIFIED BY 'rep123';</p>
<p><br>[master,slave1,slave2]<br>6.查看主从复制是否成功的一些命令<br>mysql> start slave;<br>mysql> stop slave;<br>mysql> reset slave;<br>mysql> show slave status/G;<br></p>
<p>五.所有主机上设置复制权限帐号<br>mysql> GRANT ALL PRIVILEGES ON *.* TO 'mha_rep'@'10.10.2.10' IDENTIFIED BY '123456';</p>
<p>六.manager上配置MHA文件,管理各个节点<br></p>
<p>[manager:154]<br>shell> mkdir -p /masterha/app1<br>shell> mkdir /etc/masterha<br>shell> vim /etc/masterha/app1.cnf</p>12345678910111213141516171819202122232425<code class="bash plain">[server default]<code class="bash plain">user=mha_rep <code class="bash comments">##mysql管理用

MySQL'sBLOBissuitableforstoringbinarydatawithinarelationaldatabase,whileNoSQLoptionslikeMongoDB,Redis,andCassandraofferflexible,scalablesolutionsforunstructureddata.BLOBissimplerbutcanslowdownperformancewithlargedata;NoSQLprovidesbetterscalabilityand

ToaddauserinMySQL,use:CREATEUSER'username'@'host'IDENTIFIEDBY'password';Here'showtodoitsecurely:1)Choosethehostcarefullytocontrolaccess.2)SetresourcelimitswithoptionslikeMAX_QUERIES_PER_HOUR.3)Usestrong,uniquepasswords.4)EnforceSSL/TLSconnectionswith

ToavoidcommonmistakeswithstringdatatypesinMySQL,understandstringtypenuances,choosetherighttype,andmanageencodingandcollationsettingseffectively.1)UseCHARforfixed-lengthstrings,VARCHARforvariable-length,andTEXT/BLOBforlargerdata.2)Setcorrectcharacters

MySQloffersechar, Varchar, text, Anddenumforstringdata.usecharforfixed-Lengthstrings, VarcharerForvariable-Length, text forlarger text, AndenumforenforcingdataAntegritywithaetofvalues.

Optimizing MySQLBLOB requests can be done through the following strategies: 1. Reduce the frequency of BLOB query, use independent requests or delay loading; 2. Select the appropriate BLOB type (such as TINYBLOB); 3. Separate the BLOB data into separate tables; 4. Compress the BLOB data at the application layer; 5. Index the BLOB metadata. These methods can effectively improve performance by combining monitoring, caching and data sharding in actual applications.

Mastering the method of adding MySQL users is crucial for database administrators and developers because it ensures the security and access control of the database. 1) Create a new user using the CREATEUSER command, 2) Assign permissions through the GRANT command, 3) Use FLUSHPRIVILEGES to ensure permissions take effect, 4) Regularly audit and clean user accounts to maintain performance and security.

ChooseCHARforfixed-lengthdata,VARCHARforvariable-lengthdata,andTEXTforlargetextfields.1)CHARisefficientforconsistent-lengthdatalikecodes.2)VARCHARsuitsvariable-lengthdatalikenames,balancingflexibilityandperformance.3)TEXTisidealforlargetextslikeartic

Best practices for handling string data types and indexes in MySQL include: 1) Selecting the appropriate string type, such as CHAR for fixed length, VARCHAR for variable length, and TEXT for large text; 2) Be cautious in indexing, avoid over-indexing, and create indexes for common queries; 3) Use prefix indexes and full-text indexes to optimize long string searches; 4) Regularly monitor and optimize indexes to keep indexes small and efficient. Through these methods, we can balance read and write performance and improve database efficiency.


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

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Dreamweaver Mac version
Visual web development tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

WebStorm Mac version
Useful JavaScript development tools

Zend Studio 13.0.1
Powerful PHP integrated development environment
