惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
Secure Thoughts
B
Blog
MongoDB | Blog
MongoDB | Blog
GbyAI
GbyAI
博客园 - 【当耐特】
D
DataBreaches.Net
Apple Machine Learning Research
Apple Machine Learning Research
阮一峰的网络日志
阮一峰的网络日志
I
InfoQ
人人都是产品经理
人人都是产品经理
Microsoft Azure Blog
Microsoft Azure Blog
量子位
美团技术团队
Recent Announcements
Recent Announcements
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
M
MIT News - Artificial intelligence
O
OpenAI News
SecWiki News
SecWiki News
A
About on SuperTechFans
J
Java Code Geeks
B
Blog RSS Feed
Y
Y Combinator Blog
L
LangChain Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
Attack and Defense Labs
Attack and Defense Labs
小众软件
小众软件
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Martin Fowler
Martin Fowler
博客园 - 聂微东
雷峰网
雷峰网
有赞技术团队
有赞技术团队
Google DeepMind News
Google DeepMind News
T
The Exploit Database - CXSecurity.com
N
News and Events Feed by Topic
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Microsoft Security Blog
Microsoft Security Blog
Recorded Future
Recorded Future
P
Palo Alto Networks Blog
Blog — PlanetScale
Blog — PlanetScale
N
News | PayPal Newsroom
Scott Helme
Scott Helme
L
LINUX DO - 热门话题
F
Full Disclosure
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
The Hacker News
The Hacker News
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
U
Unit 42
博客园_首页
T
Tailwind CSS Blog
T
Tenable Blog

博客园 - 一起走过的路

Nginx GeoIP2 模块编译安装与配置指南(附防国外访问实战) MySQL查询当前连接数的语句 Apollo批量给新创建的用户授可编辑权限 物理机Jenkins接入K8s环境 ingress配置https报错certificate.lua:259: call(): failed to set DER private key: d2i_PrivateKey_bio() failed, context: ssl_certificate_by_lua* elk收集分析nginx日志,并绘制图形 Zabbix Scheduled reports中文乱码 kubernetes mysql-StatefulSet报错处理 Jenkins合并代码Git报错处理过程 zabbix密码复杂度有效期安全增强,符合三级等保要求。 archery关闭导出功能 自动同步bing壁纸 CentOS7更新OpenSSH8 elk监听Java日志发送微信报警 OPENVPN 同时连接多个VPN - 一起走过的路 nginx拒绝国外IP访问 keepalived健康检查及双主MySQL健康检查脚本 执迷不悟 splunk设置索引周期和索引大小
nginx集群同步方案
一起走过的路 · 2022-03-01 · via 博客园 - 一起走过的路

之前公司同事写过rsync加触发nginx reload脚本,适合nginx配置内容完全一致的情况。

今天写一个同步指定文件的脚本,修改完主服务器。使用scp传输到其他nginx服务器上重启NGINX的脚本。适用于nginx集群部分配置相同的情况下。

一、ssh免密步骤

ssh-kengen命令生成私钥,复制~/.ssh/id_rsa.pub添加到目标机器~/.ssh/authorized_keys文件内。注意~/.ssh/authorized_keys文件权限600,~/.ssh/文件权限700

二、脚本内容

#!/bin/bash
file=$1

if [ -z "$file" ];then
    echo "请使用$0 文件名方式,例如: $? el.conf"
    exit 1
fi


function trans(){
    server=("10.0.2.5" "10.0.2.6" "10.0.2.7")
    cd /etc/nginx/
    for s in ${server[@]}
    do
        if [ $file == "nginx.conf" ];then
            scp $file root@${s}:/etc/nginx/
        else
            scp conf.d/$file root@${s}:/etc/nginx/conf.d/
        fi
        ssh root@${s} "nginx -t && nginx -s reload"
    done
}

nginx -t && nginx -s reload && trans