码迷,mamicode.com
首页 > 其他好文 > 详细

微擎主从配置

时间:2018-10-16 01:52:37      阅读:194      评论:0      收藏:0      [点我收藏+]

标签:调查   jpeg   多个   高可用   --   sql   char   主从   tps   

进行主从配置的原因:

Master(主数据库)负责写操作的负载,也就是说一切写的操作都在Master上进行,而读的操作则分摊到Slave(从数据库)上进行。这样一来的可以大大提高读取的效率。在一般的互联网应用中,经过一些数据调查得出结论,读/写的比例大概在 10:1左右 ,也就是说大量的数据操作是集中在读的操作,这也就是为什么我们会有多个Slave的原因。但是为什么要分离读和写呢?熟悉DB的研发人员都知道,写操作涉及到锁的问题,不管是行锁还是表锁还是块锁,都是比较降低系统执行效率的事情。我们这样的分离是把写操作集中在一个节点上,而读操作其其他的N个节点上进行,从另一个方面有效的提高了读的效率,保证了系统的高可用性。
$config = array();

//主库配置
$config[‘db‘][‘master‘][‘host‘] = ‘localhost‘;
$config[‘db‘][‘master‘][‘username‘] = ‘root‘;
$config[‘db‘][‘master‘][‘password‘] = ‘root‘;
$config[‘db‘][‘master‘][‘port‘] = ‘3306‘;
$config[‘db‘][‘master‘][‘database‘] = ‘weiqing‘;
$config[‘db‘][‘master‘][‘charset‘] = ‘utf8‘;
$config[‘db‘][‘master‘][‘pconnect‘] = 0;
$config[‘db‘][‘master‘][‘tablepre‘] = ‘ims_‘;

//从库配置 主从库配置应当一致
$config[‘db‘][‘slave_status‘] = false;            //是否开启主从配置
$config[‘db‘][‘slave‘][‘1‘][‘host‘] = ‘‘;         
$config[‘db‘][‘slave‘][‘1‘][‘username‘] = ‘‘;
$config[‘db‘][‘slave‘][‘1‘][‘password‘] = ‘‘;
$config[‘db‘][‘slave‘][‘1‘][‘port‘] = ‘3307‘;
$config[‘db‘][‘slave‘][‘1‘][‘database‘] = ‘‘;
$config[‘db‘][‘slave‘][‘1‘][‘charset‘] = ‘utf8‘;
$config[‘db‘][‘slave‘][‘1‘][‘pconnect‘] = 0;
$config[‘db‘][‘slave‘][‘1‘][‘tablepre‘] = ‘ims_‘;
$config[‘db‘][‘slave‘][‘1‘][‘weight‘] = 0;


$config[‘db‘][‘common‘][‘slave_except_table‘] = array(‘core_sessions‘);


// -------------------------- CONFIG COOKIE --------------------------- //
$config[‘cookie‘][‘pre‘] = ‘c432_‘;
$config[‘cookie‘][‘domain‘] = ‘‘;
$config[‘cookie‘][‘path‘] = ‘/‘;


// -------------------------- CONFIG SETTING --------------------------- //
$config[‘setting‘][‘charset‘] = ‘utf-8‘;
$config[‘setting‘][‘cache‘] = ‘memcache‘;
$config[‘setting‘][‘timezone‘] = ‘Asia/Shanghai‘;
$config[‘setting‘][‘memory_limit‘] = ‘256M‘;
$config[‘setting‘][‘filemode‘] = 0644;
$config[‘setting‘][‘authkey‘] = ‘4c2c9fd4‘;
$config[‘setting‘][‘founder‘] = ‘1‘;
$config[‘setting‘][‘development‘] = 1;
$config[‘setting‘][‘referrer‘] = 0;
$config[‘setting‘][‘https‘] = 0;


// -------------------------- CONFIG UPLOAD --------------------------- //
$config[‘upload‘][‘image‘][‘extentions‘] = array(‘gif‘, ‘jpg‘, ‘jpeg‘, ‘png‘);
$config[‘upload‘][‘image‘][‘limit‘] = 5000;
$config[‘upload‘][‘attachdir‘] = ‘attachment‘;
$config[‘upload‘][‘audio‘][‘extentions‘] = array(‘mp3‘);
$config[‘upload‘][‘audio‘][‘limit‘] = 5000;


// -------------------------- CONFIG MEMCACHE --------------------------- //
$config[‘setting‘][‘memcache‘][‘server‘] = ‘127.0.0.1‘;
$config[‘setting‘][‘memcache‘][‘port‘] = 11211;
$config[‘setting‘][‘memcache‘][‘pconnect‘] = 1;
$config[‘setting‘][‘memcache‘][‘timeout‘] = 30;
$config[‘setting‘][‘memcache‘][‘session‘] = 1;
$config[‘setting‘][‘memcache‘][‘sql‘] = 1;


// -------------------------- CONFIG PROXY --------------------------- //
$config[‘setting‘][‘proxy‘][‘host‘] = ‘‘;
$config[‘setting‘][‘proxy‘][‘auth‘] = ‘‘;

// 积分抵扣
$config[‘setting‘][‘redis‘][‘server‘] = ‘‘;
$config[‘setting‘][‘redis‘][‘port‘] = 6379;
$config[‘setting‘][‘redis‘][‘pconnect‘] = 0;
$config[‘setting‘][‘redis‘][‘requirepass‘] = ‘‘;
$config[‘setting‘][‘redis‘][‘timeout‘] = 30;

微擎主从配置

标签:调查   jpeg   多个   高可用   --   sql   char   主从   tps   

原文地址:https://www.cnblogs.com/isuansuan/p/9795126.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!