Home >Database >Mysql Tutorial >MYSQL + MHA +keepalive + VIP安装配置(一)--MYSQL安装配置

MYSQL + MHA +keepalive + VIP安装配置(一)--MYSQL安装配置

WBOY
WBOYOriginal
2016-06-01 13:14:29966browse

一、总概:

   本文介绍了MySQL高可用性的实现方案MHA,MHA由Node和Manager组成,Node运行在每一台MySQL服务器上,不管是MySQL主服务器,还是MySQL从服务器,都要安装Node。主从安装keepalived ,实现虚拟ip漂移,程序不用改IP自动切换。

二、环境

1、操作系统:centos 6.5 64位

2、数据库:   MySQL-5.6.17-1.el6.x86_64.rpm-bundle.tar 下载

3、MHA版本:mha4mysql-node-0.54-0.el6.noarch.rpm,

                    mha4mysql-manager-0.54-0.el6.noarch.rpm

4、keepalived版本:

5、主机部署:

manager机:192.168.1.201master机:192.168.1.231slave1机:192.168.1.232(备用master)

6、大致步骤:

(1)、安装MYSQL 5.6.(2)、MYSQL配置主重复制.(3)、首先用ssh-keygen实现四台主机之间相互免密钥登录.(4)、安装MHAmha4mysql-node,mha4mysql-manager 软件包(5)、在MHA配置master,slave1的相关文件。(6)、管理机manager上配置MHA文件(7)、masterha_check_ssh工具验证ssh信任登录是否成功(8)、masterha_check_repl工具验证mysql复制是否成功(9)、启动MHA manager,并监控日志文件.(10)、测试master宕机后,是否会自动切换。(11)、主从安装keepalived ,实现虚拟ip漂移。

 三、mysql安装

1、下载MYSQL 5.5

wget http://cdn.mysql.com/Downloads/MySQL-5.6/MySQL-5.6.17-1.el6.x86_64.rpm-bundle.tar<br>tar -cf MySQL-5.6.17-1.el6.x86_64.rpm-bundle.tar<br>

2、解压后文件有:

MySQL-client-5.6.17-1.el6.x86_64.rpmMySQL-devel-5.6.17-1.el6.x86_64.rpmMySQL-embedded-5.6.17-1.el6.x86_64.rpmMySQL-server-5.6.17-1.el6.x86_64.rpmMySQL-shared-5.6.17-1.el6.x86_64.rpmMySQL-shared-compat-5.6.17-1.el6.x86_64.rpmMySQL-test-5.6.17-1.el6.x86_64.rpm

  注意:其实只要安装,服务器端MySQL-server-5.6.17-1.el6.x86_64.rpm 客户端MySQL-client-5.6.17-1.el6.x86_64.rpm 及MySQL-shared-compat-5.6.17-1.el6.x86_64.rpm(可以解决一些兼容性)

3、安装

rpm -ivh MySQL-client-5.6.17-1.el6.x86_64.rpmrpm -ivh MySQL-server-5.6.17-1.el6.x86_64.rpmrpm -ivh MySQL-shared-compat-5.6.17-1.el6.x86_64.rpm

4、可能会报的错:

(1)、已有数据库的存在

[root@localhost local]# rpm -ivh MySQL-server-5.6.17-1.el6.x86_64.rpm Preparing...########################################### [100%]file /usr/share/mysql/charsets/Index.xml from install of MySQL-server-5.6.17-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.71-1.el6.x86_64file /usr/share/mysql/charsets/armscii8.xml from install of MySQL-server-5.6.17-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.71-1.el6.x86_64file /usr/share/mysql/charsets/ascii.xml from install of MySQL-server-5.6.17-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.71-1.el6.x86_64file /usr/share/mysql/charsets/cp1250.xml from install of MySQL-server-5.6.17-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.71-1.el6.x86_64

  说明:系统中已存在mysql-libs-5.1.71-1.el6.x86_64 必须把它卸载掉。解决方法:

yum -y remove mysql-libs-5.1.71*

(2)、缺少一下依赖的组件

error: Failed dependencies:	/usr/bin/perl is needed by MySQL-server-5.6.17-1.el6.x86_64	libaio.so.1()(64bit) is needed by MySQL-server-5.6.17-1.el6.x86_64	libaio.so.1(LIBAIO_0.1)(64bit) is needed by MySQL-server-5.6.17-1.el6.x86_64	libaio.so.1(LIBAIO_0.4)(64bit) is needed by MySQL-server-5.6.17-1.el6.x86_64	

 解决方法:

yum install perlyum install libaio

 再重新安装,安装成功。默认root 没有密码,端口为:3306.

5、由于是RPM安装的所以在/etc/下没有MYSQL的my.cnf文件。解决方法:

cp /usr/share/mysql/my-medium.cnf/etc/my.cnf

 这样可以修改MYSQL的一些配置文件了。

6、mysql启动、停止、重启。

service mysql start或/etc/init.d/mysql startservice mysql stop 或/etc/init.d/mysql stopservice mysql restart或/etc/init.d/mysql restart

7、创建用户,用于主从复制的账号

 CREATE USER 'username'@'host' IDENTIFIED BY 'password';

    username - 你将创建的用户名,

    host - 指定该用户在哪个主机上可以登陆,如果是本地用户可用localhost, 如果想让该用户可以从任意远程主机登陆,可以使用通配符%.

    password - 该用户的登陆密码,密码可以为空,如果为空则该用户可以不需要密码登陆服务器.

例如:
CREATE USER 'sunney'@'%' IDENTIFIED BY 'sunney';

8、用户授权

grant privileges ON databasename.tablename TO 'username'@'host' identified by "password";

例如:
grant all privilegesON *.* TO 'sunney'@'%' identified by "sunney";FLUSH PRIVILEGES//修改生效

 9、已可以远程访问数据库了。

     如上步骤两台主机:231、232都按已上步骤安装MYSQL.

四、建产mysql 主从数据库配置

[master:231]1.shell>vi /etc/my.cnfserver-id=1log-bin=mysql-binbinlog_format=mixed2.mysql>show master status;[slave1]3.change master操作mysql>change master tomaster_host='192.168.1.231',master_port=3306,master_user='sunney',master_password='sunney',master_log_file='mysql-bin.000001',master_log_pos=112;[master,slave1]4.查看主从复制是否成功的一些命令mysql>start slave;mysql>stop slave;mysql>reset slave;mysql>show slave status/G;5.所有主机上设置复制权限帐号mysql>GRANT ALL PRIVILEGES ON*.*TO'sunney'@'%'IDENTIFIED BY 'sunney';

 注意:

(1)、master_log_file='mysql-bin.000001',master_log_pos=112;

        这两名是通过maste中用: show master status;查出来的。

(2)、master与slave的server-id 是不能相同,否则不能同步成功。

       slave的server-id可以通过修改 /etc/my.cnf或

       mysql> set global server_id=2; #此处的数值和my.cnf里设置的一样就行。

五、总结

    数据库的安装及master与slave配置成功,可以进行主从同步了!主从同步的常见错误,其实不外乎就是网络、权限、iptables、SELinux等问题,我们平时注意检查这些问题,处理起来应该不是很困难,大家记得关闭iptables(或开通对应的端口)和SELinux,注意Slave_IO_Running和Slave_SQL_Running状态必须确保主Yes才行,另外也要注意从机的Seconds_Behind_Master值及主从机的server-id不可以相同!

      

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn