Giter Site home page Giter Site logo

nifi's Introduction

Reference

NiFi secure+autoscaling cluster built automatically in AWS via Terraform+Ansible.

Options

Two designs are provided, either:

  • NiFi on EC2 with Zookeeper running within the same EC2 instances, or
  • NiFi on EC2 with Zookeeper running separately in ECS Fargate.
  • Side note - for considerations about using RHEL as opposed to Ubuntu as the base EC2 OS, see rhel.md.

Requirements

  • An AWS account
  • Follow Step-by-Step (compatible with Windows and Ubuntu)

Media

  • Video Guide - a bit outdated, but still useful. Follow along with me as I deploy using the step-by-step guide below.
  • Discord - for questions, ideas, comments, or troubleshooting assistance.

Step-by-Step Terraform Deployment

Windows Users install WSL (Windows Subsystem Linux)

#############################
## Windows Subsystem Linux ##
#############################
# Launch an ELEVATED Powershell prompt (right click -> Run as Administrator)

# Enable Windows Subsystem Linux
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart

# Reboot your Windows PC
shutdown /r /t 5

# After reboot, launch a REGULAR Powershell prompt (left click).
# Do NOT proceed with an ELEVATED Powershell prompt.

# Download the Ubuntu 2004 package from Microsoft
curl.exe -L -o ubuntu-2004.appx https://aka.ms/wsl-ubuntu-2004
 
# Rename the package
Rename-Item ubuntu-2004.appx ubuntu-2004.zip
 
# Expand the zip
Expand-Archive ubuntu-2004.zip ubuntu-2004
 
# Change to the zip directory
cd ubuntu-2004
 
# Execute the ubuntu 2004 installer
.\ubuntu2004.exe
 
# Create a username and password when prompted

Install Terraform, Git, and create an SSH key pair

#############################
##  Terraform + Git + SSH  ##
#############################
# Add terraform's apt key (enter previously created password at prompt)
curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add -
 
# Add terraform's apt repository
sudo apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main"
 
# Install terraform and git
sudo apt-get update && sudo apt-get -y install terraform git
 
# Clone the project
git clone https://github.com/chadgeary/nifi

# Create SSH key pair (RETURN for defaults)
ssh-keygen

Install the AWS cli and create non-root AWS user. An AWS account is required to continue.

#############################
##          AWS            ##
#############################
# Open powershell and start WSL
wsl

# Change to home directory
cd ~

# Install python3 pip
sudo apt update && sudo DEBIAN_FRONTEND=noninteractive apt-get -q -y install python3-pip

# Install awscli via pip
pip3 install --user --upgrade awscli

# Create a non-root AWS user in the AWS web console with admin permissions
# This user must be the same user running terraform apply
# Create the user at the AWS Web Console under IAM -> Users -> Add user -> Check programmatic access and AWS Management console -> Attach existing policies -> AdministratorAccess -> copy Access key ID and Secret Access key
# See for more information: https://docs.aws.amazon.com/IAM/latest/UserGuide/getting-started_create-admin-group.html#getting-started_create-admin-group-console

# Set admin user credentials
~/.local/bin/aws configure

# Validate configuration
~/.local/bin/aws sts get-caller-identity 

# For troubleshooting EC2 instances, use the SSM Session Manager plugin
curl "https://s3.amazonaws.com/session-manager-downloads/plugin/latest/ubuntu_64bit/session-manager-plugin.deb" -o ~/session-manager-plugin.deb
sudo dpkg -i ~/session-manager-plugin.deb

# and set the SSH helper configuration for SSM Session Manager
tee -a ~/.ssh/config << EOM
host i-* mi-*
    ProxyCommand sh -c "aws ssm start-session --target %h --document-name AWS-StartSSHSession --parameters 'portNumber=%p'"
EOM

Customize the deployment - See variables section below

# Change to the project's aws directory in powershell
cd ~/nifi/zks-on-ec2/

# Open File Explorer in a separate window
# Navigate to ubuntu project directory - change \chad\ to your WSL username
%HOMEPATH%\ubuntu-2004\rootfs\home\chad\nifi\ubuntu

# Edit the nifi.tfvars file using notepad and save

Deploy

# In powershell's WSL window, change to the project's aws directory
cd ~/nifi/zks-on-ec2/

# Initialize terraform and apply the terraform state
terraform init
terraform apply -var-file="nifi.tfvars"

