Discuz! X2.5读写分离

Discuz! X2.5内置了读写分离的功能,方便一些负载比较大的站点使用,降低服务器的负载。但Discuz! X 2.5 默认未开启此功能,需要在配置文件中做相应的修改,此功能才会开启。下面介绍一下开启Discuz! X 2.5读写分离的设置方法:

1、前期准备

在配置读写分离之前,需要在数据库服务器上先配置好MySQL主从设置,设置方法详见 MySQL主从设置

2、调整配置

打开X2的配置文件,config/config_global.php:

编辑

$_config['db']['common']['slave_except_table'] = '';

改为

$_config['db']['common']['slave_except_table'] = 'common_session';

然后在刚才编辑的那行下面加入从库配置:

$_config['db']['slave']['1']['dbhost'] = '192.168.1.2';

$_config['db']['slave']['1']['dbuser'] = 'root';

$_config['db']['slave']['1']['dbpw'] = 'password';

$_config['db']['slave']['1']['dbcharset'] = 'gbk';

$_config['db']['slave']['1']['pconnect'] = '0';

$_config['db']['slave']['1']['dbname'] = 'discuz';

$_config['db']['slave']['1']['tablepre'] = 'pre_';

保存后即可生效。

如果要添加多台从库,那么可以继续添加:

$_config['db']['slave']['2']['dbhost'] = '192.168.1.3;

$_config['db']['slave']['2']['dbuser'] = 'root';

$_config['db']['slave']['2']['dbpw'] = 'password';

$_config['db']['slave']['2']['dbcharset'] = 'gbk';

$_config['db']['slave']['2']['pconnect'] = '0';

$_config['db']['slave']['2']['dbname'] = 'discuz';

$_config['db']['slave']['2']['tablepre'] = 'pre_';

posted @ 2015-04-22 11:43  Oo一切都值得  阅读(548)  评论(0编辑  收藏  举报