永中文檔在線轉(zhuǎn)換預(yù)覽基于nginx配置部署方案
永中文檔在線轉(zhuǎn)換預(yù)覽雙活實(shí)現(xiàn)方案
永中文檔在線轉(zhuǎn)換預(yù)覽服務(wù) 是永中軟件股份有限公司基于十多年核心技術(shù)積累、面向移動(dòng)互聯(lián)領(lǐng)域推出的 一款文檔處理軟件。永中采用自主可控核心技術(shù),具備快速技術(shù)和服務(wù)響應(yīng)能力,把文檔原樣輸出為 HTML,圖片等,即點(diǎn)即得、無(wú)需下載、保護(hù)文檔隱私,快速高效,輕松實(shí)現(xiàn)文檔在線安全閱讀。?
實(shí)現(xiàn)目標(biāo)
- 通過(guò)nginx實(shí)現(xiàn)業(yè)務(wù)fcsserver負(fù)載均衡,后端可以動(dòng)態(tài)擴(kuò)展應(yīng)用服務(wù)器
- nginx通過(guò)keepalived實(shí)現(xiàn)高可用,解決單點(diǎn)故障
- 通過(guò)keepalived實(shí)現(xiàn)nginx雙活配置,解決nginx主備資源使用率50%問題
- 通過(guò)dns輪詢解析域名到雙活vip,達(dá)到負(fù)載均衡效果
- 后期nginx達(dá)到瓶頸應(yīng)考慮lvs+keepalived+nginx架構(gòu),動(dòng)態(tài)擴(kuò)展nginx服務(wù)器
環(huán)境準(zhǔn)備
- 服務(wù)器可以連通外網(wǎng)或者有內(nèi)網(wǎng)yum源服務(wù)器,本次實(shí)驗(yàn)服務(wù)器可連通外網(wǎng)
- nginx01和nginx02服務(wù)器需要在同一網(wǎng)段的網(wǎng)絡(luò)內(nèi)
- 保證各服務(wù)器之前網(wǎng)絡(luò)互通
- 保證服務(wù)器的防火墻和selinux關(guān)閉
- 必須對(duì)外提供域名訪問,否則只能使用其中一個(gè)vip
- 內(nèi)網(wǎng)部署DNS服務(wù)器,模擬DNS輪詢解析
1、網(wǎng)絡(luò)架構(gòu)

2、實(shí)驗(yàn)服務(wù)器分布
| 主機(jī) | ip | 操作系統(tǒng) | 軟件 | 端口 | vip |
|---|---|---|---|---|---|
| nginx01 | 192.168.56.101 | Centos7.6 | nginx keepalived | 80 | 192.168.56.200 |
| nginx02 | 192.168.56.106 | Centos7.6 | nginx keepalived | 80 | 192.168.56.201 |
| fcs01 | 192.168.56.101 | Centos7.6 | tomcat | 8080 | |
| fcs02 | 192.168.56.106 | Centos7.6 | tomcat | 8080 | |
| 共享存儲(chǔ) | 192.168.56.108 | Centos7.6 | nfs | ||
| 緩存 | 192.168.56.108 | Centos7.6 | redis | 6379 | |
| 內(nèi)部DNS | 192.168.56.108 | Centos7.6 | bind | 53 |
3、redis
部署服務(wù)器:192.168.56.108
3.1 配置redis
/etc/redis.conf
# 監(jiān)聽地址 bind 0.0.0.0 # 認(rèn)證密碼 requirepass yozosoft
3.2 啟動(dòng)redis
systemctl enable redis --now && systemctl status redis

4、nfs
4.1 配置nfs
192.168.56.108(服務(wù)端)
# 創(chuàng)建存儲(chǔ)目錄 mkdir -p /opt/yozo/data # 修改權(quán)限 chown -R nfsnobody.nfsnobody /opt/yozo/data # 修改配置文件 vim /etc/exports /opt/yozo/data 192.168.56.0/24(rw,sync,all_squash)
192.168.56.101/192.168.56.106(客戶端)
# 創(chuàng)建掛載點(diǎn) mkdir -p /opt/yozo/data # 掛載nfs共享目錄 mount -t nfs 192.168.56.108:/opt/yozo/data /opt/yozo/data
4.2 啟動(dòng)nfs
systemctl enable rpcbind nfs --now && systemctl status rpcbind nfs