# If permissions errors appear, fix with the below command and re-run the terraform apply.
sudo chown $USER nifi.tfvars && chmod 600 nifi.tfvars

# Note the outputs from terraform after the apply completes

# Wait for the virtual machine to become ready (Ansible will setup the services for us). NiFi can take 15+ minutes to initialize.

Variables

# See nifi.tfvars

Post-Deployment

Review terraform output for quick links to State Manager (ansible) status, Load Balancer health, Cloudwatch logs, and the admin certificate in S3 which must be added to a browser for web access.

Maintenance

If modifying nifi.properties:

  1. Change the nifi.properties file in playbooks/zookeepers/ and playbooks/nodes/
  2. Re-run terraform apply -var-file="nifi.tfvars"
  3. Re-apply the SSM associations mentioned in terraform output

If re-sizing instances or otherwise modifying autoscaling group(s):

  1. Change the instance type in nifi.tfvars
  2. Re-run terraform apply -var-file="nifi.tfvars"
  3. Scale the node autoscaling group down, either all at once (min 0 / max 0) or incrementally to replace instances of the old size/AMI.
  4. Scale the zookeeper autoscaling groups down, always leave at least one zookeeper running, preferably two - e.g.:
  • If zk1, zk2, and zk3 are running, scale down zk3. Once complete, scale zk3 back up.
  • Repeat for zk2, then zk3.

nifi's People

Contributors

chadgeary avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nifi's Issues

SSH using NLB Service ports

Hi I think it was mentioned that we could use ssh on the NLB service port, something like;

ssh nifitarraform@nifi1-node-nlb-292f5-4b51c4e675374c48.elb.eu-west-2.amazonaws.com

I have added port 22 into the tcp_services_ports. Is this correct?

How can I SSH to ELB Hostname?

Hi. Thanks for letting this project into the public. In your readme, it says "ssh to ELB hostname" in order to find the keystore.pks12 file. How is that done?

I have run the project and the AWS resources have been created.

Ubuntu and Rhel7 need maintenance

Hi,
@chadgeary Getting state manger status as failed and when I check ssm logs, getting this error:

Mar 19 19:20:51 tf-nifi-zookeeper-2 sudo[11481]: pam_unix(sudo:session): session opened for user nifi by (uid=0)
Mar 19 19:20:51 tf-nifi-zookeeper-2 python3[11483]: ansible-aws_s3 Invoked with mode=get bucket=nifi-bucket-123 object=/nifi/downloads/zookeeper.tar.gz dest=/opt/
Mar 19 19:20:51 tf-nifi-zookeeper-2 python3[11483]: ansible-aws_s3 [WARNING] Module remote_tmp /home/nifi/.ansible/tmp did not exist and was created with a mode o
Mar 19 19:20:51 tf-nifi-zookeeper-2 sudo[11481]: pam_unix(sudo:session): session closed for user nifi 

Received the following errors when running terraform apply

