Skip to content

Commit 37c6c34

Browse files
committed
Release 0.1-1
0 parents  commit 37c6c34

File tree

165 files changed

+100201
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

165 files changed

+100201
-0
lines changed

Diff for: .gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/build
2+

Diff for: LICENSE

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright (C) 2017 Nginx, Inc.
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions
7+
* are met:
8+
* 1. Redistributions of source code must retain the above copyright
9+
* notice, this list of conditions and the following disclaimer.
10+
* 2. Redistributions in binary form must reproduce the above copyright
11+
* notice, this list of conditions and the following disclaimer in the
12+
* documentation and/or other materials provided with the distribution.
13+
*
14+
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17+
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20+
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22+
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23+
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24+
* SUCH DAMAGE.
25+
*/

Diff for: Makefile

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
GO_DOCKER_RUN = docker run --rm -v $(shell pwd)/cmd/sync:/go/src/github.com/nginxinc/nginx-asg-sync/cmd/sync -v $(shell pwd)/build:/build -w /go/src/github.com/nginxinc/nginx-asg-sync/cmd/sync
2+
GOLANG_CONTAINER = golang:1.8
3+
4+
all: amazon centos7 ubuntu-trusty ubuntu-xenial
5+
6+
test:
7+
$(GO_DOCKER_RUN) $(GOLANG_CONTAINER) go test
8+
9+
compile: test
10+
$(GO_DOCKER_RUN) $(GOLANG_CONTAINER) go build -o /build/nginx-asg-sync
11+
12+
amazon: compile
13+
make -C os-packages/builders/amazon/
14+
docker run --rm -v $(shell pwd)/os-packages/rpm:/rpm -v $(shell pwd)/build:/build amazon-builder
15+
16+
centos7: compile
17+
make -C os-packages/builders/centos7/
18+
docker run --rm -v $(shell pwd)/os-packages/rpm:/rpm -v $(shell pwd)/build:/build centos7-builder
19+
20+
ubuntu-xenial: compile
21+
make -C os-packages/builders/ubuntu-xenial/
22+
docker run --rm -v $(shell pwd)/os-packages/debian:/debian -v $(shell pwd)/build:/build ubuntu-xenial-builder
23+
24+
ubuntu-trusty: compile
25+
make -C os-packages/builders/ubuntu-trusty/
26+
docker run --rm -v $(shell pwd)/os-packages/debian:/debian -v $(shell pwd)/build:/build ubuntu-trusty-builder
27+
28+
clean:
29+
-rm -r build
30+
31+
.PHONY: test

Diff for: README.md