5、fcsserver
部署服務(wù)器:
192.168.56.101(fcsserver01)
192.168.56.106(fcsserver02)
5.1 部署fcs
以tomcat為中間件,本次實(shí)驗(yàn)fcs安裝目錄
/opt/yozo/fcsserver/webapps/fcsserver,/opt/yozo/fcsserver為解壓后的tomcat
部署項(xiàng)目包
mkdir opt/yozo/fcsserver/webapps/fcsserver -p unzip fcscloud.war -d opt/yozo/fcsserver/webapps/fcsserver
修改fcsserver配置文件
# /opt/yozo/fcsserver/webapps/fcsserver/WEB-INF/classes/config.properties inputDir=/opt/yozo/data/fcsdata/input # 必須指定掛載共享存儲(chǔ)目錄的 outputDir=/opt/yozo/data/fcsdata/output # 如果不提供域名,就只能配置其中一個(gè)vip;如果配置為域名,則緩存后,通過(guò)vip和fcsserver的ip將不能訪問轉(zhuǎn)換的緩存文件 viewDomain=http://www.fcsserver.com/fcsserver/
# /opt/yozo/fcsserver/webapps/fcsserver/WEB-INF/classes/application.yml
cache: #采用哪種緩存數(shù)據(jù)方式
type: redis #local,redis,mysql(local模式只適用于單機(jī),集群部署不支持)
redis:
enable: true #redis開關(guān)(預(yù)覽設(shè)置權(quán)限時(shí)需要使用redis,并發(fā)和異步waitting機(jī)制使用redis,必開)
redis:
database: 1 # Redis數(shù)據(jù)庫(kù)索引(默認(rèn)為0)
timeout: 10000 #設(shè)置客戶端超時(shí)時(shí)間,單位是毫秒,默認(rèn)為2000
password: yozosoft #密碼
#單機(jī)版
host: 192.168.56.108
port: 6379
# /opt/yozo/fcsserver/webapps/fcsserver/WEB-INF/classes/ <property name="LOG_HOME">../logs</property>
5.2 配置fcs系統(tǒng)服務(wù)
配置fcsserver.service
# cat /usr/lib/systemd/system/fcsserver.service [Unit] Description=fcsserver Service. After=network.target [Service] Type=forking Environment="PATH=/opt/yozo/jdk-8u251-amd64/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin" WorkingDirectory=/opt/yozo/fcsserver/bin ExecStart=/opt/yozo/fcsserver/bin/startup.sh Restart=always PrivateTmp=true # 可以指定相關(guān)用戶啟動(dòng)fcsserver # User=yozo # Group=yozo LimitNOFILE=65536 [Install] WantedBy=multi-user.target
如果以普通用戶啟動(dòng),需要將tomcat目錄屬主屬組設(shè)置成相應(yīng)賬戶
# 此次實(shí)驗(yàn)以yozo用戶啟動(dòng) chown -R yozo. /opt/yozo/fcsserver
5.3 啟動(dòng)fcs
systemctl enable fcsserver --now && systemctl status fcsserver

6、nginx
部署服務(wù)器:
192.168.56.101(nginx01)
192.168.56.106(nginx02)
6.1 配置nginx
/etc/nginx/conf.d/fcsserver.conf配置
server {
....
location ~ /fcsserver {
add_header Cache-Control private,no-store,max-age=0,no-cache,must-revalidate,post-check=0,pre-check=0;
proxy_redirect off;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded_Proto "http";
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_request_buffering off;
proxy_read_timeout 7200;
proxy_send_timeout 7200;
proxy_pass http://fcsserver;
}
....
}
upstream fcsserver {
server 192.168.56.101:8080 fail_timeout=60s;
server 192.168.56.106:8080 fail_timeout=60s;
keepalive 256;
}
6.2 啟動(dòng)nginx
systemctl enable nginx --now && systemctl status nginx

7、keepalived
部署服務(wù)器:
192.168.56.101(nginx01)
192.168.56.106(nginx02)
7.1 配置keepalived
7.1.1 nginx01配置
/etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
router_id proxy1
}
vrrp_script chk_nginx {
script "/etc/keepalived/check_nginx.sh"
interval 2
weight 20
fall 3
rise 2
}
vrrp_instance VI_1 {
state MASTER
interface enp0s3
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.56.200
}
track_script {
chk_nginx
}
}
vrrp_instance VI_2 {
state BACKUP
interface enp0s3
virtual_router_id 52
priority 90
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.56.201
}
track_script {
chk_nginx
}
}
7.1.2 nginx02配置
# 備份keepalived.conf mv /etc/keepalived/keepalived.conf /etc/keepalived/keepalived.confbak
/etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
router_id proxy2
}
vrrp_script chk_nginx {
script "/etc/keepalived/check_nginx.sh"
interval 2
weight 20
fall 3
rise 2
}
vrrp_instance VI_1 {
state BACKUP
interface enp0s8
virtual_router_id 51
priority 90
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.56.200
}
track_script {
chk_nginx
}
}
vrrp_instance VI_2 {
state MASTER
interface enp0s8
virtual_router_id 52
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.56.201
}
track_script {
chk_nginx
}
}
雙機(jī)/etc/keepalived/check_nginx.sh
#!/bin/bash
#時(shí)間變量,用于記錄日志
d=`date --date today +%Y%m%d_%H:%M:%S`
#計(jì)算nginx進(jìn)程數(shù)量
n=`ps -C nginx --no-heading|wc -l`
#如果進(jìn)程為0,則啟動(dòng)nginx,并且再次檢測(cè)nginx進(jìn)程數(shù)量,
#如果還為0,說(shuō)明nginx無(wú)法啟動(dòng),此時(shí)需要關(guān)閉keepalived
if [ $n -eq "0" ]; then
/etc/init.d/nginx start
n2=`ps -C nginx --no-heading|wc -l`
if [ $n2 -eq "0" ]; then
echo "$d nginx down,keepalived will stop" >> /var/log/check_ng.log
systemctl stop keepalived
fi
fi
7.2 啟動(dòng)keepalived
systemctl enable keepalived --now && systemctl status keepalived