dave@nifiubuntu:~/nifi/zks-on-ec2$ terraform apply "nifi.tfplan"
random_string.tf-nifi-random: Creating...
random_string.tf-nifi-random: Creation complete after 0s [id=3bcb9]
aws_iam_role.tf-nifi-instance-iam-role: Creating...
aws_iam_role.tf-nifi-autoscale-snsrole: Creating...
aws_iam_role.tf-nifi-iam-role-lambda-scaledown: Creating...
aws_ssm_document.tf-nifi-ssmdoc-scaledown: Creating...
aws_ssm_document.tf-nifi-ssm-playbook-doc: Creating...
aws_vpc_dhcp_options.tf-nifi-dhcp-opts: Creating...
aws_iam_role.tf-nifi-iam-role-lambda-health: Creating...
aws_cloudwatch_event_rule.tf-nifi-cloudwatch-event-rule-health: Creating...
aws_iam_role.tf-nifi-iam-role-lambda-certs: Creating...
aws_iam_role.tf-nifi-iam-role-lambda-getnifi: Creating...
aws_cloudwatch_event_rule.tf-nifi-cloudwatch-event-rule-health: Creation complete after 0s [id=nifi-event-rule-health-3bcb9]
aws_iam_service_linked_role.tf-nifi-autoscale-slr: Creating...
aws_vpc_dhcp_options.tf-nifi-dhcp-opts: Creation complete after 0s [id=dopt-0d3949796f4749c68]
aws_iam_service_linked_role.tf-nifi-autoscale-slr: Creation complete after 0s [id=arn:aws:iam::826708293712:role/aws-service-role/autoscaling.amazonaws.com/AWSServiceRoleForAutoScaling_nifi3bcb9]
aws_s3_bucket.tf-nifi-bucket: Creating...
aws_ssm_document.tf-nifi-ssmdoc-scaledown: Creation complete after 0s [id=nifi-ssmdoc-scaledown-3bcb9]
aws_ssm_document.tf-nifi-ssm-playbook-doc: Creation complete after 0s [id=nifi-ssm-playbook-doc-3bcb9]
aws_iam_role.tf-nifi-iam-role-lambda-certs: Creation complete after 1s [id=nifi-iam-role-lambda-certs-3bcb9]
aws_iam_role.tf-nifi-iam-role-lambda-scaledown: Creation complete after 1s [id=nifi-iam-role-lambda-scaledown-3bcb9]
aws_iam_role.tf-nifi-autoscale-snsrole: Creation complete after 1s [id=nifi-autoscale-sns-role-3bcb9]
aws_iam_role.tf-nifi-instance-iam-role: Creation complete after 1s [id=nifi-instance-role-3bcb9]
aws_iam_role.tf-nifi-iam-role-lambda-health: Creation complete after 1s [id=nifi-iam-role-lambda-health-3bcb9]
aws_iam_role.tf-nifi-iam-role-lambda-getnifi: Creation complete after 1s [id=nifi-iam-role-lambda-getnifi-3bcb9]
data.aws_iam_policy_document.tf-nifi-bucket: Reading...
data.aws_iam_policy_document.tf-nifi-bucket: Read complete after 0s [id=676879418]
aws_iam_instance_profile.tf-nifi-instance-profile: Creating...
aws_iam_role_policy_attachment.tf-nifi-iam-attach-lambda-certs-1: Creating...
aws_iam_role_policy_attachment.tf-nifi-iam-attach-lambda-certs-2: Creating...
aws_iam_role_policy_attachment.tf-nifi-iam-attach-lambda-1: Creating...
aws_iam_role_policy_attachment.tf-nifi-iam-attach-lambda-2: Creating...
aws_iam_role_policy_attachment.tf-nifi-iam-attach-ssm: Creating...
aws_iam_role_policy_attachment.tf-nifi-iam-attach-health-lambda-1: Creating...
aws_iam_role_policy_attachment.tf-nifi-iam-attach-health-lambda-2: Creating...
aws_iam_role_policy_attachment.tf-nifi-iam-attach-lambda-getnifi-2: Creating...
aws_iam_role_policy_attachment.tf-nifi-iam-attach-lambda-certs-1: Creation complete after 0s [id=nifi-iam-role-lambda-certs-3bcb9-20221230151318341500000002]
aws_iam_role_policy_attachment.tf-nifi-iam-attach-ssm: Creation complete after 0s [id=nifi-instance-role-3bcb9-20221230151318340800000001]
aws_iam_role_policy_attachment.tf-nifi-iam-attach-lambda-certs-2: Creation complete after 1s [id=nifi-iam-role-lambda-certs-3bcb9-20221230151318342900000003]
aws_iam_role_policy_attachment.tf-nifi-iam-attach-health-lambda-1: Creation complete after 1s [id=nifi-iam-role-lambda-health-3bcb9-20221230151318415500000005]
aws_iam_role_policy_attachment.tf-nifi-iam-attach-lambda-getnifi-1: Creating...
aws_iam_role_policy_attachment.tf-nifi-iam-attach-lambda-2: Creation complete after 1s [id=nifi-iam-role-lambda-scaledown-3bcb9-20221230151318421900000006]
aws_iam_role_policy_attachment.tf-nifi-iam-attach-health-lambda-2: Creation complete after 1s [id=nifi-iam-role-lambda-health-3bcb9-20221230151318464700000008]
aws_iam_instance_profile.tf-nifi-instance-profile: Creation complete after 1s [id=nifi-instance-profile-3bcb9]
aws_iam_role_policy_attachment.tf-nifi-iam-attach-lambda-getnifi-2: Creation complete after 1s [id=nifi-iam-role-lambda-getnifi-3bcb9-20221230151318443000000007]
aws_iam_role_policy_attachment.tf-nifi-iam-attach-lambda-1: Creation complete after 1s [id=nifi-iam-role-lambda-scaledown-3bcb9-20221230151318390100000004]
aws_s3_bucket.tf-nifi-bucket: Creation complete after 2s [id=nifi-bucket-3bcb9]
aws_iam_role_policy_attachment.tf-nifi-iam-attach-lambda-getnifi-1: Creation complete after 0s [id=nifi-iam-role-lambda-getnifi-3bcb9-20221230151318766100000009]
aws_s3_bucket_public_access_block.tf-nifi-bucket: Creating...
aws_s3_bucket_versioning.tf-nifi-bucket: Creating...
aws_s3_bucket_acl.tf-nifi-bucket: Creating...
aws_s3_bucket_policy.tf-nifi-bucket: Creating...
aws_s3_bucket_acl.tf-nifi-bucket: Creation complete after 0s [id=nifi-bucket-3bcb9,private]
aws_s3_bucket_public_access_block.tf-nifi-bucket: Creation complete after 1s [id=nifi-bucket-3bcb9]
aws_s3_bucket_versioning.tf-nifi-bucket: Creation complete after 2s [id=nifi-bucket-3bcb9]
aws_s3_bucket_policy.tf-nifi-bucket: Creation complete after 8s [id=nifi-bucket-3bcb9]

