开源OA办公平台搭建教程:基于nginx的快速集群部署-上下文分发

178 阅读4分钟

此配置适合o2集群部署或者外网访问o2server服务(如移动端h5方式访问o2)

此配置需要o2server V5.2及以上版本

主机信息

主机1:172.16.98.8(linux)

主机2:172.16.98.9(linux)

集群需求

172.16.98.8:WEB服务器,应用服务器,文件存储服务器,中心服务器

172.16.98.9:WEB服务器,应用服务器,文件存储服务器,中心服务器

数据库

mysql数据库

nginx访问域名及端口

域名:qmx.o2oa.net(可以用ip,如果域名没有解析需要配置hosts)

端口:80(o2web服务器、o2应用服务器、o2中心服务器)

分发规则(下面的上下文(如:/dev/web)不是固定的,可以根据自身需要需改):

nginx80端口匹配的上下文

o2端口服务

/dev/web/

8080(o2web服务器)

/dev/app/

20020(o2应用服务器)

/dev/center/

20030(o2中心服务器)

配置步骤

一、配置节点标识

1、在主机172.16.98.8的o2server/local目录中修改或者新增文件node.cfg,修改内容为主机的域名或者IP;

主机172.16.98.8的节点标识文件配置

172.16.98.8

2、在主机172.16.98.9的o2server/local目录中修改或者新增文件node.cfg,修改内容为主机的域名或者IP;

主机172.16.98.9的节点标识文件配置

172.16.98.9

二、配置node文件

1、从172.16.98.8主机的o2server/configSample目录中copy文件node_127.0.0.1.json到o2server/config目录,命名为node_172.16.98.8.json,再拷贝一份命名为node_172.16.98.9.json;

2、修改node_172.16.98.8.json文件如下(红色部分需关注):

{

"enable": true,

"isPrimaryCenter": true,

"center": {

"enable": true,

"order": 1.0,

"sslEnable": false,

"redeploy": true,

"port": 20030.0,

"httpProtocol": "",

"proxyHost": "qmx.o2oa.net",

"proxyPort": 20030.0,

"scanInterval": 0.0,

"configApiEnable": true,

"statEnable": true,

"statExclusions": "*.js,*.gif,*.jpg,*.png,*.css,*.ico",

"maxFormContent": 20.0

},

"application": {

"enable": true,

"port": 20020.0,

"sslEnable": false,

"proxyHost": "qmx.o2oa.net",

"proxyPort": 20020,

"redeploy": true,

"scanInterval": 0.0,

"includes": [],

"excludes": [],

"weights": [],

"scheduleWeights": [],

"statEnable": true,

"statExclusions": "*.js,*.gif,*.jpg,*.png,*.css,*.ico",

"maxFormContent": 20.0

},

"web": {

"enable": true,

"port": 8080.0,

"sslEnable": false,

"proxyHost": "",

"weight": 100.0,

"dirAllowed": false,

"statEnable": false,

"statExclusions": "*.gif,*.jpg,*.png,*.ico",

"cacheControlMaxAge": 0.0

},

"data": {

"enable": false,

"tcpPort": 20050.0,

"webPort": 20051.0,

"includes": [],

"excludes": [],

"jmxEnable": false,

"cacheSize": 512.0,

"logLevel": "WARN",

"maxTotal": 50.0,

"maxIdle": 0.0,

"statEnable": true,

"statFilter": "mergeStat",

"slowSqlMillis": 2000.0

},

"storage": {

"enable": true,

"port": 20040.0,

"sslEnable": false,

"name": "251",

"accounts": [],

"prefix": "",

"deepPath": false

},

...

}

3、修改node_172.16.98.9.json文件如下(红色部分需关注):