nginx01

nginx02

7.3 模擬故障
7.3.1 nginx01手動(dòng)關(guān)閉nginx
nginx故障后,keepalived會(huì)自動(dòng)啟動(dòng)nginx

7.3.2 nginx01手動(dòng)關(guān)閉keepalived
nginx01的vip將會(huì)綁定到nginx02上面,nginx02將會(huì)出現(xiàn)2個(gè)vip,2個(gè)vip均可以訪問fcsserver




8、DNS服務(wù)器部署
用于模擬公網(wǎng)DNS輪詢解析,實(shí)際使用中是在域名提供商處配置指向映射外網(wǎng)ip
8.1 配置dns
/etc/named.conf
zone "fcsserver.com" IN {
type master;
file "fcsserver.com.zone";
};
zone "56.168.192.in-addr.arpa" IN {
type master;
file "192.168.56.zone";
};
/var/named/fcsserver.com.zone
$TTL 86400
@ IN SOA tom jerry ( ; tom & jerry 這兩個(gè)參數(shù)本應(yīng)是主機(jī)名和郵件地址,這里隨便填寫,沒有問題
42 ; serial (d. adams)
3H ; refresh
15M ; retry
1W ; expiry
1D ) ; minimum
IN NS ns.fcsserver.com. ; notice : don't forget the dot in the end
IN MX 10 mail.fcsserver.com.
www IN A 192.168.56.200
www IN A 192.168.56.201
ns IN A 192.168.56.108
mail IN A 192.168.56.108
/var/named/192.168.56.zone
$TTL 86400
@ IN SOA ns.fcsserver.com. root (
1997022700 ; Serial
28800 ; Refresh
14400 ; Retry
3600000 ; Expire
86400 ) ; Minimum
IN NS ns.fcsserver.com.
200 IN PTR www.fcsserver.com.
201 IN PTR www.fcsserver.com.
108 IN PTR mail.fcsserver.com.
108 IN PTR ns.fcsserver.com.
修改權(quán)限
chown named. /var/named/ -R
8.2 啟動(dòng)dns服務(wù)
systemctl enable named --now && systemctl status named

9、驗(yàn)證
目標(biāo):本次實(shí)驗(yàn)有2個(gè)vip 192.168.56.200 和 192.168.56.201,需要驗(yàn)證www.fcsserver.com分別解析到2個(gè)vip上,并確認(rèn)每個(gè)vip后端服務(wù)正??捎?/p>
9.1 客戶端dns配置
測(cè)試期間,禁用其他網(wǎng)卡,只留虛擬機(jī)網(wǎng)卡

添加DNS


9.2 DNS緩存清理


9.3 域名訪問測(cè)試
測(cè)試之前需要確認(rèn)此次DNS解析是否指向所需測(cè)試的VIP,如果不是請(qǐng)刷新DNS緩存
需要測(cè)試www.fcsserver.com --> 192.168.56.200和www.fcsserver.com --> 192.168.56.201
文件轉(zhuǎn)換測(cè)試

轉(zhuǎn)換文件訪問測(cè)試

注:fcsserver的配置文件中viewDomain配置為域名,故轉(zhuǎn)換文件預(yù)覽連接只能通過(guò)www.fcsserver.com可以正常訪問,通過(guò)vip、nginx ip、fcsserver ip均不可以訪問
以上就是永中文檔在線轉(zhuǎn)換預(yù)覽雙活基于nginx的實(shí)現(xiàn)方案的詳細(xì)內(nèi)容,更多關(guān)于nginx永中文檔在線轉(zhuǎn)換預(yù)覽的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
Nginx負(fù)載均衡下的webshell連接的實(shí)現(xiàn)
在解決shell文件上傳問題、命令執(zhí)行漂移等困難后,可實(shí)現(xiàn)正常的webshell上傳,本文主要介紹了Nginx負(fù)載均衡下的webshell連接的實(shí)現(xiàn),具有一定的參考價(jià)值,感興趣的可以了解一下2024-01-01
nginx: [warn] "log_format" directive used only on "http" lev
這篇文章主要介紹了nginx: [warn] "log_format" directive used only on "http" level 解決方法,需要的朋友可以參考下2014-08-08
Nginx配置HTTP強(qiáng)制跳轉(zhuǎn)到HTTPS的解決辦法
這篇文章主要給大家介紹了關(guān)于Nginx配置HTTP強(qiáng)制跳轉(zhuǎn)到HTTPS的解決辦法,當(dāng)Nginx配置https后通常需要將用戶http請(qǐng)求強(qiáng)制跳轉(zhuǎn)到https,需要的朋友可以參考下2023-08-08
Nginx跨域設(shè)置Access-Control-Allow-Origin無(wú)效的解決辦法
今天小編就為大家分享一篇關(guān)于Nginx跨域設(shè)置Access-Control-Allow-Origin無(wú)效的解決辦法,小編覺得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來(lái)看看吧2019-02-02

