一、安装前准备

关闭iptables:

service iptables stop;

chkconfig iptables off

 

关闭SELinux

vi /etc/selinux/config


 

查询系统是否有安装mysql,如有则移除。

rpm -qa | grep mysql

 

移除已安装的mysql:

yum remove mysql-libs-5.1.66-2.el6_3.x86_64

 

二、安装数据库

安装需要的插件:

yum install perl perl-devel libaiolibaio-devel

 

安装MySQL-shared-compat 替换mysql-libs,如果不替换,在删除mysql-libs,会提示postfix依赖于mysql-libs

rpm -ivh MySQL-shared-compat-5.6.26-1.el6.x86_64.rpm

 

安装服务端:

rpm -ivh MySQL-server-5.6.26-1.el6.x86_64.rpm

 

安装客户端:

rpm -ivh MySQL-client-5.6.26-1.el6.x86_64.rpm

 

设置开机自动启动:

chkconfig mysql on

 

启动mysql

service mysql start

 

停止mysql

service mysql stop

 

获取root的密码:
more /root/.mysql_secret  

 

修改root密码并删除匿名账户:

/usr/bin/mysql_secure_installation--user=mysql

 

修改主机名:

vi /etc/sysconfig/network

vi /etc/hosts

 

修改主服务器配置文件(配置文件见附件):

vi /usr/my.cnf

 

 

 

修改从服务器配置文件(配置文件见附件):

 

 

进入mysql:

mysql -u root -p

 

show master status

show global variables like '%uuid%'

 

在两台机器上都创建复制账户并授权:

grant replication slave on *.* to 'mysql'@'192.168.2.%'identified by 'mysql';

flush privileges;   #重加载权限

 

从库连接主库:

change master to master_host='192.168.2.61',master_user='mysql',master_password='mysql', master_port=3306,master_auto_position=1;

start slave;

 

主库连接从库:

change master to master_host='192.168.2.62',master_user='mysql',master_password='mysql', master_port=3306,master_auto_position=1;

start slave;

 

三、安装并配置keepalived(配置文件见附件)

yum install keepalived

vi /etc/keepalived/keepalived.conf

 

四、测试:

grant all privileges on *.* to 'root'@'%'identified by '123456';

mysql -h "192.168.2.60" -u root –p

show variables like "server_id";

 

 

show processlist;

show databases;

show slave status\G;

show master status\G;