│ Error: Provider produced inconsistent final plan

│ When expanding the plan for aws_kms_key.tf-nifi-kmscmk-lambda to include new values learned so far during apply,
│ provider "registry.terraform.io/hashicorp/aws" produced an invalid new value for .tags_all: new element "Name"
│ has appeared.

│ This is a bug in the provider, which should be reported in the provider's own issue tracker.


│ Error: Provider produced inconsistent final plan

│ When expanding the plan for aws_kms_key.tf-nifi-kmscmk-s3 to include new values learned so far during apply,
│ provider "registry.terraform.io/hashicorp/aws" produced an invalid new value for .tags_all: new element "Name"
│ has appeared.

│ This is a bug in the provider, which should be reported in the provider's own issue tracker.


│ Error: Provider produced inconsistent final plan

│ When expanding the plan for aws_eip.tf-nifi-ng-eip2 to include new values learned so far during apply, provider
│ "registry.terraform.io/hashicorp/aws" produced an invalid new value for .tags_all: new element "Name" has
│ appeared.

│ This is a bug in the provider, which should be reported in the provider's own issue tracker.


│ Error: Provider produced inconsistent final plan

│ When expanding the plan for aws_kms_key.tf-nifi-kmscmk-sns to include new values learned so far during apply,
│ provider "registry.terraform.io/hashicorp/aws" produced an invalid new value for .tags_all: new element "Name"
│ has appeared.

│ This is a bug in the provider, which should be reported in the provider's own issue tracker.


│ Error: Provider produced inconsistent final plan

│ When expanding the plan for aws_eip.tf-nifi-ng-eip1 to include new values learned so far during apply, provider
│ "registry.terraform.io/hashicorp/aws" produced an invalid new value for .tags_all: new element "Name" has
│ appeared.

│ This is a bug in the provider, which should be reported in the provider's own issue tracker.


│ Error: Provider produced inconsistent final plan

│ When expanding the plan for aws_kms_key.tf-nifi-kmscmk-ec2 to include new values learned so far during apply,
│ provider "registry.terraform.io/hashicorp/aws" produced an invalid new value for .tags_all: new element "Name"
│ has appeared.

│ This is a bug in the provider, which should be reported in the provider's own issue tracker.


│ Error: Provider produced inconsistent final plan

│ When expanding the plan for aws_kms_key.tf-nifi-kmscmk-cloudwatch to include new values learned so far during
│ apply, provider "registry.terraform.io/hashicorp/aws" produced an invalid new value for .tags_all: new element
│ "Name" has appeared.

│ This is a bug in the provider, which should be reported in the provider's own issue tracker.


│ Error: Provider produced inconsistent final plan

│ When expanding the plan for aws_key_pair.tf-nifi-instance-key to include new values learned so far during apply,
│ provider "registry.terraform.io/hashicorp/aws" produced an invalid new value for .tags_all: new element "Name"
│ has appeared.

│ This is a bug in the provider, which should be reported in the provider's own issue tracker.


│ Error: Provider produced inconsistent final plan

│ When expanding the plan for aws_kms_key.tf-nifi-kmscmk-ssm to include new values learned so far during apply,
│ provider "registry.terraform.io/hashicorp/aws" produced an invalid new value for .tags_all: new element "Name"
│ has appeared.

