keepalived mysql

  • A+
所属分类:Linux
系统版本:Centos 7
Mysql-master: 10.0.0.6
Mysql-slave: 10.0.0.7
vip: 10.0.0.8
一.Mysql
1.安装
2.修改配置文件
Mysql-master
vim /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
max_connections=1000
symbolic-links=0
slow_query_log=on
slow_query_log_file=/var/log/mysql-slow
long_query_time=5

server-id = 1 #backup这台设置2
log-bin = mysql-bin
binlog-ignore-db = mysql,information_schema #忽略写入binlog日志的库
auto-increment-increment = 2 #字段变化增量值
auto-increment-offset = 1 #初始字段ID为1
slave-skip-errors = all #忽略所有复制产生的错误

character-set-server=utf8
collation-server=utf8_bin
default-storage-engine=INNODB
max_allowed_packet=256M
innodb_log_file_size=2GB
sql_mode = NO_AUTO_VALUE_ON_ZERO
transaction-isolation=READ-COMMITTED
binlog_format=row
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
Mysql-slave:
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
max_connections=1000
symbolic-links=0
slow_query_log=on
slow_query_log_file=/var/log/mysql-slow
long_query_time=5

server-id = 2 #backup这台设置2
log-bin = mysql-bin
binlog-ignore-db = mysql,information_schema #忽略写入binlog日志的库
auto-increment-increment = 2 #字段变化增量值
auto-increment-offset = 1 #初始字段ID为1
slave-skip-errors = all #忽略所有复制产生的错误

character-set-server=utf8
collation-server=utf8_bin
default-storage-engine=INNODB
max_allowed_packet=256M
innodb_log_file_size=2GB
sql_mode = NO_AUTO_VALUE_ON_ZERO
transaction-isolation=READ-COMMITTED
binlog_format=row
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
3.重启服务并添加端口
systemctl restart mysqld
firewall-cmd --zone=public --add-port=3306/tcp --permanent;firewall-cmd --reload
4.创建同步帐号(Master和Slave)
 mysql -u root -p
mysql> GRANT REPLICATION SLAVE ON *.* TO 'replication'@'10.0.0.%' IDENTIFIED BY 'Azure%!10@0.0';
mysql> flush privileges; 
也可测试
Mysql-master:
mysql -h 10.0.0.7 -u replication -p
Mysql-slave
mysql -h 10.0.0.6 -u replication -p
5.查看log bin和pos值并配置
mysql> show master status;
+------------------+----------+--------------+--------------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+--------------------------+-------------------+
| mysql-bin.000001 | 422 | | mysql,information_schema | |
+------------------+----------+--------------+--------------------------+-------------------+
1 row in set (0.00 sec)

Mysql-master: (log bin pos写slave的)
mysql> change master to master_host='10.0.0.7', master_user='replication',master_password='Azure%!10@0.0',master_log_file='mysql-bin.000001',master_log_pos=422;
mysql> start slave; 
Mysql-slave: (log bin pos写master的)
mysql> change master to master_host='10.0.0.6', master_user='replication',master_password='Azure%!10@0.0',master_log_file='mysql-bin.000001',master_log_pos=422;
mysql> start slave;
6.查看是否搭建成功
mysql> show slave status \G
 Slave_IO_Running: Yes
 Slave_SQL_Running: Yes
二.安装keepalived





! Configuration File for keepalived
global_defs {
   router_id MYSQL_HA
}
vrrp_instance VI_1 {
    state BACKUP
    interface ens192
    virtual_router_id 51
    priority 100
    advert_int 1
    nopreempt
    authentication {
         auth_type PASS
         auth_pass 1111
     }
     virtual_ipaddress {
     192.168.1.30/24
     }
}
virtual_server 192.168.1.30 3306 {
   delay_loop 6
   lb_algo wrr
   lb_kind DR
   persistence_timeout 50
   protocol TCP
real_server 192.168.1.28 3306 {
   weight 3
   notify_down /etc/keepalived/mysql.sh
   TCP_CHECK {

        connect_timeout 10
        nb_get_retry 3
        delay_before_retry 3
        connect_port 3306

             }

       }
 
}

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: