MHA 学习(二) 安装之 主从搭建

简介: 

  目前mysql 集群方案很多,目前整理mha 的资料  
目前感觉的话 mha 的集群做  业务量不是很大  但是对故障时间要求很严格的数据库  
如果业务  一致性要求不是很高的话   mha的架构还是很少的   你需要给slave 的读进行 负载
需要新的软件去支持  上述要求的话  还是 mmm  比较合适
如果要是对读写 一致性要求高的话  适合  pxc 的集群  mysql ndb 集群的话也不错 




一 安装数据库    

我目前就写下 过程   写的不全的地方 可以找我


提供安装脚本   
#!/bin/bash
#make zhangxu stay_sun
#date 20151110
#version 1.0




#!/bin/bash
#
#
softwhere=/tmp
mysqldir=/zx/mysql
datadir=/zx/mysql/data
pass=zhangxu
mysql_instll_log=/tmp/mysql_install.log








if [ -f "/tmp/$mysql_instll_log" ]; then


        touch $mysql_instll_log
        echo "创建日志文件" >$mysql_instll_log
else  > $mysql_instll_log
      echo "重置日志文件" >$mysql_instll_log


fi








#检查系统版本
system=`cat /etc/issue | head -1`
if [ "$system"x = "CentOS release 6.5 (Final)"x ];then


        echo  -e "检查系统版本正常" >>$mysql_instll_log


else


        echo  -e "检查系统版本" cat >>$mysql_instll_log


        echo "本脚本是针对Centos 6.5 x64系统编写的,其他系统运行可能有问题" >>$mysql_instll_log


        exit




q
fi




##############MySQL##########################################################


#检查是否安装mysql


rpm -q mysql > /dev/null


a=`echo $?`




if [ $a -eq 0 ];then


        echo "mysql is install" >>$mysql_instll_log


        yum -y remove mysql


        echo "mysql remove is ok" >>$mysql_instll_log


fi




if [ -f "/etc/my.cnf" ]; then


        mv /etc/my.cnf /opt
        echo "备份原来的mysql配置文件" >>$mysql_instll_log
fi




#检测网络联通性#


ping www.baidu.com -c 2 > /dev/null


dbnet=`echo $?`


if [ $dbnet -eq 0 ];then


        echo  -e "检查网络 true" >>$mysql_instll_log


else


        echo  -e "检查网络 FAIL] " >>$mysql_instll_log


        echo "请检查网络,否则无法使用yum" >>$mysql_instll_log


        exit


fi




#关闭selinux


setenforce 0


sed -i '7s/enforcing/disabled/' /etc/sysconfig/selinux


#安装编译环境


yum groupinstall -y "Development tools"
yum -y install pcre-devel
yum -y  groupinstall  Server Platform Development


#更新bash和openssl漏洞


yum install -y bash openssl* ntp vim


yum clean all


#更新北京时间


ntpdate ntp.fudan.edu.cn




#安装mysql组件包


yum -y install ncurses-devel openssl* cmake 


#创建用户和组


groupadd -r mysql


useradd -r -g mysql mysql


usermod  -s /sbin/nologin mysql


mkdir -p $mysqldir $datadir






if [ -f "/tmp/mysql-5.6.26.tar.gz" ]; then


        echo "mysql-5.6.26.tar.gz is found" >>$mysql_instll_log


else


        echo "未找到mysql安装包" >>$mysql_instll_log


exit


fi




#解压安装


tar zxvf $softwhere/mysql-5.6.26.tar.gz -C /usr/src


echo "解压成功 开始安装" >>$mysql_instll_log


cd /usr/src/mysql-5.6.26


cmake  -DCMAKE_INSTALL_PREFIX=$mysqldir \
-DMYSQL_DATADIR=$datadir \
-DMYSQL_TCP_PORT=3306 \
-DMYSQL_UNIX_ADDR=$datadir/mysqld.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EXTRA_CHARSETS=all \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DEXTRA_CHARSETS=all \
-DWITH_EMBEDDED_SERVER=1 \
-DWITH_SSL=bundled \
-DWITH_DEBUG=0 \
-DENABLE_DOWNLOADS=1




dbcmake=`echo $?`


if [ $dbnet -eq 0 ];then


        echo  -e "cmake 成功" >>$mysql_instll_log