+173
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
# NGINX Plus Integration with AWS Auto Scaling groups -- nginx-asg-sync
2+
3+
**nginx-asg-sync** allows [NGINX Plus](https://www.nginx.com/products/) to support scaling when load balancing [AWS Auto Scaling groups](http://docs.aws.amazon.com/autoscaling/latest/userguide/WhatIsAutoScaling.html): when the number of instances in an Auto Scaling group changes, nginx-asg-sync adds the new instances to the NGINX Plus configuration and removes the terminated ones.
4+
5+
More details on this solution are available in the blog post [Load Balancing AWS Auto Scaling Groups with NGINX Plus](https://www.nginx.com/blog/load-balancing-aws-auto-scaling-groups-nginx-plus/).
6+
7+
Below you will find instructions on how to use nginx-asg-sync.
8+
9+
## Contents
10+
11+
1. [Supported Operating Systems](#supported-operating-systems)
12+
1. [Setting up Access to the AWS API](#setting-up-access-to-the-aws-api)
13+
1. [Installation](#installation)
14+
1. [Configuration](#configuration)
15+
1. [Usage](#usage)
16+
1. [Troubleshooting](#troubleshooting)
17+
1. [Building a Software Package](#building-a-software-package)
18+
1. [Support](#support)
19+
20+
## Supported Operating Systems
21+
22+
We provide packages for the following operating systems:
23+
24+
* Ubuntu: 14.04 (Trusty), 16.04 (Xenial)
25+
* CentOS/RHEL: 7
26+
* Amazon Linux
27+
28+
Support for other operating systems can be added.
29+
30+
## Setting up Access to the AWS API
31+
32+
nginx-asg-sync uses the AWS API to get the list of IP addresses of the instances of an Auto Scaling group. To access the AWS API, nginx-asg-sync must have credentials. To provide credentials to nginx-asg-sync:
33+
34+
1. [Create an IAM role](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html) and attach the predefined `AmazonEC2ReadOnlyAccess` policy to it. This policy allows read-only access to EC2 APIs.
35+
1. When you launch the NGINX Plus instance, add this IAM role to the instance.
36+
37+
Alternatively, you can use the `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` environmental variables to provide credentials to nginx-asg-sync.
38+
39+
## Installation
40+
41+
To install nginx-asg-sync:
42+
43+
1. Download a software package for your OS with the latest version of nginx-asg-sync from the [Releases page](https://github.com/nginxinc/nginx-asg-sync/releases).
44+
1. Install the package:
45+
46+
For Amazon Linux or CentOS/RHEL, run: `$ sudo rpm -i <package-name>.rpm`
47+
48+
For Ubuntu, run: `$ sudo dpkg -i <package-name>.deb`
49+
50+
## Configuration
51+
52+
As an example, we configure NGINX Plus to load balance two AWS Auto Scaling groups -- backend-group-one and backend-group-two. NGINX Plus routes requests to the appropriate Auto Scaling group based on the request URI:
53+
54+
* Requests for /backend-one go to Backend One group.
55+
* Requests for /backend-two go to Backend Two group.
56+
57+
### NGINX Plus Configuration
58+
59+
```nginx
60+
upstream backend-one {
61+
zone backend-one 64k;
62+
state /var/lib/nginx/state/backend-one.conf;
63+
}
64+
65+
upstream backend-two {
66+
zone backend-two 64k;
67+
state /var/lib/nginx/state/backend-two.conf;
68+
}
69+
70+
server {
71+
listen 80;
72+
73+
status_zone backend;
74+
75+
location /backend-one {
76+
proxy_set_header Host $host;
77+
proxy_pass http://backend-one;
78+
}
79+
80+
location /backend-two {
81+
proxy_set_header Host $host;
82+
proxy_pass http://backend-two;
83+
}
84+
}
85+
86+
server {
87+
listen 8080;
88+
89+
root /usr/share/nginx/html;
90+
91+
location = / {
92+
return 302 /status.html;
93+
}
94+
95+
location = /status.html {
96+
}
97+
98+
location /status {
99+
access_log off;
100+
status;
101+
}
102+
103+
location /upstream_conf {
104+
upstream_conf;
105+
}
106+
}
107+
```
108+
109+
* We declare two upstream groups – **backend-one** and **backend-two**, which correspond to our Auto Scaling groups. However, we do not add any servers to the upstream groups, because the servers will be added by nginx-aws-sync. The `state` directive names the file where the dynamically configurable list of servers is stored, enabling it to persist across restarts of NGINX Plus.
110+
* We define a virtual server that listens on port 80. NGINX Plus passes requests for **/backend-one** to the instances of the Backend One group, and requests for **/backend-two** to the instances of the Backend Two group.
111+
* We define a second virtual server listening on port 8080 and configure the NGINX Plus APIs on it, which are required by nginx-asg-sync:
112+
* The on-the-fly API is available at **127.0.0.1:8080/upstream_conf**
113+
* The status API is available at **127.0.0.1:8080/status**
114+
115+
### nginx-asg-sync Configuration
116+
117+
nginx-asg-sync is configured in the file **aws.yaml** in the **/etc/nginx** folder. For our example, we define the following configuration:
118+
119+
```yaml
120+
region: us-west-2
121+
upstream_conf_endpoint: http://127.0.0.1:8080/upstream_conf
122+
status_endpoint: http://127.0.0.1:8080/status
123+
sync_interval_in_seconds: 5
124+
upstreams:
125+
- name: backend-one
126+
autoscaling_group: backend-one-group
127+
port: 80
128+
kind: http
129+
- name: backend-two
130+
autoscaling_group: backend-two-group
131+
port: 80
132+
kind: http
133+
```
134+
135+
* The `region` key defines the AWS region where we deploy NGINX Plus and the Auto Scaling groups.
136+
* The `upstream_conf` and the `status_endpoint` keys define the NGINX Plus API endpoints.
137+
* The `sync_interval_in_seconds` key defines the synchronization interval: nginx-asg-sync checks for scaling updates every 5 seconds.
138+
* The `upstreams` key defines the list of upstream groups. For each upstream group we specify:
139+
* `name` – The name we specified for the upstream block in the NGINX Plus configuration.
140+
* `autoscaling_group` – The name of the corresponding Auto Scaling group.
141+
* `port` – The port on which our backend applications are exposed.
142+
* `protocol` – The protocol of the traffic NGINX Plus load balances to the backend application, here `http`. If the application uses TCP/UDP, specify `stream` instead.
143+
144+
## Usage
145+
146+
nginx-asg-sync runs as a system service and supports the start/stop/restart commands.
147+
148+
For Ubuntu 14.04 and Amazon Linux, run: `$ sudo start|stop|restart nginx-asg-sync`
149+
150+
For Ubuntu 16.04 and CentOS7/RHEL7, run: `$ sudo service nginx-asg-sync start|stop|restart`
151+
152+
## Troubleshooting
153+
154+
If nginx-asg-sync doesn’t work as expected, check its log file available at **/var/log/nginx-aws-sync/nginx-aws-sync.log**.
155+
156+
## Building a Software Package
157+
158+
You can compile nginx-asg-sync and build a software package using the provided Makefile. Before you start building a package, make sure that the following software is installed on your system:
159+
* make
160+
* Docker
161+
162+
To build a software package, run: `$ make <os>`
163+
where `<os>` is the target OS. The following values are allowed:
164+
* `amazon` for Amazon Linux
165+
* `centos7` for CentOS7/RHEL7
166+
* `ubuntu-trusty` for Ubuntu 14.04
167+
* `ubuntu-xenial` for Ubuntu 16.04
168+
169+
If you run make without any arguments, it will build software packages for all supported OSes.
170+
171+
## Support
172+
173+
Support from the [NGINX Professional Services Team](https://www.nginx.com/services/) is available when using nginx-asg-sync.

Diff for: cmd/sync/Godeps/Godeps.json

+161
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)