**系統架構流程圖:**

## 配置:
**準備工作:**
* 1臺負載均衡服務器
* 1臺redis服務器,如果沒有可以和負載均衡服務器放在一起
* 1臺云數據庫作為主數據庫(master)
* 至少兩臺以上的服務器節點,并且在節點上面新建從數據庫(slave)
* 對數據庫主從同步或負載均衡不熟悉的童鞋請移步查看教程,[點擊查看]([http://www.hmoore.net/caike\_/diary/1284155](http://www.hmoore.net/caike_/diary/1284155))
**負載均衡配置:**
*****
### 1、打開nginx配置文件并修改以下信息:
在`server`配置一下內容:
```
server {
listen 80;
server_name wq2.mrye.xin;
}
```
添加負載均衡節點,在`http`底下添加以下內容:
```
upstream wq2.mrye.xin {
#節點一
server 47.92.100.107:85 weight=8;
#節點二
server 47.92.115.251:85 weight=2;
}
```
在upstream模塊配置完成后,要讓指定的訪問反向代理到服務器列表,所以我們需要在`server`底下繼續添加以下內容:
```
location ~ .*$ {
index index.jsp index.html;
proxy_pass http://wq2.mrye.xin ;
}
```
以上是根據權重來達到負載均衡,如以上策略不符合實際要求,請移步查看[nginx負載均衡配置
]([http://www.hmoore.net/caike\_/diary/1001782](http://www.hmoore.net/caike_/diary/1001782))
#### 2、測試
打開瀏覽器訪問`wq2.mrye.xin`并查看其效果
**mysql主從配置:**
*****
**php存儲方式配置:**
*****
#### 1、配置session共享
第一種方式,通過配置微擎自帶配置文件實現session共享,如下:
文件路徑位于:`根目錄/data/config.php`
```
//緩存類型
$config['setting']['cache'] = 'redis';
//redis配置
$config['setting']['redis']['server'] = '127.0.0.1';
$config['setting']['redis']['port'] = 6379;
$config['setting']['redis']['pconnect'] = 0;
$config['setting']['redis']['requirepass'] = '';
$config['setting']['redis']['timeout'] = 1;
//指定session存儲方式
$config['setting']['redis']['session'] = 1;
```
第二種方式,通過配置`php.ini`實現session共享,如下:
在`php.ini` 中找到`session.save_handle `和 `session.save_path`并根據以下修改:
沒有密碼時使用:
```
session.save_handler = Redis
session.save_path = "tcp://127.0.0.1:6379"
```
有密碼時使用:
```
session.save_handler = Redis
session.save_path = "tcp://127.0.0.1:6379?persistent=1&database=10&auth=myredisG506"
```
#### 2、php`session`測試
節點一(存):
訪問路徑:[http://wq2.mrye.xin/web/index.php?c=site&a=entry&do=test-index&m=og\_test](http://wq2.mrye.xin/web/index.php?c=site&a=entry&do=test-index&m=og_test),該類文件路徑:`根目錄/addons/og_test/inc/web/Test.php`
```
namespace inc\web;
class Test extends \Og_testModuleSite
{
public function index()
{
session('name','mrye');
session('age',20);
session('hegiht',173);
}
}
```
節點二(取):
訪問路徑:[http://wq2.mrye.xin/web/index.php?c=site&a=entry&do=test-get&m=og\_test](http://wq2.mrye.xin/web/index.php?c=site&a=entry&do=test-get&m=og_test),該類文件路徑:`根目錄/addons/og_test/inc/web/Test.php`
```
namespace inc\web;
class Test extends \Og_testModuleSite
{
public function get()
{
echo 'name:'.session('name');
echo 'age:'.session('age');
echo 'height:'.session('hegiht');
}
}
```
**系統配置:**
*****
數據庫配置:
```
//主數據庫(遠程數據庫)
$config['db']['master']['host'] = 'rm-2ze5wdzun67eieur7qo.mysql.rds.aliyuncs.com';
$config['db']['master']['username'] = 'haojigou';
$config['db']['master']['password'] = 'Ck6688!@#..';
$config['db']['master']['port'] = '3306';
$config['db']['master']['database'] = 'haojigou';
$config['db']['master']['charset'] = 'utf8';
$config['db']['master']['pconnect'] = 0;
$config['db']['master']['tablepre'] = 'ims_';
//主數據庫(本地數據庫)
$config['db']['slave_status'] = true;
$config['db']['slave']['1']['host'] = '127.0.0.1';
$config['db']['slave']['1']['username'] = 'haojigou';
$config['db']['slave']['1']['password'] = 'abcdsfgfdsgdg';
$config['db']['slave']['1']['port'] = '3306';
$config['db']['slave']['1']['database'] = 'haojigou';
$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['setting']['cache'] = 'redis';
```