else


        echo  -e "cmake FAIL " >>$mysql_instll_log


        echo "请检查安装包" >>$mysql_instll_log


        exit


fi




make


dbcmake=`echo $?`


if [ $dbnet -eq 0 ];then


        echo  -e "make 成功" >>$mysql_instll_log


else


        echo  -e "cmake FAIL " >>$mysql_instll_log


        echo "请检查安装包" >>$mysql_instll_log


        exit






make install


if [ $dbnet -eq 0 ];then


        echo  -e " make install 成功" >>$mysql_instll_log


else


        echo  -e "cmake FAIL install  " >>$mysql_instll_log


        echo "请检查安装包" >>$mysql_instll_log


        exit




echo "安装成功" >>$mysql_instll_log


#初始化


$softwhere/mysql/scripts/mysql_install_db \
--basedir=$mysqldir \
--datadir=$datadir \
--user=mysql


echo "初始化成功" >>$mysql_instll_log
sleep 1








#编辑配置文件








#添加启动脚本


chown mysql:mysql -R $datadir $mysqldir/mysql


cp /usr/src/mysql-5.6.26/support-files/mysql.server /etc/init.d/mysqld


chmod +x /etc/init.d/mysqld


chkconfig --add mysqld


chkconfig --level 2345 mysqld on




#添加环境变量


echo 'export PATH=$PATH':"$mysqldir/mysql/bin" > /etc/profile.d/mysql.sh


source /etc/profile.d/mysql.sh




#启动


/etc/init.d/mysqld start


echo  -e "MySQL 5.6.26 已经安装 初始化密码" >>$mysql_install_log




mysqladmin -u root password $pass


echo "完成mysql初始化密码"  >>$mysql_install_log










关闭防火墙  
/etc/init.d/iptables stop




二 配置  主从服务



 1 mysql dump 备份数据
 mysqldump -uroot -S /zx/mysql/data/mysql.sock -B test > test.sql
 
 2 导入 slave 数据库  
 mysql -uroot -D test < test.sql
 
 3 master 上面 执行
 mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000010 |      120 |              |                  |                   |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)


 4 主上执行授权

 
 grant replication slave on *.* to repl_user@'10.10.%' identified by 'rep_2014' ;


 5 slave 上执行 确认 master 主机

 change master to master_host='192.168.248.80',master_user='repl_user',master_password='rep_2014',master_log_file='mysql-bin.000010',master_log_pos=120;


 6 slave 上执行 

  start slave
  show slave status\G;
  
  
 mysql> show slave status\G;
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.168.248.80
                  Master_User: repl_user
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000004
          Read_Master_Log_Pos: 120
               Relay_Log_File: relay-bin.000013
                Relay_Log_Pos: 283
        Relay_Master_Log_File: mysql-bin.000004
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
              Replicate_Do_DB: 
          Replicate_Ignore_DB: 
           Replicate_Do_Table: 
       Replicate_Ignore_Table: 
      Replicate_Wild_Do_Table: 
  Replicate_Wild_Ignore_Table: 
                   Last_Errno: 0
                   Last_Error: 
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 120
              Relay_Log_Space: 450
              Until_Condition: None
               Until_Log_File: 
                Until_Log_Pos: 0
           Master_SSL_Allowed: No
           Master_SSL_CA_File: 
           Master_SSL_CA_Path: 
              Master_SSL_Cert: 
            Master_SSL_Cipher: 
               Master_SSL_Key: 
        Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 0
                Last_IO_Error: 
               Last_SQL_Errno: 0
               Last_SQL_Error: 
  Replicate_Ignore_Server_Ids: 
             Master_Server_Id: 2
                  Master_UUID: 5e87c498-869d-11e5-bb52-000c29cc5668
             Master_Info_File: /zx/mysql/data/master.info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it
           Master_Retry_Count: 86400
                  Master_Bind: 
      Last_IO_Error_Timestamp: 
     Last_SQL_Error_Timestamp: 
               Master_SSL_Crl: 
           Master_SSL_Crlpath: 
           Retrieved_Gtid_Set: 
            Executed_Gtid_Set: 
                Auto_Position: 0
1 row in set (0.01 sec)

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/29896444/viewspace-1970997/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/29896444/viewspace-1970997/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值