说明:
1、请用一台服务器Nginx作主节点,其他做备节点,并且开通ssh端口:22
2、编写shell脚本,执行sync_conf.sh就能执行多台文件同步
3、如果Nginx主节点删除文件,也会同步到其他备节点
#! /bin/bash
#******************************************************
# Author : 枫叶20214
# Last modified : 2023-02-21
# Filename : rsync-conf.sh
# Description : 同步Nginx证书和配置文件
#*******************************************************
# 同步到172.16.2.8
rsync -auv --delete -e 'ssh -p 777' --exclude 'rsync-conf.sh' /usr/local/openresty/nginx/conf/* root@172.16.2.8:/usr/local/openresty/nginx/conf
rsync -auv --delete -e 'ssh -p 777' --exclude 'rsync-conf.sh' /usr/local/openresty/nginx/cert/* root@172.16.2.8:/usr/local/openresty/nginx/cert
# 同步到172.16.2.9
rsync -auv --delete -e 'ssh -p 777' --exclude 'rsync-conf.sh' /usr/local/openresty/nginx/conf/* root@172.16.2.9:/usr/local/openresty/nginx/conf
rsync -auv --delete -e 'ssh -p 777' --exclude 'rsync-conf.sh' /usr/local/openresty/nginx/cert/* root@172.16.2.9:/usr/local/openresty/nginx/cert
sleep 2
# 导入Nginx文件
ssh root@172.16.2.8 -p 777 /usr/local/openresty/nginx/sbin/nginx -s reload
ssh root@172.16.2.9 -p 777 /usr/local/openresty/nginx/sbin/nginx -s reload