开源OA办公平台搭建教程:基于nginx的快速集群部署——端口分发
主机信息
主机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服务器)、82(o2应用服务器,可以为其他没有冲突的端口)、83(o2中心服务器,可以为其他没有冲突的端口)
分发规则:
nginx端口 |
o2端口服务 |
80 | 8080(o2web服务器) |
82 | 20020(o2应用服务器) |
83 | 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 |
二、准备配置文件
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": 83.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": 82.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": "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": 83.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": 82.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、进入o2server目录,执行./start_linux.sh,当显示出o2命令信息时输入start启动服务,观察center服务、app服务器、web服务启动是否正常;
2、当两台服务器都启动正常后进入nginx服务器,telnet这两台服务器3个服务的端口,确保nginx到o2服务器网络正常;
四、配置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 { ip_hash; 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; location / { root html; index index.html; proxy_pass http://webServer; 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; } } server { listen 82; server_name localhost; location / { proxy_pass http://appServer; 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; } } server { listen 83; server_name localhost; location / { proxy_pass http://centerServer; 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; } } } |
|
五、测试验证
1、浏览器访问地址:http://qmx.o2oa.net/ 使用 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 ,刷新页面正常访问;