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

推荐订阅源

P
Proofpoint News Feed
V2EX - 技术
V2EX - 技术
F
Full Disclosure
P
Privacy & Cybersecurity Law Blog
The GitHub Blog
The GitHub Blog
P
Palo Alto Networks Blog
T
Threat Research - Cisco Blogs
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Latest news
Latest news
Y
Y Combinator Blog
P
Proofpoint News Feed
Cyberwarzone
Cyberwarzone
A
Arctic Wolf
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
T
Tor Project blog
B
Blog RSS Feed
S
Schneier on Security
H
Hackread – Cybersecurity News, Data Breaches, AI and More
N
Netflix TechBlog - Medium
小众软件
小众软件
博客园 - Franky
T
The Exploit Database - CXSecurity.com
V
V2EX
V
Vulnerabilities – Threatpost
Know Your Adversary
Know Your Adversary
C
Check Point Blog
L
LINUX DO - 热门话题
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
L
Lohrmann on Cybersecurity
人人都是产品经理
人人都是产品经理
S
Securelist
U
Unit 42
博客园 - 叶小钗
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
博客园 - 三生石上(FineUI控件)
C
Cyber Attacks, Cyber Crime and Cyber Security
G
GRAHAM CLULEY
T
Tailwind CSS Blog
Stack Overflow Blog
Stack Overflow Blog
G
Google Developers Blog
量子位
Hacker News - Newest:
Hacker News - Newest: "LLM"
NISL@THU
NISL@THU
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
T
Threatpost
N
News | PayPal Newsroom
L
LangChain Blog
宝玉的分享
宝玉的分享
C
CXSECURITY Database RSS Feed - CXSecurity.com
爱范儿
爱范儿

博客园 - 一起走过的路

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