MySQL数据库支持数据库的主从复制功能,因此在集群方面具有其独特的优势,国内外大型网站架构体系中,均采用了MySQL的主从数据库配置来实现查询负载、数据库热备等功能。本人在此将如何配置实现做了个简单小结。

服务器配置,具体iP,主从库如下

主库 IP:192.168.1.189 master server
从库 IP:192.168.1.188 slave server

服务器系统为:centos5.6,下载安装软件包具体包括如下

MySQL-client-5.6.13-1.linux_glibc2.5.x86_64.rpm
MySQL-devel-5.6.13-1.linux_glibc2.5.x86_64.rpm
MySQL-server-5.6.13-1.linux_glibc2.5.x86_64.rpm
MySQL-shared-5.6.13-1.linux_glibc2.5.x86_64.rpm
MySQL-shared-compat-5.6.13-1.linux_glibc2.5.x86_64.rpm
MySQL-test-5.6.13-1.linux_glibc2.5.x86_64.rpm

一、安装mysql,通过yum命令,安装所有所需rpm文件

yum -y install libaio libaio-devel perl-Time-HiRes curl curl-devel zlib-devel openssl-devel perl cpio expat-devel gettext-devel perl-ExtUtils-MakeMaker perl-DBD-MySQL
rpm -ivh MySQL-test-5.6.13-1.linux_glibc2.5.x86_64.rpm
rpm -ivh MySQL-shared-5.6.13-1.linux_glibc2.5.x86_64.rpm  
rpm -ivh MySQL-shared-compat-5.6.13-1.linux_glibc2.5.x86_64.rpm 
rpm -ivh MySQL-server-5.6.13-1.linux_glibc2.5.x86_64.rpm 
rpm -ivh MySQL-devel-5.6.13-1.linux_glibc2.5.x86_64.rpm 
rpm -ivh MySQL-client-5.6.13-1.linux_glibc2.5.x86_64.rpm

二、修改master和slave配置,注意部分参数要根据实际情况来调整,具体步骤如下

主库/etc/my.cnf配置:

[client]
port = 3306
socket = /state/partition1/mysql/mysql.sock
default-character-set=utf8
[mysqld]
server-id=1025
log-bin=mysql-master-bin
binlog_format = mixed
expire_logs_days=15
max_connections=1000
innodb_flush_log_at_trx_commit=1
sync_binlog=1
binlog-do-db=denovo_ng
binlog-ignore-db=mysql,test,information_schema
innodb_buffer_pool_size = 46673M
skip-name-resolve
datadir = /state/partition1/mysql/data
port = 3306
socket = /state/partition1/mysql/mysql.sock
key_buffer_size=16M
max_allowed_packet=16M
join_buffer_size = 512M
sort_buffer_size = 256M
read_rnd_buffer_size = 128M 
innodb_buffer_pool_size = 40960M
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

从库/etc/my.cnf配置,具体代码如下

[client]
port = 3306
socket = /state/partition1/mysql/mysql.sock
[mysqld]
server-id=1052
datadir = /state/partition1/mysql/data
port = 3306
socket = /state/partition1/mysql/mysql.sock
user=mysql
log-bin=mysql-slave-bin
max_binlog_size=1000M
binlog_format = mixed
expire_logs_days=7
innodb_flush_log_at_trx_commit=1
sync_binlog=1
read_only=1
binlog-do-db=denovo_ng
binlog-ignore-db=mysql,test,information_schema
innodb_buffer_pool_size = 36673M
skip-name-resolve
max_connections=1000
max_user_connections=490
max_connect_errors=2
key_buffer_size=16M
max_allowed_packet=16M
join_buffer_size = 512M
sort_buffer_size = 256M
read_rnd_buffer_size = 128M 
innodb_buffer_pool_size = 40960M
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

三、进行主从库账号授权操作:

主库

grant replication slave on *.* to 'jpsync'@'192.168.1.189' identified by 'jppasswd';
flush privileges;
show master status; #查看主库信息

从库

stop slave;
change master to master_host='192.168.1.188',master_port=3306,master_user='jpsync',master_password='jppasswd', master_log_file='mysql-master-bin.000003',master_log_pos=408;  
start slave;
show slave status\G;

如果出现

Slave_IO_Running: Yes
Slave_SQL_Running: Yes

表明mysql主从库成功。

文章来源地址:http://blog.yoodb.com/yoodb/article/detail/273

最新文章

  1. Duilib源码分析(四)绘制管理器—CPaintManagerUI—(前期准备四)
  2. C#远程共享文件路径访问
  3. Linux常用到的指令汇总
  4. Xcode 插件开发
  5. nodejs 按行读取 readline
  6. 响应式布局 —— Demo
  7. nyoj 对决吃桃
  8. Iterm2/Mac自带终端工具快速进入你想进入的虚拟机教程
  9. npm由来和作用
  10. nginx——优化 Nginx access 日志
  11. freeswitch dialplan 基础
  12. ECharts上手例子
  13. 使用 IntraWeb (36) - TIWServerControllerBase
  14. Java compiler level does not match the version of the installed Java project facet解决办法
  15. centos 关闭selinux
  16. oracle 排序 row_number() over(partition by 排序字段)
  17. Axure RP chrome插件显示已损坏或者无法安装的解决方法
  18. [AI]神经网络章1 神经网络基本工作原理
  19. 【php+微擎】微擎学习相关帮助推荐
  20. csc.exe已退出,代码为-532462766

热门文章

  1. Python flask 构建可扩展的restful apl☝☝☝
  2. js二次作业
  3. 最简单的ArcGIS Engine应用程序(下)
  4. Flask中的flash
  5. Redis开发与运维:数据迁移(下)
  6. 朋友外包干了5年java,居然不知道dubbo-monitor是怎么用的?
  7. Oracle基于延时的盲注总结
  8. 16.Nginx HTTPS实践
  9. 基于 HTML5 + WebGL 的 3D 可视化挖掘机
  10. Python 中文乱码matplotlib乱码 (Windows)