│ This is a bug in the provider, which should be reported in the provider's own issue tracker.


│ Error: Provider produced inconsistent final plan

│ When expanding the plan for aws_eip.tf-nifi-ng-eip3 to include new values learned so far during apply, provider
│ "registry.terraform.io/hashicorp/aws" produced an invalid new value for .tags_all: new element "Name" has
│ appeared.

│ This is a bug in the provider, which should be reported in the provider's own issue tracker.


│ Error: Provider produced inconsistent final plan

│ When expanding the plan for aws_vpc.tf-nifi-vpc to include new values learned so far during apply, provider
│ "registry.terraform.io/hashicorp/aws" produced an invalid new value for .tags_all: new element "Name" has
│ appeared.

│ This is a bug in the provider, which should be reported in the provider's own issue tracker.

getting error when trying to download Admin certificate

Hi, I tried to deploy the cluster and it worked. However, when i try to download the Admin certificate, I get the following error:

AccessDenied The ciphertext refers to a customer master key that does not exist, does not exist in this region, or you are not allowed to access. ZRZ47BQH6ENT1WB6 XhatbJKMqo9F31Zzt2M/B6pyESgrBx86BPH9nGAUZH/G7O8cmJMl2olhhzhERkm/SX7MXJD48R0=

Unable to Access the NLB UI After Successful Execution of Terraform

Terraform apply was successful.

Apply complete! Resources: 176 added, 0 changed, 0 destroyed.

And, I obtained the following outputs:

Outputs:

tf-nifi-output = <<EOT

NiFi can take 15+ minutes to initialize a cluster, please be patient.

State Manager Association will show Status: Complete, then

NLB Target Group will show Status: healthy

State Manager Association (Zookeepers)

https://console.aws.amazon.com/systems-manager/state-manager/59329fa9-8792-451c-bf16-f6a2d5457d89/executionhistory

NLB Target Group (Zookeepers)

https://console.aws.amazon.com/ec2/v2/home?region=us-east-1#TargetGroup:targetGroupArn=arn:aws:elasticloadbalancing:us-east-1:826708293712:targetgroup/nifi-mgmt-2170-1gj84/5ef82290f0e45160

Cloudwatch Logs

https://console.aws.amazon.com/cloudwatch/home?region=us-east-1#logsV2:log-groups/log-group/$252Faws$252Fec2$252Fnifi_1gj84

Admin Certificate

https://s3.console.aws.amazon.com/s3/object/nifi-bucket-1gj84?region=us-east-1&prefix=nifi/certificates/admin/keystore.p12

NLB WebUI

https://nifi-node-nlb-1gj84-88562be6c981c467.elb.us-east-1.amazonaws.com:2170/nifi

NLB Service Ports

nifi-node-nlb-1gj84-88562be6c981c467.elb.us-east-1.amazonaws.com

Instance IDs in Cluster

AWS_PROFILE=default aws ec2 describe-instances --region us-east-1 --query 'Reservations[].Instances[*].[InstanceId, LaunchTime, [Tags[?Key==Name].Value][0][0]]' --filters Name=tag:Cluster,Values=nifi_1gj84 Name=instance-state-name,Values=pending,running --output text

Connecting via SSM, append an instance-id from above command

AWS_PROFILE=default aws ssm start-session --region us-east-1 --target

Re-run Ansible (SSM Associations)

Zookeepers

AWS_PROFILE=default aws ssm start-associations-once --region us-east-1 --association-ids 59329fa9-8792-451c-bf16-f6a2d5457d89

Nodes

AWS_PROFILE=default aws ssm start-associations-once --region us-east-1 --association-ids 28ffb38f-571e-4ecc-86cc-f914ea0d134c

I was able to successfully import the cert into my firefox and chrome.

I then tried to hit
https://nifi-node-nlb-1gj84-88562be6c981c467.elb.us-east-1.amazonaws.com:2170/nifi

It error'd out after a couple of minutes.

I then looked at Route 53, saw that Terrafolrm created a domain named "nifi1gj84.internal.

I ran the following command on the ubuntu client: host -t NS nifi1gj84.internal
Host nifi1gj84.internal not found: 3(NXDOMAIN) so clearly the host, nifi1gj84.internal can't be found.

Any guidance/suggestion re: why the host nifigj84.internal can't be found?

Ran

i installed Terraform version 1.3.6 (a version in use in July 22) and received the same error.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.