{

"enable": true,

"isPrimaryCenter": true,

"center": {

"enable": true,

"order": 2.0,

"sslEnable": false,

"redeploy": true,

"port": 20030.0,

"httpProtocol": "",

"proxyHost": "qmx.o2oa.net",

"proxyPort": 20030.0,

"scanInterval": 0.0,

"configApiEnable": true,

"statEnable": true,

"statExclusions": "*.js,*.gif,*.jpg,*.png,*.css,*.ico",

"maxFormContent": 20.0

},

"application": {

"enable": true,

"port": 20020.0,

"sslEnable": false,

"proxyHost": "qmx.o2oa.net",

"proxyPort": 20020.0,

"redeploy": true,

"scanInterval": 0.0,

"includes": [],

"excludes": [],

"weights": [],

"scheduleWeights": [],

"statEnable": true,

"statExclusions": "*.js,*.gif,*.jpg,*.png,*.css,*.ico",

"maxFormContent": 20.0

},

"web": {

"enable": true,

"port": 8080.0,

"sslEnable": false,

"proxyHost": "",

"weight": 100.0,

"dirAllowed": false,

"statEnable": false,

"statExclusions": "*.gif,*.jpg,*.png,*.ico",

"cacheControlMaxAge": 0.0

},

"data": {

"enable": false,

"tcpPort": 20050.0,

"webPort": 20051.0,

"includes": [],

"excludes": [],

"jmxEnable": false,

"cacheSize": 512.0,

"logLevel": "WARN",

"maxTotal": 50.0,

"maxIdle": 0.0,

"statEnable": true,

"statFilter": "mergeStat",

"slowSqlMillis": 2000.0

},

"storage": {

"enable": true,

"port": 20040.0,

"sslEnable": false,

"name": "252",

"accounts": [],

"prefix": "",

"deepPath": false

},

...

}

4、从172.16.98.8主机的o2server/configSample目录中copy文件externalDataSources_mysql.json到o2server/config目录,命名为externalDataSources.json,然后修改配置文件中数据库相应的配置信息;

5、从172.16.98.8上复制修改好的node_172.16.98.8.json、node_172.16.98.9.json和externalDataSources.json文件到172.16.98.9的o2server/config目录。

三、配置路径映射

1、分别从172.16.98.8和172.16.98.9主机的o2server/configSample目录中copy文件portal.json到o2server/config目录。

2、修改portal.json(修改urlMapping的内容,其他保持不变)

{
  "indexPage": {
    "enable": false,
    "portal": "",
    "page": ""
  },
  "loginPage": {
    "enable": false,
    "portal": "",
    "page": ""
  },
  "urlMapping": {
    "qmx.o2oa.net:20020": "qmx.o2oa.net/dev/app",
    "qmx.o2oa.net:20030": "qmx.o2oa.net/dev/center"
  },
  "###indexPage": "定制首页面设置.###",
  "###loginPage": "定制登录页面设置.###"
}

四、启动服务器

1、进入o2server目录,执行./start_linux.sh,当显示出o2命令信息时输入start启动服务,观察center服务、app服务器、web服务启动是否正常;

2、当两台服务器都启动正常后进入nginx服务器,telnet这两台服务器3个服务的端口,确保nginx到o2服务器网络正常;

五、配置nginx

nginx代理转发逻辑:

进入nginx的nginx.conf文件,修改配置(参考如下),然后重启nginx。

http {

include mime.types;

default_type application/octet-stream;

charset utf-8;

#access_log logs/access.log main;

client_max_body_size 100m; # 数据包大小限制

sendfile on;

tcp_nopush on;

keepalive_timeout 65;

#gzip on;

upstream webServer { # Server: 分发名

server 172.16.98.8:8080; # 分发地址1

server 172.16.98.9:8080; # 分发地址2

}

upstream appServer {

server 172.16.98.8:20020;

server 172.16.98.9:20020;

}

upstream centerServer {

server 172.16.98.8:20030;

server 172.16.98.9:20030;

}

server {

listen 80;

server_name localhost;

proxy_http_version 1.1;

proxy_read_timeout 300s;

proxy_set_header Upgrade $http_upgrade; # 支持websocket连接

proxy_set_header Connection "upgrade"; # 支持websocket连接

proxy_set_header Host $host;

proxy_set_header X-Real-IP $remote_addr;

proxy_set_header REMOTE-HOST $remote_addr;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

location /dev/web/ {

root html;

index index.html;

proxy_pass http://webServer/;

}

location /dev/app/ {

proxy_pass http://appServer/;

}

location /dev/center/ {

proxy_pass http://centerServer/;

}

}

}

六、测试验证

1、浏览器访问地址:qmx.o2oa.net/dev/web 使用 xadmin/o2登录;

2、进入98.8主机的o2server目录,键入./stop_linux.sh ,刷新页面正常访问;

3、进入98.9主机的o2server目录,键入./stop_linux.sh ,刷新页面出现502 Bad Gateway;

4、进入98.8主机的o2server目录,键入./start_linux.sh进入命令行后键入start ,刷新页面正常访问;