目錄
- 永中文檔在線轉(zhuǎn)換預(yù)覽雙活實現(xiàn)方案
- 實現(xiàn)目標
- 環(huán)境準備
- 1、網(wǎng)絡(luò)架構(gòu)
- 2、實驗服務(wù)器分布
- 3、redis
- 3.1 配置redis
- 3.2 啟動redis
- 4、nfs
- 4.1 配置nfs
- 4.2 啟動nfs
- 5、fcsserver
- 5.1 部署fcs
- 5.2 配置fcs系統(tǒng)服務(wù)
- 5.3 啟動fcs
- 6、nginx
- 6.1 配置nginx
- 6.2 啟動nginx
- 7、keepalived
- 7.1 配置keepalived
- 7.2 啟動keepalived
- 7.3 模擬故障
- 8、DNS服務(wù)器部署
- 8.1 配置dns
- 8.2 啟動dns服務(wù)
- 9、驗證
- 9.1 客戶端dns配置
- 9.2 DNS緩存清理
- 9.3 域名訪問測試
永中文檔在線轉(zhuǎn)換預(yù)覽雙活實現(xiàn)方案
永中文檔在線轉(zhuǎn)換預(yù)覽服務(wù) 是永中軟件股份有限公司基于十多年核心技術(shù)積累、面向移動互聯(lián)領(lǐng)域推出的 一款文檔處理軟件。永中采用自主可控核心技術(shù),具備快速技術(shù)和服務(wù)響應(yīng)能力,把文檔原樣輸出為 HTML,圖片等,即點即得、無需下載、保護文檔隱私,快速高效,輕松實現(xiàn)文檔在線安全閱讀。?
實現(xiàn)目標
- 通過nginx實現(xiàn)業(yè)務(wù)fcsserver負載均衡,后端可以動態(tài)擴展應(yīng)用服務(wù)器
- nginx通過keepalived實現(xiàn)高可用,解決單點故障
- 通過keepalived實現(xiàn)nginx雙活配置,解決nginx主備資源使用率50%問題
- 通過dns輪詢解析域名到雙活vip,達到負載均衡效果
- 后期nginx達到瓶頸應(yīng)考慮lvs+keepalived+nginx架構(gòu),動態(tài)擴展nginx服務(wù)器
環(huán)境準備
- 服務(wù)器可以連通外網(wǎng)或者有內(nèi)網(wǎng)yum源服務(wù)器,本次實驗服務(wù)器可連通外網(wǎng)
- nginx01和nginx02服務(wù)器需要在同一網(wǎng)段的網(wǎng)絡(luò)內(nèi)
- 保證各服務(wù)器之前網(wǎng)絡(luò)互通
- 保證服務(wù)器的防火墻和selinux關(guān)閉
- 必須對外提供域名訪問,否則只能使用其中一個vip
- 內(nèi)網(wǎng)部署DNS服務(wù)器,模擬DNS輪詢解析
1、網(wǎng)絡(luò)架構(gòu)
2、實驗服務(wù)器分布
主機 | 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 | |
共享存儲 | 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 # 認證密碼 requirepass yozosoft
3.2 啟動redis
systemctl enable redis --now && systemctl status redis
4、nfs
4.1 配置nfs
192.168.56.108(服務(wù)端)
# 創(chuàng)建存儲目錄 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)建掛載點 mkdir -p /opt/yozo/data # 掛載nfs共享目錄 mount -t nfs 192.168.56.108:/opt/yozo/data /opt/yozo/data
4.2 啟動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為中間件,本次實驗fcs安裝目錄
/opt/yozo/fcsserver/webapps/fcsserver,/opt/yozo/fcsserver為解壓后的tomcat
部署項目包
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 # 必須指定掛載共享存儲目錄的 outputDir=/opt/yozo/data/fcsdata/output # 如果不提供域名,就只能配置其中一個vip;如果配置為域名,則緩存后,通過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模式只適用于單機,集群部署不支持) redis: enable: true #redis開關(guān)(預(yù)覽設(shè)置權(quán)限時需要使用redis,并發(fā)和異步waitting機制使用redis,必開) redis: database: 1 # Redis數(shù)據(jù)庫索引(默認為0) timeout: 10000 #設(shè)置客戶端超時時間,單位是毫秒,默認為2000 password: yozosoft #密碼 #單機版 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)用戶啟動fcsserver # User=yozo # Group=yozo LimitNOFILE=65536 [Install] WantedBy=multi-user.target
如果以普通用戶啟動,需要將tomcat目錄屬主屬組設(shè)置成相應(yīng)賬戶
# 此次實驗以yozo用戶啟動 chown -R yozo. /opt/yozo/fcsserver
5.3 啟動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 啟動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 } }
雙機/etc/keepalived/check_nginx.sh
#!/bin/bash #時間變量,用于記錄日志 d=`date --date today +%Y%m%d_%H:%M:%S` #計算nginx進程數(shù)量 n=`ps -C nginx --no-heading|wc -l` #如果進程為0,則啟動nginx,并且再次檢測nginx進程數(shù)量, #如果還為0,說明nginx無法啟動,此時需要關(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 啟動keepalived
systemctl enable keepalived --now && systemctl status keepalived
nginx01
nginx02
7.3 模擬故障
7.3.1 nginx01手動關(guān)閉nginx
nginx故障后,keepalived會自動啟動nginx
7.3.2 nginx01手動關(guān)閉keepalived
nginx01的vip將會綁定到nginx02上面,nginx02將會出現(xiàn)2個vip,2個vip均可以訪問fcsserver
8、DNS服務(wù)器部署
用于模擬公網(wǎng)DNS輪詢解析,實際使用中是在域名提供商處配置指向映射外網(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 這兩個參數(shù)本應(yīng)是主機名和郵件地址,這里隨便填寫,沒有問題 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 啟動dns服務(wù)
systemctl enable named --now && systemctl status named
9、驗證
目標:本次實驗有2個vip 192.168.56.200 和 192.168.56.201,需要驗證www.fcsserver.com分別解析到2個vip上,并確認每個vip后端服務(wù)正常可用
9.1 客戶端dns配置
測試期間,禁用其他網(wǎng)卡,只留虛擬機網(wǎng)卡
添加DNS
9.2 DNS緩存清理
9.3 域名訪問測試
測試之前需要確認此次DNS解析是否指向所需測試的VIP,如果不是請刷新DNS緩存
需要測試www.fcsserver.com –> 192.168.56.200和www.fcsserver.com –> 192.168.56.201
文件轉(zhuǎn)換測試
轉(zhuǎn)換文件訪問測試
注:fcsserver的配置文件中viewDomain配置為域名,故轉(zhuǎn)換文件預(yù)覽連接只能通過www.fcsserver.com可以正常訪問,通過vip、nginx ip、fcsserver ip均不可以訪問
以上就是永中文檔在線轉(zhuǎn)換預(yù)覽雙活基于nginx的實現(xiàn)方案的詳細內(nèi)容,更多關(guān)于nginx永中文檔在線轉(zhuǎn)換預(yù)覽的資料請關(guān)注其它相關(guān)文章!