Nginx
1 前言
一个问题,一篇文章,一出故事。
笔者公司内部有基于Anycase部署的Nginx负载均衡器。多个Nginx之间的节点虽然是相互独立的,但是配置文件在多个节点间分发也需要一个工具简化。于是笔者就自己写了一个。
2 最佳实践
2.1 环境配置
2.2 部署脚本工具
2.2.1 安装脚本工具
wget -O /usr/bin/nginxtool https://github.com/tanzhenchao/nginxtool/blob/main/nginxtool chmod +x /usr/bin/nginxtool
2.2.2 安装脚本配置
mkdir /etc/nginxtool/ wget -O /etc/nginxtool/nginxtool.conf https://github.com/tanzhenchao/nginxtool/blob/main/nginxtool.conf
另外,如果是docker环境,请换成以下脚本,
mkdir /etc/nginxtool/ wget -O /etc/nginxtool/nginxtool.conf https://github.com/tanzhenchao/nginxtool/blob/main/nginxtool-for-docker
2.2.3 修改脚本配置
vim /etc/nginxtool/nginxtool.conf
按实际环境修改如下配置,
## variable definition # Define hostnames of all nodes in the cluster # Please configure name resolution in advance clusterNode="rproxy01 rproxy02 rproxy03" # Define the hostname to be configured synchronously # Please configure name resolution in advance synNode="rproxy02 rproxy03" # Define the path or directory of the synchronized configuration file synConf="/etc/nginx/nginx.conf /etc/nginx/conf.d/ /etc/nginx/public/ /etc/nginx/stream.d/ /etc/nginx/*.crt /etc/nginx/*.key"
2.3 使用脚本工具
2.3.1 获取使用帮助
nginxtool
可见如下显示,
Usage: /usr/bin/nginxtool {check|status|start|stop|reload|restart|sync}
2.3.2 使用范例
nginxtool sync nginxtool check nginxtool status nginxtool reload nginxtool stop nginxtool start nginxtool restart
没有评论