忘记密码?

一键登录

草根吧源码论坛

MySQL主从复制在Discuz!、微擎、微赞的应用配置案例

查看: 214|回复: 0

MySQL主从复制在Discuz!、微擎、微赞的应用配置案例

[复制链接]

2846

主题

5482

热度

2581

贡献

民审

Rank: 8Rank: 8

发表于 2017-2-12 10:26:41 | 显示全部楼层 |阅读模式 | 百度  360  谷歌 
分享到:
一、简述原理:
草根吧 MySQL主从复制在Discuz!、微擎、微赞的应用配置案例 主从,授权,节点,mysql,复制 精品教程
原理图
1、master记录二进制日志

2、slave的I/O线程读取master的二进制日志,并将其写入到中继日志中,SQL线程从中继日志中读取时间,并重放其中事件,更新slave的数据
二、准备工作:
关闭防火墙
#server iptables stop
关闭开机自启
#chkconfig iptables off
关闭selinux
#setenforce 0
在/etc/selinux/config 中,将SELINUX=enforcing改为SELINUX=disabled
同步时间
#ntpdate 202.120.2.101
=======================================================
三、安装mysql5.6
#cd /usr/local/src
解压mysql包
#tar -zxf MySQL-5.6.23-1.el6.x86_64.rpm-bundle.tar
用yum安装mysql,解决依赖关系
#yum install MySQL-shared-compat-5.6.23-1.el6.x86_64.rpm
#yum install MySQL-server-5.6.23-1.el6.x86_64.rpm
#yum install MySQL-client-5.6.23-1.el6.x86_64.rpm
#yum install MySQL-devel-5.6.23-1.el6.x86_64.rpm
#yum install MySQL-shared-5.6.23-1.el6.x86_64.rpm
创建数据目录
#mkdir -pv /home/mydata/data
#chown -R mysql.mysql /home//mydata
#chmod -R +w /home/mydata
四、修改配置文件
配置文件【主】
#cat /etc/my.cnf
[mysqld]
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
# These are commonly set, remove the # and set as required.
# basedir = .....
datadir = /home/mydata/data
port = 3306
socket = /var/lib/mysql/mysql.sock
log-bin = master-bin
server_id = 1
skip-external-locking
key_buffer_size = 256M
max_allowed_packet = 1M
table_open_cache = 256
pid-file = /home/mydata/data/mysql.pid
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
sort_buffer_size = 1M
read_buffer_size = 1M
read_rnd_buffer_size = 1M
myisam_sort_buffer_size = 64M
thread_cache_size = 8
query_cache_size= 16M
innodb_file_per_table = on
thread_concurrency = 8
skip_name_resolve = on
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
配置文件【从】
[mysqld]
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
# These are commonly set, remove the # and set as required.
# basedir = .....
datadir = /home/mydata/data
port = 3306
server_id = 2
pid-file = /home/mydata/data/mysql.pid
relay-log = relay-bin
socket = /var/lib/mysql/mysql.sock
skip-external-locking
key_buffer_size = 256M
max_allowed_packet = 1M
table_open_cache = 256
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
sort_buffer_size = 1M
read_buffer_size = 1M
read_rnd_buffer_size = 1M
myisam_sort_buffer_size = 64M
thread_cache_size = 8
query_cache_size= 16M
innodb_file_per_table = on
thread_concurrency = 8
skip_name_resolve = on
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
初始化MySQL
#/usr/bin/mysql_install_db --datadir=/usr/local/work/mydata --user=mysql

启动服务
#service mysql start
设置root密码

#mysql>SET PASSWORD FOR 'root'@'localhost' = PASSWORD('123456');
【主节点】授权复制权限账号给从节点
#mysql>grant replication client,replication slave on *.* to 'repuser'@'192.168.%.%' identified by 'reppasswd';
#mysql>flush privileges;
查看状态
#mysql>show master status;
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
【从节点】指定主节点,复制账号
#mysql>change master to master_host='192.168.1.6',master_user='repuser',master_password='reppasswd',master_log_file='master-bin.000001',master_log_pos=120;
查看状态
#mysql>show slave status\G
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
备注:这里只讲到mysql主从复制,但没有讲到如何实现高可用,可以利用keepalived来实现。


帖子地址: 

本文来源于草根吧源码论坛 www.caogen8.co,欢迎大家下载。
如果您没有贡献需要充值,可以直接在线充值,点击充值
如果你需要加入本站赞助VIP会员,可以直接在线开通,点击开通
如果找不到您要的资源,请搜索一下,点击搜索
回复

举报

发表回复

高级模式
您需要登录后才可以回帖 登录 | 立即注册 新浪微博登陆 用百度帐号登录 一键登录:

本版积分规则

收藏帖子 返回列表 搜索
快速回复 返回顶部 返回列表