微擎主从配置

Posted isuansuan

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了微擎主从配置相关的知识,希望对你有一定的参考价值。

进行主从配置的原因:

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;








































































以上是关于微擎主从配置的主要内容,如果未能解决你的问题,请参考以下文章

redis主从库配置

8.31 MySQL主从配置准备工作配置主配置从测试主从同步

mysql主从配置

mysql主从配置

MySQL的主从介绍配置主配置从测试主从同步

Redis主从复制的配置过程